mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
fix(referrers): fix some conformance issues (#1134)
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
committed by
GitHub
parent
feb7328f50
commit
e2c7a3c5ba
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user