@@ -19,11 +19,9 @@ const OneLoginOAuthPath = "/auth/oauth2/v2/token"
1919
2020// Configure configure account profiles
2121func 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