Skip to content

Commit

Permalink
fix: Catch Google Artifact Registry URL during OCI detection (#921)
Browse files Browse the repository at this point in the history
Signed-off-by: John Reese <john@reese.dev>
  • Loading branch information
jpreese committed Feb 21, 2024
1 parent 3eb0cde commit dfcc0d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion downloader/oci_detector.go
Expand Up @@ -10,7 +10,7 @@ import (
// them into URLs that the OCI getter can understand.
type OCIDetector struct{}

// Detect will detect if the source is an OCI registry
// Detect will detect if the source is an OCI registry.
func (d *OCIDetector) Detect(src, _ string) (string, bool, error) {
if len(src) == 0 {
return "", false, nil
Expand All @@ -33,6 +33,7 @@ func containsOCIRegistry(src string) bool {
regexp.MustCompile("azurecr.io"),
regexp.MustCompile("gcr.io"),
regexp.MustCompile("registry.gitlab.com"),
regexp.MustCompile("pkg.dev"),
regexp.MustCompile("[0-9]{12}.dkr.ecr.[a-z0-9-]*.amazonaws.com"),
regexp.MustCompile("^quay.io"),
}
Expand Down
9 changes: 9 additions & 0 deletions downloader/oci_detector_test.go
Expand Up @@ -18,6 +18,11 @@ func TestOCIDetector_Detect(t *testing.T) {
"gcr.io/conftest/policies:tag",
"oci://gcr.io/conftest/policies:tag",
},
{
"should detect google artifact registry",
"region-docker.pkg.dev/conftest/policies:tag",
"oci://region-docker.pkg.dev/conftest/policies:tag",
},
{
"should detect ecr",
"123456789012.dkr.ecr.us-east-1.amazonaws.com/conftest/policies:tag",
Expand Down Expand Up @@ -69,17 +74,21 @@ func TestOCIDetector_Detect(t *testing.T) {
"oci://::1:32123/policies:tag",
},
}

pwd := "/pwd"
d := &OCIDetector{}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
out, ok, err := d.Detect(tt.input, pwd)
if err != nil {
t.Fatalf("OCIDetector.Detect() error = %v", err)
}

if !ok {
t.Fatal("OCIDetector.Detect() not ok, should have detected")
}

if out != tt.expected {
t.Errorf("OCIDetector.Detect() output = %v, want %v", out, tt.expected)
}
Expand Down

0 comments on commit dfcc0d9

Please sign in to comment.