Merge pull request #11387 from johngmyers/aws-config

Enable reading shared config when possibly from CLI
This commit is contained in:
Kubernetes Prow Robot 2021-05-23 15:15:38 -07:00 committed by GitHub
commit 3a376e9048
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 14 deletions

View File

@ -66,7 +66,9 @@ func newRoute53(config io.Reader) (*Interface, error) {
// To avoid API throttling on busier accounts
awsConfig = awsConfig.WithMaxRetries(5)
sess, err := session.NewSession()
sess, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return nil, err
}

View File

@ -255,7 +255,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
requestLogger := newRequestLogger(2)
sess, err := session.NewSession(config)
sess, err := session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}
@ -263,7 +266,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
c.cf.Handlers.Send.PushFront(requestLogger)
c.addHandlers(region, &c.cf.Handlers)
sess, err = session.NewSession(config)
sess, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}
@ -271,7 +277,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
c.ec2.Handlers.Send.PushFront(requestLogger)
c.addHandlers(region, &c.ec2.Handlers)
sess, err = session.NewSession(config)
sess, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}
@ -279,7 +288,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
c.iam.Handlers.Send.PushFront(requestLogger)
c.addHandlers(region, &c.iam.Handlers)
sess, err = session.NewSession(config)
sess, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}
@ -287,7 +299,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
c.elb.Handlers.Send.PushFront(requestLogger)
c.addHandlers(region, &c.elb.Handlers)
sess, err = session.NewSession(config)
sess, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}
@ -295,7 +310,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
c.elbv2.Handlers.Send.PushFront(requestLogger)
c.addHandlers(region, &c.elbv2.Handlers)
sess, err = session.NewSession(config)
sess, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}
@ -303,7 +321,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
c.sts.Handlers.Send.PushFront(requestLogger)
c.addHandlers(region, &c.sts.Handlers)
sess, err = session.NewSession(config)
sess, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}
@ -311,7 +332,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
c.autoscaling.Handlers.Send.PushFront(requestLogger)
c.addHandlers(region, &c.autoscaling.Handlers)
sess, err = session.NewSession(config)
sess, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}
@ -326,7 +350,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
}
}
sess, err = session.NewSession(config)
sess, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}
@ -334,7 +361,10 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
c.sqs.Handlers.Send.PushFront(requestLogger)
c.addHandlers(region, &c.sqs.Handlers)
sess, err = session.NewSession(config)
sess, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return c, err
}

View File

@ -75,7 +75,10 @@ func ValidateRegion(region string) error {
config := aws.NewConfig().WithRegion(awsRegion)
config = config.WithCredentialsChainVerboseErrors(true)
sess, err := session.NewSession(config)
sess, err := session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return fmt.Errorf("error starting a new AWS session: %v", err)
}

View File

@ -96,7 +96,10 @@ func (s *S3Context) getClient(region string) (*s3.S3, error) {
}
}
sess, err := session.NewSession(config)
sess, err := session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return nil, fmt.Errorf("error starting new AWS session: %v", err)
}
@ -284,7 +287,10 @@ func bruteforceBucketLocation(region *string, request *s3.GetBucketLocationInput
config := &aws.Config{Region: region}
config = config.WithCredentialsChainVerboseErrors(true)
session, err := session.NewSession(config)
session, err := session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return nil, fmt.Errorf("error creating aws session: %v", err)
}