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

Keep the "library" namespace if it was specified in the image identifier #1014

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
Loading