mirror of https://github.com/containers/podman.git
Remove imageParts.{isTagged,registry,name,tag}
Finally, these members no longer have any users. Future users should usually call referenceWithRegistry / normalizedReference, and work with the returned value, instead of reintroducing these variables. Similarly, direct uses of unnormalizedRef should be rare (only for cases where the registry and/or path truly does not matter). Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
parent
797d194050
commit
449116af19
|
@ -10,10 +10,6 @@ import (
|
|||
// imageParts describes the parts of an image's name
|
||||
type imageParts struct {
|
||||
unnormalizedRef reference.Named // WARNING: Did not go through docker.io[/library] normalization
|
||||
registry string
|
||||
name string
|
||||
tag string
|
||||
isTagged bool
|
||||
hasRegistry bool
|
||||
}
|
||||
|
||||
|
@ -37,45 +33,18 @@ func GetImageBaseName(input string) (string, error) {
|
|||
|
||||
// decompose breaks an input name into an imageParts description
|
||||
func decompose(input string) (imageParts, error) {
|
||||
var (
|
||||
parts imageParts
|
||||
hasRegistry bool
|
||||
tag string
|
||||
)
|
||||
imgRef, err := reference.Parse(input)
|
||||
if err != nil {
|
||||
return parts, err
|
||||
return imageParts{}, err
|
||||
}
|
||||
unnormalizedNamed := imgRef.(reference.Named)
|
||||
ntag, isTagged := imgRef.(reference.NamedTagged)
|
||||
if !isTagged {
|
||||
tag = "latest"
|
||||
if _, hasDigest := imgRef.(reference.Digested); hasDigest {
|
||||
tag = "none"
|
||||
}
|
||||
} else {
|
||||
tag = ntag.Tag()
|
||||
}
|
||||
registry := reference.Domain(unnormalizedNamed)
|
||||
imageName := reference.Path(unnormalizedNamed)
|
||||
// ip.unnormalizedRef, because it uses reference.Parse and not reference.ParseNormalizedNamed,
|
||||
// does not use the standard heuristics for domains vs. namespaces/repos, so we need to check
|
||||
// explicitly.
|
||||
if isRegistry(registry) {
|
||||
hasRegistry = true
|
||||
} else {
|
||||
if registry != "" {
|
||||
imageName = registry + "/" + imageName
|
||||
registry = ""
|
||||
}
|
||||
}
|
||||
hasRegistry := isRegistry(reference.Domain(unnormalizedNamed))
|
||||
return imageParts{
|
||||
unnormalizedRef: unnormalizedNamed,
|
||||
registry: registry,
|
||||
hasRegistry: hasRegistry,
|
||||
name: imageName,
|
||||
tag: tag,
|
||||
isTagged: isTagged,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -13,30 +13,30 @@ func TestDecompose(t *testing.T) {
|
|||
for _, c := range []struct {
|
||||
input string
|
||||
registry, name, suspiciousTagValueForSearch string
|
||||
isTagged, hasRegistry bool
|
||||
hasRegistry bool
|
||||
}{
|
||||
{"#", "", "", "", false, false}, // Entirely invalid input
|
||||
{"#", "", "", "", false}, // Entirely invalid input
|
||||
{ // Fully qualified docker.io, name-only input
|
||||
"docker.io/library/busybox", "docker.io", "library/busybox", "latest", false, true,
|
||||
"docker.io/library/busybox", "docker.io", "library/busybox", "latest", true,
|
||||
},
|
||||
{ // Fully qualified example.com, name-only input
|
||||
"example.com/ns/busybox", "example.com", "ns/busybox", "latest", false, true,
|
||||
"example.com/ns/busybox", "example.com", "ns/busybox", "latest", true,
|
||||
},
|
||||
{ // Unqualified single-name input
|
||||
"busybox", "", "busybox", "latest", false, false,
|
||||
"busybox", "", "busybox", "latest", false,
|
||||
},
|
||||
{ // Unqualified namespaced input
|
||||
"ns/busybox", "", "ns/busybox", "latest", false, false,
|
||||
"ns/busybox", "", "ns/busybox", "latest", false,
|
||||
},
|
||||
{ // name:tag
|
||||
"example.com/ns/busybox:notlatest", "example.com", "ns/busybox", "notlatest", true, true,
|
||||
"example.com/ns/busybox:notlatest", "example.com", "ns/busybox", "notlatest", true,
|
||||
},
|
||||
{ // name@digest
|
||||
// FIXME? .suspiciousTagValueForSearch == "none"
|
||||
"example.com/ns/busybox" + digestSuffix, "example.com", "ns/busybox", "none", false, true,
|
||||
"example.com/ns/busybox" + digestSuffix, "example.com", "ns/busybox", "none", true,
|
||||
},
|
||||
{ // name:tag@digest
|
||||
"example.com/ns/busybox:notlatest" + digestSuffix, "example.com", "ns/busybox", "notlatest", true, true,
|
||||
"example.com/ns/busybox:notlatest" + digestSuffix, "example.com", "ns/busybox", "notlatest", true,
|
||||
},
|
||||
} {
|
||||
parts, err := decompose(c.input)
|
||||
|
@ -48,7 +48,6 @@ func TestDecompose(t *testing.T) {
|
|||
assert.Equal(t, c.registry, registry, c.input)
|
||||
assert.Equal(t, c.name, name, c.input)
|
||||
assert.Equal(t, c.suspiciousTagValueForSearch, suspiciousTagValueForSearch, c.input)
|
||||
assert.Equal(t, c.isTagged, parts.isTagged, c.input)
|
||||
assert.Equal(t, c.hasRegistry, parts.hasRegistry, c.input)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue