Skip to content

Commit 1eeb6f8

Browse files
committed
fix: 🐛 simplify flow and remove password repeater (#1390)
Prior to this commit, the configure flow contained multiple if statements, making the logic unnecessarily complex. Additionally, the password repeater was included, which is not required as this process is not a sign-up flow. The password repeater also caused ambiguity when passwords did not match. After this commit, The configure flow has been simplified by reducing the number of if statements, making the logic more straightforward. The password repeater has been removed entirely, as it is not needed. If the user inputs the wrong password, they can simply re-initiate the configure process. fixes #1390 Signed-off-by: Sriram Venkatesh <sriram.venkatesh@versent.com.au>
1 parent 78330b9 commit 1eeb6f8

1 file changed

Lines changed: 16 additions & 23 deletions

File tree

cmd/saml2aws/commands/configure.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ const OneLoginOAuthPath = "/auth/oauth2/v2/token"
1919

2020
// Configure configure account profiles
2121
func Configure(configFlags *flags.CommonFlags) error {
22-
2322
idpAccountName := configFlags.IdpAccount
2423
idpAccountPassword := configFlags.Password
2524

26-
// pass in alternative location of saml2aws config file, if set.
2725
cfgm, err := cfg.NewConfigManager(configFlags.ConfigFile)
2826
if err != nil {
2927
return errors.Wrap(err, "failed to load configuration")
@@ -34,39 +32,34 @@ func Configure(configFlags *flags.CommonFlags) error {
3432
return errors.Wrap(err, "failed to load idp account")
3533
}
3634

37-
// update username and hostname if supplied
3835
flags.ApplyFlagOverrides(configFlags, account)
3936

40-
// do we need to prompt for values now?
41-
if !configFlags.SkipPrompt {
42-
err = saml2aws.PromptForConfigurationDetails(account)
43-
if err != nil {
44-
return errors.Wrap(err, "failed to input configuration")
45-
}
37+
if configFlags.SkipPrompt {
38+
return saveConfiguration(cfgm, idpAccountName, account, configFlags, idpAccountPassword)
39+
}
40+
41+
if err = saml2aws.PromptForConfigurationDetails(account); err != nil {
42+
return errors.Wrap(err, "failed to input configuration")
43+
}
4644

47-
if credentials.SupportsStorage() && idpAccountPassword == "" {
48-
password := prompter.Password("Password")
49-
if password != "" {
50-
if confirmPassword := prompter.Password("Confirm"); confirmPassword == password {
51-
idpAccountPassword = password
52-
} else {
53-
log.Println("Passwords did not match")
54-
os.Exit(1)
55-
}
56-
} else {
57-
log.Println("No password supplied")
58-
}
45+
if credentials.SupportsStorage() && idpAccountPassword == "" {
46+
idpAccountPassword = prompter.Password("Enter password")
47+
if idpAccountPassword == "" {
48+
log.Println("No password supplied")
5949
}
6050
}
6151

52+
return saveConfiguration(cfgm, idpAccountName, account, configFlags, idpAccountPassword)
53+
}
54+
55+
func saveConfiguration(cfgm *cfg.ConfigManager, idpAccountName string, account *cfg.IDPAccount, configFlags *flags.CommonFlags, idpAccountPassword string) error {
6256
if credentials.SupportsStorage() {
6357
if err := storeCredentials(configFlags, account, idpAccountPassword); err != nil {
6458
return err
6559
}
6660
}
6761

68-
err = cfgm.SaveIDPAccount(idpAccountName, account)
69-
if err != nil {
62+
if err := cfgm.SaveIDPAccount(idpAccountName, account); err != nil {
7063
return errors.Wrap(err, "failed to save configuration")
7164
}
7265

0 commit comments

Comments
 (0)