diff --git a/pkg/cli/cve_cmd.go b/pkg/cli/cve_cmd.go index 68a4ec2f35..875eebc17a 100644 --- a/pkg/cli/cve_cmd.go +++ b/pkg/cli/cve_cmd.go @@ -154,7 +154,7 @@ func searchCve(searchConfig searchConfig) error { } for _, searcher := range searchers { - // there can be CVE DB readyness issues on the server side + // there can be CVE DB readiness issues on the server side // we need a retry mechanism for that specific type of errors maxAttempts := 20 diff --git a/pkg/extensions/search/convert/annotations.go b/pkg/extensions/search/convert/annotations.go index ad530fa400..99c83c8d07 100644 --- a/pkg/extensions/search/convert/annotations.go +++ b/pkg/extensions/search/convert/annotations.go @@ -133,3 +133,58 @@ func GetAnnotations(annotations, labels map[string]string) ImageAnnotations { Authors: authors, } } + +func GetIndexAnnotations(indexAnnotations, manifestAnnotations, manifestLabels map[string]string) ImageAnnotations { + annotationsFromManifest := GetAnnotations(manifestAnnotations, manifestLabels) + + description := GetDescription(indexAnnotations) + if description == "" { + description = annotationsFromManifest.Description + } + + title := GetTitle(indexAnnotations) + if title == "" { + title = annotationsFromManifest.Title + } + + documentation := GetDocumentation(indexAnnotations) + if documentation == "" { + documentation = annotationsFromManifest.Documentation + } + + source := GetSource(indexAnnotations) + if source == "" { + source = annotationsFromManifest.Source + } + + licenses := GetLicenses(indexAnnotations) + if licenses == "" { + licenses = annotationsFromManifest.Licenses + } + + categories := GetCategories(indexAnnotations) + if categories == "" { + categories = annotationsFromManifest.Labels + } + + vendor := GetVendor(indexAnnotations) + if vendor == "" { + vendor = annotationsFromManifest.Vendor + } + + authors := GetAuthors(indexAnnotations) + if authors == "" { + authors = annotationsFromManifest.Authors + } + + return ImageAnnotations{ + Description: description, + Title: title, + Documentation: documentation, + Source: source, + Licenses: licenses, + Labels: categories, + Vendor: vendor, + Authors: authors, + } +} diff --git a/pkg/extensions/search/convert/convert_test.go b/pkg/extensions/search/convert/convert_test.go index 39a75d77f7..4c3da804eb 100644 --- a/pkg/extensions/search/convert/convert_test.go +++ b/pkg/extensions/search/convert/convert_test.go @@ -770,3 +770,35 @@ func TestPaginatedConvert(t *testing.T) { So(pageInfo.ItemCount, ShouldEqual, 1) }) } + +func TestGetOneManifestAnnotations(t *testing.T) { + Convey("GetOneManifestAnnotations errors", t, func() { + manifestAnnotations, configLabels := convert.GetOneManifestAnnotations( + ispec.Index{Manifests: []ispec.Descriptor{ + {Digest: "bad-manifest"}, {Digest: "dig2"}, + }}, + map[string]mTypes.ManifestMetadata{ + "bad-manifest": { + ManifestBlob: []byte(`bad`), + ConfigBlob: []byte("{}"), + }, + }, + ) + So(manifestAnnotations, ShouldBeEmpty) + So(configLabels, ShouldBeEmpty) + + manifestAnnotations, configLabels = convert.GetOneManifestAnnotations( + ispec.Index{Manifests: []ispec.Descriptor{ + {Digest: "bad-config"}, + }}, + map[string]mTypes.ManifestMetadata{ + "bad-config": { + ManifestBlob: []byte("{}"), + ConfigBlob: []byte("bad"), + }, + }, + ) + So(manifestAnnotations, ShouldBeEmpty) + So(configLabels, ShouldBeEmpty) + }) +} diff --git a/pkg/extensions/search/convert/metadb.go b/pkg/extensions/search/convert/metadb.go index 4b607a791d..4b126c2d36 100644 --- a/pkg/extensions/search/convert/metadb.go +++ b/pkg/extensions/search/convert/metadb.go @@ -268,10 +268,11 @@ func ImageIndex2ImageSummary(ctx context.Context, repo, tag string, indexDigest indexSize = strconv.FormatInt(totalIndexSize, 10) - annotations := GetAnnotations(indexContent.Annotations, map[string]string{}) - signaturesInfo := GetSignaturesInfo(isSigned, repoMeta, indexDigest) + manifestAnnotations, configLabels := GetOneManifestAnnotations(indexContent, manifestMetaMap) + annotations := GetIndexAnnotations(indexContent.Annotations, manifestAnnotations, configLabels) + indexSummary := gql_generated.ImageSummary{ RepoName: &repo, Tag: &tag, @@ -301,6 +302,30 @@ func ImageIndex2ImageSummary(ctx context.Context, repo, tag string, indexDigest return &indexSummary, indexBlobs, nil } +func GetOneManifestAnnotations(indexContent ispec.Index, manifestMetaMap map[string]mTypes.ManifestMetadata, +) (map[string]string, map[string]string) { + if len(manifestMetaMap) == 0 || len(indexContent.Manifests) == 0 { + return map[string]string{}, map[string]string{} + } + + manifestMeta := manifestMetaMap[indexContent.Manifests[0].Digest.String()] + + manifestContent := ispec.Manifest{} + configContent := ispec.Image{} + + err := json.Unmarshal(manifestMeta.ManifestBlob, &manifestContent) + if err != nil { + return map[string]string{}, map[string]string{} + } + + err = json.Unmarshal(manifestMeta.ConfigBlob, &configContent) + if err != nil { + return map[string]string{}, map[string]string{} + } + + return manifestContent.Annotations, configContent.Config.Labels +} + func ImageManifest2ImageSummary(ctx context.Context, repo, tag string, digest godigest.Digest, skipCVE bool, repoMeta mTypes.RepoMetadata, manifestMeta mTypes.ManifestMetadata, cveInfo cveinfo.CveInfo, ) (*gql_generated.ImageSummary, map[string]int64, error) {