Skip to content

fix(config): handle directory paths for --config and HARBOR_CLI_CONFIG#994

Open
Jay2006sawant wants to merge 1 commit into
goharbor:mainfrom
Jay2006sawant:fix/config-directory-path-validation
Open

fix(config): handle directory paths for --config and HARBOR_CLI_CONFIG#994
Jay2006sawant wants to merge 1 commit into
goharbor:mainfrom
Jay2006sawant:fix/config-directory-path-validation

Conversation

@Jay2006sawant

Copy link
Copy Markdown

Description

Briefly describe what this pull request does and why the change is needed.

When --config or HARBOR_CLI_CONFIG pointed to a directory (as documented in the README), Harbor CLI persisted that directory path into data.yaml before validating it was a file. This caused a fatal error on every subsequent run until data.yaml was manually repaired.

This PR resolves directory paths to <dir>/config.yaml and ensures the config file is validated before updating data.yaml.

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • Add normalizeConfigPath to resolve directory paths to config.yaml for --config and HARBOR_CLI_CONFIG
  • Reorder InitConfig to call EnsureConfigFileExists before ApplyDataFile, preventing invalid paths from being persisted
  • Add unit tests for directory-based config paths (Test_Config_EnvVar_Directory, Test_Config_Flag_Directory)

Test plan

  • go test ./pkg/utils/... -run Test_Config
  • harbor -c ~/.config/harbor-cli version — exits 0, data.yaml stores file path
  • HARBOR_CLI_CONFIG=$HOME/.config/harbor-cli harbor version — exits 0
  • Subsequent harbor version runs work without manual data.yaml repair

Fixes goharbor#993

Signed-off-by: Jay2006sawant <jay242902@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Config directory path via --config or HARBOR_CLI_CONFIG corrupts data.yaml and bricks CLI

1 participant