diff options
author | Miloslav Trmač <mitr@redhat.com> | 2019-01-09 20:32:30 +0100 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2019-01-14 04:07:23 +0100 |
commit | 72777b7fee22e04edee08034927d5864ffc4bc3e (patch) | |
tree | 86f2794d67f79df140acdc0d1cd122ed77030ae0 /libpod/image/parts.go | |
parent | ae2a95196e9e5a3519b396105d01a3661de330ba (diff) | |
download | podman-72777b7fee22e04edee08034927d5864ffc4bc3e.tar.gz podman-72777b7fee22e04edee08034927d5864ffc4bc3e.tar.bz2 podman-72777b7fee22e04edee08034927d5864ffc4bc3e.zip |
Add imageParts.referenceWithRegistry
This is the primary goal of decompose()+assemble(), to support
qualifying an image name.
Does not have any users yet, so does not change behavior.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'libpod/image/parts.go')
-rw-r--r-- | libpod/image/parts.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libpod/image/parts.go b/libpod/image/parts.go index b7c5d1252..8d059e35b 100644 --- a/libpod/image/parts.go +++ b/libpod/image/parts.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/containers/image/docker/reference" + "github.com/pkg/errors" ) // imageParts describes the parts of an image's name @@ -76,6 +77,23 @@ func decompose(input string) (imageParts, error) { }, nil } +// referenceWithRegistry returns a (normalized) reference.Named composed of ip (with !ip.hasRegistry) +// qualified with registry. +func (ip *imageParts) referenceWithRegistry(registry string) (reference.Named, error) { + if ip.hasRegistry { + return nil, errors.Errorf("internal error: referenceWithRegistry called on imageParts with a registry (%#v)", *ip) + } + // We could build a reference.WithName+WithTag/WithDigest here, but we need to round-trip via a string + // and a ParseNormalizedNamed anyway to get the right normalization of docker.io/library, so + // just use a string directly. + qualified := registry + "/" + ip.unnormalizedRef.String() + ref, err := reference.ParseNormalizedNamed(qualified) + if err != nil { + return nil, errors.Wrapf(err, "error normalizing registry+unqualified reference %#v", qualified) + } + return ref, nil +} + // assemble concatenates an image's parts into a string func (ip *imageParts) assemble() string { spec := fmt.Sprintf("%s:%s", ip.name, ip.tag) |