diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2022-02-10 09:39:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-10 09:39:56 -0500 |
commit | ec889c819a5ae514e80eca1d2c032d9b95a01651 (patch) | |
tree | b3249da09f7a5f7f98dce07a82fa2d83695baabe /vendor/github.com/docker/distribution/reference/normalize.go | |
parent | 5b2d96fc29c17253e3ddd0e18ce5f71710b83658 (diff) | |
parent | 345413540aef90e43635a3f2f7a72e237fa90787 (diff) | |
download | podman-ec889c819a5ae514e80eca1d2c032d9b95a01651.tar.gz podman-ec889c819a5ae514e80eca1d2c032d9b95a01651.tar.bz2 podman-ec889c819a5ae514e80eca1d2c032d9b95a01651.zip |
Merge pull request #13193 from TomSweeneyRedHat/dev/tsweeney/bumpcommon4
[v4.0] Bump c/common to v0.47.4
Diffstat (limited to 'vendor/github.com/docker/distribution/reference/normalize.go')
-rw-r--r-- | vendor/github.com/docker/distribution/reference/normalize.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/github.com/docker/distribution/reference/normalize.go b/vendor/github.com/docker/distribution/reference/normalize.go index 2d71fc5e9..b3dfb7a6d 100644 --- a/vendor/github.com/docker/distribution/reference/normalize.go +++ b/vendor/github.com/docker/distribution/reference/normalize.go @@ -56,6 +56,35 @@ func ParseNormalizedNamed(s string) (Named, error) { return named, nil } +// ParseDockerRef normalizes the image reference following the docker convention. This is added +// mainly for backward compatibility. +// The reference returned can only be either tagged or digested. For reference contains both tag +// and digest, the function returns digested reference, e.g. docker.io/library/busybox:latest@ +// sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa will be returned as +// docker.io/library/busybox@sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa. +func ParseDockerRef(ref string) (Named, error) { + named, err := ParseNormalizedNamed(ref) + if err != nil { + return nil, err + } + if _, ok := named.(NamedTagged); ok { + if canonical, ok := named.(Canonical); ok { + // The reference is both tagged and digested, only + // return digested. + newNamed, err := WithName(canonical.Name()) + if err != nil { + return nil, err + } + newCanonical, err := WithDigest(newNamed, canonical.Digest()) + if err != nil { + return nil, err + } + return newCanonical, nil + } + } + return TagNameOnly(named), nil +} + // splitDockerDomain splits a repository name to domain and remotename string. // If no valid domain is found, the default domain is used. Repository name // needs to be already validated before. |