mirror of https://github.com/containers/image.git
API transition: Drop reference.XNamedTagged
Instead use distreference.NamedTagged directly. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
parent
751e8a5a2e
commit
777b215177
|
|
@ -11,9 +11,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/containers/image/docker/reference"
|
|
||||||
"github.com/containers/image/manifest"
|
"github.com/containers/image/manifest"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
|
|
||||||
type daemonImageDestination struct {
|
type daemonImageDestination struct {
|
||||||
ref daemonReference
|
ref daemonReference
|
||||||
namedTaggedRef reference.XNamedTagged // Strictly speaking redundant with ref above; having the field makes it structurally impossible for later users to fail.
|
namedTaggedRef reference.NamedTagged // Strictly speaking redundant with ref above; having the field makes it structurally impossible for later users to fail.
|
||||||
// For talking to imageLoadGoroutine
|
// For talking to imageLoadGoroutine
|
||||||
goroutineCancel context.CancelFunc
|
goroutineCancel context.CancelFunc
|
||||||
statusChannel <-chan error
|
statusChannel <-chan error
|
||||||
|
|
@ -38,7 +38,7 @@ func newImageDestination(systemCtx *types.SystemContext, ref daemonReference) (t
|
||||||
if ref.ref == nil {
|
if ref.ref == nil {
|
||||||
return nil, errors.Errorf("Invalid destination docker-daemon:%s: a destination must be a name:tag", ref.StringWithinTransport())
|
return nil, errors.Errorf("Invalid destination docker-daemon:%s: a destination must be a name:tag", ref.StringWithinTransport())
|
||||||
}
|
}
|
||||||
namedTaggedRef, ok := ref.ref.(reference.XNamedTagged)
|
namedTaggedRef, ok := ref.ref.(reference.NamedTagged)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.Errorf("Invalid destination docker-daemon:%s: a destination must be a name:tag", ref.StringWithinTransport())
|
return nil, errors.Errorf("Invalid destination docker-daemon:%s: a destination must be a name:tag", ref.StringWithinTransport())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ func NewReference(id digest.Digest, ref distreference.Named) (types.ImageReferen
|
||||||
}
|
}
|
||||||
// A github.com/distribution/reference value can have a tag and a digest at the same time!
|
// A github.com/distribution/reference value can have a tag and a digest at the same time!
|
||||||
// docker/reference does not handle that, so fail.
|
// docker/reference does not handle that, so fail.
|
||||||
_, isTagged := ref.(reference.XNamedTagged)
|
_, isTagged := ref.(distreference.NamedTagged)
|
||||||
_, isDigested := ref.(reference.XCanonical)
|
_, isDigested := ref.(reference.XCanonical)
|
||||||
if isTagged && isDigested {
|
if isTagged && isDigested {
|
||||||
return nil, errors.Errorf("docker-daemon: references with both a tag and digest are currently not supported")
|
return nil, errors.Errorf("docker-daemon: references with both a tag and digest are currently not supported")
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ func testParseReference(t *testing.T, fn func(string) (types.ImageReference, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// refWithTagAndDigest is a reference.XNamedTagged and reference.XCanonical at the same time.
|
// refWithTagAndDigest is a reference.NamedTagged and reference.XCanonical at the same time.
|
||||||
type refWithTagAndDigest struct{ reference.XCanonical }
|
type refWithTagAndDigest struct{ reference.XCanonical }
|
||||||
|
|
||||||
func (ref refWithTagAndDigest) Tag() string {
|
func (ref refWithTagAndDigest) Tag() string {
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func NewReference(ref distreference.Named) (types.ImageReference, error) {
|
||||||
// docker/reference does not handle that, so fail.
|
// docker/reference does not handle that, so fail.
|
||||||
// (Even if it were supported, the semantics of policy namespaces are unclear - should we drop
|
// (Even if it were supported, the semantics of policy namespaces are unclear - should we drop
|
||||||
// the tag or the digest first?)
|
// the tag or the digest first?)
|
||||||
_, isTagged := ref.(reference.XNamedTagged)
|
_, isTagged := ref.(distreference.NamedTagged)
|
||||||
_, isDigested := ref.(reference.XCanonical)
|
_, isDigested := ref.(reference.XCanonical)
|
||||||
if isTagged && isDigested {
|
if isTagged && isDigested {
|
||||||
return nil, errors.Errorf("Docker references with both a tag and digest are currently not supported")
|
return nil, errors.Errorf("Docker references with both a tag and digest are currently not supported")
|
||||||
|
|
@ -149,7 +149,7 @@ func (ref dockerReference) tagOrDigest() (string, error) {
|
||||||
if ref, ok := ref.ref.(reference.XCanonical); ok {
|
if ref, ok := ref.ref.(reference.XCanonical); ok {
|
||||||
return ref.XDigest().String(), nil
|
return ref.XDigest().String(), nil
|
||||||
}
|
}
|
||||||
if ref, ok := ref.ref.(reference.XNamedTagged); ok {
|
if ref, ok := ref.ref.(distreference.NamedTagged); ok {
|
||||||
return ref.Tag(), nil
|
return ref.Tag(), nil
|
||||||
}
|
}
|
||||||
// This should not happen, NewReference above refuses reference.XIsNameOnly values.
|
// This should not happen, NewReference above refuses reference.XIsNameOnly values.
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func testParseReference(t *testing.T, fn func(string) (types.ImageReference, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// refWithTagAndDigest is a reference.XNamedTagged and reference.XCanonical at the same time.
|
// refWithTagAndDigest is a reference.NamedTagged and reference.XCanonical at the same time.
|
||||||
type refWithTagAndDigest struct{ reference.XCanonical }
|
type refWithTagAndDigest struct{ reference.XCanonical }
|
||||||
|
|
||||||
func (ref refWithTagAndDigest) Tag() string {
|
func (ref refWithTagAndDigest) Tag() string {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
// The reference must satisfy !reference.XIsNameOnly().
|
// The reference must satisfy !reference.XIsNameOnly().
|
||||||
func DockerReferenceIdentity(ref distreference.Named) (string, error) {
|
func DockerReferenceIdentity(ref distreference.Named) (string, error) {
|
||||||
res := ref.Name()
|
res := ref.Name()
|
||||||
tagged, isTagged := ref.(reference.XNamedTagged)
|
tagged, isTagged := ref.(distreference.NamedTagged)
|
||||||
digested, isDigested := ref.(reference.XCanonical)
|
digested, isDigested := ref.(reference.XCanonical)
|
||||||
switch {
|
switch {
|
||||||
case isTagged && isDigested: // This should not happen, docker/reference.XParseNamed drops the tag.
|
case isTagged && isDigested: // This should not happen, docker/reference.XParseNamed drops the tag.
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ func TestDockerReference(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// refWithTagAndDigest is a reference.XNamedTagged and reference.XCanonical at the same time.
|
// refWithTagAndDigest is a reference.NamedTagged and reference.XCanonical at the same time.
|
||||||
type refWithTagAndDigest struct{ reference.XCanonical }
|
type refWithTagAndDigest struct{ reference.XCanonical }
|
||||||
|
|
||||||
func (ref refWithTagAndDigest) Tag() string {
|
func (ref refWithTagAndDigest) Tag() string {
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,6 @@ const (
|
||||||
XDefaultRepoPrefix = "library/"
|
XDefaultRepoPrefix = "library/"
|
||||||
)
|
)
|
||||||
|
|
||||||
// XNamedTagged is an object including a name and tag.
|
|
||||||
type XNamedTagged interface {
|
|
||||||
distreference.NamedTagged
|
|
||||||
}
|
|
||||||
|
|
||||||
// XCanonical reference is an object with a fully unique
|
// XCanonical reference is an object with a fully unique
|
||||||
// name including a name with hostname and digest
|
// name including a name with hostname and digest
|
||||||
type XCanonical interface {
|
type XCanonical interface {
|
||||||
|
|
@ -74,7 +69,7 @@ func XWithName(name string) (*namedRef, error) {
|
||||||
|
|
||||||
// XWithTag combines the name from "name" and the tag from "tag" to form a
|
// XWithTag combines the name from "name" and the tag from "tag" to form a
|
||||||
// reference incorporating both the name and the tag.
|
// reference incorporating both the name and the tag.
|
||||||
func XWithTag(name distreference.Named, tag string) (XNamedTagged, error) {
|
func XWithTag(name distreference.Named, tag string) (distreference.NamedTagged, error) {
|
||||||
return distreference.WithTag(name, tag)
|
return distreference.WithTag(name, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,7 +120,7 @@ func XWithDefaultTag(ref distreference.Named) distreference.Named {
|
||||||
|
|
||||||
// XIsNameOnly returns true if reference only contains a repo name.
|
// XIsNameOnly returns true if reference only contains a repo name.
|
||||||
func XIsNameOnly(ref distreference.Named) bool {
|
func XIsNameOnly(ref distreference.Named) bool {
|
||||||
if _, ok := ref.(XNamedTagged); ok {
|
if _, ok := ref.(distreference.NamedTagged); ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if _, ok := ref.(XCanonical); ok {
|
if _, ok := ref.(XCanonical); ok {
|
||||||
|
|
|
||||||
|
|
@ -249,7 +249,7 @@ func TestParseReferenceWithTagAndDigest(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, isTagged := ref.(XNamedTagged); isTagged {
|
if _, isTagged := ref.(distreference.NamedTagged); isTagged {
|
||||||
t.Fatalf("Reference from %q should not support tag", ref)
|
t.Fatalf("Reference from %q should not support tag", ref)
|
||||||
}
|
}
|
||||||
if _, isCanonical := ref.(XCanonical); !isCanonical {
|
if _, isCanonical := ref.(XCanonical); !isCanonical {
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/image/docker/reference"
|
|
||||||
"github.com/containers/image/manifest"
|
"github.com/containers/image/manifest"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
distreference "github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
@ -70,11 +69,11 @@ func manifestSchema1FromManifest(manifest []byte) (genericManifest, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// manifestSchema1FromComponents builds a new manifestSchema1 from the supplied data.
|
// manifestSchema1FromComponents builds a new manifestSchema1 from the supplied data.
|
||||||
func manifestSchema1FromComponents(ref distreference.Named, fsLayers []fsLayersSchema1, history []historySchema1, architecture string) genericManifest {
|
func manifestSchema1FromComponents(ref reference.Named, fsLayers []fsLayersSchema1, history []historySchema1, architecture string) genericManifest {
|
||||||
var name, tag string
|
var name, tag string
|
||||||
if ref != nil { // Well, what to do if it _is_ nil? Most consumers actually don't use these fields nowadays, so we might as well try not supplying them.
|
if ref != nil { // Well, what to do if it _is_ nil? Most consumers actually don't use these fields nowadays, so we might as well try not supplying them.
|
||||||
name = distreference.Path(ref)
|
name = reference.Path(ref)
|
||||||
if tagged, ok := ref.(reference.XNamedTagged); ok {
|
if tagged, ok := ref.(reference.NamedTagged); ok {
|
||||||
tag = tagged.Tag()
|
tag = tagged.Tag()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ func (t openshiftTransport) ValidatePolicyConfigurationScope(scope string) error
|
||||||
|
|
||||||
// openshiftReference is an ImageReference for OpenShift images.
|
// openshiftReference is an ImageReference for OpenShift images.
|
||||||
type openshiftReference struct {
|
type openshiftReference struct {
|
||||||
dockerReference reference.XNamedTagged
|
dockerReference distreference.NamedTagged
|
||||||
namespace string // Computed from dockerReference in advance.
|
namespace string // Computed from dockerReference in advance.
|
||||||
stream string // Computed from dockerReference in advance.
|
stream string // Computed from dockerReference in advance.
|
||||||
}
|
}
|
||||||
|
|
@ -56,15 +56,15 @@ func ParseReference(ref string) (types.ImageReference, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to parse image reference %q", ref)
|
return nil, errors.Wrapf(err, "failed to parse image reference %q", ref)
|
||||||
}
|
}
|
||||||
tagged, ok := r.(reference.XNamedTagged)
|
tagged, ok := r.(distreference.NamedTagged)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.Errorf("invalid image reference %s, expected format: 'hostname/namespace/stream:tag'", ref)
|
return nil, errors.Errorf("invalid image reference %s, expected format: 'hostname/namespace/stream:tag'", ref)
|
||||||
}
|
}
|
||||||
return NewReference(tagged)
|
return NewReference(tagged)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewReference returns an OpenShift reference for a reference.XNamedTagged
|
// NewReference returns an OpenShift reference for a distreference.NamedTagged
|
||||||
func NewReference(dockerRef reference.XNamedTagged) (types.ImageReference, error) {
|
func NewReference(dockerRef distreference.NamedTagged) (types.ImageReference, error) {
|
||||||
r := strings.SplitN(distreference.Path(dockerRef), "/", 3)
|
r := strings.SplitN(distreference.Path(dockerRef), "/", 3)
|
||||||
if len(r) != 2 {
|
if len(r) != 2 {
|
||||||
return nil, errors.Errorf("invalid image reference: %s, expected format: 'hostname/namespace/stream:tag'",
|
return nil, errors.Errorf("invalid image reference: %s, expected format: 'hostname/namespace/stream:tag'",
|
||||||
|
|
|
||||||
|
|
@ -43,14 +43,14 @@ func TestNewReference(t *testing.T) {
|
||||||
// too many ns
|
// too many ns
|
||||||
r, err := reference.XParseNamed("registry.example.com/ns1/ns2/ns3/stream:tag")
|
r, err := reference.XParseNamed("registry.example.com/ns1/ns2/ns3/stream:tag")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tagged, ok := r.(reference.XNamedTagged)
|
tagged, ok := r.(distreference.NamedTagged)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
_, err = NewReference(tagged)
|
_, err = NewReference(tagged)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
r, err = reference.XParseNamed("registry.example.com/ns/stream:tag")
|
r, err = reference.XParseNamed("registry.example.com/ns/stream:tag")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tagged, ok = r.(reference.XNamedTagged)
|
tagged, ok = r.(distreference.NamedTagged)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
_, err = NewReference(tagged)
|
_, err = NewReference(tagged)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ func (prm *prmMatchRepoDigestOrExact) matchesDockerReference(image types.Unparse
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
switch intended.(type) {
|
switch intended.(type) {
|
||||||
case reference.XNamedTagged: // Includes the case when intended has both a tag and a digest.
|
case distreference.NamedTagged: // Includes the case when intended has both a tag and a digest.
|
||||||
return signature.String() == intended.String()
|
return signature.String() == intended.String()
|
||||||
case reference.XCanonical:
|
case reference.XCanonical:
|
||||||
// We don’t actually compare the manifest digest against the signature here; that happens prSignedBy.in UnparsedImage.Manifest.
|
// We don’t actually compare the manifest digest against the signature here; that happens prSignedBy.in UnparsedImage.Manifest.
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,7 @@ func (s storageTransport) ValidatePolicyConfigurationScope(scope string) error {
|
||||||
func verboseName(name distreference.Named) string {
|
func verboseName(name distreference.Named) string {
|
||||||
name = reference.XWithDefaultTag(name)
|
name = reference.XWithDefaultTag(name)
|
||||||
tag := ""
|
tag := ""
|
||||||
if tagged, ok := name.(reference.XNamedTagged); ok {
|
if tagged, ok := name.(distreference.NamedTagged); ok {
|
||||||
tag = tagged.Tag()
|
tag = tagged.Tag()
|
||||||
}
|
}
|
||||||
return name.Name() + ":" + tag
|
return name.Name() + ":" + tag
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue