@@ -37,6 +37,7 @@ func main() {
3737 lifecyclePolicy = getenv ("PLUGIN_LIFECYCLE_POLICY" )
3838 repositoryPolicy = getenv ("PLUGIN_REPOSITORY_POLICY" )
3939 assumeRole = getenv ("PLUGIN_ASSUME_ROLE" )
40+ externalId = getenv ("PLUGIN_EXTERNAL_ID" )
4041 scanOnPush = parseBoolOrDefault (false , getenv ("PLUGIN_SCAN_ON_PUSH" ))
4142 )
4243
@@ -57,7 +58,7 @@ func main() {
5758 log .Fatal (fmt .Sprintf ("error creating aws session: %v" , err ))
5859 }
5960
60- svc := getECRClient (sess , assumeRole )
61+ svc := getECRClient (sess , assumeRole , externalId )
6162 username , password , defaultRegistry , err := getAuthInfo (svc )
6263
6364 if registry == "" {
@@ -208,11 +209,19 @@ func getenv(key ...string) (s string) {
208209 return
209210}
210211
211- func getECRClient (sess * session.Session , role string ) * ecr.ECR {
212+ func getECRClient (sess * session.Session , role string , externalId string ) * ecr.ECR {
212213 if role == "" {
213214 return ecr .New (sess )
214215 }
215- return ecr .New (sess , & aws.Config {
216- Credentials : stscreds .NewCredentials (sess , role ),
217- })
216+ if externalId != "" {
217+ return ecr .New (sess , & aws.Config {
218+ Credentials : stscreds .NewCredentials (sess , role , func (p * stscreds.AssumeRoleProvider ) {
219+ p .ExternalID = & externalId
220+ }),
221+ })
222+ } else {
223+ return ecr .New (sess , & aws.Config {
224+ Credentials : stscreds .NewCredentials (sess , role ),
225+ })
226+ }
218227}
0 commit comments