goharbor / goharbor/harbor-cli

[bug]: config apply -f fails silently to parse configuration files using the configurations wrapper

Open Beginner friendly
#1,023 2 comments 0 reactions 0 assignees View on GitHub
bug status/in-progress
Dominant language
Go
Stars
163
Forks
211
Avg merge
1m
Merged PRs (30d)
1

Description

## Description
The `harbor config apply` command fails silently when applying configuration files that nest configuration parameters under a top-level `configurations:` key (which is the format officially documented in the command synopsis). Instead of applying the configurations, the command unmarshals an empty configurations struct and outputs `✓ No changes detected.` without applying any updates or returning an error.

## Steps to Reproduce
1. Create a configuration file named `config.yaml` with the following nested structure:
```yaml
configurations:
authmode: db_auth
```
2. Run the command:
`harbor config apply -f config.yaml`
3. Observe the output:
`✓ No changes detected.`

## Expected Behavior
The configuration options nested under the `configurations` key should be parsed successfully and applied/updated on the Harbor server.

## Actual Behavior
The CLI silently ignores all fields nested under the `configurations` wrapper because the parser attempts to unmarshal the file directly into a flat `*models.Configurations` struct, which has no matching field for `configurations`.

## Environment
- OS: Windows / Linux / macOS
- Tool version: Latest main (v0.9.0-dev)
- Other relevant details: Go version 1.26.3

## Additional Context
I have verified the root cause in `cmd/harbor/root/configurations/apply.go`. The parser directly unmarshals the YAML/JSON data into `var configurations *models.Configurations` without checking for the top-level wrapper first:

```go
if err := yaml.Unmarshal(data, &configurations); err != nil {
return fmt.Errorf("failed to parse YAML: %v", err)
}
```

This can be resolved by first attempting to parse the nested structure via a wrapper struct, and falling back to the flat format to preserve backward compatibility.

Contributor guide

Open the contributing guide

Research direction

Start in cmd/harbor/root/configurations/apply.go and inspect how the YAML/JSON data is unmarshaled into models.Configurations. Reproduce the issue with harbor config apply -f config.yaml, then verify that the documented configurations wrapper is applied while the flat format remains compatible. Done means the command no longer reports no changes for nested configuration input.

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
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.