Skip to content

Commit

Permalink
adding support for externalId
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Sheldon committed Sep 17, 2021
1 parent 72ef7b1 commit e44c2d4
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 e44c2d4

Please sign in to comment.