oras-project / oras-go

ORAS Go library
https://oras.land
Apache License 2.0
179 stars 96 forks source link

Request: Add Public Function for Finding Referrers and Filtering by Artifact Type #657

Closed nathan-joslin closed 9 months ago

nathan-joslin commented 10 months ago

User Story

As a user of oras-go I would like to discover referrers of a manifest and filter by ArtifactType. I have a GraphStorage which only gives me access to Predecessors. I'd like to take advantage of the referrers API for optimization.

Limits of Current Functionality

The FilterArtifactType option for ExtendedCopyGraph provides this filtering, but the condition of copying limits its use.

As the GraphStorage I have is originally a registry.Repository, I have the option of elevating my GraphStorage to a registry.Repository giving me access to repository.Referrers. However, this has a side effect on my unit tests which use a memory.Store; a PredecessorFinder not a registry.ReferrerLister.

The implementation of func (opts *ExendedCopyGraphOptions) FilterArtifactType(regex) provides a "fallback" mechanism, where a non registry.ReferrerLister uses Predecessors instead, which seems useful to both the memory.Store in my unit tests as well as my GraphStorage.

nathan-joslin commented 10 months ago

Perhaps a duplicate of issue 392

Wwwsylvia commented 10 months ago

Hi @nathan-joslin , thanks for opening the issue. We would like to gain a better understanding of your use cases. Are there any other scenarios where Referrers and FilterArtifactType are required, besides in unit testing?

nathan-joslin commented 10 months ago

@Wwwsylvia Apologies for the confusion. My use case is not within a unit test. I have a GraphStorage where I'd like to fetch manifests of a particular ArtifactType. As I only have access to Predecessors with a GraphStorage, I have to filter by ArtifactType myself, which does not take advantage of the referrers API.

I noticed similar existing implementations of using the referrers API with ReadOnlyGraphStorages. For instance the Referrers function in oras (also referenced in issue 392), and the FilterArtifactType option in oras-go. The first implementation does not apply to my use case as it's not oras-go and internal. The second implementation must be used by ExtendedCopyGraph, which does not apply to my use case as I do not wish to copy to a destination GraphStorage.

The related issue 392 proposes letting content.Stores implement registry.ReferrerLister because they have access to Predecessors. I believe a similar proposal should be made for GraphStorages as they also have access to Predecessors.

shizhMSFT commented 10 months ago

I think this issue can be potentially resolved by #659 as per https://github.com/oras-project/oras-go/pull/659#discussion_r1429535685.

nathan-joslin commented 10 months ago

I agree with your comment.