From f1c8c414080c0cec46355c02cd42a1b5304b6788 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 30 Apr 2023 17:53:17 +0200 Subject: [PATCH] Descriptor: do not implement Describable interface Commit cb6f0023500c3d2afb8c9f3ee4a0097526192156 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 in 2ff77c00bad887928be04367f0dd58f6aed5b756. 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 - Updates ManifestBuilder interface and implementations to accept a `Descriptor`. After this patch, the caller is responsible for changing a describable type into a descriptor; builder.AppendReference(describable.Descriptor()) Signed-off-by: Sebastiaan van Stijn --- blobs.go | 9 --------- manifest/ocischema/builder.go | 4 ++-- manifest/schema2/builder.go | 4 ++-- manifests.go | 6 +++++- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/blobs.go b/blobs.go index 3f81f35cb..000430b14 100644 --- a/blobs.go +++ b/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. diff --git a/manifest/ocischema/builder.go b/manifest/ocischema/builder.go index 736910a9c..204f2ee10 100644 --- a/manifest/ocischema/builder.go +++ b/manifest/ocischema/builder.go @@ -96,8 +96,8 @@ 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()) +func (mb *Builder) AppendReference(ref distribution.Descriptor) error { + mb.layers = append(mb.layers, ref) return nil } diff --git a/manifest/schema2/builder.go b/manifest/schema2/builder.go index 97cf12a0e..d432ad60b 100644 --- a/manifest/schema2/builder.go +++ b/manifest/schema2/builder.go @@ -46,8 +46,8 @@ 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()) +func (mb *Builder) AppendReference(ref distribution.Descriptor) error { + mb.dependencies = append(mb.dependencies, ref) return nil } diff --git a/manifests.go b/manifests.go index 04558c654..97b246d20 100644 --- a/manifests.go +++ b/manifests.go @@ -48,8 +48,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 }