Skip to content

Commit f322269

Browse files
authored
#617 Allow ExportCredentialSuffix to be nil and only warn if so, a blank (#915)
suffix won't warn
1 parent 1471a4e commit f322269

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

pkg/assume/assume.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,13 @@ func AssumeCommand(c *cli.Context) error {
464464
return err
465465
}
466466
var profileName string
467-
if cfg.ExportCredentialSuffix != "" {
468-
profileName = profile.Name + "-" + cfg.ExportCredentialSuffix
469-
467+
if cfg.ExportCredentialSuffix == nil {
468+
profileName = profile.Name
469+
clio.Warn("No credential suffix found. This can cause issues with using exported credentials if conflicting profiles exist. Run `granted settings export-suffix set` to set one. Set to empty string to supress this warning")
470+
} else if *cfg.ExportCredentialSuffix != "" {
471+
profileName = profile.Name + "-" + *cfg.ExportCredentialSuffix
470472
} else {
471473
profileName = profile.Name
472-
clio.Warn("No credential suffix found. This can cause issues with using exported credentials if conflicting profiles exist. Run `granted settings export-suffix set` to set one.")
473474
}
474475

475476
credentialsFilePath := cfaws.GetAWSCredentialsPath()

pkg/cfaws/cred_exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func ExportCredsToProfile(profileName string, creds aws.Credentials) error {
4545
return err
4646
}
4747

48-
if cfg.ExportCredentialSuffix != "" {
49-
profileName = profileName + "-" + cfg.ExportCredentialSuffix
48+
if cfg.ExportCredentialSuffix != nil && *cfg.ExportCredentialSuffix!= "" {
49+
profileName = profileName + "-" + *cfg.ExportCredentialSuffix
5050
}
5151

5252
credentialsFile.DeleteSection(profileName)

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Config struct {
4949

5050
Keyring *KeyringConfig `toml:",omitempty"`
5151
Ordering string
52-
ExportCredentialSuffix string
52+
ExportCredentialSuffix *string
5353
// AccessRequestURL is a Granted Approvals URL that users can visit
5454
// to request access, in the event that we receive a ForbiddenException
5555
// denying access to assume a particular role.

pkg/granted/settings/export.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ var ExportSettingsCommand = cli.Command{
2020
if err != nil {
2121
return err
2222
}
23-
fmt.Println(cfg.ExportCredentialSuffix)
23+
if cfg.ExportCredentialSuffix != nil {
24+
fmt.Println(*cfg.ExportCredentialSuffix)
25+
}
2426
return nil
2527
},
2628
}
@@ -44,7 +46,7 @@ var SetExportSettingsCommand = cli.Command{
4446
return err
4547
}
4648

47-
cfg.ExportCredentialSuffix = selection
49+
cfg.ExportCredentialSuffix = &selection
4850
err = cfg.Save()
4951
if err != nil {
5052
return err

0 commit comments

Comments
 (0)