mirror of
https://github.com/containers/podman.git
synced 2025-09-22 20:56:21 +08:00
support tag@digest notation
Vendor in the latest HEAd of containers/common to implicitly support the tag@digest notation for images. To remain compatible with Docker, the tag will be stripped off the image reference and is entirely ignored. Fixes: #6721 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
51
vendor/github.com/containers/common/libimage/normalize.go
generated
vendored
51
vendor/github.com/containers/common/libimage/normalize.go
generated
vendored
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/containers/image/v5/docker/reference"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// NormalizeName normalizes the provided name according to the conventions by
|
||||
@ -40,6 +41,11 @@ func NormalizeName(name string) (reference.Named, error) {
|
||||
}
|
||||
|
||||
if _, hasTag := named.(reference.NamedTagged); hasTag {
|
||||
// Strip off the tag of a tagged and digested reference.
|
||||
named, err = normalizeTaggedDigestedNamed(named)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return named, nil
|
||||
}
|
||||
if _, hasDigest := named.(reference.Digested); hasDigest {
|
||||
@ -90,3 +96,48 @@ func ToNameTagPairs(repoTags []reference.Named) ([]NameTagPair, error) {
|
||||
}
|
||||
return pairs, nil
|
||||
}
|
||||
|
||||
// normalizeTaggedDigestedString strips the tag off the specified string iff it
|
||||
// is tagged and digested. Note that the tag is entirely ignored to match
|
||||
// Docker behavior.
|
||||
func normalizeTaggedDigestedString(s string) (string, error) {
|
||||
// Note that the input string is not expected to be parseable, so we
|
||||
// return it verbatim in error cases.
|
||||
ref, err := reference.Parse(s)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
named, ok := ref.(reference.Named)
|
||||
if !ok {
|
||||
return s, nil
|
||||
}
|
||||
named, err = normalizeTaggedDigestedNamed(named)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return named.String(), nil
|
||||
}
|
||||
|
||||
// normalizeTaggedDigestedNamed strips the tag off the specified named
|
||||
// reference iff it is tagged and digested. Note that the tag is entirely
|
||||
// ignored to match Docker behavior.
|
||||
func normalizeTaggedDigestedNamed(named reference.Named) (reference.Named, error) {
|
||||
_, isTagged := named.(reference.NamedTagged)
|
||||
if !isTagged {
|
||||
return named, nil
|
||||
}
|
||||
digested, isDigested := named.(reference.Digested)
|
||||
if !isDigested {
|
||||
return named, nil
|
||||
}
|
||||
|
||||
// Now strip off the tag.
|
||||
newNamed := reference.TrimNamed(named)
|
||||
// And re-add the digest.
|
||||
newNamed, err := reference.WithDigest(newNamed, digested.Digest())
|
||||
if err != nil {
|
||||
return named, err
|
||||
}
|
||||
logrus.Debugf("Stripped off tag from tagged and digested reference %q", named.String())
|
||||
return newNamed, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user