Skip to content

Commit

Permalink
Merge pull request #190 from anchore/fix-registry-override
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleyjones authored Apr 10, 2024
2 parents a5fa97a + cc3643d commit fabb8ab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/inventory/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func getRegistryOverrideNormalisedImageTag(imageTag, missingRegistryOverride str
if missingRegistryOverride != "" {
parts := strings.Split(imageTag, "/")
if len(parts) <= 2 {
// Check if the first part is a registry by seeing if it is a domain
if len(parts) > 1 && (strings.Contains(parts[0], ".") || strings.Contains(parts[0], ":")) {
return imageTag
}
// Assume no registry is present and only image and/or repo
return fmt.Sprintf("%s/%s", missingRegistryOverride, imageTag)
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/inventory/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,30 @@ func Test_getRegistryOverrideNormalisedImageTag(t *testing.T) {
},
want: "library/reponame/myimage:0.0.1",
},
{
name: "returns image tag without overridden registry if only registry and image are given, and it can be determined that registry is a domain name not a repo/library",
args: args{
imageTag: "docker.io/myimage:0.0.1",
missingRegistryOverride: "custom.registry.io",
},
want: "docker.io/myimage:0.0.1",
},
{
name: "returns image tag without overridden registry if only registry and image are given, and it can be determined that registry is a domain name not a repo/library",
args: args{
imageTag: "localhost:1234/myimage:0.0.1",
missingRegistryOverride: "custom.registry.io",
},
want: "localhost:1234/myimage:0.0.1",
},
{
name: "returns image tag without overridden registry if only registry and image are given, and it can be determined that registry is a domain name not a repo/library",
args: args{
imageTag: "my.registry:1234/myimage:0.0.1",
missingRegistryOverride: "custom.registry.io",
},
want: "my.registry:1234/myimage:0.0.1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit fabb8ab

Please sign in to comment.