Skip to content

Commit

Permalink
Fix error message when profile nor env vars found
Browse files Browse the repository at this point in the history
  • Loading branch information
mtibben committed Mar 8, 2022
1 parent 9a93123 commit 67d1aea
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ConfigureLoginCommand(app *kingpin.Application, a *AwsVault) {
Short('s').
BoolVar(&input.UseStdout)

cmd.Arg("profile", "Name of the profile").
cmd.Arg("profile", "Name of the profile. If none given, credentials will be sourced from env vars").
HintAction(a.MustGetProfileNames).
StringVar(&input.ProfileName)

Expand Down Expand Up @@ -114,13 +114,10 @@ func LoginCommand(input LoginCommandInput, f *vault.ConfigFile, keyring keyring.
if err != nil {
return fmt.Errorf("Failed to get credentials: %w", err)
}
if creds.SessionToken == "" {
// When sourcing credentials from the environment, it's possible a session token wasn't set
// Generating a sign-in link requires temporary credentials, so we return an error
// NOTE: We deliberately chose to have this logic here rather than in 'EnvironmentVariablesCredentialsProvider'
// to make it possible to reuse it for other commands than `aws-vault login` in the future
return fmt.Errorf("failed to retrieve a session token. Cannot generate a login URL without it")
if creds.AccessKeyID == "" && input.ProfileName == "" {
return fmt.Errorf("argument 'profile' not provided, nor any AWS env vars found. Try --help")
}

jsonBytes, err := json.Marshal(map[string]string{
"sessionId": creds.AccessKeyID,
"sessionKey": creds.SecretAccessKey,
Expand Down

0 comments on commit 67d1aea

Please sign in to comment.