fix(config): handle directory paths for --config and HARBOR_CLI_CONFIG#994
fix(config): handle directory paths for --config and HARBOR_CLI_CONFIG#994Jay2006sawant wants to merge 1 commit into
Conversation
Fixes goharbor#993 Signed-off-by: Jay2006sawant <jay242902@gmail.com>
|
@Vad1mo PTAL! |
qcserestipy
left a comment
There was a problem hiding this comment.
Thank you for catching this! This can be simplified by just checking for file or dir in DetermineConfigPath. Added tests and normalization function can therefore be removed/adapted.
| return "", fmt.Errorf("failed to resolve absolute path for config file: %w", err) | ||
| } | ||
| return harborConfigPath, nil | ||
| return normalizeConfigPath(cfgFile) |
There was a problem hiding this comment.
the cli should return an error instead of automagically appending a config.yaml suffix. it should be enough to check here whether the path is a file or dir. if dir fail
|
@Jay2006sawant Please check out the suggested changes |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #994 +/- ##
=========================================
- Coverage 10.99% 9.18% -1.81%
=========================================
Files 173 321 +148
Lines 8671 16083 +7412
=========================================
+ Hits 953 1478 +525
- Misses 7612 14472 +6860
- Partials 106 133 +27 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Briefly describe what this pull request does and why the change is needed.
When
--configorHARBOR_CLI_CONFIGpointed to a directory (as documented in the README), Harbor CLI persisted that directory path intodata.yamlbefore validating it was a file. This caused a fatal error on every subsequent run untildata.yamlwas manually repaired.This PR resolves directory paths to
<dir>/config.yamland ensures the config file is validated before updatingdata.yaml.Type of Change
Please select the relevant type.
Changes
normalizeConfigPathto resolve directory paths toconfig.yamlfor--configandHARBOR_CLI_CONFIGInitConfigto callEnsureConfigFileExistsbeforeApplyDataFile, preventing invalid paths from being persistedTest_Config_EnvVar_Directory,Test_Config_Flag_Directory)Test plan
go test ./pkg/utils/... -run Test_Configharbor -c ~/.config/harbor-cli version— exits 0,data.yamlstores file pathHARBOR_CLI_CONFIG=$HOME/.config/harbor-cli harbor version— exits 0harbor versionruns work without manualdata.yamlrepair