Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support referrers for oci image manifests #43

Merged
merged 2 commits into from
Dec 2, 2022
Merged

feat: support referrers for oci image manifests #43

merged 2 commits into from
Dec 2, 2022

Conversation

wangxiaoxuan273
Copy link

Resolves #39
Part 9 of #21

Signed-off-by: wangxiaoxuan273 wangxiaoxuan119@gmail.com

Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
@wangxiaoxuan273
Copy link
Author

wangxiaoxuan273 commented Nov 28, 2022

Test result:
image

Prettified result:

{
   "schemaVersion":2,
   "mediaType":"application/vnd.oci.image.index.v1+json",
   "manifests":[
      {
         "mediaType":"application/vnd.oci.artifact.manifest.v1+json",
         "digest":"sha256:93cfbed4ad9a5fe39436532df1c3efb5b596099148c02be64a2f94af19fa78f5",
         "size":404,
         "annotations":{
            "bar":"bbaarr",
            "foo":"ffoooo"
         },
         "artifactType":"application/vnd.example.sbom.v1"
      },
      {
         "mediaType":"application/vnd.oci.artifact.manifest.v1+json",
         "digest":"sha256:d5bafe428707b0e38d7392afcdc82cbf58a0a4aeb56bcc304efea4874602f350",
         "size":390,
         "annotations":{
            "tick":"tock",
            "woo":"doo"
         },
         "artifactType":"application/referrer2"
      }
   ]
}

Comment on lines 181 to 186
func getArtifactReferrers(ctx context.Context,
blobStatter distribution.BlobStatter,
referrerDigest digest.Digest,
man distribution.Manifest,
referrers *[]v1.Descriptor,
artifactType string) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the code pattern

func doSomething(result *[]any)

Try golang-style

func doSomething(result []any) []any

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, you don't even need to pass the referrers. All you want to return is a referrer descriptor.

Think about

func generateReferrerFromArtifact(ctx context.Context, blobStatter distribution.BlobStatter, referrerDigest digest.Digest, man *ociartifact.DeserializedManifest, artifactType string) (v1.Descriptor, error)

You could apply the same thing to getImageReferrers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Changed accordingly.

func getArtifactReferrers(ctx context.Context,
blobStatter distribution.BlobStatter,
referrerDigest digest.Digest,
man distribution.Manifest,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

Suggested change
man distribution.Manifest,
man *ociartifact.DeserializedManifest,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed accordingly.

case *ociartifact.DeserializedManifest:
return getArtifactReferrers(ctx, blobStatter, referrerDigest, man, &referrers, artifactType)
default:
return fmt.Errorf("referrers not supported for this manifest type")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it return nil to keep the previous behavior?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed accordingly.

return nil
}

func getImageReferrers(ctx context.Context,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Image Manifest, the media type of the config is used as the artifact type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added filtering with config media type.

Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
@codecov-commenter
Copy link

Codecov Report

Merging #43 (f421e8e) into main (9ac1115) will decrease coverage by 0.17%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main      #43      +/-   ##
==========================================
- Coverage   56.48%   56.31%   -0.18%     
==========================================
  Files         108      108              
  Lines       11176    11211      +35     
==========================================
  Hits         6313     6313              
- Misses       4153     4188      +35     
  Partials      710      710              
Impacted Files Coverage Δ
registry/handlers/referrers.go 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shizhMSFT shizhMSFT merged commit 8c6c680 into oras-project:main Dec 2, 2022
@wangxiaoxuan273 wangxiaoxuan273 deleted the image-referrers branch December 2, 2022 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support referrers for OCI image manifest
4 participants