Skip to content
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

auth: init recognizes --access-token #1395

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

auth: init recognizes --access-token #1395

wants to merge 4 commits into from

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
@@ -146,7 +146,14 @@ To create new contexts, see the help for `+"`"+`doctl auth init`+"`"+`.`, Writer
// XDG_CONFIG_HOME is not set, use $HOME/.config. On Windows use %APPDATA%/doctl/config.
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