mirror of https://github.com/containers/image.git
API transition: Drop reference.XCanonical
Instead use distreference.Canonical directly. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
parent
c91c7c2ebb
commit
cc0f48aa03
|
|
@ -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!
|
||||
// docker/reference does not handle that, so fail.
|
||||
_, isTagged := ref.(distreference.NamedTagged)
|
||||
_, isDigested := ref.(reference.XCanonical)
|
||||
_, isDigested := ref.(distreference.Canonical)
|
||||
if isTagged && isDigested {
|
||||
return nil, errors.Errorf("docker-daemon: references with both a tag and digest are currently not supported")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/containers/image/docker/reference"
|
||||
"github.com/containers/image/types"
|
||||
distreference "github.com/docker/distribution/reference"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"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.
|
||||
type refWithTagAndDigest struct{ reference.XCanonical }
|
||||
// refWithTagAndDigest is a reference.NamedTagged and reference.Canonical at the same time.
|
||||
type refWithTagAndDigest struct{ distreference.Canonical }
|
||||
|
||||
func (ref refWithTagAndDigest) Tag() string {
|
||||
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!
|
||||
parsed, err = reference.XParseNamed("busybox@" + sha256digest)
|
||||
require.NoError(t, err)
|
||||
refDigested, ok := parsed.(reference.XCanonical)
|
||||
refDigested, ok := parsed.(distreference.Canonical)
|
||||
require.True(t, ok)
|
||||
tagDigestRef := refWithTagAndDigest{refDigested}
|
||||
_, err = NewReference("", tagDigestRef)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// the tag or the digest first?)
|
||||
_, isTagged := ref.(distreference.NamedTagged)
|
||||
_, isDigested := ref.(reference.XCanonical)
|
||||
_, isDigested := ref.(distreference.Canonical)
|
||||
if isTagged && isDigested {
|
||||
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.
|
||||
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
|
||||
}
|
||||
if ref, ok := ref.ref.(distreference.NamedTagged); ok {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/containers/image/docker/reference"
|
||||
"github.com/containers/image/types"
|
||||
distreference "github.com/docker/distribution/reference"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"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.
|
||||
type refWithTagAndDigest struct{ reference.XCanonical }
|
||||
// refWithTagAndDigest is a reference.NamedTagged and reference.Canonical at the same time.
|
||||
type refWithTagAndDigest struct{ distreference.Canonical }
|
||||
|
||||
func (ref refWithTagAndDigest) Tag() string {
|
||||
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!
|
||||
parsed, err = reference.XParseNamed("busybox" + sha256digest)
|
||||
require.NoError(t, err)
|
||||
refDigested, ok := parsed.(reference.XCanonical)
|
||||
refDigested, ok := parsed.(distreference.Canonical)
|
||||
require.True(t, ok)
|
||||
tagDigestRef := refWithTagAndDigest{refDigested}
|
||||
_, err = NewReference(tagDigestRef)
|
||||
|
|
|
|||
|
|
@ -3,24 +3,22 @@ package policyconfiguration
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
"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,
|
||||
// as a backend for ImageReference.PolicyConfigurationIdentity.
|
||||
// The reference must satisfy !reference.XIsNameOnly().
|
||||
func DockerReferenceIdentity(ref distreference.Named) (string, error) {
|
||||
func DockerReferenceIdentity(ref reference.Named) (string, error) {
|
||||
res := ref.Name()
|
||||
tagged, isTagged := ref.(distreference.NamedTagged)
|
||||
digested, isDigested := ref.(reference.XCanonical)
|
||||
tagged, isTagged := ref.(reference.NamedTagged)
|
||||
digested, isDigested := ref.(reference.Canonical)
|
||||
switch {
|
||||
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()
|
||||
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:
|
||||
res = res + ":" + tagged.Tag()
|
||||
case isDigested:
|
||||
|
|
@ -34,7 +32,7 @@ func DockerReferenceIdentity(ref distreference.Named) (string, error) {
|
|||
// DockerReferenceNamespaces returns a list of other policy configuration namespaces to search,
|
||||
// as a backend for ImageReference.PolicyConfigurationIdentity.
|
||||
// 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
|
||||
// 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",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/containers/image/docker/reference"
|
||||
distreference "github.com/docker/distribution/reference"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"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.
|
||||
type refWithTagAndDigest struct{ reference.XCanonical }
|
||||
// refWithTagAndDigest is a reference.NamedTagged and reference.Canonical at the same time.
|
||||
type refWithTagAndDigest struct{ distreference.Canonical }
|
||||
|
||||
func (ref refWithTagAndDigest) Tag() string {
|
||||
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!
|
||||
parsed, err = reference.XParseNamed("busybox@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
|
||||
require.NoError(t, err)
|
||||
refDigested, ok := parsed.(reference.XCanonical)
|
||||
refDigested, ok := parsed.(distreference.Canonical)
|
||||
require.True(t, ok)
|
||||
tagDigestRef := refWithTagAndDigest{refDigested}
|
||||
id, err = DockerReferenceIdentity(tagDigestRef)
|
||||
|
|
|
|||
|
|
@ -23,12 +23,6 @@ const (
|
|||
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
|
||||
// the Named interface. The reference must have a name, otherwise an error is
|
||||
// returned.
|
||||
|
|
@ -104,7 +98,7 @@ func XIsNameOnly(ref distreference.Named) bool {
|
|||
if _, ok := ref.(distreference.NamedTagged); ok {
|
||||
return false
|
||||
}
|
||||
if _, ok := ref.(XCanonical); ok {
|
||||
if _, ok := ref.(distreference.Canonical); ok {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ func TestParseReferenceWithTagAndDigest(t *testing.T) {
|
|||
if _, isTagged := ref.(distreference.NamedTagged); isTagged {
|
||||
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)
|
||||
}
|
||||
if expected, actual := "busybox@sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa", distreference.FamiliarString(ref); actual != expected {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package image
|
||||
|
||||
import (
|
||||
"github.com/containers/image/docker/reference"
|
||||
"github.com/containers/image/manifest"
|
||||
"github.com/containers/image/types"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
|
@ -52,7 +52,7 @@ func (i *UnparsedImage) Manifest() ([]byte, string, error) {
|
|||
// this immediately protects also any user of types.Image.
|
||||
ref := i.Reference().DockerReference()
|
||||
if ref != nil {
|
||||
if canonical, ok := ref.(reference.XCanonical); ok {
|
||||
if canonical, ok := ref.(reference.Canonical); ok {
|
||||
digest := digest.Digest(canonical.Digest())
|
||||
matches, err := manifest.MatchesDigest(m, digest)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func (prm *prmMatchRepoDigestOrExact) matchesDockerReference(image types.Unparse
|
|||
switch intended.(type) {
|
||||
case distreference.NamedTagged: // Includes the case when intended has both a tag and a digest.
|
||||
return signature.String() == intended.String()
|
||||
case reference.XCanonical:
|
||||
case distreference.Canonical:
|
||||
// We don’t 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,
|
||||
// we know that signature digest matches intended.Digest() (but intended.Digest() and signature digest may use different algorithms)
|
||||
|
|
|
|||
Loading…
Reference in New Issue