Skip to content

Commit

Permalink
remote internal ArtifactDescriptor
Browse files Browse the repository at this point in the history
Signed-off-by: Aviral Takkar <aviral26@users.noreply.github.com>
  • Loading branch information
aviral26 committed Sep 1, 2021
1 parent 3a69fd4 commit 6aeabcf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 28 deletions.
20 changes: 2 additions & 18 deletions manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"mime"

"github.com/opencontainers/go-digest"
orasartifact "github.com/oras-project/artifacts-spec/specs-go/v1"
)

// Manifest represents a registry object specifying a set of
Expand Down Expand Up @@ -47,23 +48,6 @@ type ManifestBuilder interface {
AppendReference(dependency Describable) error
}

// ArtifactDescriptor describes targeted reference type content.
type ArtifactDescriptor struct {
// MediaType describe the type of the content. All text based formats are
// encoded as utf-8.
MediaType string `json:"mediaType,omitempty"`

// Size in bytes of content.
Size int64 `json:"size,omitempty"`

// Digest uniquely identifies the content. A byte stream can be verified
// against this digest.
Digest string `json:"digest,omitempty"`

// ArtifactType specifies the artifact type of the content.
ArtifactType string `json:"artifactType,omitempty"`
}

// ManifestService describes operations on image manifests.
type ManifestService interface {
// Exists returns true if the manifest exists.
Expand All @@ -81,7 +65,7 @@ type ManifestService interface {

// Referrers returns a collection of manifests which reference the given manifest,
// filtered by artifactType.
Referrers(ctx context.Context, dgst digest.Digest, artifactType string) ([]ArtifactDescriptor, error)
Referrers(ctx context.Context, dgst digest.Digest, artifactType string) ([]orasartifact.Descriptor, error)
}

// ManifestEnumerator enables iterating over manifests
Expand Down
3 changes: 2 additions & 1 deletion registry/client/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/distribution/distribution/v3/registry/storage/cache"
"github.com/distribution/distribution/v3/registry/storage/cache/memory"
"github.com/opencontainers/go-digest"
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
)

// Registry provides an interface for calling Repositories, which returns a catalog of repositories.
Expand Down Expand Up @@ -397,7 +398,7 @@ type manifests struct {
etags map[string]string
}

func (ms *manifests) Referrers(_ context.Context, _ digest.Digest, _ string) ([]distribution.ArtifactDescriptor, error) {
func (ms *manifests) Referrers(_ context.Context, _ digest.Digest, _ string) ([]orasartifacts.Descriptor, error) {
return nil, fmt.Errorf("not implemented")
}

Expand Down
7 changes: 4 additions & 3 deletions registry/handlers/referrers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"net/http"

"github.com/distribution/distribution/v3"
dcontext "github.com/distribution/distribution/v3/context"
"github.com/distribution/distribution/v3/registry/api/errcode"
v2 "github.com/distribution/distribution/v3/registry/api/v2"
dcontext "github.com/distribution/distribution/v3/context"
"github.com/gorilla/handlers"
"github.com/opencontainers/go-digest"
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
)

// referrersDispatcher takes the request context and builds the
Expand All @@ -29,7 +30,7 @@ func referrersDispatcher(ctx *Context, r *http.Request) http.Handler {

// referrersResponse describes the response body of the referrers API.
type referrersResponse struct {
Referrers []distribution.ArtifactDescriptor `json:"references"`
Referrers []orasartifacts.Descriptor `json:"references"`
}

// referrersHandler handles http operations on manifest referrers.
Expand Down Expand Up @@ -70,7 +71,7 @@ func (h *referrersHandler) Get(w http.ResponseWriter, r *http.Request) {
}

if referrers == nil {
referrers = []distribution.ArtifactDescriptor{}
referrers = []orasartifacts.Descriptor{}
}

response := referrersResponse{}
Expand Down
3 changes: 2 additions & 1 deletion registry/proxy/proxymanifeststore.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/distribution/distribution/v3/reference"
"github.com/distribution/distribution/v3/registry/proxy/scheduler"
"github.com/opencontainers/go-digest"
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
)

// todo(richardscothern): from cache control header or config
Expand All @@ -25,7 +26,7 @@ type proxyManifestStore struct {

var _ distribution.ManifestService = &proxyManifestStore{}

func (pms proxyManifestStore) Referrers(_ context.Context, _ digest.Digest, _ string) ([]distribution.ArtifactDescriptor, error) {
func (pms proxyManifestStore) Referrers(_ context.Context, _ digest.Digest, _ string) ([]orasartifacts.Descriptor, error) {
return nil, distribution.ErrUnsupported
}

Expand Down
3 changes: 2 additions & 1 deletion registry/proxy/proxymanifeststore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/distribution/distribution/v3/testutil"
"github.com/docker/libtrust"
"github.com/opencontainers/go-digest"
orasartifacts "github.com/oras-project/artifacts-spec/specs-go/v1"
)

type statsManifest struct {
Expand Down Expand Up @@ -61,7 +62,7 @@ func (sm statsManifest) Put(ctx context.Context, manifest distribution.Manifest,
return sm.manifests.Put(ctx, manifest)
}

func (sm statsManifest) Referrers(ctx context.Context, dgst digest.Digest, referrerType string) ([]distribution.ArtifactDescriptor, error) {
func (sm statsManifest) Referrers(ctx context.Context, dgst digest.Digest, referrerType string) ([]orasartifacts.Descriptor, error) {
sm.stats["referrers"]++
return sm.Referrers(ctx, dgst, referrerType)
}
Expand Down
8 changes: 4 additions & 4 deletions registry/storage/manifeststore.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ func (ms *manifestStore) Put(ctx context.Context, manifest distribution.Manifest
}

// Referrers returns referrer manifests filtered by the given referrerType.
func (ms *manifestStore) Referrers(ctx context.Context, revision digest.Digest, referrerType string) ([]distribution.ArtifactDescriptor, error) {
func (ms *manifestStore) Referrers(ctx context.Context, revision digest.Digest, referrerType string) ([]orasartifactv1.Descriptor, error) {
dcontext.GetLogger(ms.ctx).Debug("(*manifestStore).Referrers")

var referrers []distribution.ArtifactDescriptor
var referrers []orasartifactv1.Descriptor

err := ms.referrersStore(ctx, revision, referrerType).Enumerate(ctx, func(referrerRevision digest.Digest) error {
man, err := ms.Get(ctx, referrerRevision)
Expand All @@ -184,10 +184,10 @@ func (ms *manifestStore) Referrers(ctx context.Context, revision digest.Digest,
return err
}
desc.MediaType, _, _ = man.Payload()
referrers = append(referrers, distribution.ArtifactDescriptor{
referrers = append(referrers, orasartifactv1.Descriptor{
MediaType: desc.MediaType,
Size: desc.Size,
Digest: desc.Digest.String(),
Digest: desc.Digest,
ArtifactType: orasArtifactMan.ArtifactType(),
})
return nil
Expand Down

0 comments on commit 6aeabcf

Please sign in to comment.