mirror of
https://github.com/project-zot/zot.git
synced 2025-01-06 22:40:28 -05:00
ba6f347d8d
Which could be imported independently. See more details: 1. "zotregistry.io/zot/pkg/test/common" - currently used as tcommon "zotregistry.io/zot/pkg/test/common" - inside pkg/test test "zotregistry.io/zot/pkg/test/common" - in tests . "zotregistry.io/zot/pkg/test/common" - in tests Decouple zb from code in test/pkg in order to keep the size small. 2. "zotregistry.io/zot/pkg/test/image-utils" - curently used as . "zotregistry.io/zot/pkg/test/image-utils" 3. "zotregistry.io/zot/pkg/test/deprecated" - curently used as "zotregistry.io/zot/pkg/test/deprecated" This one will bre replaced gradually by image-utils in the future. 4. "zotregistry.io/zot/pkg/test/signature" - (cosign + notation) use as "zotregistry.io/zot/pkg/test/signature" 5. "zotregistry.io/zot/pkg/test/auth" - (bearer + oidc) curently used as authutils "zotregistry.io/zot/pkg/test/auth" 6. "zotregistry.io/zot/pkg/test/oci-utils" - curently used as ociutils "zotregistry.io/zot/pkg/test/oci-utils" Some unused functions were removed, some were replaced, and in a few cases specific funtions were moved to the files they were used in. Added an interface for the StoreController, this reduces the number of imports of the entire image store, decreasing binary size for tests. If the zb code was still coupled with pkg/test, this would have reflected in zb size. Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
110 lines
3.3 KiB
Go
110 lines
3.3 KiB
Go
package ociutils
|
|
|
|
import (
|
|
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
|
|
|
mTypes "zotregistry.io/zot/pkg/meta/types"
|
|
imageUtil "zotregistry.io/zot/pkg/test/image-utils"
|
|
)
|
|
|
|
type RepoImage struct {
|
|
imageUtil.Image
|
|
Tag string
|
|
Statistics mTypes.DescriptorStatistics
|
|
}
|
|
|
|
type RepoMultiArchImage struct {
|
|
imageUtil.MultiarchImage
|
|
ImageStatistics map[string]mTypes.DescriptorStatistics
|
|
Tag string
|
|
}
|
|
|
|
type Repo struct {
|
|
Name string
|
|
Images []RepoImage
|
|
MultiArchImages []RepoMultiArchImage
|
|
IsBookmarked bool
|
|
IsStarred bool
|
|
}
|
|
|
|
func GetMetadataForRepos(repos ...Repo) ([]mTypes.RepoMetadata, map[string]mTypes.ManifestMetadata,
|
|
map[string]mTypes.IndexData,
|
|
) {
|
|
var (
|
|
reposMetadata = []mTypes.RepoMetadata{}
|
|
manifestMetadataMap = map[string]mTypes.ManifestMetadata{}
|
|
indexDataMap = map[string]mTypes.IndexData{}
|
|
)
|
|
|
|
for _, repo := range repos {
|
|
repoMeta := mTypes.RepoMetadata{
|
|
Name: repo.Name,
|
|
Tags: map[string]mTypes.Descriptor{},
|
|
Signatures: map[string]mTypes.ManifestSignatures{},
|
|
Statistics: map[string]mTypes.DescriptorStatistics{},
|
|
IsStarred: repo.IsStarred,
|
|
IsBookmarked: repo.IsBookmarked,
|
|
}
|
|
|
|
for _, image := range repo.Images {
|
|
addImageMetaToMetaDB(image, repoMeta, manifestMetadataMap)
|
|
}
|
|
|
|
for _, multiArch := range repo.MultiArchImages {
|
|
if multiArch.ImageStatistics == nil {
|
|
multiArch.ImageStatistics = map[string]mTypes.DescriptorStatistics{}
|
|
}
|
|
|
|
repoMeta.Tags[multiArch.Tag] = mTypes.Descriptor{
|
|
MediaType: ispec.MediaTypeImageIndex,
|
|
Digest: multiArch.DigestStr(),
|
|
}
|
|
|
|
repoMeta.Statistics[multiArch.DigestStr()] = multiArch.ImageStatistics[multiArch.DigestStr()]
|
|
|
|
for _, image := range multiArch.Images {
|
|
addImageMetaToMetaDB(RepoImage{
|
|
Image: image,
|
|
Statistics: multiArch.ImageStatistics[image.DigestStr()],
|
|
}, repoMeta, manifestMetadataMap)
|
|
}
|
|
|
|
indexDataMap[multiArch.IndexDescriptor.Digest.String()] = mTypes.IndexData{
|
|
IndexBlob: multiArch.IndexDescriptor.Data,
|
|
}
|
|
}
|
|
|
|
reposMetadata = append(reposMetadata, repoMeta)
|
|
}
|
|
|
|
return reposMetadata, manifestMetadataMap, indexDataMap
|
|
}
|
|
|
|
func addImageMetaToMetaDB(image RepoImage, repoMeta mTypes.RepoMetadata,
|
|
manifestMetadataMap map[string]mTypes.ManifestMetadata,
|
|
) {
|
|
if image.Tag != "" {
|
|
repoMeta.Tags[image.Tag] = mTypes.Descriptor{
|
|
MediaType: ispec.MediaTypeImageManifest,
|
|
Digest: image.DigestStr(),
|
|
}
|
|
}
|
|
// here we can do many more checks about the images like check for referrers, signatures but it's not needed yet
|
|
// I need just the tags for now and the fake signature.
|
|
|
|
// This is done just to mark a manifest as signed in the resulted RepoMeta
|
|
if image.Manifest.ArtifactType == imageUtil.TestFakeSignatureArtType && image.Manifest.Subject != nil {
|
|
signedManifestDig := image.Manifest.Subject.Digest.String()
|
|
repoMeta.Signatures[signedManifestDig] = mTypes.ManifestSignatures{
|
|
"fakeSignature": []mTypes.SignatureInfo{{SignatureManifestDigest: image.ManifestDescriptor.Digest.String()}},
|
|
}
|
|
}
|
|
|
|
repoMeta.Statistics[image.DigestStr()] = image.Statistics
|
|
|
|
manifestMetadataMap[image.DigestStr()] = mTypes.ManifestMetadata{
|
|
ManifestBlob: image.ManifestDescriptor.Data,
|
|
ConfigBlob: image.ConfigDescriptor.Data,
|
|
DownloadCount: image.Statistics.DownloadCount,
|
|
}
|
|
}
|