-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Config flag error ignored during login #251 #259
feat: Config flag error ignored during login #251 #259
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution.
Also we can store user-defined config path in data file. to persist across sessions.
-
update config default location to
$XDG_CONFIG_HOME/harbor-cli/config.yaml
-
store the data file in
$XDG_DATA_HOME/harbor-cli/data
which is also~/.local/share/harbor-cli/data
. In the data file we can store the user defined config path. -
With this we will be having the robust config option for the harbor-cli.
pkg/views/login/create.go
Outdated
huh.NewInput(). | ||
Title("Config File"). | ||
Value(&loginView.Config). | ||
Description("Path to the config file"). | ||
Validate(func(str string) error { | ||
if strings.TrimSpace(str) == "" { | ||
return errors.New("config file cannot be empty or only spaces") | ||
} | ||
if isValid := utils.ValidateConfigPath(str); !isValid { | ||
return errors.New("The config file path is not valid. It should be a valid path with a .yaml or .yml extension") | ||
} | ||
return nil | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having config as an input to login command. We can have --config
as global flag. with which user can specify the default config location to store the config.
@qcserestipy Please sign your commits |
@bupd Thank you for your feedback! Yes, you were right. The config was set as a global flag already. I removed the option from the login screen. The credential handling is now moved to the runLogin function only. I will start looking into the $XDG_CONFIG_HOME config handling you suggested. |
The changes ensure that the application consistently references the active configuration, manages multiple credential sets efficiently, and maintains a reliable state across different operations. Key Changes
Showcase1The datafile is created and it contains info about the config path which is in the config2.yaml file 2 and 3I log in to the server and choose a new config file called config.yaml. The login proceeds, the file is created and the data file is updated. 4The data file contains information about an old file config3.yaml that does not exist anymore. The cli crashes. The user is informed to create a new blank config3.yaml or change the name to a new config file where the data file gets updated. 5The usual harbor subcommands can read the peristent config file specified in data.yaml, or use a config file that is given on the fly by the --config flag. |
@bupd Is there a good way to test this code in unit tests? |
log.Fatalf("Unable to determine user home directory: %v", err) | ||
} | ||
|
||
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does UserHomeDir() not already respect the XDG_CONFIG_HOME?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the instructions in this specification. According to section 3 the xdg home should default to $HOME/.config in case the XDG environment variables are not set in the shell/env. Therefore I thought it could be helpful to check whether a user has a $HOME, since this might not be fulfilled for e.g. machine users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I will double check whether the result in the expected behavior, and want to include this in some unit testing.
@qcserestipy make sure you comple the DCO part -> https://github.com/goharbor/harbor-cli/pull/259/checks?check_run_id=33351002182 |
…igpath flag check to determine if given Signed-off-by: qcserestipy <[email protected]>
Signed-off-by: qcserestipy <[email protected]>
…ion to runLogin function Signed-off-by: qcserestipy <[email protected]>
…e logic that keeps track of the last active config; Made DataFile and ConfigFile Available through global pointer. Adjusted harbor client to retrieve credentials through config pointer; Added funtionality to login run to update credentials after login Signed-off-by: qcserestipy <[email protected]>
Signed-off-by: qcserestipy <[email protected]>
…G flag Signed-off-by: qcserestipy <[email protected]>
…ionality for Config and Data Pointer Signed-off-by: qcserestipy <[email protected]>
2b0ee51
to
17a1886
Compare
@qcserestipy can you also address the discussion points we can than move forward |
…sts; added config tests; adapted login tests to work with new config management Signed-off-by: Patrick Eschenbach <[email protected]>
…sts; added config tests; adapted login tests to work with new config management Signed-off-by: Patrick Eschenbach <[email protected]>
@Vad1mo Thank you for making me aware of the sign-off issue, I tried to resolve with the link you mentioned. I added some tests for the config and adapted the tests for the login subcommand. Are there other points that I did not cover, yet? |
I removed the WIP tag for now |
…g pipeline about unused err in config_test.go Signed-off-by: Patrick Eschenbach <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
Fixes #251
This pull request is currently work in progress.
Description
This pull request focuses on configuration handling and the login process.
Changes
Open Changes
Even though this PR is still WIP I would be happy to receive your feedback on any code changes.