diff --git a/pkg/cli/client.go b/pkg/cli/client.go index 0cb1e0fc..a9bcea7c 100644 --- a/pkg/cli/client.go +++ b/pkg/cli/client.go @@ -217,6 +217,8 @@ func (p *requestsPool) doJob(ctx context.Context, job *httpJob) { p.outputCh <- stringResult{"", err} } + verbose := *job.config.verbose + switch header.Get("Content-Type") { case ispec.MediaTypeImageManifest: image, err := fetchImageManifestStruct(ctx, job) @@ -230,7 +232,7 @@ func (p *requestsPool) doJob(ctx context.Context, job *httpJob) { } platformStr := getPlatformStr(image.Manifests[0].Platform) - str, err := image.string(*job.config.outputFormat, len(job.imageName), len(job.tagName), len(platformStr)) + str, err := image.string(*job.config.outputFormat, len(job.imageName), len(job.tagName), len(platformStr), verbose) if err != nil { if isContextDone(ctx) { return @@ -258,7 +260,7 @@ func (p *requestsPool) doJob(ctx context.Context, job *httpJob) { platformStr := getPlatformStr(image.Manifests[0].Platform) - str, err := image.string(*job.config.outputFormat, len(job.imageName), len(job.tagName), len(platformStr)) + str, err := image.string(*job.config.outputFormat, len(job.imageName), len(job.tagName), len(platformStr), verbose) if err != nil { if isContextDone(ctx) { return @@ -300,7 +302,7 @@ func fetchImageIndexStruct(ctx context.Context, job *httpJob) (*imageStruct, err imageSize := indexSize - manifestList := make([]manifestStruct, 0, len(indexContent.Manifests)) + manifestList := make([]common.ManifestSummary, 0, len(indexContent.Manifests)) for _, manifestDescriptor := range indexContent.Manifests { manifest, err := fetchManifestStruct(ctx, job.imageName, manifestDescriptor.Digest.String(), @@ -312,7 +314,7 @@ func fetchImageIndexStruct(ctx context.Context, job *httpJob) (*imageStruct, err imageSize += int64(atoiWithDefault(manifest.Size, 0)) if manifestDescriptor.Platform != nil { - manifest.Platform = platform{ + manifest.Platform = common.Platform{ Os: manifestDescriptor.Platform.OS, Arch: manifestDescriptor.Platform.Architecture, Variant: manifestDescriptor.Platform.Variant, @@ -333,7 +335,6 @@ func fetchImageIndexStruct(ctx context.Context, job *httpJob) (*imageStruct, err Manifests: manifestList, Size: strconv.FormatInt(imageSize, 10), IsSigned: isIndexSigned, - verbose: *job.config.verbose, }, nil } @@ -357,18 +358,17 @@ func fetchImageManifestStruct(ctx context.Context, job *httpJob) (*imageStruct, Tag: job.tagName, Digest: manifest.Digest, MediaType: ispec.MediaTypeImageManifest, - Manifests: []manifestStruct{ + Manifests: []common.ManifestSummary{ manifest, }, Size: manifest.Size, IsSigned: manifest.IsSigned, - verbose: *job.config.verbose, }, nil } func fetchManifestStruct(ctx context.Context, repo, manifestReference string, searchConf searchConfig, username, password string, -) (manifestStruct, error) { +) (common.ManifestSummary, error) { manifestResp := ispec.Manifest{} URL := fmt.Sprintf("%s/v2/%s/manifests/%s", @@ -378,10 +378,10 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se *searchConf.verifyTLS, *searchConf.debug, &manifestResp, searchConf.resultWriter) if err != nil { if isContextDone(ctx) { - return manifestStruct{}, context.Canceled + return common.ManifestSummary{}, context.Canceled } - return manifestStruct{}, err + return common.ManifestSummary{}, err } manifestDigest := header.Get("docker-content-digest") @@ -390,10 +390,10 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se configContent, err := fetchConfig(ctx, repo, configDigest, searchConf, username, password) if err != nil { if isContextDone(ctx) { - return manifestStruct{}, context.Canceled + return common.ManifestSummary{}, context.Canceled } - return manifestStruct{}, err + return common.ManifestSummary{}, err } opSys := "" @@ -420,7 +420,7 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se manifestSize, err := strconv.ParseInt(header.Get("Content-Length"), 10, 64) if err != nil { - return manifestStruct{}, err + return common.ManifestSummary{}, err } var imageSize int64 @@ -428,15 +428,15 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se imageSize += manifestResp.Config.Size imageSize += manifestSize - layers := []layer{} + layers := []common.LayerSummary{} for _, entry := range manifestResp.Layers { imageSize += entry.Size layers = append( layers, - layer{ - Size: entry.Size, + common.LayerSummary{ + Size: fmt.Sprintf("%v", entry.Size), Digest: entry.Digest.String(), }, ) @@ -445,11 +445,11 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se isSigned := isCosignSigned(ctx, repo, manifestDigest, searchConf, username, password) || isNotationSigned(ctx, repo, manifestDigest, searchConf, username, password) - return manifestStruct{ + return common.ManifestSummary{ ConfigDigest: configDigest, Digest: manifestDigest, Layers: layers, - Platform: platform{Os: opSys, Arch: arch, Variant: variant}, + Platform: common.Platform{Os: opSys, Arch: arch, Variant: variant}, Size: strconv.FormatInt(imageSize, 10), IsSigned: isSigned, }, nil diff --git a/pkg/cli/discover.go b/pkg/cli/discover.go index baf05d82..21415332 100644 --- a/pkg/cli/discover.go +++ b/pkg/cli/discover.go @@ -25,7 +25,7 @@ type schemaList struct { } `json:"queryType"` //nolint:tagliatelle // graphQL schema } `json:"__schema"` //nolint:tagliatelle // graphQL schema } `json:"data"` - Errors []common.ErrorGraphQL `json:"errors"` + Errors []common.ErrorGQL `json:"errors"` } func containsGQLQuery(queryList []field, query string) bool { diff --git a/pkg/cli/image_cmd_test.go b/pkg/cli/image_cmd_test.go index f24be698..8ac21ff4 100644 --- a/pkg/cli/image_cmd_test.go +++ b/pkg/cli/image_cmd_test.go @@ -29,6 +29,7 @@ import ( zotErrors "zotregistry.io/zot/errors" "zotregistry.io/zot/pkg/api" "zotregistry.io/zot/pkg/api/config" + "zotregistry.io/zot/pkg/common" extconf "zotregistry.io/zot/pkg/extensions/config" "zotregistry.io/zot/pkg/test" ) @@ -753,13 +754,18 @@ func TestOutputFormat(t *testing.T) { space := regexp.MustCompile(`\s+`) str := space.ReplaceAllString(buff.String(), " ") So(strings.TrimSpace(str), ShouldEqual, `{ "repoName": "dummyImageName", "tag": "tag", `+ - `"Manifests": [ { "configDigest": "sha256:4c10985c40365538426f2ba8cf0c21384a7769be502a550dcc0601b3736625e0", `+ - `"digest": "sha256:6e2f80bf9cfaabad474fbaf8ad68fdb652f776ea80b63492ecca404e5f6446a6", `+ - `"layers": [ { "size": "0", "digest": "sha256:c122a146f0d02349be211bb95cc2530f4a5793f96edbdfa00860f741e5d8c0e6" } ], `+ //nolint:lll - `"platform": { "os": "os", "arch": "arch", "variant": "" }, `+ - `"size": "123445", "isSigned": false } ], `+ - `"size": "123445", "digest": "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", `+ - `"mediaType": "application/vnd.oci.image.manifest.v1+json", "isSigned": false }`) + `"digest": "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", `+ + `"mediaType": "application/vnd.oci.image.manifest.v1+json", `+ + `"manifests": [ { "digest": "sha256:6e2f80bf9cfaabad474fbaf8ad68fdb652f776ea80b63492ecca404e5f6446a6", `+ + `"configDigest": "sha256:4c10985c40365538426f2ba8cf0c21384a7769be502a550dcc0601b3736625e0", `+ + `"lastUpdated": "0001-01-01T00:00:00Z", "size": "123445", "platform": { "os": "os", "arch": "arch", `+ + `"variant": "" }, "isSigned": false, "downloadCount": 0, `+ + `"layers": [ { "size": "", "digest": "sha256:c122a146f0d02349be211bb95cc2530f4a5793f96edbdfa00860f741e5d8c0e6", `+ + `"score": 0 } ], "history": null, "vulnerabilities": { "maxSeverity": "", "count": 0 }, `+ + `"referrers": null, "artifactType": "" } ], "size": "123445", `+ + `"downloadCount": 0, "lastUpdated": "0001-01-01T00:00:00Z", "description": "", "isSigned": false, "licenses": "", `+ + `"labels": "", "title": "", "source": "", "documentation": "", "authors": "", "vendor": "", `+ + `"vulnerabilities": { "maxSeverity": "", "count": 0 }, "referrers": null }`) So(err, ShouldBeNil) }) @@ -779,14 +785,18 @@ func TestOutputFormat(t *testing.T) { strings.TrimSpace(str), ShouldEqual, `reponame: dummyImageName tag: tag `+ - `manifests: - `+ - `configdigest: sha256:4c10985c40365538426f2ba8cf0c21384a7769be502a550dcc0601b3736625e0 `+ + `digest: sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 `+ + `mediatype: application/vnd.oci.image.manifest.v1+json manifests: - `+ `digest: sha256:6e2f80bf9cfaabad474fbaf8ad68fdb652f776ea80b63492ecca404e5f6446a6 `+ - `layers: - size: 0 digest: sha256:c122a146f0d02349be211bb95cc2530f4a5793f96edbdfa00860f741e5d8c0e6 `+ - `platform: os: os arch: arch variant: "" `+ - `size: "123445" issigned: false `+ - `size: "123445" digest: sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 `+ - `mediatype: application/vnd.oci.image.manifest.v1+json issigned: false`, + `configdigest: sha256:4c10985c40365538426f2ba8cf0c21384a7769be502a550dcc0601b3736625e0 `+ + `lastupdated: 0001-01-01T00:00:00Z size: "123445" platform: os: os arch: arch variant: "" `+ + `issigned: false downloadcount: 0 layers: - size: "" `+ + `digest: sha256:c122a146f0d02349be211bb95cc2530f4a5793f96edbdfa00860f741e5d8c0e6 score: 0 `+ + `history: [] vulnerabilities: maxseverity: "" count: 0 referrers: [] artifacttype: "" `+ + `size: "123445" downloadcount: 0 `+ + `lastupdated: 0001-01-01T00:00:00Z description: "" issigned: false licenses: "" labels: "" `+ + `title: "" source: "" documentation: "" authors: "" vendor: "" vulnerabilities: maxseverity: "" `+ + `count: 0 referrers: []`, ) So(err, ShouldBeNil) @@ -809,14 +819,18 @@ func TestOutputFormat(t *testing.T) { strings.TrimSpace(str), ShouldEqual, `reponame: dummyImageName tag: tag `+ - `manifests: - `+ + `digest: sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 `+ + `mediatype: application/vnd.oci.image.manifest.v1+json `+ + `manifests: - digest: sha256:6e2f80bf9cfaabad474fbaf8ad68fdb652f776ea80b63492ecca404e5f6446a6 `+ `configdigest: sha256:4c10985c40365538426f2ba8cf0c21384a7769be502a550dcc0601b3736625e0 `+ - `digest: sha256:6e2f80bf9cfaabad474fbaf8ad68fdb652f776ea80b63492ecca404e5f6446a6 `+ - `layers: - size: 0 digest: sha256:c122a146f0d02349be211bb95cc2530f4a5793f96edbdfa00860f741e5d8c0e6 `+ - `platform: os: os arch: arch variant: "" `+ - `size: "123445" issigned: false `+ - `size: "123445" digest: sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 `+ - `mediatype: application/vnd.oci.image.manifest.v1+json issigned: false`, + `lastupdated: 0001-01-01T00:00:00Z size: "123445" platform: os: os arch: arch variant: "" `+ + `issigned: false downloadcount: 0 layers: - size: "" `+ + `digest: sha256:c122a146f0d02349be211bb95cc2530f4a5793f96edbdfa00860f741e5d8c0e6 score: 0 `+ + `history: [] vulnerabilities: maxseverity: "" count: 0 referrers: [] artifacttype: "" `+ + `size: "123445" downloadcount: 0 `+ + `lastupdated: 0001-01-01T00:00:00Z description: "" issigned: false licenses: "" labels: "" `+ + `title: "" source: "" documentation: "" authors: "" vendor: "" vulnerabilities: maxseverity: `+ + `"" count: 0 referrers: []`, ) So(err, ShouldBeNil) }) @@ -1698,18 +1712,18 @@ func (service mockService) getRepos(ctx context.Context, config searchConfig, us func (service mockService) getDerivedImageListGQL(ctx context.Context, config searchConfig, username, password string, derivedImage string, -) (*imageListStructForDerivedImagesGQL, error) { - imageListGQLResponse := &imageListStructForDerivedImagesGQL{} - imageListGQLResponse.Data.Results = []imageStruct{ +) (*common.DerivedImageListResponse, error) { + imageListGQLResponse := &common.DerivedImageListResponse{} + imageListGQLResponse.DerivedImageList.Results = []common.ImageSummary{ { RepoName: "dummyImageName", Tag: "tag", - Manifests: []manifestStruct{ + Manifests: []common.ManifestSummary{ { Digest: godigest.FromString("Digest").String(), ConfigDigest: godigest.FromString("ConfigDigest").String(), Size: "123445", - Layers: []layer{{Digest: godigest.FromString("LayerDigest").String()}}, + Layers: []common.LayerSummary{{Digest: godigest.FromString("LayerDigest").String()}}, }, }, Size: "123445", @@ -1721,18 +1735,18 @@ func (service mockService) getDerivedImageListGQL(ctx context.Context, config se func (service mockService) getBaseImageListGQL(ctx context.Context, config searchConfig, username, password string, derivedImage string, -) (*imageListStructForBaseImagesGQL, error) { - imageListGQLResponse := &imageListStructForBaseImagesGQL{} - imageListGQLResponse.Data.Results = []imageStruct{ +) (*common.BaseImageListResponse, error) { + imageListGQLResponse := &common.BaseImageListResponse{} + imageListGQLResponse.BaseImageList.Results = []common.ImageSummary{ { RepoName: "dummyImageName", Tag: "tag", - Manifests: []manifestStruct{ + Manifests: []common.ManifestSummary{ { Digest: godigest.FromString("Digest").String(), ConfigDigest: godigest.FromString("ConfigDigest").String(), Size: "123445", - Layers: []layer{{Digest: godigest.FromString("LayerDigest").String()}}, + Layers: []common.LayerSummary{{Digest: godigest.FromString("LayerDigest").String()}}, }, }, Size: "123445", @@ -1744,20 +1758,20 @@ func (service mockService) getBaseImageListGQL(ctx context.Context, config searc func (service mockService) getImagesGQL(ctx context.Context, config searchConfig, username, password string, imageName string, -) (*imageListStructGQL, error) { - imageListGQLResponse := &imageListStructGQL{} - imageListGQLResponse.Data.Results = []imageStruct{ +) (*common.ImageListResponse, error) { + imageListGQLResponse := &common.ImageListResponse{} + imageListGQLResponse.PaginatedImagesResult.Results = []common.ImageSummary{ { RepoName: "dummyImageName", Tag: "tag", MediaType: ispec.MediaTypeImageManifest, Digest: godigest.FromString("test").String(), - Manifests: []manifestStruct{ + Manifests: []common.ManifestSummary{ { Digest: godigest.FromString("Digest").String(), ConfigDigest: godigest.FromString("ConfigDigest").String(), Size: "123445", - Layers: []layer{{Digest: godigest.FromString("LayerDigest").String()}}, + Layers: []common.LayerSummary{{Digest: godigest.FromString("LayerDigest").String()}}, }, }, Size: "123445", @@ -1769,19 +1783,19 @@ func (service mockService) getImagesGQL(ctx context.Context, config searchConfig func (service mockService) getImagesByDigestGQL(ctx context.Context, config searchConfig, username, password string, digest string, -) (*imageListStructForDigestGQL, error) { - imageListGQLResponse := &imageListStructForDigestGQL{} - imageListGQLResponse.Data.Results = []imageStruct{ +) (*common.ImagesForDigest, error) { + imageListGQLResponse := &common.ImagesForDigest{} + imageListGQLResponse.Results = []common.ImageSummary{ { RepoName: "randomimageName", Tag: "tag", MediaType: ispec.MediaTypeImageManifest, Digest: godigest.FromString("test").String(), - Manifests: []manifestStruct{ + Manifests: []common.ManifestSummary{ { Digest: godigest.FromString("Digest").String(), ConfigDigest: godigest.FromString("ConfigDigest").String(), - Layers: []layer{{Digest: godigest.FromString("LayerDigest").String()}}, + Layers: []common.LayerSummary{{Digest: godigest.FromString("LayerDigest").String()}}, Size: "123445", }, }, @@ -1794,54 +1808,54 @@ func (service mockService) getImagesByDigestGQL(ctx context.Context, config sear func (service mockService) getImagesByCveIDGQL(ctx context.Context, config searchConfig, username, password string, digest string, -) (*imagesForCve, error) { - imagesForCve := &imagesForCve{ +) (*common.ImagesForCve, error) { + imagesForCve := &common.ImagesForCve{ Errors: nil, - Data: struct { - PaginatedImagesResult `json:"ImageListForCVE"` //nolint:tagliatelle + ImagesForCVEList: struct { + common.PaginatedImagesResult `json:"ImageListForCVE"` //nolint:tagliatelle }{}, } imagesForCve.Errors = nil mockedImage := service.getMockedImageByName("anImage") - imagesForCve.Data.Results = []imageStruct{mockedImage} + imagesForCve.Results = []common.ImageSummary{common.ImageSummary(mockedImage)} return imagesForCve, nil } func (service mockService) getTagsForCVEGQL(ctx context.Context, config searchConfig, username, password, imageName, cveID string, -) (*imagesForCve, error) { - images := &imagesForCve{ +) (*common.ImagesForCve, error) { + images := &common.ImagesForCve{ Errors: nil, - Data: struct { - PaginatedImagesResult `json:"ImageListForCVE"` //nolint:tagliatelle // graphQL schema + ImagesForCVEList: struct { + common.PaginatedImagesResult `json:"ImageListForCVE"` //nolint:tagliatelle // graphQL schema }{}, } images.Errors = nil mockedImage := service.getMockedImageByName(imageName) - images.Data.Results = []imageStruct{mockedImage} + images.Results = []common.ImageSummary{common.ImageSummary(mockedImage)} return images, nil } func (service mockService) getFixedTagsForCVEGQL(ctx context.Context, config searchConfig, username, password, imageName, cveID string, -) (*fixedTags, error) { - fixedTags := &fixedTags{ +) (*common.FixedTags, error) { + fixedTags := &common.FixedTags{ Errors: nil, - Data: struct { - PaginatedImagesResult `json:"ImageListWithCVEFixed"` //nolint:tagliatelle // graphQL schema + ImageListWithCVEFixed: struct { + common.PaginatedImagesResult `json:"ImageListWithCVEFixed"` //nolint:tagliatelle // graphQL schema }{}, } fixedTags.Errors = nil mockedImage := service.getMockedImageByName(imageName) - fixedTags.Data.Results = []imageStruct{mockedImage} + fixedTags.Results = []common.ImageSummary{common.ImageSummary(mockedImage)} return fixedTags, nil } @@ -1879,11 +1893,11 @@ func (service mockService) getMockedImageByName(imageName string) imageStruct { image := imageStruct{} image.RepoName = imageName image.Tag = "tag" - image.Manifests = []manifestStruct{ + image.Manifests = []common.ManifestSummary{ { Digest: godigest.FromString("Digest").String(), ConfigDigest: godigest.FromString("ConfigDigest").String(), - Layers: []layer{{Digest: godigest.FromString("LayerDigest").String()}}, + Layers: []common.LayerSummary{{Digest: godigest.FromString("LayerDigest").String()}}, Size: "123445", }, } @@ -1903,18 +1917,18 @@ func (service mockService) getAllImages(ctx context.Context, config searchConfig image.Tag = "tag" image.Digest = godigest.FromString("test").String() image.MediaType = ispec.MediaTypeImageManifest - image.Manifests = []manifestStruct{ + image.Manifests = []common.ManifestSummary{ { Digest: godigest.FromString("Digest").String(), ConfigDigest: godigest.FromString("ConfigDigest").String(), - Layers: []layer{{Digest: godigest.FromString("LayerDigest").String()}}, + Layers: []common.LayerSummary{{Digest: godigest.FromString("LayerDigest").String()}}, Size: "123445", - Platform: platform{Os: "os", Arch: "arch"}, + Platform: common.Platform{Os: "os", Arch: "arch"}, }, } image.Size = "123445" - str, err := image.string(*config.outputFormat, len(image.RepoName), len(image.Tag), len("os/Arch")) + str, err := image.string(*config.outputFormat, len(image.RepoName), len(image.Tag), len("os/Arch"), *config.verbose) if err != nil { channel <- stringResult{"", err} @@ -1935,18 +1949,18 @@ func (service mockService) getImageByName(ctx context.Context, config searchConf image.Tag = "tag" image.Digest = godigest.FromString("test").String() image.MediaType = ispec.MediaTypeImageManifest - image.Manifests = []manifestStruct{ + image.Manifests = []common.ManifestSummary{ { Digest: godigest.FromString("Digest").String(), ConfigDigest: godigest.FromString("ConfigDigest").String(), - Layers: []layer{{Digest: godigest.FromString("LayerDigest").String()}}, + Layers: []common.LayerSummary{{Digest: godigest.FromString("LayerDigest").String()}}, Size: "123445", - Platform: platform{Os: "os", Arch: "arch"}, + Platform: common.Platform{Os: "os", Arch: "arch"}, }, } image.Size = "123445" - str, err := image.string(*config.outputFormat, len(image.RepoName), len(image.Tag), len("os/Arch")) + str, err := image.string(*config.outputFormat, len(image.RepoName), len(image.Tag), len("os/Arch"), *config.verbose) if err != nil { channel <- stringResult{"", err} diff --git a/pkg/cli/searcher.go b/pkg/cli/searcher.go index 8bb0a302..5ae18fed 100644 --- a/pkg/cli/searcher.go +++ b/pkg/cli/searcher.go @@ -188,7 +188,13 @@ func getImages(config searchConfig) error { return err } - return printResult(config, imageList.Data.Results) + imageListData := []imageStruct{} + + for _, image := range imageList.Results { + imageListData = append(imageListData, imageStruct(image)) + } + + return printResult(config, imageListData) } type imagesByDigestSearcher struct{} @@ -241,7 +247,13 @@ func (search derivedImageListSearcherGQL) search(config searchConfig) (bool, err return true, err } - if err := printResult(config, imageList.Data.Results); err != nil { + imageListData := []imageStruct{} + + for _, image := range imageList.DerivedImageList.Results { + imageListData = append(imageListData, imageStruct(image)) + } + + if err := printResult(config, imageListData); err != nil { return true, err } @@ -266,7 +278,13 @@ func (search baseImageListSearcherGQL) search(config searchConfig) (bool, error) return true, err } - if err := printResult(config, imageList.Data.Results); err != nil { + imageListData := []imageStruct{} + + for _, image := range imageList.BaseImageList.Results { + imageListData = append(imageListData, imageStruct(image)) + } + + if err := printResult(config, imageListData); err != nil { return true, err } @@ -292,7 +310,13 @@ func (search imagesByDigestSearcherGQL) search(config searchConfig) (bool, error return true, err } - if err := printResult(config, imageList.Data.Results); err != nil { + imageListData := []imageStruct{} + + for _, image := range imageList.Results { + imageListData = append(imageListData, imageStruct(image)) + } + + if err := printResult(config, imageListData); err != nil { return true, err } @@ -431,7 +455,13 @@ func (search imagesByCVEIDSearcherGQL) search(config searchConfig) (bool, error) return true, err } - if err := printResult(config, imageList.Data.Results); err != nil { + imageListData := []imageStruct{} + + for _, image := range imageList.Results { + imageListData = append(imageListData, imageStruct(image)) + } + + if err := printResult(config, imageListData); err != nil { return true, err } @@ -557,7 +587,9 @@ func getTagsByCVE(config searchConfig) error { return err } - imageList = fixedTags.Data.Results + for _, image := range fixedTags.Results { + imageList = append(imageList, imageStruct(image)) + } } else { tags, err := config.searchService.getTagsForCVEGQL(ctx, config, username, password, *config.params["imageName"], *config.params["cveID"]) @@ -565,7 +597,10 @@ func getTagsByCVE(config searchConfig) error { return err } - imageList = tags.Data.Results + imageList = nil + for _, image := range tags.Results { + imageList = append(imageList, imageStruct(image)) + } } return printResult(config, imageList) @@ -798,9 +833,9 @@ func printResult(config searchConfig, imageList []imageStruct) error { for i := range imageList { img := imageList[i] - img.verbose = *config.verbose + verbose := *config.verbose - out, err := img.string(*config.outputFormat, maxImgNameLen, maxTagLen, maxPlatformLen) + out, err := img.string(*config.outputFormat, maxImgNameLen, maxTagLen, maxPlatformLen, verbose) if err != nil { return err } diff --git a/pkg/cli/service.go b/pkg/cli/service.go index 3036b67b..7c0828a4 100644 --- a/pkg/cli/service.go +++ b/pkg/cli/service.go @@ -27,21 +27,21 @@ import ( type SearchService interface { //nolint:interfacebloat getImagesGQL(ctx context.Context, config searchConfig, username, password string, - imageName string) (*imageListStructGQL, error) + imageName string) (*common.ImageListResponse, error) getImagesByDigestGQL(ctx context.Context, config searchConfig, username, password string, - digest string) (*imageListStructForDigestGQL, error) + digest string) (*common.ImagesForDigest, error) getCveByImageGQL(ctx context.Context, config searchConfig, username, password, imageName string, searchedCVE string) (*cveResult, error) getImagesByCveIDGQL(ctx context.Context, config searchConfig, username, password string, - digest string) (*imagesForCve, error) + digest string) (*common.ImagesForCve, error) getTagsForCVEGQL(ctx context.Context, config searchConfig, username, password, imageName, - cveID string) (*imagesForCve, error) + cveID string) (*common.ImagesForCve, error) getFixedTagsForCVEGQL(ctx context.Context, config searchConfig, username, password, imageName, - cveID string) (*fixedTags, error) + cveID string) (*common.FixedTags, error) getDerivedImageListGQL(ctx context.Context, config searchConfig, username, password string, - derivedImage string) (*imageListStructForDerivedImagesGQL, error) + derivedImage string) (*common.DerivedImageListResponse, error) getBaseImageListGQL(ctx context.Context, config searchConfig, username, password string, - baseImage string) (*imageListStructForBaseImagesGQL, error) + baseImage string) (*common.BaseImageListResponse, error) getAllImages(ctx context.Context, config searchConfig, username, password string, channel chan stringResult, wtgrp *sync.WaitGroup) @@ -69,7 +69,7 @@ func NewSearchService() SearchService { func (service searchService) getDerivedImageListGQL(ctx context.Context, config searchConfig, username, password string, derivedImage string, -) (*imageListStructForDerivedImagesGQL, error) { +) (*common.DerivedImageListResponse, error) { query := fmt.Sprintf(` { DerivedImageList(image:"%s"){ @@ -93,7 +93,7 @@ func (service searchService) getDerivedImageListGQL(ctx context.Context, config } }`, derivedImage) - result := &imageListStructForDerivedImagesGQL{} + result := &common.DerivedImageListResponse{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) if errResult := checkResultGraphQLQuery(ctx, err, result.Errors); errResult != nil { @@ -105,7 +105,7 @@ func (service searchService) getDerivedImageListGQL(ctx context.Context, config func (service searchService) getBaseImageListGQL(ctx context.Context, config searchConfig, username, password string, baseImage string, -) (*imageListStructForBaseImagesGQL, error) { +) (*common.BaseImageListResponse, error) { query := fmt.Sprintf(` { BaseImageList(image:"%s"){ @@ -129,7 +129,7 @@ func (service searchService) getBaseImageListGQL(ctx context.Context, config sea } }`, baseImage) - result := &imageListStructForBaseImagesGQL{} + result := &common.BaseImageListResponse{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) if errResult := checkResultGraphQLQuery(ctx, err, result.Errors); errResult != nil { @@ -141,7 +141,7 @@ func (service searchService) getBaseImageListGQL(ctx context.Context, config sea func (service searchService) getImagesGQL(ctx context.Context, config searchConfig, username, password string, imageName string, -) (*imageListStructGQL, error) { +) (*common.ImageListResponse, error) { query := fmt.Sprintf(` { ImageList(repo: "%s") { @@ -163,7 +163,7 @@ func (service searchService) getImagesGQL(ctx context.Context, config searchConf } }`, imageName) - result := &imageListStructGQL{} + result := &common.ImageListResponse{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) @@ -176,7 +176,7 @@ func (service searchService) getImagesGQL(ctx context.Context, config searchConf func (service searchService) getImagesByDigestGQL(ctx context.Context, config searchConfig, username, password string, digest string, -) (*imageListStructForDigestGQL, error) { +) (*common.ImagesForDigest, error) { query := fmt.Sprintf(` { ImageListForDigest(id: "%s") { @@ -197,7 +197,7 @@ func (service searchService) getImagesByDigestGQL(ctx context.Context, config se } }`, digest) - result := &imageListStructForDigestGQL{} + result := &common.ImagesForDigest{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) @@ -210,7 +210,7 @@ func (service searchService) getImagesByDigestGQL(ctx context.Context, config se func (service searchService) getImagesByCveIDGQL(ctx context.Context, config searchConfig, username, password, cveID string, -) (*imagesForCve, error) { +) (*common.ImagesForCve, error) { query := fmt.Sprintf(` { ImageListForCVE(id: "%s") { @@ -231,7 +231,7 @@ func (service searchService) getImagesByCveIDGQL(ctx context.Context, config sea } }`, cveID) - result := &imagesForCve{} + result := &common.ImagesForCve{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) @@ -263,7 +263,7 @@ func (service searchService) getCveByImageGQL(ctx context.Context, config search func (service searchService) getTagsForCVEGQL(ctx context.Context, config searchConfig, username, password, imageName, cveID string, -) (*imagesForCve, error) { +) (*common.ImagesForCve, error) { query := fmt.Sprintf(` { ImageListForCVE(id: "%s") { @@ -283,7 +283,7 @@ func (service searchService) getTagsForCVEGQL(ctx context.Context, config search } }`, cveID) - result := &imagesForCve{} + result := &common.ImagesForCve{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) @@ -296,7 +296,7 @@ func (service searchService) getTagsForCVEGQL(ctx context.Context, config search func (service searchService) getFixedTagsForCVEGQL(ctx context.Context, config searchConfig, username, password, imageName, cveID string, -) (*fixedTags, error) { +) (*common.FixedTags, error) { query := fmt.Sprintf(` { ImageListWithCVEFixed(id: "%s", image: "%s") { @@ -317,7 +317,7 @@ func (service searchService) getFixedTagsForCVEGQL(ctx context.Context, config s }`, cveID, imageName) - result := &fixedTags{} + result := &common.FixedTags{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) @@ -464,7 +464,7 @@ func (service searchService) getImagesByCveID(ctx context.Context, config search }`, cvid) - result := &imagesForCve{} + result := &common.ImagesForCve{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) if err != nil { @@ -498,7 +498,7 @@ func (service searchService) getImagesByCveID(ctx context.Context, config search go rlim.startRateLimiter(ctx) - for _, image := range result.Data.Results { + for _, image := range result.Results { localWg.Add(1) go addManifestCallToPool(ctx, config, rlim, username, password, image.RepoName, image.Tag, rch, &localWg) @@ -533,7 +533,7 @@ func (service searchService) getImagesByDigest(ctx context.Context, config searc }`, digest) - result := &imagesForDigest{} + result := &common.ImagesForDigest{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) if err != nil { @@ -567,7 +567,7 @@ func (service searchService) getImagesByDigest(ctx context.Context, config searc go rlim.startRateLimiter(ctx) - for _, image := range result.Data.Results { + for _, image := range result.Results { localWg.Add(1) go addManifestCallToPool(ctx, config, rlim, username, password, image.RepoName, image.Tag, rch, &localWg) @@ -602,7 +602,7 @@ func (service searchService) getImageByNameAndCVEID(ctx context.Context, config }`, cvid) - result := &imagesForCve{} + result := &common.ImagesForCve{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) if err != nil { @@ -636,7 +636,7 @@ func (service searchService) getImageByNameAndCVEID(ctx context.Context, config go rlim.startRateLimiter(ctx) - for _, image := range result.Data.Results { + for _, image := range result.Results { if !strings.EqualFold(imageName, image.RepoName) { continue } @@ -728,7 +728,7 @@ func (service searchService) getFixedTagsForCVE(ctx context.Context, config sear } }`, cvid, imageName) - result := &fixedTags{} + result := &common.FixedTags{} err := service.makeGraphQLQuery(ctx, config, username, password, query, result) if err != nil { @@ -762,7 +762,7 @@ func (service searchService) getFixedTagsForCVE(ctx context.Context, config sear go rlim.startRateLimiter(ctx) - for _, img := range result.Data.Results { + for _, img := range result.Results { localWg.Add(1) go addManifestCallToPool(ctx, config, rlim, username, password, imageName, img.Tag, rch, &localWg) @@ -844,7 +844,7 @@ func (service searchService) makeGraphQLQuery(ctx context.Context, return nil } -func checkResultGraphQLQuery(ctx context.Context, err error, resultErrors []common.ErrorGraphQL, +func checkResultGraphQLQuery(ctx context.Context, err error, resultErrors []common.ErrorGQL, ) error { if err != nil { if isContextDone(ctx) { @@ -900,8 +900,8 @@ func addManifestCallToPool(ctx context.Context, config searchConfig, pool *reque } type cveResult struct { - Errors []common.ErrorGraphQL `json:"errors"` - Data cveData `json:"data"` + Errors []common.ErrorGQL `json:"errors"` + Data cveData `json:"data"` } type tagListResp struct { @@ -991,101 +991,12 @@ func (cve cveResult) stringYAML() (string, error) { return string(body), nil } -type fixedTags struct { - Errors []common.ErrorGraphQL `json:"errors"` - Data struct { - PaginatedImagesResult `json:"ImageListWithCVEFixed"` //nolint:tagliatelle // graphQL schema - } `json:"data"` -} +type imageStruct common.ImageSummary -type imagesForCve struct { - Errors []common.ErrorGraphQL `json:"errors"` - Data struct { - PaginatedImagesResult `json:"ImageListForCVE"` //nolint:tagliatelle // graphQL schema - } `json:"data"` -} - -type PaginatedImagesResult struct { - Results []imageStruct `json:"results"` -} - -type imageStruct struct { - RepoName string `json:"repoName"` - Tag string `json:"tag"` - Manifests []manifestStruct - Size string `json:"size"` - Digest string `json:"digest"` - MediaType string `json:"mediaType"` - IsSigned bool `json:"isSigned"` - verbose bool -} - -type manifestStruct struct { - ConfigDigest string `json:"configDigest"` - Digest string `json:"digest"` - Layers []layer `json:"layers"` - Platform platform `json:"platform"` - Size string `json:"size"` - IsSigned bool `json:"isSigned"` -} - -type platform struct { - Os string `json:"os"` - Arch string `json:"arch"` - Variant string `json:"variant"` -} - -type DerivedImageList struct { - Results []imageStruct `json:"results"` -} -type BaseImageList struct { - Results []imageStruct `json:"results"` -} - -type imageListStructGQL struct { - Errors []common.ErrorGraphQL `json:"errors"` - Data struct { - PaginatedImagesResult `json:"ImageList"` //nolint:tagliatelle - } `json:"data"` -} - -type imageListStructForDigestGQL struct { - Errors []common.ErrorGraphQL `json:"errors"` - Data struct { - PaginatedImagesResult `json:"ImageListForDigest"` //nolint:tagliatelle - } `json:"data"` -} - -type imageListStructForDerivedImagesGQL struct { - Errors []common.ErrorGraphQL `json:"errors"` - Data struct { - PaginatedImagesResult `json:"DerivedImageList"` //nolint:tagliatelle - } `json:"data"` -} - -type imageListStructForBaseImagesGQL struct { - Errors []common.ErrorGraphQL `json:"errors"` - Data struct { - PaginatedImagesResult `json:"BaseImageList"` //nolint:tagliatelle - } `json:"data"` -} - -type imagesForDigest struct { - Errors []common.ErrorGraphQL `json:"errors"` - Data struct { - PaginatedImagesResult `json:"ImageListForDigest"` //nolint:tagliatelle // graphQL schema - } `json:"data"` -} - -type layer struct { - Size int64 `json:"size,string"` - Digest string `json:"digest"` -} - -func (img imageStruct) string(format string, maxImgNameLen, maxTagLen, maxPlatformLen int) (string, error) { +func (img imageStruct) string(format string, maxImgNameLen, maxTagLen, maxPlatformLen int, verbose bool) (string, error) { //nolint: lll switch strings.ToLower(format) { case "", defaultOutoutFormat: - return img.stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen) + return img.stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen, verbose) case "json": return img.stringJSON() case "yml", "yaml": @@ -1095,7 +1006,7 @@ func (img imageStruct) string(format string, maxImgNameLen, maxTagLen, maxPlatfo } } -func (img imageStruct) stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen int) (string, error) { +func (img imageStruct) stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen int, verbose bool) (string, error) { var builder strings.Builder table := getImageTableWriter(&builder) @@ -1107,7 +1018,7 @@ func (img imageStruct) stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen table.SetColMinWidth(colSizeIndex, sizeWidth) table.SetColMinWidth(colIsSignedIndex, isSignedWidth) - if img.verbose { + if verbose { table.SetColMinWidth(colConfigIndex, configWidth) table.SetColMinWidth(colLayersIndex, layersWidth) } @@ -1138,7 +1049,7 @@ func (img imageStruct) stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen tagName += offset } - err := addImageToTable(table, &img, maxPlatformLen, imageName, tagName) + err := addImageToTable(table, &img, maxPlatformLen, imageName, tagName, verbose) if err != nil { return "", err } @@ -1149,20 +1060,20 @@ func (img imageStruct) stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen } func addImageToTable(table *tablewriter.Table, img *imageStruct, maxPlatformLen int, - imageName, tagName string, + imageName, tagName string, verbose bool, ) error { switch img.MediaType { case ispec.MediaTypeImageManifest: - return addManifestToTable(table, imageName, tagName, &img.Manifests[0], maxPlatformLen, img.verbose) + return addManifestToTable(table, imageName, tagName, &img.Manifests[0], maxPlatformLen, verbose) case ispec.MediaTypeImageIndex: - return addImageIndexToTable(table, img, maxPlatformLen, imageName, tagName) + return addImageIndexToTable(table, img, maxPlatformLen, imageName, tagName, verbose) } return nil } func addImageIndexToTable(table *tablewriter.Table, img *imageStruct, maxPlatformLen int, - imageName, tagName string, + imageName, tagName string, verbose bool, ) error { indexDigest, err := godigest.Parse(img.Digest) if err != nil { @@ -1178,7 +1089,7 @@ func addImageIndexToTable(table *tablewriter.Table, img *imageStruct, maxPlatfor row[colSizeIndex] = ellipsize(strings.ReplaceAll(humanize.Bytes(imgSize), " ", ""), sizeWidth, ellipsis) row[colIsSignedIndex] = strconv.FormatBool(img.IsSigned) - if img.verbose { + if verbose { row[colConfigIndex] = "" row[colLayersIndex] = "" } @@ -1186,7 +1097,7 @@ func addImageIndexToTable(table *tablewriter.Table, img *imageStruct, maxPlatfor table.Append(row) for i := range img.Manifests { - err := addManifestToTable(table, "", "", &img.Manifests[i], maxPlatformLen, img.verbose) + err := addManifestToTable(table, "", "", &img.Manifests[i], maxPlatformLen, verbose) if err != nil { return err } @@ -1195,7 +1106,7 @@ func addImageIndexToTable(table *tablewriter.Table, img *imageStruct, maxPlatfor return nil } -func addManifestToTable(table *tablewriter.Table, imageName, tagName string, manifest *manifestStruct, +func addManifestToTable(table *tablewriter.Table, imageName, tagName string, manifest *common.ManifestSummary, maxPlatformLen int, verbose bool, ) error { manifestDigest, err := godigest.Parse(manifest.Digest) @@ -1238,8 +1149,8 @@ func addManifestToTable(table *tablewriter.Table, imageName, tagName string, man if verbose { for _, entry := range manifest.Layers { - layerSize := entry.Size - size := ellipsize(strings.ReplaceAll(humanize.Bytes(uint64(layerSize)), " ", ""), sizeWidth, ellipsis) + layerSize, _ := strconv.ParseUint(entry.Size, 10, 64) + size := ellipsize(strings.ReplaceAll(humanize.Bytes(layerSize), " ", ""), sizeWidth, ellipsis) layerDigest, err := godigest.Parse(entry.Digest) if err != nil { @@ -1264,7 +1175,7 @@ func addManifestToTable(table *tablewriter.Table, imageName, tagName string, man return nil } -func getPlatformStr(platf platform) string { +func getPlatformStr(platf common.Platform) string { if platf.Arch == "" && platf.Os == "" { return "" } diff --git a/pkg/common/model.go b/pkg/common/model.go index b245d85f..14f9adb8 100644 --- a/pkg/common/model.go +++ b/pkg/common/model.go @@ -4,6 +4,11 @@ import ( "time" ) +type PageInfo struct { + TotalCount int + ItemCount int +} + type RepoInfo struct { Summary RepoSummary ImageSummaries []ImageSummary `json:"images"` @@ -21,6 +26,11 @@ type RepoSummary struct { NewestImage ImageSummary `json:"newestImage"` } +type PaginatedImagesResult struct { + Results []ImageSummary `json:"results"` + Page PageInfo `json:"page"` +} + type ImageSummary struct { RepoName string `json:"repoName"` Tag string `json:"tag"` @@ -49,6 +59,7 @@ type ManifestSummary struct { LastUpdated time.Time `json:"lastUpdated"` Size string `json:"size"` Platform Platform `json:"platform"` + IsSigned bool `json:"isSigned"` DownloadCount int `json:"downloadCount"` Layers []LayerSummary `json:"layers"` History []LayerHistory `json:"history"` @@ -58,13 +69,9 @@ type ManifestSummary struct { } type Platform struct { - Os string `json:"os"` - Arch string `json:"arch"` -} - -type ErrorGraphQL struct { - Message string `json:"message"` - Path []string `json:"path"` + Os string `json:"os"` + Arch string `json:"arch"` + Variant string `json:"variant"` } type ImageVulnerabilitySummary struct { @@ -103,3 +110,138 @@ type Annotation struct { Key string `json:"key"` Value string `json:"value"` } + +type FixedTags struct { + Errors []ErrorGQL `json:"errors"` + ImageListWithCVEFixed `json:"data"` +} + +type ImageListWithCVEFixed struct { + PaginatedImagesResult `json:"ImageListWithCVEFixed"` //nolint:tagliatelle // graphQL schema +} + +type ImagesForCve struct { + Errors []ErrorGQL `json:"errors"` + ImagesForCVEList `json:"data"` +} + +type ImagesForCVEList struct { + PaginatedImagesResult `json:"ImageListForCVE"` //nolint:tagliatelle // graphQL schema +} + +type ImagesForDigest struct { + Errors []ErrorGQL `json:"errors"` + ImagesForDigestList `json:"data"` +} + +type ImagesForDigestList struct { + PaginatedImagesResult `json:"ImageListForDigest"` //nolint:tagliatelle // graphQL schema +} + +type RepoWithNewestImageResponse struct { + RepoListWithNewestImage `json:"data"` + Errors []ErrorGQL `json:"errors"` +} + +type DerivedImageListResponse struct { + DerivedImageList `json:"data"` + Errors []ErrorGQL `json:"errors"` +} + +type BaseImageListResponse struct { + BaseImageList `json:"data"` + Errors []ErrorGQL `json:"errors"` +} + +type DerivedImageList struct { + PaginatedImagesResult `json:"derivedImageList"` +} + +type BaseImageList struct { + PaginatedImagesResult `json:"baseImageList"` +} + +type ImageListResponse struct { + ImageList `json:"data"` + Errors []ErrorGQL `json:"errors"` +} + +type ImageList struct { + PaginatedImagesResult `json:"imageList"` +} + +type ExpandedRepoInfoResp struct { + ExpandedRepoInfo `json:"data"` + Errors []ErrorGQL `json:"errors"` +} + +type ReferrersResp struct { + ReferrersResult `json:"data"` + Errors []ErrorGQL `json:"errors"` +} + +type ReferrersResult struct { + Referrers []Referrer `json:"referrers"` +} +type GlobalSearchResultResp struct { + GlobalSearchResult `json:"data"` + Errors []ErrorGQL `json:"errors"` +} + +type GlobalSearchResult struct { + GlobalSearch `json:"globalSearch"` +} + +type GlobalSearch struct { + Images []ImageSummary `json:"images"` + Repos []RepoSummary `json:"repos"` + Layers []LayerSummary `json:"layers"` + Page PageInfo `json:"page"` +} + +type ExpandedRepoInfo struct { + RepoInfo `json:"expandedRepoInfo"` +} + +type PaginatedReposResult struct { + Results []RepoSummary `json:"results"` + Page PageInfo `json:"page"` +} + +//nolint:tagliatelle // graphQL schema +type RepoListWithNewestImage struct { + PaginatedReposResult `json:"RepoListWithNewestImage"` +} + +type ErrorGQL struct { + Message string `json:"message"` + Path []string `json:"path"` +} + +type SingleImageSummary struct { + ImageSummary `json:"Image"` //nolint:tagliatelle +} +type ImageSummaryResult struct { + SingleImageSummary `json:"data"` + Errors []ErrorGQL `json:"errors"` +} + +//nolint:tagliatelle // graphQL schema +type StarredRepos struct { + PaginatedReposResult `json:"StarredRepos"` +} + +//nolint:tagliatelle // graphQL schema +type BookmarkedRepos struct { + PaginatedReposResult `json:"BookmarkedRepos"` +} + +type StarredReposResponse struct { + StarredRepos `json:"data"` + Errors []ErrorGQL `json:"errors"` +} + +type BookmarkedReposResponse struct { + BookmarkedRepos `json:"data"` + Errors []ErrorGQL `json:"errors"` +} diff --git a/pkg/extensions/search/cve/cve.go b/pkg/extensions/search/cve/cve.go index 4962256d..694c343c 100644 --- a/pkg/extensions/search/cve/cve.go +++ b/pkg/extensions/search/cve/cve.go @@ -21,7 +21,7 @@ import ( type CveInfo interface { GetImageListForCVE(repo, cveID string) ([]cvemodel.TagInfo, error) GetImageListWithCVEFixed(repo, cveID string) ([]cvemodel.TagInfo, error) - GetCVEListForImage(repo, tag string, searchedCVE string, pageinput PageInput) ([]cvemodel.CVE, PageInfo, error) + GetCVEListForImage(repo, tag string, searchedCVE string, pageinput PageInput) ([]cvemodel.CVE, common.PageInfo, error) GetCVESummaryForImage(repo, tag string) (ImageCVESummary, error) CompareSeverities(severity1, severity2 string) int UpdateDB() error @@ -232,24 +232,24 @@ func filterCVEList(cveMap map[string]cvemodel.CVE, searchedCVE string, pageFinde func (cveinfo BaseCveInfo) GetCVEListForImage(repo, tag string, searchedCVE string, pageInput PageInput) ( []cvemodel.CVE, - PageInfo, + common.PageInfo, error, ) { isValidImage, err := cveinfo.Scanner.IsImageFormatScannable(repo, tag) if !isValidImage { - return []cvemodel.CVE{}, PageInfo{}, err + return []cvemodel.CVE{}, common.PageInfo{}, err } image := getImageString(repo, tag) cveMap, err := cveinfo.Scanner.ScanImage(image) if err != nil { - return []cvemodel.CVE{}, PageInfo{}, err + return []cvemodel.CVE{}, common.PageInfo{}, err } pageFinder, err := NewCvePageFinder(pageInput.Limit, pageInput.Offset, pageInput.SortBy, cveinfo) if err != nil { - return []cvemodel.CVE{}, PageInfo{}, err + return []cvemodel.CVE{}, common.PageInfo{}, err } filterCVEList(cveMap, searchedCVE, pageFinder) diff --git a/pkg/extensions/search/cve/pagination.go b/pkg/extensions/search/cve/pagination.go index 07e4896b..1bdfd258 100644 --- a/pkg/extensions/search/cve/pagination.go +++ b/pkg/extensions/search/cve/pagination.go @@ -5,6 +5,7 @@ import ( "sort" zerr "zotregistry.io/zot/errors" + "zotregistry.io/zot/pkg/common" cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model" ) @@ -46,7 +47,7 @@ func SortBySeverity(pageBuffer []cvemodel.CVE, cveInfo CveInfo) func(i, j int) b // and returning a specific page. type PageFinder interface { Add(cve cvemodel.CVE) - Page() ([]cvemodel.CVE, PageInfo) + Page() ([]cvemodel.CVE, common.PageInfo) Reset() } @@ -94,12 +95,12 @@ func (bpt *CvePageFinder) Add(cve cvemodel.CVE) { bpt.pageBuffer = append(bpt.pageBuffer, cve) } -func (bpt *CvePageFinder) Page() ([]cvemodel.CVE, PageInfo) { +func (bpt *CvePageFinder) Page() ([]cvemodel.CVE, common.PageInfo) { if len(bpt.pageBuffer) == 0 { - return []cvemodel.CVE{}, PageInfo{} + return []cvemodel.CVE{}, common.PageInfo{} } - pageInfo := &PageInfo{} + pageInfo := &common.PageInfo{} sort.Slice(bpt.pageBuffer, SortFunctions()[bpt.sortBy](bpt.pageBuffer, bpt.cveInfo)) @@ -131,11 +132,6 @@ func (bpt *CvePageFinder) Page() ([]cvemodel.CVE, PageInfo) { return cves, *pageInfo } -type PageInfo struct { - TotalCount int - ItemCount int -} - type PageInput struct { Limit int Offset int diff --git a/pkg/extensions/search/digest_test.go b/pkg/extensions/search/digest_test.go index 806a563a..acbeaf39 100644 --- a/pkg/extensions/search/digest_test.go +++ b/pkg/extensions/search/digest_test.go @@ -18,14 +18,14 @@ import ( "zotregistry.io/zot/pkg/api" "zotregistry.io/zot/pkg/api/config" "zotregistry.io/zot/pkg/api/constants" + "zotregistry.io/zot/pkg/common" extconf "zotregistry.io/zot/pkg/extensions/config" - "zotregistry.io/zot/pkg/meta/repodb" . "zotregistry.io/zot/pkg/test" ) type ImgResponseForDigest struct { - ImgListForDigest ImgListForDigest `json:"data"` - Errors []ErrorGQL `json:"errors"` + ImgListForDigest ImgListForDigest `json:"data"` + Errors []common.ErrorGQL `json:"errors"` } //nolint:tagliatelle // graphQL schema @@ -44,7 +44,7 @@ type ImgInfo struct { type PaginatedImagesResultForDigest struct { Results []ImgInfo `json:"results"` - Page repodb.PageInfo `json:"page"` + Page common.PageInfo `json:"page"` } func TestDigestSearchHTTP(t *testing.T) { diff --git a/pkg/extensions/search/resolver_test.go b/pkg/extensions/search/resolver_test.go index 23c8ee21..f7634edd 100644 --- a/pkg/extensions/search/resolver_test.go +++ b/pkg/extensions/search/resolver_test.go @@ -35,11 +35,11 @@ func TestGlobalSearch(t *testing.T) { Convey("RepoDB SearchRepos error", func() { mockRepoDB := mocks.RepoDBMock{ SearchReposFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error, ) { return make([]repodb.RepoMetadata, 0), make(map[string]repodb.ManifestMetadata), - map[string]repodb.IndexData{}, repodb.PageInfo{}, ErrTestError + map[string]repodb.IndexData{}, common.PageInfo{}, ErrTestError }, } responseContext := graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, @@ -56,7 +56,7 @@ func TestGlobalSearch(t *testing.T) { Convey("RepoDB SearchRepo is successful", func() { mockRepoDB := mocks.RepoDBMock{ SearchReposFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "repo1", @@ -115,7 +115,7 @@ func TestGlobalSearch(t *testing.T) { }, } - return repos, manifestMetas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -144,7 +144,7 @@ func TestGlobalSearch(t *testing.T) { Convey("RepoDB SearchRepo Bad manifest referenced", func() { mockRepoDB := mocks.RepoDBMock{ SearchReposFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "repo1", @@ -175,7 +175,7 @@ func TestGlobalSearch(t *testing.T) { }, } - return repos, manifestMetas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -215,7 +215,7 @@ func TestGlobalSearch(t *testing.T) { Convey("RepoDB SearchRepo good manifest referenced and bad config blob", func() { mockRepoDB := mocks.RepoDBMock{ SearchReposFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "repo1", @@ -246,7 +246,7 @@ func TestGlobalSearch(t *testing.T) { }, } - return repos, manifestMetas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -285,11 +285,11 @@ func TestGlobalSearch(t *testing.T) { Convey("RepoDB SearchTags gives error", func() { mockRepoDB := mocks.RepoDBMock{ SearchTagsFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error, ) { return make([]repodb.RepoMetadata, 0), make(map[string]repodb.ManifestMetadata), - map[string]repodb.IndexData{}, repodb.PageInfo{}, ErrTestError + map[string]repodb.IndexData{}, common.PageInfo{}, ErrTestError }, } const query = "repo1:1.0.1" @@ -308,7 +308,7 @@ func TestGlobalSearch(t *testing.T) { Convey("RepoDB SearchTags is successful", func() { mockRepoDB := mocks.RepoDBMock{ SearchTagsFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "repo1", @@ -361,7 +361,7 @@ func TestGlobalSearch(t *testing.T) { }, } - return repos, manifestMetas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -395,11 +395,11 @@ func TestRepoListWithNewestImage(t *testing.T) { mockRepoDB := mocks.RepoDBMock{ SearchReposFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error, ) { return make([]repodb.RepoMetadata, 0), make(map[string]repodb.ManifestMetadata), - map[string]repodb.IndexData{}, repodb.PageInfo{}, ErrTestError + map[string]repodb.IndexData{}, common.PageInfo{}, ErrTestError }, } responseContext := graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, @@ -422,7 +422,7 @@ func TestRepoListWithNewestImage(t *testing.T) { Convey("RepoDB SearchRepo bad manifest referenced", func() { mockRepoDB := mocks.RepoDBMock{ SearchReposFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "repo1", @@ -478,7 +478,7 @@ func TestRepoListWithNewestImage(t *testing.T) { }, } - return repos, manifestMetas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -504,7 +504,7 @@ func TestRepoListWithNewestImage(t *testing.T) { createTime2 := createTime.Add(time.Second) mockRepoDB := mocks.RepoDBMock{ SearchReposFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { pageFinder, err := repodb.NewBaseRepoPageFinder(requestedPage.Limit, requestedPage.Offset, requestedPage.SortBy) So(err, ShouldBeNil) @@ -585,7 +585,7 @@ func TestRepoListWithNewestImage(t *testing.T) { }, } - return repos, manifestMetas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } Convey("RepoDB missing requestedPage", func() { @@ -673,11 +673,11 @@ func TestGetFilteredPaginatedRepos(t *testing.T) { nil, mocks.RepoDBMock{ FilterReposFn: func(ctx context.Context, filter repodb.FilterRepoFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, ErrTestError + common.PageInfo{}, ErrTestError }, }, ) @@ -691,11 +691,11 @@ func TestImageListForDigest(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, ErrTestError + common.PageInfo{}, ErrTestError }, } @@ -709,7 +709,7 @@ func TestImageListForDigest(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "test", @@ -736,7 +736,7 @@ func TestImageListForDigest(t *testing.T) { }, } - return repos, manifestMetaDatas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetaDatas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -757,7 +757,7 @@ func TestImageListForDigest(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "test", @@ -790,7 +790,7 @@ func TestImageListForDigest(t *testing.T) { repos[0].Tags = matchedTags - return repos, manifestMetaDatas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetaDatas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -830,7 +830,7 @@ func TestImageListForDigest(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "test", @@ -868,7 +868,7 @@ func TestImageListForDigest(t *testing.T) { repos[0].Tags = matchedTags - return repos, manifestMetaDatas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetaDatas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -904,7 +904,7 @@ func TestImageListForDigest(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "test", @@ -944,7 +944,7 @@ func TestImageListForDigest(t *testing.T) { repos[0].Tags = matchedTags - return repos, manifestMetaDatas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetaDatas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -978,7 +978,7 @@ func TestImageListForDigest(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "test", @@ -1013,7 +1013,7 @@ func TestImageListForDigest(t *testing.T) { repos[i].Tags = matchedTags } - return repos, manifestMetaDatas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetaDatas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -1047,14 +1047,14 @@ func TestImageListForDigest(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error, ) { pageFinder, err := repodb.NewBaseImagePageFinder(requestedPage.Limit, requestedPage.Offset, requestedPage.SortBy) if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, err + common.PageInfo{}, err } repos := []repodb.RepoMetadata{ @@ -1097,7 +1097,7 @@ func TestImageListForDigest(t *testing.T) { repos, _ = pageFinder.Page() - return repos, manifestMetaDatas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetaDatas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -1330,11 +1330,11 @@ func TestImageList(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, - map[string]repodb.IndexData{}, repodb.PageInfo{}, ErrTestError + map[string]repodb.IndexData{}, common.PageInfo{}, ErrTestError }, } @@ -1349,7 +1349,7 @@ func TestImageList(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { repos := []repodb.RepoMetadata{ { Name: "test", @@ -1393,7 +1393,7 @@ func TestImageList(t *testing.T) { }, } - return repos, manifestMetaDatas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetaDatas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } @@ -1558,10 +1558,10 @@ func TestQueryResolverErrors(t *testing.T) { mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, ErrTestError + common.PageInfo{}, ErrTestError }, }, mocks.CveInfoMock{}, @@ -1584,10 +1584,10 @@ func TestQueryResolverErrors(t *testing.T) { mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, ErrTestError + common.PageInfo{}, ErrTestError }, }, mocks.CveInfoMock{}, @@ -1611,9 +1611,9 @@ func TestQueryResolverErrors(t *testing.T) { SearchReposFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { - return nil, nil, nil, repodb.PageInfo{}, ErrTestError + return nil, nil, nil, common.PageInfo{}, ErrTestError }, }, mocks.CveInfoMock{}, @@ -1635,9 +1635,9 @@ func TestQueryResolverErrors(t *testing.T) { SearchReposFn: func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { - return nil, nil, nil, repodb.PageInfo{}, ErrTestError + return nil, nil, nil, common.PageInfo{}, ErrTestError }, }, mocks.CveInfoMock{}, @@ -1658,10 +1658,10 @@ func TestQueryResolverErrors(t *testing.T) { mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, ErrTestError + common.PageInfo{}, ErrTestError }, }, mocks.CveInfoMock{}, @@ -1754,10 +1754,10 @@ func TestQueryResolverErrors(t *testing.T) { mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, ErrTestError + common.PageInfo{}, ErrTestError }, GetRepoMetaFn: func(repo string) (repodb.RepoMetadata, error) { return repodb.RepoMetadata{ @@ -2588,10 +2588,10 @@ func TestDerivedImageList(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { return make([]repodb.RepoMetadata, 0), make(map[string]repodb.ManifestMetadata), - make(map[string]repodb.IndexData), repodb.PageInfo{}, ErrTestError + make(map[string]repodb.IndexData), common.PageInfo{}, ErrTestError }, GetRepoMetaFn: func(repo string) (repodb.RepoMetadata, error) { return repodb.RepoMetadata{}, ErrTestError @@ -2629,10 +2629,10 @@ func TestDerivedImageList(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, nil + common.PageInfo{}, nil }, GetRepoMetaFn: func(repo string) (repodb.RepoMetadata, error) { return repodb.RepoMetadata{ @@ -2779,7 +2779,7 @@ func TestDerivedImageList(t *testing.T) { }, FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { pageFinder, err := repodb.NewBaseImagePageFinder(requestedPage.Limit, requestedPage.Offset, requestedPage.SortBy) So(err, ShouldBeNil) @@ -2857,10 +2857,10 @@ func TestBaseImageList(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, ErrTestError + common.PageInfo{}, ErrTestError }, GetRepoMetaFn: func(repo string) (repodb.RepoMetadata, error) { return repodb.RepoMetadata{}, ErrTestError @@ -2898,10 +2898,10 @@ func TestBaseImageList(t *testing.T) { mockSearchDB := mocks.RepoDBMock{ FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, nil + common.PageInfo{}, nil }, GetRepoMetaFn: func(repo string) (repodb.RepoMetadata, error) { return repodb.RepoMetadata{ @@ -3042,7 +3042,7 @@ func TestBaseImageList(t *testing.T) { }, FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { pageFinder, err := repodb.NewBaseImagePageFinder(requestedPage.Limit, requestedPage.Offset, requestedPage.SortBy) So(err, ShouldBeNil) @@ -3217,7 +3217,7 @@ func TestBaseImageList(t *testing.T) { }, FilterTagsFn: func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + common.PageInfo, error, ) { pageFinder, err := repodb.NewBaseImagePageFinder(requestedPage.Limit, requestedPage.Offset, requestedPage.SortBy) So(err, ShouldBeNil) @@ -3252,7 +3252,7 @@ func TestBaseImageList(t *testing.T) { }) } - return repos, manifestMetas, map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + return repos, manifestMetas, map[string]repodb.IndexData{}, common.PageInfo{}, nil }, } responseContext := graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, diff --git a/pkg/extensions/search/search_test.go b/pkg/extensions/search/search_test.go index 20a4455a..1b46113f 100644 --- a/pkg/extensions/search/search_test.go +++ b/pkg/extensions/search/search_test.go @@ -56,118 +56,6 @@ var ( ErrPutManifest = errors.New("can't put manifest") ) -type RepoWithNewestImageResponse struct { - RepoListWithNewestImage RepoListWithNewestImage `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - -type DerivedImageListResponse struct { - DerivedImageList DerivedImageList `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - -type BaseImageListResponse struct { - BaseImageList BaseImageList `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - -type ImageListResponse struct { - ImageList ImageList `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - -type ImageList struct { - PaginatedImagesResult `json:"imageList"` -} - -type DerivedImageList struct { - PaginatedImagesResult `json:"derivedImageList"` -} -type BaseImageList struct { - PaginatedImagesResult `json:"baseImageList"` -} - -type ExpandedRepoInfoResp struct { - ExpandedRepoInfo ExpandedRepoInfo `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - -type ReferrersResp struct { - ReferrersResult ReferrersResult `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - -type ReferrersResult struct { - Referrers []zcommon.Referrer `json:"referrers"` -} -type GlobalSearchResultResp struct { - GlobalSearchResult GlobalSearchResult `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - -type GlobalSearchResult struct { - GlobalSearch GlobalSearch `json:"globalSearch"` -} - -type GlobalSearch struct { - Images []zcommon.ImageSummary `json:"images"` - Repos []zcommon.RepoSummary `json:"repos"` - Layers []zcommon.LayerSummary `json:"layers"` - Page repodb.PageInfo `json:"page"` -} - -type ExpandedRepoInfo struct { - RepoInfo zcommon.RepoInfo `json:"expandedRepoInfo"` -} - -type PaginatedReposResult struct { - Results []zcommon.RepoSummary `json:"results"` - Page repodb.PageInfo `json:"page"` -} - -type PaginatedImagesResult struct { - Results []zcommon.ImageSummary `json:"results"` - Page repodb.PageInfo `json:"page"` -} - -//nolint:tagliatelle // graphQL schema -type RepoListWithNewestImage struct { - PaginatedReposResult `json:"RepoListWithNewestImage"` -} - -type ErrorGQL struct { - Message string `json:"message"` - Path []string `json:"path"` -} - -type SingleImageSummary struct { - ImageSummary zcommon.ImageSummary `json:"Image"` //nolint:tagliatelle -} -type ImageSummaryResult struct { - SingleImageSummary SingleImageSummary `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - -//nolint:tagliatelle // graphQL schema -type StarredRepos struct { - PaginatedReposResult `json:"StarredRepos"` -} - -//nolint:tagliatelle // graphQL schema -type BookmarkedRepos struct { - PaginatedReposResult `json:"BookmarkedRepos"` -} - -type StarredReposResponse struct { - StarredRepos `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - -type BookmarkedReposResponse struct { - BookmarkedRepos `json:"data"` - Errors []ErrorGQL `json:"errors"` -} - func readFileAndSearchString(filePath string, stringToMatch string, timeout time.Duration) (bool, error) { ctx, cancelFunc := context.WithTimeout(context.Background(), timeout) defer cancelFunc() @@ -554,12 +442,12 @@ func TestRepoListWithNewestImage(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - var responseStruct RepoWithNewestImageResponse + var responseStruct zcommon.RepoWithNewestImageResponse err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results), ShouldEqual, 2) - So(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Page.ItemCount, ShouldEqual, 2) - So(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Page.TotalCount, ShouldEqual, 4) + So(len(responseStruct.Results), ShouldEqual, 2) + So(responseStruct.Page.ItemCount, ShouldEqual, 2) + So(responseStruct.Page.TotalCount, ShouldEqual, 4) }) Convey("Test repoListWithNewestImage with pagination, no limit or offset", func() { @@ -588,12 +476,12 @@ func TestRepoListWithNewestImage(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - var responseStruct RepoWithNewestImageResponse + var responseStruct zcommon.RepoWithNewestImageResponse err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results), ShouldEqual, 4) - So(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Page.ItemCount, ShouldEqual, 4) - So(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Page.TotalCount, ShouldEqual, 4) + So(len(responseStruct.Results), ShouldEqual, 4) + So(responseStruct.Page.ItemCount, ShouldEqual, 4) + So(responseStruct.Page.TotalCount, ShouldEqual, 4) }) Convey("Test repoListWithNewestImage multiple", func() { @@ -611,12 +499,12 @@ func TestRepoListWithNewestImage(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - var responseStruct RepoWithNewestImageResponse + var responseStruct zcommon.RepoWithNewestImageResponse err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results), ShouldEqual, 4) + So(len(responseStruct.Results), ShouldEqual, 4) - images := responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results + images := responseStruct.Results So(images[0].NewestImage.Tag, ShouldEqual, "0.0.1") query = `{ @@ -641,9 +529,9 @@ func TestRepoListWithNewestImage(t *testing.T) { err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results), ShouldEqual, 1) + So(len(responseStruct.Results), ShouldEqual, 1) - repos := responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results + repos := responseStruct.Results So(repos[0].NewestImage.Tag, ShouldEqual, "0.0.1") query = `{ @@ -670,9 +558,9 @@ func TestRepoListWithNewestImage(t *testing.T) { err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results), ShouldEqual, 4) + So(len(responseStruct.Results), ShouldEqual, 4) - images = responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results + images = responseStruct.Results So(images[0].NewestImage.Tag, ShouldEqual, "0.0.1") So(images[0].NewestImage.Vulnerabilities.Count, ShouldEqual, 0) So(images[0].NewestImage.Vulnerabilities.MaxSeverity, ShouldEqual, "") @@ -880,12 +768,12 @@ func TestRepoListWithNewestImage(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - var responseStruct RepoWithNewestImageResponse + var responseStruct zcommon.RepoWithNewestImageResponse err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results), ShouldEqual, 4) + So(len(responseStruct.Results), ShouldEqual, 4) - repos := responseStruct.RepoListWithNewestImage.PaginatedReposResult.Results + repos := responseStruct.Results So(repos[0].NewestImage.Tag, ShouldEqual, "0.0.1") for _, repo := range repos { @@ -1031,18 +919,18 @@ func TestGetReferrersGQL(t *testing.T) { So(resp.StatusCode(), ShouldEqual, 200) So(resp.Body(), ShouldNotBeNil) - referrersResp := &ReferrersResp{} + referrersResp := &zcommon.ReferrersResp{} err = json.Unmarshal(resp.Body(), referrersResp) So(err, ShouldBeNil) So(referrersResp.Errors, ShouldBeNil) - So(referrersResp.ReferrersResult.Referrers[0].ArtifactType, ShouldEqual, artifactType) - So(referrersResp.ReferrersResult.Referrers[0].MediaType, ShouldEqual, ispec.MediaTypeImageManifest) + So(referrersResp.Referrers[0].ArtifactType, ShouldEqual, artifactType) + So(referrersResp.Referrers[0].MediaType, ShouldEqual, ispec.MediaTypeImageManifest) - So(referrersResp.ReferrersResult.Referrers[0].Annotations[0].Key, ShouldEqual, "com.artifact.format") - So(referrersResp.ReferrersResult.Referrers[0].Annotations[0].Value, ShouldEqual, "test") + So(referrersResp.Referrers[0].Annotations[0].Key, ShouldEqual, "com.artifact.format") + So(referrersResp.Referrers[0].Annotations[0].Value, ShouldEqual, "test") - So(referrersResp.ReferrersResult.Referrers[0].Digest, ShouldEqual, artifactManifestDigest) + So(referrersResp.Referrers[0].Digest, ShouldEqual, artifactManifestDigest) }) Convey("referrers for image index", t, func() { @@ -1159,19 +1047,19 @@ func TestGetReferrersGQL(t *testing.T) { So(resp.StatusCode(), ShouldEqual, 200) So(resp.Body(), ShouldNotBeNil) - referrersResp := &ReferrersResp{} + referrersResp := &zcommon.ReferrersResp{} err = json.Unmarshal(resp.Body(), referrersResp) So(err, ShouldBeNil) So(referrersResp.Errors, ShouldBeNil) - So(len(referrersResp.ReferrersResult.Referrers), ShouldEqual, 1) - So(referrersResp.ReferrersResult.Referrers[0].ArtifactType, ShouldEqual, artifactType) - So(referrersResp.ReferrersResult.Referrers[0].MediaType, ShouldEqual, ispec.MediaTypeImageManifest) + So(len(referrersResp.Referrers), ShouldEqual, 1) + So(referrersResp.Referrers[0].ArtifactType, ShouldEqual, artifactType) + So(referrersResp.Referrers[0].MediaType, ShouldEqual, ispec.MediaTypeImageManifest) - So(referrersResp.ReferrersResult.Referrers[0].Annotations[0].Key, ShouldEqual, "com.artifact.format") - So(referrersResp.ReferrersResult.Referrers[0].Annotations[0].Value, ShouldEqual, "test") + So(referrersResp.Referrers[0].Annotations[0].Key, ShouldEqual, "com.artifact.format") + So(referrersResp.Referrers[0].Annotations[0].Value, ShouldEqual, "test") - So(referrersResp.ReferrersResult.Referrers[0].Digest, ShouldEqual, artifactManifestDigest) + So(referrersResp.Referrers[0].Digest, ShouldEqual, artifactManifestDigest) }) } @@ -1266,20 +1154,20 @@ func TestExpandedRepoInfo(t *testing.T) { resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(resp, ShouldNotBeNil) So(err, ShouldBeNil) - responseStruct := &ExpandedRepoInfoResp{} + responseStruct := &zcommon.ExpandedRepoInfoResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &ExpandedRepoInfoResp{} + responseStruct = &zcommon.ExpandedRepoInfoResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.ExpandedRepoInfo.RepoInfo.Summary, ShouldNotBeEmpty) - So(responseStruct.ExpandedRepoInfo.RepoInfo.Summary.Name, ShouldEqual, "test1") - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries), ShouldEqual, 2) + So(responseStruct.Summary, ShouldNotBeEmpty) + So(responseStruct.Summary.Name, ShouldEqual, "test1") + So(len(responseStruct.ImageSummaries), ShouldEqual, 2) }) Convey("Test expanded repo info", t, func() { @@ -1356,12 +1244,12 @@ func TestExpandedRepoInfo(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &ExpandedRepoInfoResp{} + responseStruct := &zcommon.ExpandedRepoInfoResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.ExpandedRepoInfo.RepoInfo.Summary, ShouldNotBeEmpty) - So(responseStruct.ExpandedRepoInfo.RepoInfo.Summary.Name, ShouldEqual, "zot-cve-test") + So(responseStruct.Summary, ShouldNotBeEmpty) + So(responseStruct.Summary.Name, ShouldEqual, "zot-cve-test") query = `{ ExpandedRepoInfo(repo:"zot-cve-test"){ @@ -1381,18 +1269,18 @@ func TestExpandedRepoInfo(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &ExpandedRepoInfoResp{} + responseStruct = &zcommon.ExpandedRepoInfoResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries), ShouldNotEqual, 0) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) _, testManifestDigest, _, err := testStorage.GetImageManifest("zot-cve-test", "0.0.1") So(err, ShouldBeNil) found := false - for _, m := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries { + for _, m := range responseStruct.ImageSummaries { if m.Manifests[0].Digest == testManifestDigest.String() { found = true So(m.IsSigned, ShouldEqual, false) @@ -1410,14 +1298,14 @@ func TestExpandedRepoInfo(t *testing.T) { err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries), ShouldNotEqual, 0) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) _, testManifestDigest, _, err = testStorage.GetImageManifest("zot-cve-test", "0.0.1") So(err, ShouldBeNil) found = false - for _, m := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries { + for _, m := range responseStruct.ImageSummaries { if m.Manifests[0].Digest == testManifestDigest.String() { found = true So(m.IsSigned, ShouldEqual, true) @@ -1457,14 +1345,14 @@ func TestExpandedRepoInfo(t *testing.T) { err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries), ShouldNotEqual, 0) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) _, testManifestDigest, _, err = testStorage.GetImageManifest("zot-test", "0.0.1") So(err, ShouldBeNil) found = false - for _, m := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries { + for _, m := range responseStruct.ImageSummaries { if m.Manifests[0].Digest == testManifestDigest.String() { found = true So(m.IsSigned, ShouldEqual, false) @@ -1482,14 +1370,14 @@ func TestExpandedRepoInfo(t *testing.T) { err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries), ShouldNotEqual, 0) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) _, testManifestDigest, _, err = testStorage.GetImageManifest("zot-test", "0.0.1") So(err, ShouldBeNil) found = false - for _, m := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries { + for _, m := range responseStruct.ImageSummaries { if m.Manifests[0].Digest == testManifestDigest.String() { found = true So(m.IsSigned, ShouldEqual, true) @@ -1550,7 +1438,7 @@ func TestExpandedRepoInfo(t *testing.T) { So(err, ShouldBeNil) // ------- Make the call to GQL and see that it doesn't crash - responseStruct := &ExpandedRepoInfoResp{} + responseStruct := &zcommon.ExpandedRepoInfoResp{} query := ` { ExpandedRepoInfo(repo:"repo"){ @@ -1571,9 +1459,9 @@ func TestExpandedRepoInfo(t *testing.T) { err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries), ShouldEqual, 2) + So(len(responseStruct.ImageSummaries), ShouldEqual, 2) - repoInfo := responseStruct.ExpandedRepoInfo.RepoInfo + repoInfo := responseStruct.RepoInfo foundTagTest := false foundTagRefTag := false @@ -1635,7 +1523,7 @@ func TestExpandedRepoInfo(t *testing.T) { err = uploadNewRepoTag("3.0", repoName, baseURL, layers) So(err, ShouldBeNil) - responseStruct := &ExpandedRepoInfoResp{} + responseStruct := &zcommon.ExpandedRepoInfoResp{} query := ` { ExpandedRepoInfo(repo:"test-repo"){ @@ -1656,12 +1544,12 @@ func TestExpandedRepoInfo(t *testing.T) { err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries), ShouldNotEqual, 0) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries), ShouldNotEqual, 0) + So(len(responseStruct.ImageSummaries[0].Manifests[0].Layers), ShouldNotEqual, 0) - So(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[0].Tag, ShouldEqual, "3.0") - So(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[1].Tag, ShouldEqual, "2.0") - So(responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries[2].Tag, ShouldEqual, "1.0") + So(responseStruct.ImageSummaries[0].Tag, ShouldEqual, "3.0") + So(responseStruct.ImageSummaries[1].Tag, ShouldEqual, "2.0") + So(responseStruct.ImageSummaries[2].Tag, ShouldEqual, "1.0") }) Convey("With Multiarch Images", t, func() { @@ -1746,7 +1634,7 @@ func TestExpandedRepoInfo(t *testing.T) { defer ctlrManager.StopServer() // ------- Test ExpandedRepoInfo - responseStruct := &ExpandedRepoInfoResp{} + responseStruct := &zcommon.ExpandedRepoInfoResp{} query := ` { @@ -1769,10 +1657,10 @@ func TestExpandedRepoInfo(t *testing.T) { err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ExpandedRepoInfo.RepoInfo.Summary.Platforms), ShouldNotEqual, 5) + So(len(responseStruct.Summary.Platforms), ShouldNotEqual, 5) found := false - for _, is := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries { + for _, is := range responseStruct.ImageSummaries { if is.Tag == "1.0.0" { found = true @@ -1782,7 +1670,7 @@ func TestExpandedRepoInfo(t *testing.T) { So(found, ShouldBeTrue) found = false - for _, is := range responseStruct.ExpandedRepoInfo.RepoInfo.ImageSummaries { + for _, is := range responseStruct.ImageSummaries { if is.Tag == "2.0.0" { found = true @@ -2184,7 +2072,7 @@ func TestDerivedImageList(t *testing.T) { } }` - responseStruct := &DerivedImageListResponse{} + responseStruct := &zcommon.DerivedImageListResponse{} contains := false resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) @@ -2860,7 +2748,7 @@ func TestBaseImageList(t *testing.T) { } }` - responseStruct := &BaseImageListResponse{} + responseStruct := &zcommon.BaseImageListResponse{} contains := false resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(query)) So(err, ShouldBeNil) @@ -3004,12 +2892,12 @@ func TestGlobalSearchImageAuthor(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStructImages := &GlobalSearchResultResp{} + responseStructImages := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStructImages) So(err, ShouldBeNil) - So(responseStructImages.GlobalSearchResult.GlobalSearch.Images[0].Authors, ShouldEqual, "author name") + So(responseStructImages.Images[0].Authors, ShouldEqual, "author name") query = ` { @@ -3031,12 +2919,12 @@ func TestGlobalSearchImageAuthor(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStructRepos := &GlobalSearchResultResp{} + responseStructRepos := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStructRepos) So(err, ShouldBeNil) - So(responseStructRepos.GlobalSearchResult.GlobalSearch.Repos[0].NewestImage.Authors, ShouldEqual, "author name") + So(responseStructRepos.Repos[0].NewestImage.Authors, ShouldEqual, "author name") }) Convey("Test global search with author in manifest's config", t, func() { @@ -3067,12 +2955,12 @@ func TestGlobalSearchImageAuthor(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStructImages := &GlobalSearchResultResp{} + responseStructImages := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStructImages) So(err, ShouldBeNil) - So(responseStructImages.GlobalSearchResult.GlobalSearch.Images[0].Authors, ShouldEqual, "ZotUser") + So(responseStructImages.Images[0].Authors, ShouldEqual, "ZotUser") query = ` { @@ -3094,12 +2982,12 @@ func TestGlobalSearchImageAuthor(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStructRepos := &GlobalSearchResultResp{} + responseStructRepos := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStructRepos) So(err, ShouldBeNil) - So(responseStructRepos.GlobalSearchResult.GlobalSearch.Repos[0].NewestImage.Authors, ShouldEqual, "ZotUser") + So(responseStructRepos.Repos[0].NewestImage.Authors, ShouldEqual, "ZotUser") }) } @@ -3316,23 +3204,23 @@ func TestGlobalSearch(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) // Make sure the repo/image counts match before comparing actual content - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldNotBeNil) - t.Logf("returned images: %v", responseStruct.GlobalSearchResult.GlobalSearch.Images) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldBeEmpty) - t.Logf("returned repos: %v", responseStruct.GlobalSearchResult.GlobalSearch.Repos) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Repos), ShouldEqual, 2) - t.Logf("returned layers: %v", responseStruct.GlobalSearchResult.GlobalSearch.Layers) - So(responseStruct.GlobalSearchResult.GlobalSearch.Layers, ShouldBeEmpty) + So(responseStruct.Images, ShouldNotBeNil) + t.Logf("returned images: %v", responseStruct.Images) + So(responseStruct.Images, ShouldBeEmpty) + t.Logf("returned repos: %v", responseStruct.Repos) + So(len(responseStruct.Repos), ShouldEqual, 2) + t.Logf("returned layers: %v", responseStruct.GlobalSearch.Layers) + So(responseStruct.Layers, ShouldBeEmpty) newestImageMap := make(map[string]zcommon.ImageSummary) actualRepoMap := make(map[string]zcommon.RepoSummary) - for _, repo := range responseStruct.GlobalSearchResult.GlobalSearch.Repos { + for _, repo := range responseStruct.Repos { newestImageMap[repo.Name] = repo.NewestImage actualRepoMap[repo.Name] = repo } @@ -3406,17 +3294,17 @@ func TestGlobalSearch(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldNotBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Repos, ShouldBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Layers, ShouldBeEmpty) + So(responseStruct.Images, ShouldNotBeEmpty) + So(responseStruct.Repos, ShouldBeEmpty) + So(responseStruct.Layers, ShouldBeEmpty) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Images), ShouldEqual, 1) - actualImageSummary := responseStruct.GlobalSearchResult.GlobalSearch.Images[0] + So(len(responseStruct.Images), ShouldEqual, 1) + actualImageSummary := responseStruct.Images[0] So(actualImageSummary.Tag, ShouldEqual, "1.0.1") expectedImageSummary, ok := allExpectedImageSummaryMap["repo1:1.0.1"] @@ -3643,23 +3531,23 @@ func TestGlobalSearch(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) // Make sure the repo/image counts match before comparing actual content - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldNotBeNil) - t.Logf("returned images: %v", responseStruct.GlobalSearchResult.GlobalSearch.Images) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldBeEmpty) - t.Logf("returned repos: %v", responseStruct.GlobalSearchResult.GlobalSearch.Repos) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Repos), ShouldEqual, 2) - t.Logf("returned layers: %v", responseStruct.GlobalSearchResult.GlobalSearch.Layers) - So(responseStruct.GlobalSearchResult.GlobalSearch.Layers, ShouldBeEmpty) + So(responseStruct.Images, ShouldNotBeNil) + t.Logf("returned images: %v", responseStruct.Images) + So(responseStruct.Images, ShouldBeEmpty) + t.Logf("returned repos: %v", responseStruct.Repos) + So(len(responseStruct.Repos), ShouldEqual, 2) + t.Logf("returned layers: %v", responseStruct.Layers) + So(responseStruct.Layers, ShouldBeEmpty) newestImageMap := make(map[string]zcommon.ImageSummary) actualRepoMap := make(map[string]zcommon.RepoSummary) - for _, repo := range responseStruct.GlobalSearchResult.GlobalSearch.Repos { + for _, repo := range responseStruct.Repos { newestImageMap[repo.Name] = repo.NewestImage actualRepoMap[repo.Name] = repo } @@ -3733,17 +3621,17 @@ func TestGlobalSearch(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldNotBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Repos, ShouldBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Layers, ShouldBeEmpty) + So(responseStruct.Images, ShouldNotBeEmpty) + So(responseStruct.Repos, ShouldBeEmpty) + So(responseStruct.Layers, ShouldBeEmpty) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Images), ShouldEqual, 1) - actualImageSummary := responseStruct.GlobalSearchResult.GlobalSearch.Images[0] + So(len(responseStruct.Images), ShouldEqual, 1) + actualImageSummary := responseStruct.Images[0] So(actualImageSummary.Tag, ShouldEqual, "1.0.1") expectedImageSummary, ok := allExpectedImageSummaryMap["repo1:1.0.1"] @@ -3825,7 +3713,7 @@ func TestCleaningFilteringParamsGlobalSearch(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -3899,13 +3787,13 @@ func TestGlobalSearchFiltering(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Repos, ShouldNotBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Repos[0].Name, ShouldResemble, "signed-repo") + So(responseStruct.Repos, ShouldNotBeEmpty) + So(responseStruct.Repos[0].Name, ShouldResemble, "signed-repo") }) } @@ -3946,7 +3834,7 @@ func TestGlobalSearchWithInvalidInput(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -3968,7 +3856,7 @@ func TestGlobalSearchWithInvalidInput(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -3990,7 +3878,7 @@ func TestGlobalSearchWithInvalidInput(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -4111,12 +3999,12 @@ func TestImageList(t *testing.T) { So(resp.StatusCode(), ShouldEqual, 200) So(resp, ShouldNotBeNil) - var responseStruct ImageListResponse + var responseStruct zcommon.ImageListResponse err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ImageList.Results), ShouldEqual, len(tags)) - So(len(responseStruct.ImageList.Results[0].Manifests[0].History), ShouldEqual, len(imageConfigInfo.History)) + So(len(responseStruct.Results), ShouldEqual, len(tags)) + So(len(responseStruct.Results[0].Manifests[0].History), ShouldEqual, len(imageConfigInfo.History)) }) Convey("Pagination with valid params", func() { @@ -4148,11 +4036,11 @@ func TestImageList(t *testing.T) { So(resp.StatusCode(), ShouldEqual, 200) So(resp, ShouldNotBeNil) - var responseStruct ImageListResponse + var responseStruct zcommon.ImageListResponse err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ImageList.Results), ShouldEqual, limit) + So(len(responseStruct.Results), ShouldEqual, limit) }) }) } @@ -4209,16 +4097,16 @@ func TestGlobalSearchPagination(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Repos, ShouldNotBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Layers, ShouldBeEmpty) + So(responseStruct.Images, ShouldBeEmpty) + So(responseStruct.Repos, ShouldNotBeEmpty) + So(responseStruct.Layers, ShouldBeEmpty) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Repos), ShouldEqual, 3) + So(len(responseStruct.Repos), ShouldEqual, 3) }) Convey("Limit is lower than the repo count", func() { @@ -4236,16 +4124,16 @@ func TestGlobalSearchPagination(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Repos, ShouldNotBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Layers, ShouldBeEmpty) + So(responseStruct.Images, ShouldBeEmpty) + So(responseStruct.Repos, ShouldNotBeEmpty) + So(responseStruct.Layers, ShouldBeEmpty) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Repos), ShouldEqual, 2) + So(len(responseStruct.Repos), ShouldEqual, 2) }) Convey("PageInfo returned proper response", func() { @@ -4267,18 +4155,18 @@ func TestGlobalSearchPagination(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Repos, ShouldNotBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Layers, ShouldBeEmpty) + So(responseStruct.Images, ShouldBeEmpty) + So(responseStruct.Repos, ShouldNotBeEmpty) + So(responseStruct.Layers, ShouldBeEmpty) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Repos), ShouldEqual, 2) - So(responseStruct.GlobalSearchResult.GlobalSearch.Page.TotalCount, ShouldEqual, 3) - So(responseStruct.GlobalSearchResult.GlobalSearch.Page.ItemCount, ShouldEqual, 2) + So(len(responseStruct.Repos), ShouldEqual, 2) + So(responseStruct.Page.TotalCount, ShouldEqual, 3) + So(responseStruct.Page.ItemCount, ShouldEqual, 2) }) Convey("PageInfo when limit is bigger than the repo count", func() { @@ -4300,18 +4188,18 @@ func TestGlobalSearchPagination(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Repos, ShouldNotBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Layers, ShouldBeEmpty) + So(responseStruct.Images, ShouldBeEmpty) + So(responseStruct.Repos, ShouldNotBeEmpty) + So(responseStruct.Layers, ShouldBeEmpty) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Repos), ShouldEqual, 3) - So(responseStruct.GlobalSearchResult.GlobalSearch.Page.TotalCount, ShouldEqual, 3) - So(responseStruct.GlobalSearchResult.GlobalSearch.Page.ItemCount, ShouldEqual, 3) + So(len(responseStruct.Repos), ShouldEqual, 3) + So(responseStruct.Page.TotalCount, ShouldEqual, 3) + So(responseStruct.Page.ItemCount, ShouldEqual, 3) }) Convey("PageInfo when limit and offset have 0 value", func() { @@ -4333,18 +4221,18 @@ func TestGlobalSearchPagination(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Repos, ShouldNotBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Layers, ShouldBeEmpty) + So(responseStruct.Images, ShouldBeEmpty) + So(responseStruct.Repos, ShouldNotBeEmpty) + So(responseStruct.Layers, ShouldBeEmpty) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Repos), ShouldEqual, 3) - So(responseStruct.GlobalSearchResult.GlobalSearch.Page.TotalCount, ShouldEqual, 3) - So(responseStruct.GlobalSearchResult.GlobalSearch.Page.ItemCount, ShouldEqual, 3) + So(len(responseStruct.Repos), ShouldEqual, 3) + So(responseStruct.Page.TotalCount, ShouldEqual, 3) + So(responseStruct.Page.ItemCount, ShouldEqual, 3) }) }) } @@ -4471,12 +4359,12 @@ func TestRepoDBWhenSigningImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeTrue) + So(responseStruct.Images[0].IsSigned, ShouldBeTrue) // check image 2 is signed also because it has the same manifest resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryImage2)) @@ -4484,12 +4372,12 @@ func TestRepoDBWhenSigningImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeTrue) + So(responseStruct.Images[0].IsSigned, ShouldBeTrue) // delete the signature resp, err = resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + @@ -4503,12 +4391,12 @@ func TestRepoDBWhenSigningImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeFalse) + So(responseStruct.Images[0].IsSigned, ShouldBeFalse) }) Convey("Cover errors when signing with cosign", func() { @@ -4557,12 +4445,12 @@ func TestRepoDBWhenSigningImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeTrue) + So(responseStruct.Images[0].IsSigned, ShouldBeTrue) }) Convey("Sign with notation index", func() { @@ -4574,12 +4462,12 @@ func TestRepoDBWhenSigningImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeTrue) + So(responseStruct.Images[0].IsSigned, ShouldBeTrue) }) Convey("Sign with cosign index", func() { @@ -4592,12 +4480,12 @@ func TestRepoDBWhenSigningImages(t *testing.T) { So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeTrue) + So(responseStruct.Images[0].IsSigned, ShouldBeTrue) }) }) } @@ -4757,7 +4645,7 @@ func RunRepoDBIndexTests(baseURL, port string) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -4775,7 +4663,7 @@ func RunRepoDBIndexTests(baseURL, port string) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -4796,7 +4684,7 @@ func RunRepoDBIndexTests(baseURL, port string) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -5402,12 +5290,12 @@ func TestRepoDBWhenReadingImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images, ShouldNotBeEmpty) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].DownloadCount, ShouldEqual, 3) + So(responseStruct.Images, ShouldNotBeEmpty) + So(responseStruct.Images[0].DownloadCount, ShouldEqual, 3) }) Convey("Error when incrementing", func() { @@ -5498,12 +5386,12 @@ func TestRepoDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Images), ShouldEqual, 2) + So(len(responseStruct.Images), ShouldEqual, 2) Convey("Delete a normal tag", func() { resp, err := resty.R().Delete(baseURL + "/v2/" + "repo1" + "/manifests/" + "1.0.1") @@ -5516,13 +5404,13 @@ func TestRepoDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Images), ShouldEqual, 1) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].Tag, ShouldEqual, "1.0.2") + So(len(responseStruct.Images), ShouldEqual, 1) + So(responseStruct.Images[0].Tag, ShouldEqual, "1.0.2") }) Convey("Delete a cosign signature", func() { @@ -5548,12 +5436,12 @@ func TestRepoDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeTrue) + So(responseStruct.Images[0].IsSigned, ShouldBeTrue) // get signatur digest log := log.NewLogger("debug", "") @@ -5593,12 +5481,12 @@ func TestRepoDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeFalse) + So(responseStruct.Images[0].IsSigned, ShouldBeFalse) }) Convey("Delete a notary signature", func() { @@ -5625,12 +5513,12 @@ func TestRepoDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeTrue) + So(responseStruct.Images[0].IsSigned, ShouldBeTrue) // get signatur digest log := log.NewLogger("debug", "") @@ -5687,12 +5575,12 @@ func TestRepoDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(responseStruct.GlobalSearchResult.GlobalSearch.Images[0].IsSigned, ShouldBeFalse) + So(responseStruct.Images[0].IsSigned, ShouldBeFalse) }) Convey("Delete a referrer", func() { @@ -5724,13 +5612,13 @@ func TestRepoDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &ReferrersResp{} + responseStruct := &zcommon.ReferrersResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ReferrersResult.Referrers), ShouldEqual, 1) - So(responseStruct.ReferrersResult.Referrers[0].Digest, ShouldResemble, referrerImage.Reference) + So(len(responseStruct.Referrers), ShouldEqual, 1) + So(responseStruct.Referrers[0].Digest, ShouldResemble, referrerImage.Reference) statusCode, err := DeleteImage("repo1", referrerImage.Reference, "badURL") So(err, ShouldNotBeNil) @@ -5746,12 +5634,12 @@ func TestRepoDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &ReferrersResp{} + responseStruct = &zcommon.ReferrersResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.ReferrersResult.Referrers), ShouldEqual, 0) + So(len(responseStruct.Referrers), ShouldEqual, 0) }) Convey("Deleting causes errors", func() { @@ -5955,7 +5843,7 @@ func TestSearchSize(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(configSize+layersSize+manifestSize, ShouldNotBeZeroValue) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -5992,7 +5880,7 @@ func TestSearchSize(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(configSize+layersSize+manifestSize, ShouldNotBeZeroValue) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -6043,11 +5931,11 @@ func TestSearchSize(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(configSize+layersSize+manifestSize, ShouldNotBeZeroValue) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - So(len(responseStruct.GlobalSearchResult.GlobalSearch.Images), ShouldEqual, 2) + So(len(responseStruct.Images), ShouldEqual, 2) // check that the repo size is the same // query for repos query = ` @@ -6078,7 +5966,7 @@ func TestSearchSize(t *testing.T) { So(resp.StatusCode(), ShouldEqual, http.StatusOK) So(configSize+layersSize+manifestSize, ShouldNotBeZeroValue) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &zcommon.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) @@ -6205,7 +6093,7 @@ func TestImageSummary(t *testing.T) { So(err, ShouldBeNil) var ( - imgSummaryResponse ImageSummaryResult + imgSummaryResponse zcommon.ImageSummaryResult strQuery string targetURL string resp *resty.Response @@ -6247,7 +6135,7 @@ func TestImageSummary(t *testing.T) { So(err, ShouldBeNil) So(imgSummaryResponse, ShouldNotBeNil) So(imgSummaryResponse.SingleImageSummary, ShouldNotBeNil) - So(imgSummaryResponse.SingleImageSummary.ImageSummary, ShouldNotBeNil) + So(imgSummaryResponse.ImageSummary, ShouldNotBeNil) imgSummary := imgSummaryResponse.SingleImageSummary.ImageSummary So(imgSummary.RepoName, ShouldContainSubstring, repoName) So(imgSummary.Tag, ShouldContainSubstring, tagTarget) @@ -6289,7 +6177,7 @@ func TestImageSummary(t *testing.T) { So(err, ShouldBeNil) So(imgSummaryResponse, ShouldNotBeNil) So(imgSummaryResponse.SingleImageSummary, ShouldNotBeNil) - So(imgSummaryResponse.SingleImageSummary.ImageSummary, ShouldNotBeNil) + So(imgSummaryResponse.ImageSummary, ShouldNotBeNil) So(len(imgSummaryResponse.Errors), ShouldEqual, 1) So(imgSummaryResponse.Errors[0].Message, @@ -6309,7 +6197,7 @@ func TestImageSummary(t *testing.T) { So(err, ShouldBeNil) So(imgSummaryResponse, ShouldNotBeNil) So(imgSummaryResponse.SingleImageSummary, ShouldNotBeNil) - So(imgSummaryResponse.SingleImageSummary.ImageSummary, ShouldNotBeNil) + So(imgSummaryResponse.ImageSummary, ShouldNotBeNil) So(len(imgSummaryResponse.Errors), ShouldEqual, 1) So(imgSummaryResponse.Errors[0].Message, @@ -6415,7 +6303,7 @@ func TestImageSummary(t *testing.T) { ) So(err, ShouldBeNil) var ( - imgSummaryResponse ImageSummaryResult + imgSummaryResponse zcommon.ImageSummaryResult strQuery string targetURL string resp *resty.Response @@ -6436,9 +6324,9 @@ func TestImageSummary(t *testing.T) { So(err, ShouldBeNil) So(imgSummaryResponse, ShouldNotBeNil) So(imgSummaryResponse.SingleImageSummary, ShouldNotBeNil) - So(imgSummaryResponse.SingleImageSummary.ImageSummary, ShouldNotBeNil) + So(imgSummaryResponse.ImageSummary, ShouldNotBeNil) - imgSummary := imgSummaryResponse.SingleImageSummary.ImageSummary + imgSummary := imgSummaryResponse.ImageSummary So(imgSummary.RepoName, ShouldContainSubstring, repoName) So(imgSummary.Tag, ShouldContainSubstring, tagTarget) So(imgSummary.Manifests[0].ConfigDigest, ShouldContainSubstring, configDigest.Encoded()) @@ -6490,7 +6378,7 @@ func TestImageSummary(t *testing.T) { queryImg1 := fmt.Sprintf(query, 1) queryImg2 := fmt.Sprintf(query, 2) - var imgSummaryResponse ImageSummaryResult + var imgSummaryResponse zcommon.ImageSummaryResult ctlrManager := NewControllerManager(ctlr) ctlrManager.StartAndWait(port) @@ -6561,7 +6449,7 @@ func TestImageSummary(t *testing.T) { } }` - var expandedRepoInfoResp ExpandedRepoInfoResp + var expandedRepoInfoResp zcommon.ExpandedRepoInfoResp resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + url.QueryEscape(queryExpRepoInfo)) diff --git a/pkg/extensions/search/userprefs_test.go b/pkg/extensions/search/userprefs_test.go index 754a8e0e..1e134039 100644 --- a/pkg/extensions/search/userprefs_test.go +++ b/pkg/extensions/search/userprefs_test.go @@ -147,7 +147,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := StarredReposResponse{} + responseStruct := common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -162,7 +162,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = StarredReposResponse{} + responseStruct = common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 1) @@ -181,7 +181,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = StarredReposResponse{} + responseStruct = common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -196,7 +196,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := StarredReposResponse{} + responseStruct := common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -211,7 +211,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = StarredReposResponse{} + responseStruct = common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -226,7 +226,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := StarredReposResponse{} + responseStruct := common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -241,7 +241,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = StarredReposResponse{} + responseStruct = common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -256,7 +256,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := StarredReposResponse{} + responseStruct := common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -271,7 +271,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = StarredReposResponse{} + responseStruct = common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 1) @@ -290,7 +290,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = StarredReposResponse{} + responseStruct = common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -305,7 +305,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := BookmarkedReposResponse{} + responseStruct := common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -320,7 +320,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = BookmarkedReposResponse{} + responseStruct = common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 1) @@ -338,7 +338,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = BookmarkedReposResponse{} + responseStruct = common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -353,7 +353,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := BookmarkedReposResponse{} + responseStruct := common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -368,7 +368,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = BookmarkedReposResponse{} + responseStruct = common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -383,7 +383,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := BookmarkedReposResponse{} + responseStruct := common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -398,7 +398,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = BookmarkedReposResponse{} + responseStruct = common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -413,7 +413,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := BookmarkedReposResponse{} + responseStruct := common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -428,7 +428,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = BookmarkedReposResponse{} + responseStruct = common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 1) @@ -446,7 +446,7 @@ func TestUserData(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = BookmarkedReposResponse{} + responseStruct = common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 0) @@ -577,7 +577,7 @@ func TestChangingRepoState(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - responseStruct := StarredReposResponse{} + responseStruct := common.StarredReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(len(responseStruct.Results), ShouldEqual, 1) @@ -599,7 +599,7 @@ func TestChangingRepoState(t *testing.T) { So(resp, ShouldNotBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusOK) - responseStruct := BookmarkedReposResponse{} + responseStruct := common.BookmarkedReposResponse{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) So(err, ShouldBeNil) @@ -714,12 +714,12 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := &GlobalSearchResultResp{} + responseStruct := &common.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - foundRepos := responseStruct.GlobalSearchResult.GlobalSearch.Repos + foundRepos := responseStruct.Repos So(len(foundRepos), ShouldEqual, 4) // Filter by IsStarred = true @@ -730,12 +730,12 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &common.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - foundRepos = responseStruct.GlobalSearchResult.GlobalSearch.Repos + foundRepos = responseStruct.Repos So(len(foundRepos), ShouldEqual, 2) So(foundRepos, ShouldContain, common.RepoSummary{Name: sRepo, IsStarred: true, IsBookmarked: false}) So(foundRepos, ShouldContain, common.RepoSummary{Name: sbRepo, IsStarred: true, IsBookmarked: true}) @@ -752,12 +752,12 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &common.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - foundRepos = responseStruct.GlobalSearchResult.GlobalSearch.Repos + foundRepos = responseStruct.Repos So(len(foundRepos), ShouldEqual, 1) So(foundRepos, ShouldContain, common.RepoSummary{Name: sRepo, IsStarred: true, IsBookmarked: false}) @@ -773,12 +773,12 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &common.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - foundRepos = responseStruct.GlobalSearchResult.GlobalSearch.Repos + foundRepos = responseStruct.Repos So(len(foundRepos), ShouldEqual, 2) So(foundRepos, ShouldContain, common.RepoSummary{Name: bRepo, IsStarred: false, IsBookmarked: true}) So(foundRepos, ShouldContain, common.RepoSummary{Name: sbRepo, IsStarred: true, IsBookmarked: true}) @@ -795,12 +795,12 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = &GlobalSearchResultResp{} + responseStruct = &common.GlobalSearchResultResp{} err = json.Unmarshal(resp.Body(), responseStruct) So(err, ShouldBeNil) - foundRepos = responseStruct.GlobalSearchResult.GlobalSearch.Repos + foundRepos = responseStruct.Repos So(len(foundRepos), ShouldEqual, 1) So(foundRepos, ShouldContain, common.RepoSummary{Name: bRepo, IsStarred: false, IsBookmarked: true}) }) @@ -886,12 +886,12 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct := ExpandedRepoInfoResp{} + responseStruct := common.ExpandedRepoInfoResp{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - repoInfo := responseStruct.ExpandedRepoInfo.RepoInfo + repoInfo := responseStruct.RepoInfo So(repoInfo.Summary.IsBookmarked, ShouldBeTrue) So(repoInfo.Summary.IsStarred, ShouldBeTrue) @@ -921,12 +921,12 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = ExpandedRepoInfoResp{} + responseStruct = common.ExpandedRepoInfoResp{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - repoInfo = responseStruct.ExpandedRepoInfo.RepoInfo + repoInfo = responseStruct.RepoInfo So(repoInfo.Summary.IsBookmarked, ShouldBeFalse) So(repoInfo.Summary.IsStarred, ShouldBeTrue) @@ -956,12 +956,12 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = ExpandedRepoInfoResp{} + responseStruct = common.ExpandedRepoInfoResp{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - repoInfo = responseStruct.ExpandedRepoInfo.RepoInfo + repoInfo = responseStruct.RepoInfo So(repoInfo.Summary.IsBookmarked, ShouldBeTrue) So(repoInfo.Summary.IsStarred, ShouldBeFalse) @@ -987,12 +987,12 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, 200) - responseStruct = ExpandedRepoInfoResp{} + responseStruct = common.ExpandedRepoInfoResp{} err = json.Unmarshal(resp.Body(), &responseStruct) So(err, ShouldBeNil) - repoInfo = responseStruct.ExpandedRepoInfo.RepoInfo + repoInfo = responseStruct.RepoInfo So(repoInfo.Summary.IsBookmarked, ShouldBeFalse) So(repoInfo.Summary.IsStarred, ShouldBeFalse) }) diff --git a/pkg/meta/repodb/boltdb-wrapper/boltdb_wrapper.go b/pkg/meta/repodb/boltdb-wrapper/boltdb_wrapper.go index b1ce4224..4b6bb767 100644 --- a/pkg/meta/repodb/boltdb-wrapper/boltdb_wrapper.go +++ b/pkg/meta/repodb/boltdb-wrapper/boltdb_wrapper.go @@ -961,7 +961,7 @@ func (bdw *DBWrapper) DeleteSignature(repo string, signedManifestDigest godigest func (bdw *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, -) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, +) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, zcommon.PageInfo, error, ) { var ( @@ -969,13 +969,13 @@ func (bdw *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter foundManifestMetadataMap = make(map[string]repodb.ManifestMetadata) foundindexDataMap = make(map[string]repodb.IndexData) pageFinder repodb.PageFinder - pageInfo repodb.PageInfo + pageInfo zcommon.PageInfo ) pageFinder, err := repodb.NewBaseRepoPageFinder(requestedPage.Limit, requestedPage.Offset, requestedPage.SortBy) if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, err + zcommon.PageInfo{}, err } err = bdw.DB.View(func(transaction *bbolt.Tx) error { @@ -1291,7 +1291,7 @@ func NewManifestMetadata(manifestDigest string, repoMeta repodb.RepoMetadata, func (bdw *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, - repodb.PageInfo, error, + zcommon.PageInfo, error, ) { var ( foundRepos = make([]repodb.RepoMetadata, 0) @@ -1300,13 +1300,13 @@ func (bdw *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, foundManifestMetadataMap = make(map[string]repodb.ManifestMetadata) foundindexDataMap = make(map[string]repodb.IndexData) pageFinder repodb.PageFinder - pageInfo repodb.PageInfo + pageInfo zcommon.PageInfo ) pageFinder, err := repodb.NewBaseImagePageFinder(requestedPage.Limit, requestedPage.Offset, requestedPage.SortBy) if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, err + zcommon.PageInfo{}, err } err = bdw.DB.View(func(transaction *bbolt.Tx) error { @@ -1432,12 +1432,12 @@ func (bdw *DBWrapper) FilterRepos(ctx context.Context, filter repodb.FilterRepoFunc, requestedPage repodb.PageInput, ) ( - []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error, + []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, zcommon.PageInfo, error, ) { var ( foundRepos = make([]repodb.RepoMetadata, 0) pageFinder repodb.PageFinder - pageInfo repodb.PageInfo + pageInfo zcommon.PageInfo ) pageFinder, err := repodb.NewBaseRepoPageFinder( @@ -1494,14 +1494,14 @@ func (bdw *DBWrapper) FilterRepos(ctx context.Context, func (bdw *DBWrapper) SearchTags(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, -) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { +) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, zcommon.PageInfo, error) { var ( foundRepos = make([]repodb.RepoMetadata, 0) manifestMetadataMap = make(map[string]repodb.ManifestMetadata) indexDataMap = make(map[string]repodb.IndexData) foundManifestMetadataMap = make(map[string]repodb.ManifestMetadata) foundindexDataMap = make(map[string]repodb.IndexData) - pageInfo repodb.PageInfo + pageInfo zcommon.PageInfo pageFinder repodb.PageFinder ) @@ -1509,13 +1509,13 @@ func (bdw *DBWrapper) SearchTags(ctx context.Context, searchText string, filter pageFinder, err := repodb.NewBaseImagePageFinder(requestedPage.Limit, requestedPage.Offset, requestedPage.SortBy) if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, err + zcommon.PageInfo{}, err } searchedRepo, searchedTag, err := common.GetRepoTag(searchText) if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - repodb.PageInfo{}, + zcommon.PageInfo{}, fmt.Errorf("repodb: error while parsing search text, invalid format %w", err) } diff --git a/pkg/meta/repodb/dynamodb-wrapper/dynamo_wrapper.go b/pkg/meta/repodb/dynamodb-wrapper/dynamo_wrapper.go index 1f305a4d..f18c5e12 100644 --- a/pkg/meta/repodb/dynamodb-wrapper/dynamo_wrapper.go +++ b/pkg/meta/repodb/dynamodb-wrapper/dynamo_wrapper.go @@ -769,13 +769,13 @@ func (dwr *DBWrapper) GetMultipleRepoMeta(ctx context.Context, func (dwr *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, -) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { +) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, zcommon.PageInfo, error) { var ( manifestMetadataMap = make(map[string]repodb.ManifestMetadata) indexDataMap = make(map[string]repodb.IndexData) repoMetaAttributeIterator dynamo.AttributesIterator pageFinder repodb.PageFinder - pageInfo repodb.PageInfo + pageInfo zcommon.PageInfo userBookmarks = getUserBookmarks(ctx, dwr) userStars = getUserStars(ctx, dwr) @@ -1077,13 +1077,13 @@ func (dwr *DBWrapper) collectImageIndexFilterInfo(indexDigest string, repoMeta r func (dwr *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, -) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { +) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, zcommon.PageInfo, error) { var ( manifestMetadataMap = make(map[string]repodb.ManifestMetadata) indexDataMap = make(map[string]repodb.IndexData) repoMetaAttributeIterator dynamo.AttributesIterator pageFinder repodb.PageFinder - pageInfo repodb.PageInfo + pageInfo zcommon.PageInfo userBookmarks = getUserBookmarks(ctx, dwr) userStars = getUserStars(ctx, dwr) ) @@ -1224,11 +1224,11 @@ func (dwr *DBWrapper) FilterRepos(ctx context.Context, filter repodb.FilterRepoFunc, requestedPage repodb.PageInput, ) ( - []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error, + []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, zcommon.PageInfo, error, ) { var ( repoMetaAttributeIterator dynamo.AttributesIterator - pageInfo repodb.PageInfo + pageInfo zcommon.PageInfo userBookmarks = getUserBookmarks(ctx, dwr) userStars = getUserStars(ctx, dwr) ) @@ -1282,13 +1282,13 @@ func (dwr *DBWrapper) FilterRepos(ctx context.Context, func (dwr *DBWrapper) SearchTags(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, -) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { +) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, zcommon.PageInfo, error) { var ( manifestMetadataMap = make(map[string]repodb.ManifestMetadata) indexDataMap = make(map[string]repodb.IndexData) repoMetaAttributeIterator dynamo.AttributesIterator pageFinder repodb.PageFinder - pageInfo repodb.PageInfo + pageInfo zcommon.PageInfo userBookmarks = getUserBookmarks(ctx, dwr) userStars = getUserStars(ctx, dwr) ) diff --git a/pkg/meta/repodb/pagination.go b/pkg/meta/repodb/pagination.go index 1b4af9cb..c1fb37cd 100644 --- a/pkg/meta/repodb/pagination.go +++ b/pkg/meta/repodb/pagination.go @@ -5,13 +5,14 @@ import ( "sort" zerr "zotregistry.io/zot/errors" + "zotregistry.io/zot/pkg/common" ) // PageFinder permits keeping a pool of objects using Add // and returning a specific page. type PageFinder interface { Add(detailedRepoMeta DetailedRepoMeta) - Page() ([]RepoMetadata, PageInfo) + Page() ([]RepoMetadata, common.PageInfo) Reset() } @@ -58,12 +59,12 @@ func (bpt *RepoPageFinder) Add(namedRepoMeta DetailedRepoMeta) { bpt.pageBuffer = append(bpt.pageBuffer, namedRepoMeta) } -func (bpt *RepoPageFinder) Page() ([]RepoMetadata, PageInfo) { +func (bpt *RepoPageFinder) Page() ([]RepoMetadata, common.PageInfo) { if len(bpt.pageBuffer) == 0 { - return []RepoMetadata{}, PageInfo{} + return []RepoMetadata{}, common.PageInfo{} } - pageInfo := &PageInfo{} + pageInfo := &common.PageInfo{} sort.Slice(bpt.pageBuffer, SortFunctions()[bpt.sortBy](bpt.pageBuffer)) @@ -142,12 +143,12 @@ func (bpt *ImagePageFinder) Add(namedRepoMeta DetailedRepoMeta) { bpt.pageBuffer = append(bpt.pageBuffer, namedRepoMeta) } -func (bpt *ImagePageFinder) Page() ([]RepoMetadata, PageInfo) { +func (bpt *ImagePageFinder) Page() ([]RepoMetadata, common.PageInfo) { if len(bpt.pageBuffer) == 0 { - return []RepoMetadata{}, PageInfo{} + return []RepoMetadata{}, common.PageInfo{} } - pageInfo := PageInfo{} + pageInfo := common.PageInfo{} for _, drm := range bpt.pageBuffer { repo := drm.RepoMetadata @@ -190,7 +191,7 @@ func (bpt *ImagePageFinder) Page() ([]RepoMetadata, PageInfo) { // offset is larger than the number of tags if repoStartIndex >= len(bpt.pageBuffer) { - return []RepoMetadata{}, PageInfo{} + return []RepoMetadata{}, common.PageInfo{} } // finish counting remaining tags inside the first repo meta diff --git a/pkg/meta/repodb/repodb.go b/pkg/meta/repodb/repodb.go index a08d42c8..f5776b3f 100644 --- a/pkg/meta/repodb/repodb.go +++ b/pkg/meta/repodb/repodb.go @@ -5,6 +5,8 @@ import ( "time" godigest "github.com/opencontainers/go-digest" + + "zotregistry.io/zot/pkg/common" ) // Used to model changes to an object after a call to the DB. @@ -95,19 +97,19 @@ type RepoDB interface { //nolint:interfacebloat // SearchRepos searches for repos given a search string SearchRepos(ctx context.Context, searchText string, filter Filter, requestedPage PageInput) ( - []RepoMetadata, map[string]ManifestMetadata, map[string]IndexData, PageInfo, error) + []RepoMetadata, map[string]ManifestMetadata, map[string]IndexData, common.PageInfo, error) // SearchTags searches for images(repo:tag) given a search string SearchTags(ctx context.Context, searchText string, filter Filter, requestedPage PageInput) ( - []RepoMetadata, map[string]ManifestMetadata, map[string]IndexData, PageInfo, error) + []RepoMetadata, map[string]ManifestMetadata, map[string]IndexData, common.PageInfo, error) // FilterRepos filters for repos given a filter function FilterRepos(ctx context.Context, filter FilterRepoFunc, requestedPage PageInput) ( - []RepoMetadata, map[string]ManifestMetadata, map[string]IndexData, PageInfo, error) + []RepoMetadata, map[string]ManifestMetadata, map[string]IndexData, common.PageInfo, error) // FilterTags filters for images given a filter function FilterTags(ctx context.Context, filter FilterFunc, - requestedPage PageInput) ([]RepoMetadata, map[string]ManifestMetadata, map[string]IndexData, PageInfo, error) + requestedPage PageInput) ([]RepoMetadata, map[string]ManifestMetadata, map[string]IndexData, common.PageInfo, error) // GetStarredRepos returns starred repos and takes current user in consideration GetStarredRepos(ctx context.Context) ([]string, error) @@ -216,11 +218,6 @@ type PageInput struct { SortBy SortCriteria } -type PageInfo struct { - TotalCount int - ItemCount int -} - type Filter struct { Os []*string Arch []*string diff --git a/pkg/test/mocks/cve_mock.go b/pkg/test/mocks/cve_mock.go index 514699d3..cc4368c8 100644 --- a/pkg/test/mocks/cve_mock.go +++ b/pkg/test/mocks/cve_mock.go @@ -1,6 +1,7 @@ package mocks import ( + "zotregistry.io/zot/pkg/common" cveinfo "zotregistry.io/zot/pkg/extensions/search/cve" cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model" ) @@ -9,7 +10,7 @@ type CveInfoMock struct { GetImageListForCVEFn func(repo, cveID string) ([]cvemodel.TagInfo, error) GetImageListWithCVEFixedFn func(repo, cveID string) ([]cvemodel.TagInfo, error) GetCVEListForImageFn func(repo string, reference string, searchedCVE string, pageInput cveinfo.PageInput, - ) ([]cvemodel.CVE, cveinfo.PageInfo, error) + ) ([]cvemodel.CVE, common.PageInfo, error) GetCVESummaryForImageFn func(repo string, reference string, ) (cveinfo.ImageCVESummary, error) CompareSeveritiesFn func(severity1, severity2 string) int @@ -36,14 +37,14 @@ func (cveInfo CveInfoMock) GetCVEListForImage(repo string, reference string, searchedCVE string, pageInput cveinfo.PageInput, ) ( []cvemodel.CVE, - cveinfo.PageInfo, + common.PageInfo, error, ) { if cveInfo.GetCVEListForImageFn != nil { return cveInfo.GetCVEListForImageFn(repo, reference, searchedCVE, pageInput) } - return []cvemodel.CVE{}, cveinfo.PageInfo{}, nil + return []cvemodel.CVE{}, common.PageInfo{}, nil } func (cveInfo CveInfoMock) GetCVESummaryForImage(repo string, reference string, diff --git a/pkg/test/mocks/repo_db_mock.go b/pkg/test/mocks/repo_db_mock.go index f5930841..3f53b6cc 100644 --- a/pkg/test/mocks/repo_db_mock.go +++ b/pkg/test/mocks/repo_db_mock.go @@ -5,6 +5,7 @@ import ( godigest "github.com/opencontainers/go-digest" + "zotregistry.io/zot/pkg/common" "zotregistry.io/zot/pkg/meta/repodb" ) @@ -62,17 +63,17 @@ type RepoDBMock struct { DeleteSignatureFn func(repo string, signedManifestDigest godigest.Digest, sm repodb.SignatureMetadata) error SearchReposFn func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput) ( - []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) + []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) SearchTagsFn func(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput) ( - []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) + []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) FilterReposFn func(ctx context.Context, filter repodb.FilterRepoFunc, requestedPage repodb.PageInput) ( - []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) + []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) FilterTagsFn func(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, - ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) + ) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) SearchDigestsFn func(ctx context.Context, searchText string, requestedPage repodb.PageInput) ( []repodb.RepoMetadata, map[string]repodb.ManifestMetadata, error) @@ -251,46 +252,46 @@ func (sdm RepoDBMock) DeleteSignature(repo string, signedManifestDigest godigest func (sdm RepoDBMock) SearchRepos(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, -) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { +) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { if sdm.SearchReposFn != nil { return sdm.SearchReposFn(ctx, searchText, filter, requestedPage) } return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, - map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + map[string]repodb.IndexData{}, common.PageInfo{}, nil } func (sdm RepoDBMock) SearchTags(ctx context.Context, searchText string, filter repodb.Filter, requestedPage repodb.PageInput, -) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { +) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { if sdm.SearchTagsFn != nil { return sdm.SearchTagsFn(ctx, searchText, filter, requestedPage) } return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, - map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + map[string]repodb.IndexData{}, common.PageInfo{}, nil } func (sdm RepoDBMock) FilterRepos(ctx context.Context, filter repodb.FilterRepoFunc, requestedPage repodb.PageInput, -) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { +) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { if sdm.FilterReposFn != nil { return sdm.FilterReposFn(ctx, filter, requestedPage) } return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, - map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + map[string]repodb.IndexData{}, common.PageInfo{}, nil } func (sdm RepoDBMock) FilterTags(ctx context.Context, filter repodb.FilterFunc, requestedPage repodb.PageInput, -) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, repodb.PageInfo, error) { +) ([]repodb.RepoMetadata, map[string]repodb.ManifestMetadata, map[string]repodb.IndexData, common.PageInfo, error) { if sdm.FilterTagsFn != nil { return sdm.FilterTagsFn(ctx, filter, requestedPage) } return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, - map[string]repodb.IndexData{}, repodb.PageInfo{}, nil + map[string]repodb.IndexData{}, common.PageInfo{}, nil } func (sdm RepoDBMock) SearchDigests(ctx context.Context, searchText string, requestedPage repodb.PageInput,