@@ -540,55 +540,61 @@ func (w *WebSSOAuthentication) promptForRole(idp string, roleARNs []string, conf
540540// promptForIDP prompt operator for the AWS IdP ARN given a slice of IdP ARNs.
541541// If the fedApp has already been selected via an ask one survey we don't need
542542// to pretty print out the IdP name again.
543- func (w * WebSSOAuthentication ) promptForIDP (idpARNs []string , configIDPs map [string ]string ) (idpARN string , err error ) {
543+ func (w * WebSSOAuthentication ) promptForIDP (idpARNs []string , configIDPs map [string ]string ) (idpArnChoice string , err error ) {
544544 if len (idpARNs ) == 0 {
545- return idpARN , errors .New (noIDPsError )
545+ return "" , errors .New (noIDPsError )
546546 }
547547
548- if len (idpARNs ) == 1 || w .config .AWSIAMIdP () != "" {
549- idpARN = w .config .AWSIAMIdP ()
550- if len (idpARNs ) == 1 {
551- idpARN = idpARNs [0 ]
552- }
553- if w .fedAppAlreadySelected {
554- return idpARN , nil
555- }
548+ // idpLabels are the friendly names if configured or the ARNs itself
549+ idpLabels := make ([]string , len (idpARNs ))
550+ idpArnByLabel := make (map [string ]string , len (idpARNs ))
551+ for i , arn := range idpARNs {
552+ idpLabel := w .choiceFriendlyLabelIDP (arn , arn , configIDPs )
553+ idpArnByLabel [idpLabel ] = arn
554+ idpLabels [i ] = idpLabel
555+ }
556+
557+ var idpLabelChoice string
556558
557- idpLabel := w .choiceFriendlyLabelIDP (idpARN , idpARN , configIDPs )
558- idpData := idpTemplateData {
559- IDP : idpLabel ,
559+ // There is only a single choice so go ahead and use its label
560+ if len (idpARNs ) == 1 {
561+ idpArn := idpARNs [0 ]
562+ idpLabelChoice = w .choiceFriendlyLabelIDP (idpArn , idpArn , configIDPs )
563+ }
564+
565+ // The user already provided their choice via config
566+ if idpLabelChoice == "" && w .config .AWSIAMIdP () != "" {
567+ iArg := w .config .AWSIAMIdP ()
568+ idpLabelChoice = w .choiceFriendlyLabelIDP (iArg , iArg , configIDPs )
569+ }
570+
571+ // Prompt the user to choose
572+ if idpLabelChoice == "" {
573+ prompt := & survey.Select {
574+ Message : chooseIDP ,
575+ Options : idpLabels ,
560576 }
561- rich , _ , err := core .RunTemplate (idpSelectedTemplate , idpData )
577+ err = survey .AskOne (prompt , & idpLabelChoice , survey .WithValidator (survey .Required ), stderrIsOutAskOpt )
578+ if err != nil {
579+ return "" , fmt .Errorf (askIDPError , err )
580+ }
581+ } else if ! w .fedAppAlreadySelected {
582+ // The choice was determined without prompting the user and the fedApp has not already been selected so pretty print the idp
583+ rich , _ , err := core .RunTemplate (idpSelectedTemplate , idpTemplateData {
584+ IDP : idpLabelChoice ,
585+ })
562586 if err != nil {
563587 return "" , err
564588 }
565589 fmt .Fprintln (os .Stderr , rich )
566- return idpARN , nil
567- }
568-
569- idpChoices := make (map [string ]string , len (idpARNs ))
570- idpChoiceLabels := make ([]string , len (idpARNs ))
571- for i , arn := range idpARNs {
572- idpLabel := w .choiceFriendlyLabelIDP (arn , arn , configIDPs )
573- idpChoices [idpLabel ] = arn
574- idpChoiceLabels [i ] = idpLabel
575590 }
576591
577- var idpChoice string
578- prompt := & survey.Select {
579- Message : chooseIDP ,
580- Options : idpChoiceLabels ,
581- }
582- err = survey .AskOne (prompt , & idpChoice , survey .WithValidator (survey .Required ), stderrIsOutAskOpt )
583- if err != nil {
584- return idpARN , fmt .Errorf (askIDPError , err )
585- }
586- idpARN = idpChoices [idpChoice ]
587- if idpARN == "" {
588- return idpARN , errors .New (idpValueNotSelectedError )
592+ idpArnChoice = idpArnByLabel [idpLabelChoice ]
593+ if idpArnChoice == "" {
594+ return idpArnChoice , errors .New (idpValueNotSelectedError )
589595 }
590596
591- return idpARN , nil
597+ return idpArnChoice , nil
592598}
593599
594600// promptForIdpAndRole UX to prompt operator for the AWS role whose credentials
0 commit comments