Skip to content

Commit

Permalink
Merge pull request #142 from lnguyen/master
Browse files Browse the repository at this point in the history
Adding support for assume role arn
  • Loading branch information
Rui Yang authored May 16, 2023
2 parents 2e4cdf9 + afb521c commit 4022f1a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ bucket.
* `secret_access_key`: *Required.* The AWS secret key to use when accessing
the bucket.

* `assume_role_arn`: *Optional.* The AWS role to assume when using access keys.

* `session_token`: *Optional.* The AWS session token to use when accessing
the bucket.

Expand Down
31 changes: 21 additions & 10 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/blang/semver"
Expand Down Expand Up @@ -72,7 +73,17 @@ func FromSource(source models.Source) (Driver, error) {
awsConfig.Endpoint = aws.String(source.Endpoint)
}

svc := s3.New(session.New(awsConfig))
s3Session := session.New(awsConfig)

var s3Client *s3.S3
if source.AssumeRoleArn != "" {
creds := stscreds.NewCredentials(s3Session, source.AssumeRoleArn)
s3Client = s3.New(s3Session, &aws.Config{Credentials: creds})
} else {
s3Client = s3.New(s3Session)
}

svc := s3Client

if source.UseV2Signing {
setv2Handlers(svc)
Expand All @@ -91,15 +102,15 @@ func FromSource(source models.Source) (Driver, error) {
return &GitDriver{
InitialVersion: initialVersion,

URI: source.URI,
Branch: source.Branch,
PrivateKey: source.PrivateKey,
Username: source.Username,
Password: source.Password,
File: source.File,
GitUser: source.GitUser,
CommitMessage: source.CommitMessage,
SkipSSLVerification: source.SkipSSLVerification,
URI: source.URI,
Branch: source.Branch,
PrivateKey: source.PrivateKey,
Username: source.Username,
Password: source.Password,
File: source.File,
GitUser: source.GitUser,
CommitMessage: source.CommitMessage,
SkipSSLVerification: source.SkipSSLVerification,
}, nil

case models.DriverSwift:
Expand Down
1 change: 1 addition & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Source struct {
Key string `json:"key"`
AccessKeyID string `json:"access_key_id"`
SecretAccessKey string `json:"secret_access_key"`
AssumeRoleArn string `json:"assume_role_arn"`
SessionToken string `json:"session_token"`
RegionName string `json:"region_name"`
Endpoint string `json:"endpoint"`
Expand Down

0 comments on commit 4022f1a

Please sign in to comment.