Skip to content

Commit

Permalink
Support private registry in oras (#102)
Browse files Browse the repository at this point in the history
Signed-off-by: Tejaswini Duggaraju <naduggar@microsoft.com>
  • Loading branch information
mnltejaswini authored Nov 30, 2021
1 parent a57f4b9 commit 2628973
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/xlab/treeprint v1.1.0
oras.land/oras-go v0.5.1-0.20211118233813-9ec21342ac6c
oras.land/oras-go v0.5.1-0.20211129233629-3b1e924da9d7
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2530,8 +2530,8 @@ mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jC
mvdan.cc/unparam v0.0.0-20210104141923-aac4ce9116a7/go.mod h1:hBpJkZE8H/sb+VRFvw2+rBpHNsTBcvSpk61hr8mzXZE=
nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
oras.land/oras-go v0.5.1-0.20211118233813-9ec21342ac6c h1:ahEyjNEVBRqxTZglDwnUgapWmeHCZe4kDOQwN6epf6g=
oras.land/oras-go v0.5.1-0.20211118233813-9ec21342ac6c/go.mod h1:s/Q8+g2H7MHrEImZfquIA+RpBdV7fb4CQDff10i/DQ4=
oras.land/oras-go v0.5.1-0.20211129233629-3b1e924da9d7 h1:iCxH9uBANXN6z4OLwblnrOabOtcUnc3ylv5TpXhQ/ts=
oras.land/oras-go v0.5.1-0.20211129233629-3b1e924da9d7/go.mod h1:s/Q8+g2H7MHrEImZfquIA+RpBdV7fb4CQDff10i/DQ4=
pack.ag/amqp v0.11.2/go.mod h1:4/cbmt4EJXSKlG6LCfWHoqmN0uFdy5i/+YFz+fTfhV4=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
Expand Down
21 changes: 4 additions & 17 deletions pkg/referrerstore/oras/oras.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"encoding/json"
"fmt"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
oci "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/pkg/content"
"oras.land/oras-go/pkg/oras"
Expand Down Expand Up @@ -105,12 +103,13 @@ func (store *orasStore) ListReferrers(ctx context.Context, subjectReference comm
return referrerstore.ListReferrersResult{}, err
}

ref := fmt.Sprintf("%s@%s", subjectReference.Path, subjectReference.Digest)
var referrerDescriptors []artifactspec.Descriptor
if artifactTypes == nil {
artifactTypes = []string{""}
}
for _, artifactType := range artifactTypes {
_, res, err := oras.Discover(ctx, registryClient.Resolver, subjectReference.Original, artifactType)
_, res, err := oras.Discover(ctx, registryClient.Resolver, ref, artifactType)
if err != nil {
return referrerstore.ListReferrersResult{}, err
}
Expand Down Expand Up @@ -177,26 +176,14 @@ func (store *orasStore) GetReferenceManifest(ctx context.Context, subjectReferen
}

func (store *orasStore) GetSubjectDescriptor(ctx context.Context, subjectReference common.Reference) (*ocispecs.SubjectDescriptor, error) {
ref, err := name.ParseReference(subjectReference.Original)
registryClient, err := store.createRegistryClient(subjectReference)
if err != nil {
return nil, err
}
dig, err := remote.Head(ref)
_, desc, err := registryClient.Resolve(ctx, subjectReference.Original)
if err != nil {
return nil, err
}

dg, err := digest.Parse(dig.Digest.String())
if err != nil {
return nil, err
}

desc := oci.Descriptor{
MediaType: string(dig.MediaType),
Digest: dg,
Size: dig.Size,
URLs: dig.URLs,
}
return &ocispecs.SubjectDescriptor{Descriptor: desc}, nil
}

Expand Down

0 comments on commit 2628973

Please sign in to comment.