MCPcopy Create free account
hub / github.com/containers/common / NormalizeName

Function NormalizeName

libimage/normalize.go:55–95  ·  view source on GitHub ↗

NormalizeName normalizes the provided name according to the conventions by Podman and Buildah. If tag and digest are missing, the "latest" tag will be used. If it's a short name, it will be prefixed with "localhost/". References to docker.io are normalized according to the Docker conventions. For

(name string)

Source from the content-addressed store, hash-verified

53// References to docker.io are normalized according to the Docker conventions.
54// For instance, "docker.io/foo" turns into "docker.io/library/foo".
55func NormalizeName(name string) (reference.Named, error) {
56 // NOTE: this code is in symmetrie with containers/image/pkg/shortnames.
57 ref, err := reference.Parse(name)
58 if err != nil {
59 return nil, errors.Wrapf(err, "error normalizing name %q", name)
60 }
61
62 named, ok := ref.(reference.Named)
63 if !ok {
64 return nil, errors.Errorf("%q is not a named reference", name)
65 }
66
67 // Enforce "localhost" if needed.
68 registry := reference.Domain(named)
69 if !(strings.ContainsAny(registry, ".:") || registry == "localhost") {
70 name = toLocalImageName(ref.String())
71 }
72
73 // Another parse which also makes sure that docker.io references are
74 // correctly normalized (e.g., docker.io/alpine to
75 // docker.io/library/alpine).
76 named, err = reference.ParseNormalizedNamed(name)
77 if err != nil {
78 return nil, err
79 }
80
81 if _, hasTag := named.(reference.NamedTagged); hasTag {
82 // Strip off the tag of a tagged and digested reference.
83 named, err = normalizeTaggedDigestedNamed(named)
84 if err != nil {
85 return nil, err
86 }
87 return named, nil
88 }
89 if _, hasDigest := named.(reference.Digested); hasDigest {
90 return named, nil
91 }
92
93 // Make sure to tag "latest".
94 return reference.TagNameOnly(named), nil
95}
96
97// prefix the specified name with "localhost/".
98func toLocalImageName(name string) string {

Callers 8

TagMethod · 0.85
UntagMethod · 0.85
copyFromDefaultMethod · 0.85
saveDockerArchiveMethod · 0.85
CreateManifestListMethod · 0.85
ResolveNameMethod · 0.85
TestNormalizeNameFunction · 0.85

Calls 4

toLocalImageNameFunction · 0.85
ParseMethod · 0.45
StringMethod · 0.45

Tested by 1

TestNormalizeNameFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…