diff --git a/oci/auth/aws/auth.go b/oci/auth/aws/auth.go index 0442772c..ae08fb06 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 3ced59fa..578843c9 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",