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

If ACTIVESTATE_API_KEY is set, try to authenticate with it, or explicitly error out. #3520

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/runners/auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package auth

import (
"os"

"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/keypairs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/output"
Expand Down Expand Up @@ -91,6 +94,14 @@ func (a *Auth) authenticate(params *AuthParams) error {
return auth.AuthenticateWithToken(params.Token, a.Auth)
}

if apiKey := os.Getenv(constants.APIKeyEnvVarName); apiKey != "" {
err := auth.AuthenticateWithToken(apiKey, a.Auth)
if err != nil {
return locale.WrapError(err, "err_auth_api_key", "Failed to authenticate with [ACTIONABLE]{{.V0}}[/RESET] environment variable", constants.APIKeyEnvVarName)
}
return nil
}
Comment on lines +97 to +103
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this error reporting should be in the lower level auth package. The user would only get this error message if they explicitly ran state auth but we are attempting to authenticate with the api key environment variable through multiple code paths in the auth package. See here for one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I did originally, but I couldn't trigger it without state auth. We have lots of places that check auth.Authenticated() and bail out with "you must be logged in" if not. I was only able to show my message using state auth. The only callers of your linked method are "Sync" (not applicable to this PR), and "Client". All instances of the latter appear to be walled behind auth.Authenticated() checks, so in practice, I think we're okay.

Given that the confusion arises around the whole state auth flow, I figured this was an okay place to put it.


if params.NonInteractive {
return locale.NewInputError("err_auth_needinput")
}
Expand Down
Loading