Skip to content

Conversation

danaelhe
Copy link
Member

Addresses #1394

Before:

go run cmd/doctl/main.go auth init --access-token "$token" --context=anotherone
Please authenticate doctl for use with your DigitalOcean account. You can generate a token in the control panel at https://cloud.digitalocean.com/account/api/tokens

❯ Enter your access token:

After:

go run cmd/doctl/main.go auth init --access-token "$token" --context=anotherone
Using token for context anotherone

Validating token... ✔

@danaelhe danaelhe requested a review from a team July 24, 2023 15:30
func RunAuthInit(retrieveUserTokenFunc func() (string, error)) func(c *CmdConfig) error {
return func(c *CmdConfig) error {
token := c.getContextAccessToken()
token := viper.GetString(doctl.ArgAccessToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this has some unintended consequences. As the top level access-token item in the config file is bound to the flag value, there is no way for us to determine if this is passed on the command line or sourced from the config file for the default context.

So this breaks initializing a new non-default context without passing the flag. If a default context is already configured, it's token just gets used:

$ rm ~/.config/doctl/config.yaml 
$ ./builds/doctl auth init
Please authenticate doctl for use with your DigitalOcean account. You can generate a token in the control panel at https://cloud.digitalocean.com/account/api/tokens

❯ Enter your access token:  ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●

Validating token... ✔

$ ./builds/doctl auth init --context test
Using token for context test

Validating token... ✔

I'm not sure if there is a simple solution here. This may need to wait until we can do deeper changes to how contexts work.

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.

3 participants