Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentiuNiculae committed Sep 25, 2023
1 parent 0eafc7d commit 81bb57b
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 53 deletions.
89 changes: 45 additions & 44 deletions pkg/extensions/search/convert/metadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,8 @@ func GetSignaturesInfo(isSigned bool, repoMeta mTypes.RepoMetadata, indexDigest
return signaturesInfo
}

func PaginatedProtoRepoMeta2RepoSummaries(ctx context.Context, repoMetaList []*proto_go.ProtoRepoMeta,
imageDataMap map[string]*proto_go.ImageData, filter mTypes.Filter, pageInput pagination.PageInput, cveInfo cveinfo.CveInfo,
func PaginatedProtoRepoMeta2RepoSummaries(ctx context.Context, repoMetaList []mTypes.RepoMetadata2,
imageDataMap map[string]mTypes.ImageData2, filter mTypes.Filter, pageInput pagination.PageInput, cveInfo cveinfo.CveInfo,
skip SkipQGLField,
) ([]*gql_generated.RepoSummary, zcommon.PageInfo, error) {
reposPageFinder, err := pagination.NewRepoSumPageFinder(pageInput.Limit, pageInput.Offset, pageInput.SortBy)
Expand All @@ -894,7 +894,7 @@ func PaginatedProtoRepoMeta2RepoSummaries(ctx context.Context, repoMetaList []*p
return page, pageInfo, nil
}

func ProtoRepoMeta2RepoSummary(ctx context.Context, repoMeta *proto_go.ProtoRepoMeta, imageDataMap map[string]*proto_go.ImageData,
func ProtoRepoMeta2RepoSummary(ctx context.Context, repoMeta mTypes.RepoMetadata2, imageDataMap map[string]mTypes.ImageData2,
) *gql_generated.RepoSummary {
var (
repoName = repoMeta.Name
Expand Down Expand Up @@ -985,8 +985,8 @@ type (
BlobDigest = string
)

func ProtoDescriptor2ImageSummary(ctx context.Context, descriptor *proto_go.Descriptor, repo, tag string,
repoMeta *proto_go.ProtoRepoMeta, imageDataMap map[ManifestDigest]*proto_go.ImageData,
func ProtoDescriptor2ImageSummary(ctx context.Context, descriptor mTypes.Descriptor, repo, tag string,
repoMeta mTypes.RepoMetadata2, imageDataMap map[ManifestDigest]mTypes.ImageData2,
) (*gql_generated.ImageSummary, map[BlobDigest]int64, error) {
switch descriptor.MediaType {
case ispec.MediaTypeImageManifest:
Expand All @@ -999,8 +999,8 @@ func ProtoDescriptor2ImageSummary(ctx context.Context, descriptor *proto_go.Desc
}
}

func ProtoImageIndex2ImageSummary(ctx context.Context, repo, tag, digest string, repoMeta *proto_go.ProtoRepoMeta,
imageDataMap map[string]*proto_go.ImageData,
func ProtoImageIndex2ImageSummary(ctx context.Context, repo, tag, digest string, repoMeta mTypes.RepoMetadata2,
imageDataMap map[ManifestDigest]mTypes.ImageData2,
) (*gql_generated.ImageSummary, map[BlobDigest]int64, error) {
imageIndex := imageDataMap[digest]

Expand Down Expand Up @@ -1033,7 +1033,7 @@ func ProtoImageIndex2ImageSummary(ctx context.Context, repo, tag, digest string,
indexLastUpdated = *imageManifestSummary.LastUpdated
}

annotations := GetAnnotations(imageManifest.Annotations, imageManifest.Config.Config.Labels)
annotations := GetAnnotations(imageManifest.Annotations, imageManifest.ConfigContent.Config.Labels)

if manifestAnnotations == nil {
manifestAnnotations = &annotations
Expand All @@ -1044,14 +1044,14 @@ func ProtoImageIndex2ImageSummary(ctx context.Context, repo, tag, digest string,
manifestSummaries = append(manifestSummaries, imageManifestSummary.Manifests[0])
}

signaturesInfo := GetProtoSignaturesInfo(isSigned, repoMeta, digest)
signaturesInfo := GetSignaturesInfo(isSigned, mTypes.RepoMetadata(repoMeta), godigest.Digest(digest))

if manifestAnnotations == nil {
// The index doesn't have manifests
manifestAnnotations = &ImageAnnotations{}
}

annotations := GetIndexAnnotations(imageIndex.Annotations, manifestAnnotations)
annotations := GetIndexAnnotations(imageIndex.Index.Annotations, manifestAnnotations)

indexSummary := gql_generated.ImageSummary{
RepoName: &repo,
Expand All @@ -1072,68 +1072,73 @@ func ProtoImageIndex2ImageSummary(ctx context.Context, repo, tag, digest string,
Source: &annotations.Source,
Vendor: &annotations.Vendor,
Authors: &annotations.Authors,
Referrers: getProtoReferrers(repoMeta.Referrers[digest]),
Referrers: getReferrers(repoMeta.Referrers[digest]),
}

return &indexSummary, indexBlobs, nil
}

func ProtoImageManifest2ImageSummary(ctx context.Context, repo, tag string, repoMeta *proto_go.ProtoRepoMeta,
imageData *proto_go.ImageData,
func ProtoImageManifest2ImageSummary(ctx context.Context, repo, tag string, repoMeta mTypes.RepoMetadata2,
imageData mTypes.ImageData2,
) (*gql_generated.ImageSummary, map[BlobDigest]int64, error) {
manifest := imageData.Manifests[0]

var (
repoName = repo
configDigest = manifest.Config.Digest
artifactType = manifest.ArtifactType
platform = getPlatform(manifest.Config.Platform)
imageLastUpdated = zcommon.GetProtoImageLastUpdated(manifest.Config) // TODO: we can cache this
downloadCount = int(repoMeta.Statistics[manifest.Digest].DownloadCount)
isSigned = isImageSigned(repoMeta.Signatures[manifest.Digest])
configDigest = manifest.Config.Digest.String()
configSize = manifest.Config.Size
manifestDigest = manifest.Digest.String()
manifestSize = int64(manifest.Size)
mediaType = manifest.MediaType
artifactType = zcommon.GetManifestArtifactType(imageData.Manifests[0].Manifest)
platform = getPlatform(manifest.ConfigContent.Platform)
imageLastUpdated = zcommon.GetImageLastUpdated(manifest.ConfigContent) // TODO: we can cache this
downloadCount = int(repoMeta.Statistics[manifest.Digest.String()].DownloadCount)
isSigned = isImageSigned(repoMeta.Signatures[manifest.Digest.String()])
)

imageSize, imageBlobsMap := getProtoImageBlobsInfo(manifest)
annotations := GetAnnotations(manifest.Annotations, manifest.Config.Config.Labels) // TODO: This can be cached
imageSize, imageBlobsMap := getImageBlobsInfo(manifestDigest, manifestSize, configDigest, configSize, manifest.Layers)
imageSizeStr := strconv.FormatInt(imageSize, 10)
annotations := GetAnnotations(manifest.Annotations, manifest.ConfigContent.Config.Labels) // TODO: This can be cached

authors := annotations.Authors
if authors == "" {
authors = manifest.Config.GetAuthor()
authors = manifest.ConfigContent.Author
}

historyEntries, err := getAllProtoHistory(manifest) // TODO: this can be cached
historyEntries, err := getAllHistory(manifest.Manifest, manifest.ConfigContent) // TODO: this can be cached
if err != nil {
graphql.AddError(ctx, gqlerror.Errorf("error generating history on tag %s in repo %s: "+
"manifest digest: %s, error: %s", tag, repo, manifest.Digest, err.Error()))
}

signaturesInfo := GetProtoSignaturesInfo(isSigned, repoMeta, manifest.Digest)
signaturesInfo := GetSignaturesInfo(isSigned, mTypes.RepoMetadata(repoMeta), manifest.Digest)

manifestSummary := gql_generated.ManifestSummary{
Digest: &manifest.Digest,
Digest: &manifestDigest,
ConfigDigest: &configDigest,
LastUpdated: &imageLastUpdated,
Size: &imageSize,
Size: &imageSizeStr,
IsSigned: &isSigned,
SignatureInfo: signaturesInfo,
Platform: &platform,
DownloadCount: &downloadCount,
Layers: getProtoLayersSummaries(manifest),
Layers: getLayersSummaries(manifest.Manifest),
History: historyEntries,
Referrers: getProtoReferrers(repoMeta.Referrers[manifest.Digest]),
ArtifactType: artifactType,
Referrers: getReferrers(repoMeta.Referrers[manifestDigest]),
ArtifactType: &artifactType,
}

imageSummary := gql_generated.ImageSummary{
RepoName: &repoName,
Tag: &tag,
Digest: &manifest.Digest,
MediaType: manifest.MediaType,
Digest: &manifestDigest,
MediaType: &mediaType,
Manifests: []*gql_generated.ManifestSummary{&manifestSummary},
LastUpdated: &imageLastUpdated,
IsSigned: &isSigned,
SignatureInfo: signaturesInfo,
Size: &imageSize,
Size: &imageSizeStr,
DownloadCount: &downloadCount,
Description: &annotations.Description,
Title: &annotations.Title,
Expand Down Expand Up @@ -1252,30 +1257,26 @@ func getProtoImageBlobsInfo(manifest *proto_go.ManifestData) (string, map[string
return strconv.FormatInt(imageSize, 10), imageBlobsMap
}

func isImageSigned(manifestSignatures *proto_go.ManifestSignatures) bool {
for _, signatures := range manifestSignatures.Map {
if len(signatures.List) > 0 {
func isImageSigned(manifestSignatures mTypes.ManifestSignatures) bool {
for _, signatures := range manifestSignatures {
if len(signatures) > 0 {
return true
}
}

return false
}

func getPlatform(platform *proto_go.Platform) gql_generated.Platform {
if platform == nil {
return gql_generated.Platform{}
}

func getPlatform(platform ispec.Platform) gql_generated.Platform {
return gql_generated.Platform{
Os: &platform.Os,
Os: ref(platform.OS),
Arch: ref(getArch(platform.Architecture, platform.Variant)),
}
}

func getArch(arch string, variant *string) string {
if variant != nil && *variant != "" {
arch = arch + "/" + *variant
func getArch(arch string, variant string) string {
if variant != "" {
arch = arch + "/" + variant
}

return arch
Expand Down
Loading

0 comments on commit 81bb57b

Please sign in to comment.