From dae59f2400c74ff5c16e2f2ee8d6cbe1d2033274 Mon Sep 17 00:00:00 2001 From: Andres Koetsier Date: Wed, 1 Nov 2017 16:09:11 +0100 Subject: [PATCH] Allow ecr login with default aws credential chain --- cmd/drone-docker-ecr/main.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/drone-docker-ecr/main.go b/cmd/drone-docker-ecr/main.go index 03456af..3f518b0 100644 --- a/cmd/drone-docker-ecr/main.go +++ b/cmd/drone-docker-ecr/main.go @@ -11,7 +11,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecr" ) @@ -32,14 +31,14 @@ func main() { region = defaultRegion } - os.Setenv("AWS_ACCESS_KEY_ID", key) - os.Setenv("AWS_SECRET_ACCESS_KEY", secret) os.Setenv("AWS_REGION", region) - sess, err := session.NewSession(&aws.Config{ - Credentials: credentials.NewEnvCredentials(), - Region: ®ion, - }) + if key != "" && secret != "" { + os.Setenv("AWS_ACCESS_KEY_ID", key) + os.Setenv("AWS_SECRET_ACCESS_KEY", secret) + } + + sess, err := session.NewSession(&aws.Config{Region: ®ion}) if err != nil { log.Fatal(fmt.Sprintf("error creating aws session: %v", err)) @@ -48,7 +47,7 @@ func main() { svc := ecr.New(sess) username, password, registry, err := getAuthInfo(svc) if err != nil { - os.Exit(1) + log.Fatal(fmt.Sprintf("error getting ECR auth: %v", err)) } if !strings.HasPrefix(repo, registry) {