goharbor / goharbor/harbor-cli

[bug]: quota update prefills a storage limit its own form rejects

Open Beginner friendly
#1,096 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
163
Forks
211
Avg merge
1m
Merged PRs (30d)
1

Description

## Description

`harbor quota update` prefills the interactive form with the quota's current storage limit. The prefilled value is always a decimal string, but the "Quota Limit" input validates with `strconv.ParseInt`, so the default it hands the user is never accepted.

`pkg/views/quota/update/view.go` builds the default from `BytesToStorageString`, which formats the limit as `"%.1f GiB"` or `"%.2f MiB"`:

```go
rawStorage := list.BytesToStorageString(quta.Hard["storage"])
storagearr := strings.Split(rawStorage, " ")
...
value = storagearr[0] // "50.0"
```

and then validates it with:

```go
intval, err := strconv.ParseInt(str, 10, 64)
if err != nil {
return errors.New("Quota limit must be a valid integer")
}
```

`ParseInt("50.0")` fails, so submitting the form without editing the field always errors out. This holds for every possible limit, not just some:

| hard limit (bytes) | BytesToStorageString | prefilled value | accepted by the form |
|---|---|---|---|
| -1 (unlimited) | `-0.00 MiB` | `-0.00` | no |
| 0 | `0.00 MiB` | `0.00` | no |
| 536870912 (512 MiB) | `512.00 MiB` | `512.00` | no |
| 1073741824 (1 GiB) | `1.0 GiB` | `1.0` | no |
| 53687091200 (50 GiB) | `50.0 GiB` | `50.0` | no |

A second problem is visible in the same table: a project with an unlimited quota (`hard["storage"] == -1`) is reported as `current storage: -0.00 MiB`. The quota list view already special-cases `-1` and prints `Unlimited`; the update view does not.

## Steps to Reproduce

1. Pick a project with a storage quota set, e.g. 50 GiB.
2. Run the interactive update path (no `--storage` flag):

```bash
harbor quota update --project-name
```

3. Leave the prefilled "Quota Limit" value as-is and press Enter.

## Expected Behavior

The prefilled limit is a value the form accepts, so confirming an unchanged form is a no-op rather than an error. An unlimited quota is reported as `Unlimited`.

## Actual Behavior

The form rejects its own default with `Quota limit must be a valid integer`. The user has to clear the field and retype the number. An unlimited quota is reported as `current storage: -0.00 MiB`.

Image

Image

## Environment

- OS: macOS
- Tool version: Harbor CLI from `main` (d98afec)
- Other relevant details: reproduced against the current `origin/main` implementation

## Additional Context

Related, in the same function:

- `storageUnit := storagearr[1]` indexes the split result without a length check. It is safe today only because `BytesToStorageString` always emits a space, so it is a latent index-out-of-range rather than an active one.
- `fmt.Printf("current storage: %v", rawStorage)` has no trailing newline, so the form renders on the same line as the message.

I'd like to work on this.

Contributor guide

Open the contributing guide

Research direction

Start in pkg/views/quota/update/view.go and trace how BytesToStorageString supplies the interactive form's default and how the Quota Limit validator parses it. Reproduce with harbor quota update --project-name , then confirm an unchanged limit is accepted and an unlimited quota is displayed as Unlimited without the formatting issues described.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.