From d5e983acffd62d679956adcd6e32ff03c58973dd Mon Sep 17 00:00:00 2001 From: barbacbd Date: Fri, 20 Jun 2025 13:03:09 -0400 Subject: [PATCH] OCPBUGS-56658: When AWS_PROFILE is invalid ask for credentials ** The credentials changed in AWS SDK V2. When the AWS_PROFILE environment variable was set to an invalid value the install would not proceed through the failure. The inention was to ask for the aws key and id information. Now the information will be added to the survey, and the information will be added to the config in .aws. --- pkg/asset/installconfig/aws/ec2.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pkg/asset/installconfig/aws/ec2.go b/pkg/asset/installconfig/aws/ec2.go index c213d20170..05957cfbf9 100644 --- a/pkg/asset/installconfig/aws/ec2.go +++ b/pkg/asset/installconfig/aws/ec2.go @@ -5,14 +5,25 @@ import ( "fmt" "time" + awsv2 "github.com/aws/aws-sdk-go-v2/aws" cfgv2 "github.com/aws/aws-sdk-go-v2/config" ec2v2 "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" - "github.com/sirupsen/logrus" ) +func setUserCredsInConfig(ctx context.Context) (awsv2.Config, error) { + if err := getUserCredentials(); err != nil { + return awsv2.Config{}, err + } + cfg, err := cfgv2.LoadDefaultConfig(ctx, cfgv2.WithRegion("us-east-1")) + if err != nil { + return awsv2.Config{}, fmt.Errorf("failed to create AWS config: %w", err) + } + return cfg, nil +} + // GetRegions get all regions that are accessible. func GetRegions(ctx context.Context) ([]string, error) { // Create a basic/default config. The function is currently called during the survey. @@ -20,17 +31,16 @@ func GetRegions(ctx context.Context) ([]string, error) { // the DescribeRegions call will fail immediately. cfg, err := cfgv2.LoadDefaultConfig(ctx, cfgv2.WithRegion("us-east-1")) if err != nil { - return nil, fmt.Errorf("failed to create config from platform: %w", err) + cfg, err = setUserCredsInConfig(ctx) + if err != nil { + return nil, err + } } if _, err = cfg.Credentials.Retrieve(ctx); err != nil { - logrus.Debugf("failed to retrieve AWS credentials: %v", err) - if err = getUserCredentials(); err != nil { - return nil, err - } - cfg, err = cfgv2.LoadDefaultConfig(ctx, cfgv2.WithRegion("us-east-1")) + cfg, err = setUserCredsInConfig(ctx) if err != nil { - return nil, fmt.Errorf("failed to create config from platform: %w", err) + return nil, err } } client := ec2v2.NewFromConfig(cfg)