Descriptor: do not implement Describable interface
Commitcb6f002350
implemented a generic Manifest interface to represent manifests in the registry and remove references to schema specific manifests. As part of this refactor, the Describable interface was introduced, which allowed for a single ManifestBuilder interface to handle both schema1 and schema2 manifests. Implementations of Describable are generally objects which can be described, not simply descriptors, but for convenience, this interface was also implemented on Descriptor in2ff77c00ba
. This interface served its purpose, but no longer needed for most cases; schema2 (and OCI) descriptors do not need this method, making it only needed for `schema1.Reference`, which is now deprecated. Requiring this interface to be implemented limits interoperability between distribution's Descriptor and the OCI Descriptor types, which are identical in every other way, except for the presence of the Describable interface. This patch: - Removes the `Descriptor.Descriptor()` method (no longer implementing the `Describable` interface). - Updates ManifestBuilder interface and implementations to accept either a `Descriptor`, a `Describable`, or (for schema1), a `schema1.Reference`. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
29b5e79f82
commit
4b146db990
6 changed files with 53 additions and 19 deletions
9
blobs.go
9
blobs.go
|
@ -85,15 +85,6 @@ type Descriptor struct {
|
|||
// depend on the simplicity of this type.
|
||||
}
|
||||
|
||||
// Descriptor returns the descriptor, to make it satisfy the Describable
|
||||
// interface. Note that implementations of Describable are generally objects
|
||||
// which can be described, not simply descriptors; this exception is in place
|
||||
// to make it more convenient to pass actual descriptors to functions that
|
||||
// expect Describable objects.
|
||||
func (d Descriptor) Descriptor() Descriptor {
|
||||
return d
|
||||
}
|
||||
|
||||
// BlobStatter makes blob descriptors available by digest. The service may
|
||||
// provide a descriptor of a different digest if the provided digest is not
|
||||
// canonical.
|
||||
|
|
|
@ -96,8 +96,20 @@ func (mb *Builder) Build(ctx context.Context) (distribution.Manifest, error) {
|
|||
}
|
||||
|
||||
// AppendReference adds a reference to the current ManifestBuilder.
|
||||
func (mb *Builder) AppendReference(d distribution.Describable) error {
|
||||
mb.layers = append(mb.layers, d.Descriptor())
|
||||
//
|
||||
// The reference must be either a [distribution.Descriptor] or a
|
||||
// [distribution.Describable].
|
||||
func (mb *Builder) AppendReference(reference any) error {
|
||||
var descriptor distribution.Descriptor
|
||||
if dt, ok := reference.(distribution.Descriptor); ok {
|
||||
descriptor = dt
|
||||
} else if dt, ok := reference.(distribution.Describable); ok {
|
||||
descriptor = dt.Descriptor()
|
||||
} else {
|
||||
return errors.New("invalid type for reference: should be either a Descriptor or a Describable")
|
||||
}
|
||||
|
||||
mb.layers = append(mb.layers, descriptor)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -247,10 +247,20 @@ func (mb *configManifestBuilder) emptyTar(ctx context.Context) (digest.Digest, e
|
|||
|
||||
// AppendReference adds a reference to the current ManifestBuilder.
|
||||
//
|
||||
// The reference must be either a [distribution.Descriptor] or a
|
||||
// [distribution.Describable].
|
||||
//
|
||||
// Deprecated: Docker Image Manifest v2, Schema 1 is deprecated since 2015.
|
||||
// Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification.
|
||||
func (mb *configManifestBuilder) AppendReference(d distribution.Describable) error {
|
||||
descriptor := d.Descriptor()
|
||||
func (mb *configManifestBuilder) AppendReference(reference any) error {
|
||||
var descriptor distribution.Descriptor
|
||||
if dt, ok := reference.(distribution.Descriptor); ok {
|
||||
descriptor = dt
|
||||
} else if dt, ok := reference.(distribution.Describable); ok {
|
||||
descriptor = dt.Descriptor()
|
||||
} else {
|
||||
return errors.New("invalid type for reference: should be either a Descriptor or a Describable")
|
||||
}
|
||||
|
||||
if err := descriptor.Digest.Validate(); err != nil {
|
||||
return err
|
||||
|
|
|
@ -59,10 +59,12 @@ func (mb *referenceManifestBuilder) Build(ctx context.Context) (distribution.Man
|
|||
|
||||
// AppendReference adds a reference to the current ManifestBuilder.
|
||||
//
|
||||
// The reference must be a [Reference].
|
||||
//
|
||||
// Deprecated: Docker Image Manifest v2, Schema 1 is deprecated since 2015.
|
||||
// Use Docker Image Manifest v2, Schema 2, or the OCI Image Specification.
|
||||
func (mb *referenceManifestBuilder) AppendReference(d distribution.Describable) error {
|
||||
r, ok := d.(Reference)
|
||||
func (mb *referenceManifestBuilder) AppendReference(reference any) error {
|
||||
r, ok := reference.(Reference)
|
||||
if !ok {
|
||||
return fmt.Errorf("unable to add non-reference type to v1 builder")
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package schema2
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/distribution/distribution/v3"
|
||||
"github.com/opencontainers/go-digest"
|
||||
|
@ -74,8 +75,20 @@ func (mb *builder) Build(ctx context.Context) (distribution.Manifest, error) {
|
|||
}
|
||||
|
||||
// AppendReference adds a reference to the current ManifestBuilder.
|
||||
func (mb *builder) AppendReference(d distribution.Describable) error {
|
||||
mb.dependencies = append(mb.dependencies, d.Descriptor())
|
||||
//
|
||||
// The reference must be either a [distribution.Descriptor] or a
|
||||
// [distribution.Describable].
|
||||
func (mb *builder) AppendReference(d any) error {
|
||||
var descriptor distribution.Descriptor
|
||||
if dt, ok := d.(distribution.Descriptor); ok {
|
||||
descriptor = dt
|
||||
} else if dt, ok := d.(distribution.Describable); ok {
|
||||
descriptor = dt.Descriptor()
|
||||
} else {
|
||||
return errors.New("invalid type for reference: should be either a Descriptor or a Describable")
|
||||
}
|
||||
|
||||
mb.dependencies = append(mb.dependencies, descriptor)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
10
manifests.go
10
manifests.go
|
@ -44,7 +44,9 @@ type ManifestBuilder interface {
|
|||
//
|
||||
// The destination of the reference is dependent on the manifest type and
|
||||
// the dependency type.
|
||||
AppendReference(dependency Describable) error
|
||||
//
|
||||
// The dependency must be either a [Descriptor] or a [Describable].
|
||||
AppendReference(dependency any) error
|
||||
}
|
||||
|
||||
// ManifestService describes operations on image manifests.
|
||||
|
@ -69,8 +71,12 @@ type ManifestEnumerator interface {
|
|||
Enumerate(ctx context.Context, ingester func(digest.Digest) error) error
|
||||
}
|
||||
|
||||
// Describable is an interface for descriptors
|
||||
// Describable is an interface for descriptors.
|
||||
//
|
||||
// Implementations of Describable are generally objects which can be
|
||||
// described, not simply descriptors.
|
||||
type Describable interface {
|
||||
// Descriptor returns the descriptor.
|
||||
Descriptor() Descriptor
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue