Skip to content

Commit

Permalink
Keep the "library" namespace if it was specified in the image identif…
Browse files Browse the repository at this point in the history
…ier.

Fixes #1012.

Signed-off-by: Alessandro Zanatta <[email protected]>
  • Loading branch information
AlessandroZanatta committed Jan 17, 2025
1 parent 9affc21 commit 2d54b13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions registry-scanner/pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func NewFromIdentifier(identifier string) *ContainerImage {
}
img.ImageAlias = alias
img.ImageName = reference.Path(parsed)
// if library/ was added to the image name, remove it
if !strings.HasPrefix(imgRef, "library/") {
// if library/ was added to the image name,
// but the original identifier did not have it, remove it
if !strings.Contains(imgRef, "library/") {
img.ImageName = strings.TrimPrefix(img.ImageName, "library/")
}
if digested, ok := parsed.(reference.Digested); ok {
Expand Down
12 changes: 12 additions & 0 deletions registry-scanner/pkg/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ func Test_ParseImageTags(t *testing.T) {
assert.Equal(t, "classic-web", image.ImageName)
assert.Nil(t, image.ImageTag)
})
t.Run("#1012 Parse docker.io image and keep library if present", func(t *testing.T) {
image := NewFromIdentifier("docker.io/library/postgres")
assert.Equal(t, "docker.io", image.RegistryURL)
assert.Equal(t, "library/postgres", image.ImageName)
assert.Nil(t, image.ImageTag)
})
t.Run("#1012 Parse docker.io image and do not keep library if absent", func(t *testing.T) {
image := NewFromIdentifier("docker.io/postgres")
assert.Equal(t, "docker.io", image.RegistryURL)
assert.Equal(t, "postgres", image.ImageName)
assert.Nil(t, image.ImageTag)
})
}

func Test_ImageToString(t *testing.T) {
Expand Down

0 comments on commit 2d54b13

Please sign in to comment.