API transition: Drop reference.XCanonical

Instead use distreference.Canonical directly.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač 2017-01-20 07:22:38 +01:00
parent c91c7c2ebb
commit cc0f48aa03
10 changed files with 27 additions and 32 deletions

View File

@ -83,7 +83,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.(distreference.NamedTagged) _, isTagged := ref.(distreference.NamedTagged)
_, isDigested := ref.(reference.XCanonical) _, isDigested := ref.(distreference.Canonical)
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")
} }

View File

@ -5,6 +5,7 @@ import (
"github.com/containers/image/docker/reference" "github.com/containers/image/docker/reference"
"github.com/containers/image/types" "github.com/containers/image/types"
distreference "github.com/docker/distribution/reference"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -90,8 +91,8 @@ func testParseReference(t *testing.T, fn func(string) (types.ImageReference, err
} }
} }
// refWithTagAndDigest is a reference.NamedTagged and reference.XCanonical at the same time. // refWithTagAndDigest is a reference.NamedTagged and reference.Canonical at the same time.
type refWithTagAndDigest struct{ reference.XCanonical } type refWithTagAndDigest struct{ distreference.Canonical }
func (ref refWithTagAndDigest) Tag() string { func (ref refWithTagAndDigest) Tag() string {
return "notLatest" return "notLatest"
@ -145,7 +146,7 @@ func TestNewReference(t *testing.T) {
// 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!
parsed, err = reference.XParseNamed("busybox@" + sha256digest) parsed, err = reference.XParseNamed("busybox@" + sha256digest)
require.NoError(t, err) require.NoError(t, err)
refDigested, ok := parsed.(reference.XCanonical) refDigested, ok := parsed.(distreference.Canonical)
require.True(t, ok) require.True(t, ok)
tagDigestRef := refWithTagAndDigest{refDigested} tagDigestRef := refWithTagAndDigest{refDigested}
_, err = NewReference("", tagDigestRef) _, err = NewReference("", tagDigestRef)

View File

@ -64,7 +64,7 @@ func NewReference(ref distreference.Named) (types.ImageReference, error) {
// (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.(distreference.NamedTagged) _, isTagged := ref.(distreference.NamedTagged)
_, isDigested := ref.(reference.XCanonical) _, isDigested := ref.(distreference.Canonical)
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")
} }
@ -146,7 +146,7 @@ func (ref dockerReference) DeleteImage(ctx *types.SystemContext) error {
// tagOrDigest returns a tag or digest from the reference. // tagOrDigest returns a tag or digest from the reference.
func (ref dockerReference) tagOrDigest() (string, error) { func (ref dockerReference) tagOrDigest() (string, error) {
if ref, ok := ref.ref.(reference.XCanonical); ok { if ref, ok := ref.ref.(distreference.Canonical); ok {
return ref.Digest().String(), nil return ref.Digest().String(), nil
} }
if ref, ok := ref.ref.(distreference.NamedTagged); ok { if ref, ok := ref.ref.(distreference.NamedTagged); ok {

View File

@ -5,6 +5,7 @@ import (
"github.com/containers/image/docker/reference" "github.com/containers/image/docker/reference"
"github.com/containers/image/types" "github.com/containers/image/types"
distreference "github.com/docker/distribution/reference"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -67,8 +68,8 @@ func testParseReference(t *testing.T, fn func(string) (types.ImageReference, err
} }
} }
// refWithTagAndDigest is a reference.NamedTagged and reference.XCanonical at the same time. // refWithTagAndDigest is a reference.NamedTagged and reference.Canonical at the same time.
type refWithTagAndDigest struct{ reference.XCanonical } type refWithTagAndDigest struct{ distreference.Canonical }
func (ref refWithTagAndDigest) Tag() string { func (ref refWithTagAndDigest) Tag() string {
return "notLatest" return "notLatest"
@ -102,7 +103,7 @@ func TestNewReference(t *testing.T) {
// 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!
parsed, err = reference.XParseNamed("busybox" + sha256digest) parsed, err = reference.XParseNamed("busybox" + sha256digest)
require.NoError(t, err) require.NoError(t, err)
refDigested, ok := parsed.(reference.XCanonical) refDigested, ok := parsed.(distreference.Canonical)
require.True(t, ok) require.True(t, ok)
tagDigestRef := refWithTagAndDigest{refDigested} tagDigestRef := refWithTagAndDigest{refDigested}
_, err = NewReference(tagDigestRef) _, err = NewReference(tagDigestRef)

View File

@ -3,24 +3,22 @@ package policyconfiguration
import ( import (
"strings" "strings"
"github.com/docker/distribution/reference"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/containers/image/docker/reference"
distreference "github.com/docker/distribution/reference"
) )
// DockerReferenceIdentity returns a string representation of the reference, suitable for policy lookup, // DockerReferenceIdentity returns a string representation of the reference, suitable for policy lookup,
// as a backend for ImageReference.PolicyConfigurationIdentity. // as a backend for ImageReference.PolicyConfigurationIdentity.
// The reference must satisfy !reference.XIsNameOnly(). // The reference must satisfy !reference.XIsNameOnly().
func DockerReferenceIdentity(ref distreference.Named) (string, error) { func DockerReferenceIdentity(ref reference.Named) (string, error) {
res := ref.Name() res := ref.Name()
tagged, isTagged := ref.(distreference.NamedTagged) tagged, isTagged := ref.(reference.NamedTagged)
digested, isDigested := ref.(reference.XCanonical) digested, isDigested := ref.(reference.Canonical)
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.
return "", errors.Errorf("Unexpected Docker reference %s with both a name and a digest", distreference.FamiliarString(ref)) return "", errors.Errorf("Unexpected Docker reference %s with both a name and a digest", reference.FamiliarString(ref))
case !isTagged && !isDigested: // This should not happen, the caller is expected to ensure !reference.XIsNameOnly() case !isTagged && !isDigested: // This should not happen, the caller is expected to ensure !reference.XIsNameOnly()
return "", errors.Errorf("Internal inconsistency: Docker reference %s with neither a tag nor a digest", distreference.FamiliarString(ref)) return "", errors.Errorf("Internal inconsistency: Docker reference %s with neither a tag nor a digest", reference.FamiliarString(ref))
case isTagged: case isTagged:
res = res + ":" + tagged.Tag() res = res + ":" + tagged.Tag()
case isDigested: case isDigested:
@ -34,7 +32,7 @@ func DockerReferenceIdentity(ref distreference.Named) (string, error) {
// DockerReferenceNamespaces returns a list of other policy configuration namespaces to search, // DockerReferenceNamespaces returns a list of other policy configuration namespaces to search,
// as a backend for ImageReference.PolicyConfigurationIdentity. // as a backend for ImageReference.PolicyConfigurationIdentity.
// The reference must satisfy !reference.XIsNameOnly(). // The reference must satisfy !reference.XIsNameOnly().
func DockerReferenceNamespaces(ref distreference.Named) []string { func DockerReferenceNamespaces(ref reference.Named) []string {
// Look for a match of the repository, and then of the possible parent // Look for a match of the repository, and then of the possible parent
// namespaces. Note that this only happens on the expanded host names // namespaces. Note that this only happens on the expanded host names
// and repository names, i.e. "busybox" is looked up as "docker.io/library/busybox", // and repository names, i.e. "busybox" is looked up as "docker.io/library/busybox",

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"github.com/containers/image/docker/reference" "github.com/containers/image/docker/reference"
distreference "github.com/docker/distribution/reference"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -62,8 +63,8 @@ func TestDockerReference(t *testing.T) {
} }
} }
// refWithTagAndDigest is a reference.NamedTagged and reference.XCanonical at the same time. // refWithTagAndDigest is a reference.NamedTagged and reference.Canonical at the same time.
type refWithTagAndDigest struct{ reference.XCanonical } type refWithTagAndDigest struct{ distreference.Canonical }
func (ref refWithTagAndDigest) Tag() string { func (ref refWithTagAndDigest) Tag() string {
return "notLatest" return "notLatest"
@ -82,7 +83,7 @@ func TestDockerReferenceIdentity(t *testing.T) {
// 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!
parsed, err = reference.XParseNamed("busybox@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") parsed, err = reference.XParseNamed("busybox@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
require.NoError(t, err) require.NoError(t, err)
refDigested, ok := parsed.(reference.XCanonical) refDigested, ok := parsed.(distreference.Canonical)
require.True(t, ok) require.True(t, ok)
tagDigestRef := refWithTagAndDigest{refDigested} tagDigestRef := refWithTagAndDigest{refDigested}
id, err = DockerReferenceIdentity(tagDigestRef) id, err = DockerReferenceIdentity(tagDigestRef)

View File

@ -23,12 +23,6 @@ const (
XDefaultRepoPrefix = "library/" XDefaultRepoPrefix = "library/"
) )
// XCanonical reference is an object with a fully unique
// name including a name with hostname and digest
type XCanonical interface {
distreference.Canonical
}
// XParseNamed parses s and returns a syntactically valid reference implementing // XParseNamed parses s and returns a syntactically valid reference implementing
// the Named interface. The reference must have a name, otherwise an error is // the Named interface. The reference must have a name, otherwise an error is
// returned. // returned.
@ -104,7 +98,7 @@ func XIsNameOnly(ref distreference.Named) bool {
if _, ok := ref.(distreference.NamedTagged); ok { if _, ok := ref.(distreference.NamedTagged); ok {
return false return false
} }
if _, ok := ref.(XCanonical); ok { if _, ok := ref.(distreference.Canonical); ok {
return false return false
} }
return true return true

View File

@ -252,7 +252,7 @@ func TestParseReferenceWithTagAndDigest(t *testing.T) {
if _, isTagged := ref.(distreference.NamedTagged); 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.(distreference.Canonical); !isCanonical {
t.Fatalf("Reference from %q should not support digest", ref) t.Fatalf("Reference from %q should not support digest", ref)
} }
if expected, actual := "busybox@sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa", distreference.FamiliarString(ref); actual != expected { if expected, actual := "busybox@sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa", distreference.FamiliarString(ref); actual != expected {

View File

@ -1,9 +1,9 @@
package image package image
import ( import (
"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/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -52,7 +52,7 @@ func (i *UnparsedImage) Manifest() ([]byte, string, error) {
// this immediately protects also any user of types.Image. // this immediately protects also any user of types.Image.
ref := i.Reference().DockerReference() ref := i.Reference().DockerReference()
if ref != nil { if ref != nil {
if canonical, ok := ref.(reference.XCanonical); ok { if canonical, ok := ref.(reference.Canonical); ok {
digest := digest.Digest(canonical.Digest()) digest := digest.Digest(canonical.Digest())
matches, err := manifest.MatchesDigest(m, digest) matches, err := manifest.MatchesDigest(m, digest)
if err != nil { if err != nil {

View File

@ -50,7 +50,7 @@ func (prm *prmMatchRepoDigestOrExact) matchesDockerReference(image types.Unparse
switch intended.(type) { switch intended.(type) {
case distreference.NamedTagged: // 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 distreference.Canonical:
// We dont actually compare the manifest digest against the signature here; that happens prSignedBy.in UnparsedImage.Manifest. // We dont actually compare the manifest digest against the signature here; that happens prSignedBy.in UnparsedImage.Manifest.
// Becase UnparsedImage.Manifest verifies the intended.Digest() against the manifest, and prSignedBy verifies the signature digest against the manifest, // Becase UnparsedImage.Manifest verifies the intended.Digest() against the manifest, and prSignedBy verifies the signature digest against the manifest,
// we know that signature digest matches intended.Digest() (but intended.Digest() and signature digest may use different algorithms) // we know that signature digest matches intended.Digest() (but intended.Digest() and signature digest may use different algorithms)