Skip to content

Commit

Permalink
Add regex to support ECR as OCI Helm registry
Browse files Browse the repository at this point in the history
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 <benjamin.seifert@niche.com>
  • Loading branch information
Ben committed Sep 26, 2022
1 parent daa2fc2 commit 58128d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion oci/auth/aws/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ 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,
// otherwise empty strings and `false`.
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
}
Expand Down
6 changes: 4 additions & 2 deletions oci/auth/aws/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 58128d9

Please sign in to comment.