Skip to content

Commit

Permalink
Merge pull request drone-plugins#333 from jimsheldon/ecr-externalid
Browse files Browse the repository at this point in the history
adding support for externalId
  • Loading branch information
eoinmcafee00 authored Sep 23, 2021
2 parents 72ef7b1 + e44c2d4 commit 607b04a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cmd/drone-ecr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func main() {
lifecyclePolicy = getenv("PLUGIN_LIFECYCLE_POLICY")
repositoryPolicy = getenv("PLUGIN_REPOSITORY_POLICY")
assumeRole = getenv("PLUGIN_ASSUME_ROLE")
externalId = getenv("PLUGIN_EXTERNAL_ID")
scanOnPush = parseBoolOrDefault(false, getenv("PLUGIN_SCAN_ON_PUSH"))
)

Expand All @@ -57,7 +58,7 @@ func main() {
log.Fatal(fmt.Sprintf("error creating aws session: %v", err))
}

svc := getECRClient(sess, assumeRole)
svc := getECRClient(sess, assumeRole, externalId)
username, password, defaultRegistry, err := getAuthInfo(svc)

if registry == "" {
Expand Down Expand Up @@ -208,11 +209,19 @@ func getenv(key ...string) (s string) {
return
}

func getECRClient(sess *session.Session, role string) *ecr.ECR {
func getECRClient(sess *session.Session, role string, externalId string) *ecr.ECR {
if role == "" {
return ecr.New(sess)
}
return ecr.New(sess, &aws.Config{
Credentials: stscreds.NewCredentials(sess, role),
})
if externalId != "" {
return ecr.New(sess, &aws.Config{
Credentials: stscreds.NewCredentials(sess, role, func(p *stscreds.AssumeRoleProvider) {
p.ExternalID = &externalId
}),
})
} else {
return ecr.New(sess, &aws.Config{
Credentials: stscreds.NewCredentials(sess, role),
})
}
}

0 comments on commit 607b04a

Please sign in to comment.