Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Catch Google Artifact Registry URL during OCI detection #921

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion downloader/oci_detector.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading