mirror of
https://github.com/project-zot/zot.git
synced 2025-03-11 02:17:43 -05:00
fix(referrers): fix some conformance issues (#1134)
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
parent
feb7328f50
commit
e2c7a3c5ba
16 changed files with 191 additions and 77 deletions
|
@ -53,6 +53,7 @@ import (
|
|||
extconf "zotregistry.io/zot/pkg/extensions/config"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
storageConstants "zotregistry.io/zot/pkg/storage/constants"
|
||||
"zotregistry.io/zot/pkg/storage/local"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
)
|
||||
|
@ -4346,6 +4347,33 @@ func TestArtifactReferences(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
So(resp.Header().Get("Content-Type"), ShouldEqual, ispec.MediaTypeImageIndex)
|
||||
|
||||
var index ispec.Index
|
||||
err = json.Unmarshal(resp.Body(), &index)
|
||||
So(err, ShouldBeNil)
|
||||
So(index.Manifests, ShouldNotBeEmpty)
|
||||
So(index.Annotations[storageConstants.ReferrerFilterAnnotation], ShouldNotBeEmpty)
|
||||
|
||||
// filter by multiple artifactTypes
|
||||
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet,
|
||||
baseURL+fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()), nil)
|
||||
So(err, ShouldBeNil)
|
||||
values := url.Values{}
|
||||
values.Add("artifactType", artifactType)
|
||||
values.Add("artifactType", "foobar")
|
||||
req.URL.RawQuery = values.Encode()
|
||||
rsp, err := http.DefaultClient.Do(req)
|
||||
So(err, ShouldBeNil)
|
||||
defer rsp.Body.Close()
|
||||
So(rsp.StatusCode, ShouldEqual, http.StatusOK)
|
||||
So(rsp.Header.Get("Content-Type"), ShouldEqual, ispec.MediaTypeImageIndex)
|
||||
body, err := io.ReadAll(rsp.Body)
|
||||
So(err, ShouldBeNil)
|
||||
err = json.Unmarshal(body, &index)
|
||||
So(err, ShouldBeNil)
|
||||
So(index.Manifests, ShouldNotBeEmpty)
|
||||
So(index.Annotations[storageConstants.ReferrerFilterAnnotation], ShouldNotBeEmpty)
|
||||
So(len(strings.Split(index.Annotations[storageConstants.ReferrerFilterAnnotation], ",")), ShouldEqual, 2)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -427,9 +427,9 @@ type ImageIndex struct {
|
|||
|
||||
func getReferrers(ctx context.Context, routeHandler *RouteHandler,
|
||||
imgStore storage.ImageStore, name string, digest godigest.Digest,
|
||||
artifactType string,
|
||||
artifactTypes []string,
|
||||
) (ispec.Index, error) {
|
||||
references, err := imgStore.GetReferrers(name, digest, artifactType)
|
||||
references, err := imgStore.GetReferrers(name, digest, artifactTypes)
|
||||
if err != nil {
|
||||
if routeHandler.c.Config.Extensions != nil &&
|
||||
routeHandler.c.Config.Extensions.Sync != nil &&
|
||||
|
@ -445,7 +445,7 @@ func getReferrers(ctx context.Context, routeHandler *RouteHandler,
|
|||
return ispec.Index{}, err
|
||||
}
|
||||
|
||||
references, err = imgStore.GetReferrers(name, digest, artifactType)
|
||||
references, err = imgStore.GetReferrers(name, digest, artifactTypes)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -482,26 +482,14 @@ func (rh *RouteHandler) GetReferrers(response http.ResponseWriter, request *http
|
|||
return
|
||||
}
|
||||
|
||||
// filter by artifact type
|
||||
artifactType := ""
|
||||
// filter by artifact type (more than one can be specified)
|
||||
artifactTypes := request.URL.Query()["artifactType"]
|
||||
|
||||
artifactTypes, ok := request.URL.Query()["artifactType"]
|
||||
if ok {
|
||||
if len(artifactTypes) != 1 {
|
||||
rh.c.Log.Error().Msg("invalid artifact types")
|
||||
response.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
artifactType = artifactTypes[0]
|
||||
}
|
||||
|
||||
rh.c.Log.Info().Str("digest", digest.String()).Str("artifactType", artifactType).Msg("getting manifest")
|
||||
rh.c.Log.Info().Str("digest", digest.String()).Interface("artifactType", artifactTypes).Msg("getting manifest")
|
||||
|
||||
imgStore := rh.getImageStore(name)
|
||||
|
||||
referrers, err := getReferrers(request.Context(), rh, imgStore, name, digest, artifactType)
|
||||
referrers, err := getReferrers(request.Context(), rh, imgStore, name, digest, artifactTypes)
|
||||
if err != nil {
|
||||
if errors.Is(err, zerr.ErrManifestNotFound) || errors.Is(err, zerr.ErrRepoNotFound) {
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).Msg("manifest not found")
|
||||
|
|
|
@ -862,18 +862,18 @@ func TestGetReferrersGQL(t *testing.T) {
|
|||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
So(resp.Body(), ShouldNotBeNil)
|
||||
|
||||
refferrsResp := &ReferrersResp{}
|
||||
referrersResp := &ReferrersResp{}
|
||||
|
||||
err = json.Unmarshal(resp.Body(), refferrsResp)
|
||||
err = json.Unmarshal(resp.Body(), referrersResp)
|
||||
So(err, ShouldBeNil)
|
||||
So(refferrsResp.Errors, ShouldBeNil)
|
||||
So(refferrsResp.ReferrersResult.Referrers[0].ArtifactType, ShouldEqual, artifactType)
|
||||
So(refferrsResp.ReferrersResult.Referrers[0].MediaType, ShouldEqual, ispec.MediaTypeArtifactManifest)
|
||||
So(referrersResp.Errors, ShouldBeNil)
|
||||
So(referrersResp.ReferrersResult.Referrers[0].ArtifactType, ShouldEqual, artifactType)
|
||||
So(referrersResp.ReferrersResult.Referrers[0].MediaType, ShouldEqual, ispec.MediaTypeArtifactManifest)
|
||||
|
||||
So(refferrsResp.ReferrersResult.Referrers[0].Annotations[0].Key, ShouldEqual, "com.artifact.format")
|
||||
So(refferrsResp.ReferrersResult.Referrers[0].Annotations[0].Value, ShouldEqual, "test")
|
||||
So(referrersResp.ReferrersResult.Referrers[0].Annotations[0].Key, ShouldEqual, "com.artifact.format")
|
||||
So(referrersResp.ReferrersResult.Referrers[0].Annotations[0].Value, ShouldEqual, "test")
|
||||
|
||||
So(refferrsResp.ReferrersResult.Referrers[0].Digest, ShouldEqual, artifactManifestDigest)
|
||||
So(referrersResp.ReferrersResult.Referrers[0].Digest, ShouldEqual, artifactManifestDigest)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ type ComplexityRoot struct {
|
|||
ImageListForCve func(childComplexity int, id string, requestedPage *PageInput) int
|
||||
ImageListForDigest func(childComplexity int, id string, requestedPage *PageInput) int
|
||||
ImageListWithCVEFixed func(childComplexity int, id string, image string, requestedPage *PageInput) int
|
||||
Referrers func(childComplexity int, repo string, digest string, typeArg string) int
|
||||
Referrers func(childComplexity int, repo string, digest string, typeArg []string) int
|
||||
RepoListWithNewestImage func(childComplexity int, requestedPage *PageInput) int
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ type QueryResolver interface {
|
|||
DerivedImageList(ctx context.Context, image string, requestedPage *PageInput) (*PaginatedImagesResult, error)
|
||||
BaseImageList(ctx context.Context, image string, requestedPage *PageInput) (*PaginatedImagesResult, error)
|
||||
Image(ctx context.Context, image string) (*ImageSummary, error)
|
||||
Referrers(ctx context.Context, repo string, digest string, typeArg string) ([]*Referrer, error)
|
||||
Referrers(ctx context.Context, repo string, digest string, typeArg []string) ([]*Referrer, error)
|
||||
}
|
||||
|
||||
type executableSchema struct {
|
||||
|
@ -752,7 +752,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Query.Referrers(childComplexity, args["repo"].(string), args["digest"].(string), args["type"].(string)), true
|
||||
return e.complexity.Query.Referrers(childComplexity, args["repo"].(string), args["digest"].(string), args["type"].([]string)), true
|
||||
|
||||
case "Query.RepoListWithNewestImage":
|
||||
if e.complexity.Query.RepoListWithNewestImage == nil {
|
||||
|
@ -1209,7 +1209,7 @@ type Query {
|
|||
Returns a list of descriptors of an image or artifact manifest that are found in a <repo> and have a subject field of <digest>
|
||||
Can be filtered based on a specific artifact type <type>
|
||||
"""
|
||||
Referrers(repo: String!, digest: String!, type: String!): [Referrer]!
|
||||
Referrers(repo: String!, digest: String!, type: [String!]): [Referrer]!
|
||||
}
|
||||
`, BuiltIn: false},
|
||||
}
|
||||
|
@ -1480,10 +1480,10 @@ func (ec *executionContext) field_Query_Referrers_args(ctx context.Context, rawA
|
|||
}
|
||||
}
|
||||
args["digest"] = arg1
|
||||
var arg2 string
|
||||
var arg2 []string
|
||||
if tmp, ok := rawArgs["type"]; ok {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("type"))
|
||||
arg2, err = ec.unmarshalNString2string(ctx, tmp)
|
||||
arg2, err = ec.unmarshalOString2ᚕstringᚄ(ctx, tmp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -5050,7 +5050,7 @@ func (ec *executionContext) _Query_Referrers(ctx context.Context, field graphql.
|
|||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Query().Referrers(rctx, fc.Args["repo"].(string), fc.Args["digest"].(string), fc.Args["type"].(string))
|
||||
return ec.resolvers.Query().Referrers(rctx, fc.Args["repo"].(string), fc.Args["digest"].(string), fc.Args["type"].([]string))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
|
@ -10307,6 +10307,44 @@ func (ec *executionContext) marshalOSortCriteria2ᚖzotregistryᚗioᚋzotᚋpkg
|
|||
return v
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalOString2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
}
|
||||
var vSlice []interface{}
|
||||
if v != nil {
|
||||
vSlice = graphql.CoerceList(v)
|
||||
}
|
||||
var err error
|
||||
res := make([]string, len(vSlice))
|
||||
for i := range vSlice {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i))
|
||||
res[i], err = ec.unmarshalNString2string(ctx, vSlice[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalOString2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler {
|
||||
if v == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
ret := make(graphql.Array, len(v))
|
||||
for i := range v {
|
||||
ret[i] = ec.marshalNString2string(ctx, sel, v[i])
|
||||
}
|
||||
|
||||
for _, e := range ret {
|
||||
if e == graphql.Null {
|
||||
return graphql.Null
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalOString2ᚕᚖstring(ctx context.Context, v interface{}) ([]*string, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
|
|
|
@ -1005,12 +1005,12 @@ func getImageList(ctx context.Context, repo string, repoDB repodb.RepoDB, cveInf
|
|||
return imageList, nil
|
||||
}
|
||||
|
||||
func getReferrers(store storage.ImageStore, repoName string, digest string, artifactType string, log log.Logger) (
|
||||
func getReferrers(store storage.ImageStore, repoName string, digest string, artifactTypes []string, log log.Logger) (
|
||||
[]*gql_generated.Referrer, error,
|
||||
) {
|
||||
results := make([]*gql_generated.Referrer, 0)
|
||||
|
||||
index, err := store.GetReferrers(repoName, godigest.Digest(digest), artifactType)
|
||||
index, err := store.GetReferrers(repoName, godigest.Digest(digest), artifactTypes)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error extracting referrers list")
|
||||
|
||||
|
|
|
@ -1087,12 +1087,12 @@ func TestGetReferrers(t *testing.T) {
|
|||
Convey("GetReferrers returns error", func() {
|
||||
testLogger := log.NewLogger("debug", "")
|
||||
mockedStore := mocks.MockedImageStore{
|
||||
GetReferrersFn: func(repo string, digest godigest.Digest, artifactType string) (ispec.Index, error) {
|
||||
GetReferrersFn: func(repo string, digest godigest.Digest, artifactType []string) (ispec.Index, error) {
|
||||
return ispec.Index{}, ErrTestError
|
||||
},
|
||||
}
|
||||
|
||||
_, err := getReferrers(mockedStore, "test", "", "", testLogger)
|
||||
_, err := getReferrers(mockedStore, "test", "", nil, testLogger)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
|
@ -1108,7 +1108,7 @@ func TestGetReferrers(t *testing.T) {
|
|||
},
|
||||
}
|
||||
mockedStore := mocks.MockedImageStore{
|
||||
GetReferrersFn: func(repo string, digest godigest.Digest, artifactType string) (ispec.Index, error) {
|
||||
GetReferrersFn: func(repo string, digest godigest.Digest, artifactTypes []string) (ispec.Index, error) {
|
||||
return ispec.Index{
|
||||
Manifests: []ispec.Descriptor{
|
||||
referrerDescriptor,
|
||||
|
@ -1117,7 +1117,7 @@ func TestGetReferrers(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
referrers, err := getReferrers(mockedStore, "test", "", "", testLogger)
|
||||
referrers, err := getReferrers(mockedStore, "test", "", nil, testLogger)
|
||||
So(err, ShouldBeNil)
|
||||
So(*referrers[0].ArtifactType, ShouldEqual, referrerDescriptor.ArtifactType)
|
||||
So(*referrers[0].MediaType, ShouldEqual, referrerDescriptor.MediaType)
|
||||
|
@ -1566,7 +1566,7 @@ func TestQueryResolverErrors(t *testing.T) {
|
|||
log,
|
||||
storage.StoreController{
|
||||
DefaultStore: mocks.MockedImageStore{
|
||||
GetReferrersFn: func(repo string, digest godigest.Digest, artifactType string) (ispec.Index, error) {
|
||||
GetReferrersFn: func(repo string, digest godigest.Digest, artifactTypes []string) (ispec.Index, error) {
|
||||
return ispec.Index{}, ErrTestError
|
||||
},
|
||||
},
|
||||
|
@ -1579,7 +1579,7 @@ func TestQueryResolverErrors(t *testing.T) {
|
|||
resolverConfig,
|
||||
}
|
||||
|
||||
_, err := qr.Referrers(ctx, "repo", "", "")
|
||||
_, err := qr.Referrers(ctx, "repo", "", nil)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -260,5 +260,5 @@ type Query {
|
|||
Returns a list of descriptors of an image or artifact manifest that are found in a <repo> and have a subject field of <digest>
|
||||
Can be filtered based on a specific artifact type <type>
|
||||
"""
|
||||
Referrers(repo: String!, digest: String!, type: String!): [Referrer]!
|
||||
Referrers(repo: String!, digest: String!, type: [String!]): [Referrer]!
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ func (r *queryResolver) Image(ctx context.Context, image string) (*gql_generated
|
|||
}
|
||||
|
||||
// Referrers is the resolver for the Referrers field.
|
||||
func (r *queryResolver) Referrers(ctx context.Context, repo string, digest string, typeArg string) ([]*gql_generated.Referrer, error) {
|
||||
func (r *queryResolver) Referrers(ctx context.Context, repo string, digest string, typeArg []string) ([]*gql_generated.Referrer, error) {
|
||||
store := r.storeController.GetImageStore(repo)
|
||||
|
||||
referrers, err := getReferrers(store, repo, digest, typeArg, r.log)
|
||||
|
|
|
@ -527,7 +527,7 @@ func (sig *signaturesCopier) canSkipOCIRefs(localRepo, digestStr string, index i
|
|||
|
||||
// check oci references already synced
|
||||
if len(index.Manifests) > 0 {
|
||||
localRefs, err := imageStore.GetReferrers(localRepo, digest, "")
|
||||
localRefs, err := imageStore.GetReferrers(localRepo, digest, nil)
|
||||
if err != nil {
|
||||
if errors.Is(err, zerr.ErrManifestNotFound) {
|
||||
return false, nil
|
||||
|
|
|
@ -530,7 +530,27 @@ func GetOrasReferrers(imgStore ImageStore, repo string, gdigest godigest.Digest,
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func GetReferrers(imgStore ImageStore, repo string, gdigest godigest.Digest, artifactType string,
|
||||
func getReferrerFilterAnnotation(artifactTypes []string) string {
|
||||
// as per spec, return what filters were applied as an annotation if artifactTypes
|
||||
annotation := ""
|
||||
|
||||
for _, artifactType := range artifactTypes {
|
||||
if artifactType == "" {
|
||||
// ignore empty artifactTypes
|
||||
continue
|
||||
}
|
||||
|
||||
if annotation == "" {
|
||||
annotation = artifactType
|
||||
} else {
|
||||
annotation += "," + artifactType
|
||||
}
|
||||
}
|
||||
|
||||
return annotation
|
||||
}
|
||||
|
||||
func GetReferrers(imgStore ImageStore, repo string, gdigest godigest.Digest, artifactTypes []string,
|
||||
log zerolog.Logger,
|
||||
) (ispec.Index, error) {
|
||||
nilIndex := ispec.Index{}
|
||||
|
@ -580,8 +600,22 @@ func GetReferrers(imgStore ImageStore, repo string, gdigest godigest.Digest, art
|
|||
}
|
||||
|
||||
// filter by artifact type
|
||||
if artifactType != "" && mfst.Config.MediaType != artifactType {
|
||||
continue
|
||||
if len(artifactTypes) > 0 {
|
||||
found := false
|
||||
|
||||
for _, artifactType := range artifactTypes {
|
||||
if artifactType != "" && mfst.Config.MediaType != artifactType {
|
||||
continue
|
||||
}
|
||||
|
||||
found = true
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, ispec.Descriptor{
|
||||
|
@ -604,8 +638,21 @@ func GetReferrers(imgStore ImageStore, repo string, gdigest godigest.Digest, art
|
|||
}
|
||||
|
||||
// filter by artifact type
|
||||
if artifactType != "" && art.ArtifactType != artifactType {
|
||||
continue
|
||||
if len(artifactTypes) > 0 {
|
||||
found := false
|
||||
for _, artifactType := range artifactTypes {
|
||||
if artifactType != "" && art.ArtifactType != artifactType {
|
||||
continue
|
||||
}
|
||||
|
||||
found = true
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, ispec.Descriptor{
|
||||
|
@ -625,9 +672,10 @@ func GetReferrers(imgStore ImageStore, repo string, gdigest godigest.Digest, art
|
|||
Annotations: map[string]string{},
|
||||
}
|
||||
|
||||
// response was filtered by artifactType
|
||||
if artifactType != "" {
|
||||
index.Annotations[storageConstants.ReferrerFilterAnnotation] = ""
|
||||
// as per spec, return what filters were applied as an annotation if artifactTypes
|
||||
if annotation := getReferrerFilterAnnotation(artifactTypes); annotation != "" {
|
||||
index.Annotations[storageConstants.ReferrerFilterAnnotation] = annotation
|
||||
log.Info().Str("annotation", annotation).Msg("filters applied")
|
||||
}
|
||||
|
||||
return index, nil
|
||||
|
|
|
@ -127,18 +127,22 @@ func TestGetReferrersErrors(t *testing.T) {
|
|||
validDigest := godigest.FromBytes([]byte("blob"))
|
||||
|
||||
Convey("Trigger invalid digest error", func(c C) {
|
||||
_, err := storage.GetReferrers(imgStore, "zot-test", "invalidDigest", artifactType, log.With().Caller().Logger())
|
||||
_, err := storage.GetReferrers(imgStore, "zot-test", "invalidDigest",
|
||||
[]string{artifactType}, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", "invalidDigest", artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", "invalidDigest",
|
||||
artifactType, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("Trigger repo not found error", func(c C) {
|
||||
_, err := storage.GetReferrers(imgStore, "zot-test", validDigest, artifactType, log.With().Caller().Logger())
|
||||
_, err := storage.GetReferrers(imgStore, "zot-test", validDigest,
|
||||
[]string{artifactType}, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", validDigest, artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", validDigest,
|
||||
artifactType, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
|
@ -169,10 +173,12 @@ func TestGetReferrersErrors(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest, artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest,
|
||||
[]string{artifactType}, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", validDigest, artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", validDigest,
|
||||
artifactType, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
|
@ -186,7 +192,8 @@ func TestGetReferrersErrors(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest, artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest,
|
||||
[]string{artifactType}, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
|
@ -210,10 +217,12 @@ func TestGetReferrersErrors(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", validDigest, artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", validDigest,
|
||||
artifactType, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", digest, artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetOrasReferrers(imgStore, "zot-test", digest,
|
||||
artifactType, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
|
@ -239,7 +248,8 @@ func TestGetReferrersErrors(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest, artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest,
|
||||
[]string{artifactType}, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
|
@ -265,7 +275,8 @@ func TestGetReferrersErrors(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest, artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest,
|
||||
[]string{artifactType}, log.With().Caller().Logger())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
|
@ -298,7 +309,8 @@ func TestGetReferrersErrors(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest, artifactType, log.With().Caller().Logger())
|
||||
_, err = storage.GetReferrers(imgStore, "zot-test", validDigest,
|
||||
[]string{artifactType}, log.With().Caller().Logger())
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1349,14 +1349,14 @@ func (is *ImageStoreLocal) DeleteBlob(repo string, digest godigest.Digest) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (is *ImageStoreLocal) GetReferrers(repo string, gdigest godigest.Digest, artifactType string,
|
||||
func (is *ImageStoreLocal) GetReferrers(repo string, gdigest godigest.Digest, artifactTypes []string,
|
||||
) (ispec.Index, error) {
|
||||
var lockLatency time.Time
|
||||
|
||||
is.RLock(&lockLatency)
|
||||
defer is.RUnlock(&lockLatency)
|
||||
|
||||
return storage.GetReferrers(is, repo, gdigest, artifactType, is.log)
|
||||
return storage.GetReferrers(is, repo, gdigest, artifactTypes, is.log)
|
||||
}
|
||||
|
||||
func (is *ImageStoreLocal) GetOrasReferrers(repo string, gdigest godigest.Digest, artifactType string,
|
||||
|
|
|
@ -1266,14 +1266,14 @@ func (is *ObjectStorage) GetBlobContent(repo string, digest godigest.Digest) ([]
|
|||
return blobBuf, nil
|
||||
}
|
||||
|
||||
func (is *ObjectStorage) GetReferrers(repo string, gdigest godigest.Digest, artifactType string,
|
||||
func (is *ObjectStorage) GetReferrers(repo string, gdigest godigest.Digest, artifactTypes []string,
|
||||
) (ispec.Index, error) {
|
||||
var lockLatency time.Time
|
||||
|
||||
is.RLock(&lockLatency)
|
||||
defer is.RUnlock(&lockLatency)
|
||||
|
||||
return storage.GetReferrers(is, repo, gdigest, artifactType, is.log)
|
||||
return storage.GetReferrers(is, repo, gdigest, artifactTypes, is.log)
|
||||
}
|
||||
|
||||
func (is *ObjectStorage) GetOrasReferrers(repo string, gdigest godigest.Digest, artifactType string,
|
||||
|
|
|
@ -517,7 +517,7 @@ func TestGetOrasAndOCIReferrers(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
So(n, ShouldEqual, buflen)
|
||||
|
||||
Convey("Get oci referrers - application/vnd.oci.image.manifest.v1+json", func(c C) {
|
||||
Convey("Get OCI Referrers - application/vnd.oci.image.manifest.v1+json", func(c C) {
|
||||
artifactType := "application/vnd.example.icecream.v1"
|
||||
// push artifact config blob
|
||||
configBody := []byte("{}")
|
||||
|
@ -559,7 +559,7 @@ func TestGetOrasAndOCIReferrers(t *testing.T) {
|
|||
_, err = imgStore.PutImageManifest(repo, manDigest.Encoded(), ispec.MediaTypeImageManifest, manBuf)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
index, err := imgStore.GetReferrers(repo, mdigest, artifactType)
|
||||
index, err := imgStore.GetReferrers(repo, mdigest, []string{artifactType})
|
||||
So(err, ShouldBeNil)
|
||||
So(index, ShouldNotBeEmpty)
|
||||
So(index.Manifests[0].ArtifactType, ShouldEqual, artifactType)
|
||||
|
@ -597,7 +597,7 @@ func TestGetOrasAndOCIReferrers(t *testing.T) {
|
|||
_, err = imgStore.PutImageManifest(repo, manDigest.Encoded(), ispec.MediaTypeArtifactManifest, manBuf)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
index, err := imgStore.GetReferrers(repo, mdigest, artifactType)
|
||||
index, err := imgStore.GetReferrers(repo, mdigest, []string{artifactType})
|
||||
So(err, ShouldBeNil)
|
||||
So(index, ShouldNotBeEmpty)
|
||||
So(index.Manifests[1].ArtifactType, ShouldEqual, artifactType)
|
||||
|
@ -1240,7 +1240,7 @@ func TestNegativeCasesObjectsStorage(t *testing.T) {
|
|||
Convey("Test GetReferrers", func(c C) {
|
||||
imgStore = createMockStorage(testDir, tdir, false, &StorageDriverMock{})
|
||||
d := godigest.FromBytes([]byte(""))
|
||||
_, err := imgStore.GetReferrers(testImage, d, "application/image")
|
||||
_, err := imgStore.GetReferrers(testImage, d, []string{"application/image"})
|
||||
So(err, ShouldNotBeNil)
|
||||
So(err, ShouldEqual, zerr.ErrRepoBadVersion)
|
||||
})
|
||||
|
|
|
@ -49,7 +49,7 @@ type ImageStore interface { //nolint:interfacebloat
|
|||
DeleteBlob(repo string, digest godigest.Digest) error
|
||||
GetIndexContent(repo string) ([]byte, error)
|
||||
GetBlobContent(repo string, digest godigest.Digest) ([]byte, error)
|
||||
GetReferrers(repo string, digest godigest.Digest, artifactType string) (ispec.Index, error)
|
||||
GetReferrers(repo string, digest godigest.Digest, artifactTypes []string) (ispec.Index, error)
|
||||
GetOrasReferrers(repo string, digest godigest.Digest, artifactType string) ([]artifactspec.Descriptor, error)
|
||||
RunGCRepo(repo string) error
|
||||
RunGCPeriodically(interval time.Duration, sch *scheduler.Scheduler)
|
||||
|
|
|
@ -40,7 +40,7 @@ type MockedImageStore struct {
|
|||
DeleteBlobFn func(repo string, digest godigest.Digest) error
|
||||
GetIndexContentFn func(repo string) ([]byte, error)
|
||||
GetBlobContentFn func(repo string, digest godigest.Digest) ([]byte, error)
|
||||
GetReferrersFn func(repo string, digest godigest.Digest, artifactType string) (ispec.Index, error)
|
||||
GetReferrersFn func(repo string, digest godigest.Digest, artifactTypes []string) (ispec.Index, error)
|
||||
GetOrasReferrersFn func(repo string, digest godigest.Digest, artifactType string) ([]artifactspec.Descriptor, error)
|
||||
URLForPathFn func(path string) (string, error)
|
||||
RunGCRepoFn func(repo string) error
|
||||
|
@ -290,10 +290,10 @@ func (is MockedImageStore) GetBlobContent(repo string, digest godigest.Digest) (
|
|||
|
||||
func (is MockedImageStore) GetReferrers(
|
||||
repo string, digest godigest.Digest,
|
||||
artifactType string,
|
||||
artifactTypes []string,
|
||||
) (ispec.Index, error) {
|
||||
if is.GetReferrersFn != nil {
|
||||
return is.GetReferrersFn(repo, digest, artifactType)
|
||||
return is.GetReferrersFn(repo, digest, artifactTypes)
|
||||
}
|
||||
|
||||
return ispec.Index{}, nil
|
||||
|
|
Loading…
Add table
Reference in a new issue