Skip to content

Commit 67d1aea

Browse files
committed
Fix error message when profile nor env vars found
1 parent 9a93123 commit 67d1aea

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

cli/login.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func ConfigureLoginCommand(app *kingpin.Application, a *AwsVault) {
5454
Short('s').
5555
BoolVar(&input.UseStdout)
5656

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

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

0 commit comments

Comments
 (0)