Skip to content

Commit 0293910

Browse files
authored
Update plugin.go
1 parent 415d47e commit 0293910

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

plugin.go

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type Plugin struct {
100100
// set externalID for assume role
101101
ExternalID string
102102

103-
// set OIDC ID Token to retrieve temporary credentials
103+
// set OIDC ID Token to retrieve temporary credentials
104104
IdToken string
105105
}
106106

@@ -435,69 +435,69 @@ func (p *Plugin) downloadS3Objects(client *s3.S3, sourceDir string) error {
435435

436436
// createS3Client creates and returns an S3 client based on the plugin configuration
437437
func (p *Plugin) createS3Client() *s3.S3 {
438-
conf := &aws.Config{
439-
Region: aws.String(p.Region),
440-
Endpoint: &p.Endpoint,
441-
DisableSSL: aws.Bool(strings.HasPrefix(p.Endpoint, "http://")),
442-
S3ForcePathStyle: aws.Bool(p.PathStyle),
443-
}
444-
445-
sess, err := session.NewSession(conf)
446-
if err != nil {
447-
log.Fatalf("failed to create AWS session: %v", err)
448-
}
449-
450-
if p.Key != "" && p.Secret != "" {
451-
conf.Credentials = credentials.NewStaticCredentials(p.Key, p.Secret, "")
452-
} else if p.IdToken != "" && p.AssumeRole != "" {
453-
creds, err := assumeRoleWithWebIdentity(sess, p.AssumeRole, p.AssumeRoleSessionName, p.IdToken)
454-
if err != nil {
455-
log.Fatalf("failed to assume role with web identity: %v", err)
456-
}
457-
conf.Credentials = creds
458-
} else if p.AssumeRole != "" {
459-
conf.Credentials = assumeRole(p.AssumeRole, p.AssumeRoleSessionName, p.ExternalID)
460-
} else {
461-
log.Warn("AWS Key and/or Secret not provided (falling back to ec2 instance profile)")
462-
}
463-
464-
client := s3.New(sess, conf)
465-
466-
if len(p.UserRoleArn) > 0 {
467-
// Create new credentials by assuming the UserRoleArn (with ExternalID when provided)
468-
creds := stscreds.NewCredentials(sess, p.UserRoleArn, func(provider *stscreds.AssumeRoleProvider) {
469-
if p.UserRoleExternalID != "" {
470-
provider.ExternalID = aws.String(p.UserRoleExternalID)
471-
}
472-
})
473-
474-
// Create a new session with the new credentials
475-
confWithUserRole := &aws.Config{
476-
Region: aws.String(p.Region),
477-
Credentials: creds,
478-
}
479-
480-
sessWithUserRole, err := session.NewSession(confWithUserRole)
481-
if err != nil {
482-
log.Fatalf("failed to create AWS session with user role: %v", err)
483-
}
484-
485-
client = s3.New(sessWithUserRole)
486-
}
487-
488-
return client
438+
conf := &aws.Config{
439+
Region: aws.String(p.Region),
440+
Endpoint: &p.Endpoint,
441+
DisableSSL: aws.Bool(strings.HasPrefix(p.Endpoint, "http://")),
442+
S3ForcePathStyle: aws.Bool(p.PathStyle),
443+
}
444+
445+
sess, err := session.NewSession(conf)
446+
if err != nil {
447+
log.Fatalf("failed to create AWS session: %v", err)
448+
}
449+
450+
if p.Key != "" && p.Secret != "" {
451+
conf.Credentials = credentials.NewStaticCredentials(p.Key, p.Secret, "")
452+
} else if p.IdToken != "" && p.AssumeRole != "" {
453+
creds, err := assumeRoleWithWebIdentity(sess, p.AssumeRole, p.AssumeRoleSessionName, p.IdToken)
454+
if err != nil {
455+
log.Fatalf("failed to assume role with web identity: %v", err)
456+
}
457+
conf.Credentials = creds
458+
} else if p.AssumeRole != "" {
459+
conf.Credentials = assumeRole(p.AssumeRole, p.AssumeRoleSessionName, p.ExternalID)
460+
} else {
461+
log.Warn("AWS Key and/or Secret not provided (falling back to ec2 instance profile)")
462+
}
463+
464+
client := s3.New(sess, conf)
465+
466+
if len(p.UserRoleArn) > 0 {
467+
// Create new credentials by assuming the UserRoleArn (with ExternalID when provided)
468+
creds := stscreds.NewCredentials(sess, p.UserRoleArn, func(provider *stscreds.AssumeRoleProvider) {
469+
if p.UserRoleExternalID != "" {
470+
provider.ExternalID = aws.String(p.UserRoleExternalID)
471+
}
472+
})
473+
474+
// Create a new session with the new credentials
475+
confWithUserRole := &aws.Config{
476+
Region: aws.String(p.Region),
477+
Credentials: creds,
478+
}
479+
480+
sessWithUserRole, err := session.NewSession(confWithUserRole)
481+
if err != nil {
482+
log.Fatalf("failed to create AWS session with user role: %v", err)
483+
}
484+
485+
client = s3.New(sessWithUserRole)
486+
}
487+
488+
return client
489489
}
490490

491491
func assumeRoleWithWebIdentity(sess *session.Session, roleArn, roleSessionName, idToken string) (*credentials.Credentials, error) {
492-
svc := sts.New(sess)
493-
input := &sts.AssumeRoleWithWebIdentityInput{
494-
RoleArn: aws.String(roleArn),
495-
RoleSessionName: aws.String(roleSessionName),
496-
WebIdentityToken: aws.String(idToken),
497-
}
498-
result, err := svc.AssumeRoleWithWebIdentity(input)
499-
if err != nil {
500-
log.Fatalf("failed to assume role with web identity: %v", err)
501-
}
502-
return credentials.NewStaticCredentials(*result.Credentials.AccessKeyId, *result.Credentials.SecretAccessKey, *result.Credentials.SessionToken), nil
492+
svc := sts.New(sess)
493+
input := &sts.AssumeRoleWithWebIdentityInput{
494+
RoleArn: aws.String(roleArn),
495+
RoleSessionName: aws.String(roleSessionName),
496+
WebIdentityToken: aws.String(idToken),
497+
}
498+
result, err := svc.AssumeRoleWithWebIdentity(input)
499+
if err != nil {
500+
log.Fatalf("failed to assume role with web identity: %v", err)
501+
}
502+
return credentials.NewStaticCredentials(*result.Credentials.AccessKeyId, *result.Credentials.SecretAccessKey, *result.Credentials.SessionToken), nil
503503
}

0 commit comments

Comments
 (0)