Skip to content

Commit

Permalink
Merge pull request #19 from m5i-work/optional
Browse files Browse the repository at this point in the history
Optional field
  • Loading branch information
avtakkar authored Jul 18, 2022
2 parents e610c1f + d3e5a14 commit f98a060
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/ncw/swift v1.0.47
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.1
github.com/oras-project/artifacts-spec v1.0.0-rc.1
github.com/oras-project/artifacts-spec v1.0.0-rc.2
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.0.0
github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43 // indirect
Expand Down
7 changes: 2 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/oras-project/artifacts-spec v1.0.0-draft.1 h1:AyD++MU8sif5eyyvPbT5qskkJA9VZynYVoroVFTXPLM=
github.com/oras-project/artifacts-spec v1.0.0-draft.1/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
github.com/oras-project/artifacts-spec v1.0.0-rc.1 h1:bCHf9mPbrgiNwQFyVzBX79BYZVAl0OUrmvICZOCOwts=
github.com/oras-project/artifacts-spec v1.0.0-rc.1/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/oras-project/artifacts-spec v1.0.0-rc.2 h1:9SMCNSxkJEHqWGDiMCuy6TXHgvjgwXGdXZZGXLKQvVE=
github.com/oras-project/artifacts-spec v1.0.0-rc.2/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
7 changes: 5 additions & 2 deletions registry/extension/oras/artifactmanifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ func (a Manifest) References() []distribution.Descriptor {
}

// Subject returns the the subject manifest this artifact references.
func (a Manifest) Subject() distribution.Descriptor {
return distribution.Descriptor{
func (a Manifest) Subject() *distribution.Descriptor {
if a.inner.Subject == nil {
return nil
}
return &distribution.Descriptor{
MediaType: a.inner.Subject.MediaType,
Digest: a.inner.Subject.Digest,
Size: a.inner.Subject.Size,
Expand Down
16 changes: 11 additions & 5 deletions registry/extension/oras/artifactmanifesthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ func (amh *artifactManifestHandler) verifyManifest(ctx context.Context, dm Deser

// Validate subject manifest.
subject := dm.Subject()
exists, err := ms.Exists(ctx, subject.Digest)
if !exists || err == distribution.ErrBlobUnknown {
errs = append(errs, distribution.ErrManifestBlobUnknown{Digest: subject.Digest})
} else if err != nil {
errs = append(errs, err)
if subject != nil {
exists, err := ms.Exists(ctx, subject.Digest)
if !exists || err == distribution.ErrBlobUnknown {
errs = append(errs, distribution.ErrManifestBlobUnknown{Digest: subject.Digest})
} else if err != nil {
errs = append(errs, err)
}
}
}

Expand All @@ -136,6 +138,10 @@ func (amh *artifactManifestHandler) verifyManifest(ctx context.Context, dm Deser

// indexReferrers indexes the subject of the given revision in its referrers index store.
func (amh *artifactManifestHandler) indexReferrers(ctx context.Context, dm DeserializedManifest, revision digest.Digest) error {
if dm.Subject() == nil {
return nil
}

// [TODO] We can use artifact type in the link path to support filtering by artifact type
// but need to consider the max path length in different os
//artifactType := dm.ArtifactType()
Expand Down
15 changes: 12 additions & 3 deletions registry/extension/oras/artifactmanifesthandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestVerifyArtifactManifestPut(t *testing.T) {
Blobs: []orasartifacts.Descriptor{
artifactBlobDescriptor,
},
Subject: orasartifacts.Descriptor{
Subject: &orasartifacts.Descriptor{
MediaType: dm.MediaType,
Size: int64(len(dmPayload)),
Digest: dg,
Expand All @@ -134,7 +134,7 @@ func TestVerifyArtifactManifestPut(t *testing.T) {
MediaType string
ArtifactType string
Blobs []orasartifacts.Descriptor
Subject orasartifacts.Descriptor
Subject *orasartifacts.Descriptor
Annotations map[string]string
Err error
}
Expand Down Expand Up @@ -166,12 +166,21 @@ func TestVerifyArtifactManifestPut(t *testing.T) {
template.Annotations(),
errInvalidArtifactType,
},
// no subject
{
orasartifacts.MediaTypeArtifactManifest,
template.inner.ArtifactType,
template.inner.Blobs,
nil,
template.Annotations(),
nil,
},
// invalid subject
{
orasartifacts.MediaTypeArtifactManifest,
template.inner.ArtifactType,
template.inner.Blobs,
orasartifacts.Descriptor{
&orasartifacts.Descriptor{
MediaType: dm.MediaType,
Size: int64(len(dmPayload)),
Digest: digest.FromString("sha256:invalid"),
Expand Down
2 changes: 1 addition & 1 deletion registry/handlers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ func TestReferrers(t *testing.T) {
Blobs: []orasartifacts.Descriptor{
artifactBlobDescriptor,
},
Subject: orasartifacts.Descriptor{
Subject: &orasartifacts.Descriptor{
MediaType: schema2.MediaTypeManifest,
Size: int64(len(p)),
Digest: dgst,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ github.com/opencontainers/go-digest
## explicit
github.com/opencontainers/image-spec/specs-go
github.com/opencontainers/image-spec/specs-go/v1
# github.com/oras-project/artifacts-spec v1.0.0-rc.1
# github.com/oras-project/artifacts-spec v1.0.0-rc.2
## explicit
github.com/oras-project/artifacts-spec/specs-go/v1
# github.com/prometheus/client_golang v1.1.0
Expand Down

0 comments on commit f98a060

Please sign in to comment.