Skip to content

Commit

Permalink
add possibility to turn on ECR image scanning for repos created by ec…
Browse files Browse the repository at this point in the history
…r plugin
  • Loading branch information
Roman Voitenko committed Sep 30, 2020
1 parent e4056d8 commit d8b6b48
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 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")
scanOnPush = parseBoolOrDefault(false, getenv("PLUGIN_SCAN_ON_PUSH"))
)

// set the region
Expand Down Expand Up @@ -72,7 +73,7 @@ func main() {
}

if create {
err = ensureRepoExists(svc, trimHostname(repo, registry))
err = ensureRepoExists(svc, trimHostname(repo, registry), scanOnPush)
if err != nil {
log.Fatal(fmt.Sprintf("error creating ECR repo: %v", err))
}
Expand Down Expand Up @@ -118,9 +119,10 @@ func trimHostname(repo, registry string) string {
return repo
}

func ensureRepoExists(svc *ecr.ECR, name string) (err error) {
func ensureRepoExists(svc *ecr.ECR, name string, scanOnPush bool) (err error) {
input := &ecr.CreateRepositoryInput{}
input.SetRepositoryName(name)
input.SetImageScanningConfiguration(&ecr.ImageScanningConfiguration{ScanOnPush: &scanOnPush})
_, err = svc.CreateRepository(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == ecr.ErrCodeRepositoryAlreadyExistsException {
Expand Down

0 comments on commit d8b6b48

Please sign in to comment.