Skip to content

Commit

Permalink
show provider error details
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
  • Loading branch information
fjogeleit committed Jul 29, 2023
1 parent b7618d8 commit 4a05ef8
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions pkg/helper/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"go.uber.org/zap"
)

var enable = true

type AWSClient interface {
// Upload given Data the configured AWS storage
Upload(body *bytes.Buffer, key string) error
Expand Down Expand Up @@ -147,26 +149,32 @@ func createConfig(accessKeyID, secretAccessKey, region, endpoint string) *aws.Co

sess := session.Must(session.NewSession(baseConfig))

return &aws.Config{
Region: baseConfig.Region,
Endpoint: baseConfig.Endpoint,
Credentials: credentials.NewChainCredentials([]credentials.Provider{
&credentials.StaticProvider{
Value: credentials.Value{
AccessKeyID: accessKeyID,
SecretAccessKey: secretAccessKey,
},
},
&credentials.EnvProvider{},
stscreds.NewWebIdentityRoleProvider(
sts.New(sess),
os.Getenv("AWS_ROLE_ARN"),
"",
os.Getenv("AWS_WEB_IDENTITY_TOKEN_FILE"),
),
&ec2rolecreds.EC2RoleProvider{
Client: ec2metadata.New(sess),
var provider credentials.Provider

if accessKeyID != "" && secretAccessKey != "" {
provider = &credentials.StaticProvider{
Value: credentials.Value{
AccessKeyID: accessKeyID,
SecretAccessKey: secretAccessKey,
},
}),
}
} else if os.Getenv("AWS_ROLE_ARN") != "" && os.Getenv("AWS_WEB_IDENTITY_TOKEN_FILE") != "" {
provider = stscreds.NewWebIdentityRoleProvider(
sts.New(sess),
os.Getenv("AWS_ROLE_ARN"),
"",
os.Getenv("AWS_WEB_IDENTITY_TOKEN_FILE"),
)
} else {
provider = &ec2rolecreds.EC2RoleProvider{
Client: ec2metadata.New(sess),
}
}

return &aws.Config{
Region: baseConfig.Region,
Endpoint: baseConfig.Endpoint,
CredentialsChainVerboseErrors: aws.Bool(true),
Credentials: credentials.NewCredentials(provider),
}
}

0 comments on commit 4a05ef8

Please sign in to comment.