Skip to content

Commit a411bc3

Browse files
committed
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.
1 parent 7b227fa commit a411bc3

File tree

1 file changed

+18
-8
lines changed
  • pkg/asset/installconfig/aws

1 file changed

+18
-8
lines changed

pkg/asset/installconfig/aws/ec2.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,44 @@ package aws
33
import (
44
"context"
55
"fmt"
6+
awsv2 "github.com/aws/aws-sdk-go-v2/aws"
67
"time"
78

89
cfgv2 "github.com/aws/aws-sdk-go-v2/config"
910
ec2v2 "github.com/aws/aws-sdk-go-v2/service/ec2"
1011
"github.com/aws/aws-sdk-go/aws"
1112
"github.com/aws/aws-sdk-go/aws/session"
1213
"github.com/aws/aws-sdk-go/service/ec2"
13-
"github.com/sirupsen/logrus"
1414
)
1515

16+
func setUserCredsInConfig(ctx context.Context) (awsv2.Config, error) {
17+
if err := getUserCredentials(); err != nil {
18+
return awsv2.Config{}, err
19+
}
20+
cfg, err := cfgv2.LoadDefaultConfig(ctx, cfgv2.WithRegion("us-east-1"))
21+
if err != nil {
22+
return awsv2.Config{}, fmt.Errorf("failed to create AWS config: %w", err)
23+
}
24+
return cfg, nil
25+
}
26+
1627
// GetRegions get all regions that are accessible.
1728
func GetRegions(ctx context.Context) ([]string, error) {
1829
// Create a basic/default config. The function is currently called during the survey.
1930
// Pass the default region (used for survey purposes) as the region here. Without a region
2031
// the DescribeRegions call will fail immediately.
2132
cfg, err := cfgv2.LoadDefaultConfig(ctx, cfgv2.WithRegion("us-east-1"))
2233
if err != nil {
23-
return nil, fmt.Errorf("failed to create config from platform: %w", err)
34+
cfg, err = setUserCredsInConfig(ctx)
35+
if err != nil {
36+
return nil, err
37+
}
2438
}
2539

2640
if _, err = cfg.Credentials.Retrieve(ctx); err != nil {
27-
logrus.Debugf("failed to retrieve AWS credentials: %v", err)
28-
if err = getUserCredentials(); err != nil {
29-
return nil, err
30-
}
31-
cfg, err = cfgv2.LoadDefaultConfig(ctx, cfgv2.WithRegion("us-east-1"))
41+
cfg, err = setUserCredsInConfig(ctx)
3242
if err != nil {
33-
return nil, fmt.Errorf("failed to create config from platform: %w", err)
43+
return nil, err
3444
}
3545
}
3646
client := ec2v2.NewFromConfig(cfg)

0 commit comments

Comments
 (0)