From 60f80da5581dafa585b3a7c5f44c3434e4b45ff4 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 23 Sep 2022 18:23:07 +0000 Subject: [PATCH] Add regex to support ECR as OCI Helm registry This change adds a new regex to parse AWS ECR OCI URLs when to allow URLs that point to the root of an AWS account's ECR registry, instead of forcing all repositories to contain a "/" character. Signed-off-by: Ben Seifert --- oci/auth/aws/auth.go | 6 +++++- oci/auth/aws/auth_test.go | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/oci/auth/aws/auth.go b/oci/auth/aws/auth.go index 0442772c3..ae08fb065 100644 --- a/oci/auth/aws/auth.go +++ b/oci/auth/aws/auth.go @@ -34,6 +34,7 @@ import ( ) var registryPartRe = regexp.MustCompile(`([0-9+]*).dkr.ecr.([^/.]*)\.(amazonaws\.com[.cn]*)/([^:]+):?(.*)`) +var registryPartReNoRepo = regexp.MustCompile(`([0-9+]*).dkr.ecr.([^/.]*)\.(amazonaws\.com[.cn]*)`) // ParseImage returns the AWS account ID and region and `true` if // the image repository is hosted in AWS's Elastic Container Registry, @@ -41,7 +42,10 @@ var registryPartRe = regexp.MustCompile(`([0-9+]*).dkr.ecr.([^/.]*)\.(amazonaws\ func ParseImage(image string) (accountId, awsEcrRegion string, ok bool) { registryParts := registryPartRe.FindAllStringSubmatch(image, -1) if len(registryParts) < 1 || len(registryParts[0]) < 3 { - return "", "", false + registryParts = registryPartReNoRepo.FindAllStringSubmatch(image, -1) + if len(registryParts) < 1 || len(registryParts[0]) < 3 { + return "", "", false + } } return registryParts[0][1], registryParts[0][2], true } diff --git a/oci/auth/aws/auth_test.go b/oci/auth/aws/auth_test.go index 3ced59fa7..578843c92 100644 --- a/oci/auth/aws/auth_test.go +++ b/oci/auth/aws/auth_test.go @@ -51,8 +51,10 @@ func TestParseImage(t *testing.T) { wantOK: true, }, { - image: "012345678901.dkr.ecr.us-east-1.amazonaws.com", - wantOK: false, + image: "012345678901.dkr.ecr.us-east-1.amazonaws.com", + wantAccountID: "012345678901", + wantRegion: "us-east-1", + wantOK: true, }, { image: "gcr.io/foo/bar:baz",