-
Notifications
You must be signed in to change notification settings - Fork 18
feat(auth): add --no-keyring flag to address keyring access issues (#643) #653
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "github.com/UpCloudLtd/upcloud-cli/v3/internal/config" | ||
| "github.com/UpCloudLtd/upcloud-cli/v3/internal/output" | ||
| "github.com/spf13/pflag" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| // LoginCommand creates the "account login" command | ||
|
|
@@ -57,14 +58,42 @@ func (s *loginCommand) executeWithToken(exec commands.Executor) (output.Output, | |
| return nil, fmt.Errorf("failed to read token from standard input: %w", err) | ||
| } | ||
|
|
||
| msg := "Saving provided token to the system keyring." | ||
| exec.PushProgressStarted(msg) | ||
| err = config.SaveTokenToKeyring(strings.TrimSpace(token)) | ||
| if err != nil { | ||
| return commands.HandleError(exec, msg, err) | ||
| } | ||
| token = strings.TrimSpace(token) | ||
|
|
||
| exec.PushProgressSuccess(msg) | ||
| // Check if keyring is disabled via global flag or config | ||
| // Note: We check the flag directly because the config isn't loaded for offline commands | ||
| noKeyring, _ := s.Cobra().Root().PersistentFlags().GetBool("no-keyring") | ||
| // Also check if it was set in config via viper (if available) | ||
| if !noKeyring && s.Cobra().Root().PersistentFlags().Changed("config") { | ||
| // Config file was specified, check if no-keyring is set there | ||
| v := viper.New() | ||
| configFile, _ := s.Cobra().Root().PersistentFlags().GetString("config") | ||
| if configFile != "" { | ||
| v.SetConfigFile(configFile) | ||
| v.SetConfigType("yaml") | ||
| _ = v.ReadInConfig() | ||
| noKeyring = v.GetBool("no-keyring") | ||
| } | ||
| } | ||
| if noKeyring { | ||
| // Get config file path from flag if specified | ||
| configFile, _ := s.Cobra().Root().PersistentFlags().GetString("config") | ||
| msg := "Saving token to configuration file (keyring disabled)." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use the token saved with upctl in our other tooling as well (see credentials helper), so this should be saved in more generic location (e.g. UpCloud level config instead of UpCloud CLI level) 🤔
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we open a separate issue for this? Such a separate place should also have a config option to alter it. |
||
| exec.PushProgressStarted(msg) | ||
| err = config.SaveTokenToConfigFile(token, configFile) | ||
| if err != nil { | ||
| return commands.HandleError(exec, msg, err) | ||
| } | ||
| exec.PushProgressSuccess(msg) | ||
| } else { | ||
| msg := "Saving provided token to the system keyring." | ||
| exec.PushProgressStarted(msg) | ||
| err = config.SaveTokenToKeyring(token) | ||
| if err != nil { | ||
| return commands.HandleError(exec, msg, err) | ||
| } | ||
| exec.PushProgressSuccess(msg) | ||
| } | ||
|
|
||
| return output.None{}, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,10 @@ func BuildRootCmd(conf *config.Config) cobra.Command { | |
| &conf.GlobalFlags.Debug, "debug", false, | ||
| "Print out more verbose debug logs.", | ||
| ) | ||
| flags.BoolVar( | ||
| &conf.GlobalFlags.NoKeyring, "no-keyring", false, | ||
| "Disable system keyring integration for credential storage.", | ||
| ) | ||
|
Comment on lines
+105
to
+108
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment from #643 to make it visible for other reviewers:
|
||
| flags.DurationVarP( | ||
| &conf.GlobalFlags.ClientTimeout, "client-timeout", "t", | ||
| 0, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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 checking for
--no-keyringwe could write to a config file if keyring access failed because of a specific error. In that case an warning should be printed.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.
In case keyring is available the token is put in there unless
--no-keyringoption is present. The PR also fixes an example when--configoption was ignored.