From 50dccdff12f5fa5a0ab4b4f1702e6d2cfbb9e852 Mon Sep 17 00:00:00 2001 From: Laurentiu Niculae Date: Tue, 24 Oct 2023 12:39:40 +0300 Subject: [PATCH] refactor(meta): rename Signed-off-by: Laurentiu Niculae --- Makefile | 15 +- errors/errors.go | 2 +- examples/config-all-remote.json | 2 +- examples/config-dynamodb.json | 2 +- pkg/api/controller_test.go | 16 +- pkg/cli/client/cve_cmd_test.go | 2 +- pkg/extensions/extension_image_trust_test.go | 4 +- pkg/extensions/imagetrust/image_trust.go | 8 +- .../imagetrust/image_trust_disabled.go | 2 +- .../imagetrust/image_trust_disabled_test.go | 4 +- pkg/extensions/imagetrust/image_trust_test.go | 40 +- .../search/convert/convert_internal_test.go | 16 +- pkg/extensions/search/convert/convert_test.go | 68 +-- pkg/extensions/search/convert/metadb.go | 113 ++--- pkg/extensions/search/cve/cve.go | 4 +- pkg/extensions/search/cve/cve_test.go | 36 +- pkg/extensions/search/cve/pagination_test.go | 4 +- pkg/extensions/search/cve/scan.go | 16 +- pkg/extensions/search/cve/scan_test.go | 30 +- pkg/extensions/search/cve/trivy/scanner.go | 10 +- .../search/cve/trivy/scanner_internal_test.go | 14 +- pkg/extensions/search/resolver.go | 72 ++-- pkg/extensions/search/resolver_test.go | 190 ++++----- pkg/extensions/search/search_test.go | 4 +- pkg/extensions/sync/sync_internal_test.go | 4 +- pkg/extensions/sync/sync_test.go | 6 +- pkg/meta/boltdb/boltdb.go | 216 +++++----- pkg/meta/boltdb/boltdb_test.go | 2 +- pkg/meta/boltdb/buckets.go | 2 +- pkg/meta/common/common.go | 24 +- pkg/meta/convert/convert.go | 124 +++--- pkg/meta/convert/convert_proto.go | 30 +- pkg/meta/dynamodb/dynamodb.go | 240 +++++------ pkg/meta/dynamodb/dynamodb_test.go | 26 +- pkg/meta/dynamodb/parameters.go | 2 +- pkg/meta/meta.go | 4 +- pkg/meta/meta_test.go | 400 +++++++++--------- pkg/meta/parse.go | 8 +- pkg/meta/parse_test.go | 10 +- pkg/meta/proto/meta.proto | 10 +- pkg/meta/proto_go/config.pb.go | 2 +- pkg/meta/proto_go/descriptor.pb.go | 2 +- pkg/meta/proto_go/index.pb.go | 2 +- pkg/meta/proto_go/manifest.pb.go | 2 +- pkg/meta/proto_go/meta.pb.go | 108 ++--- pkg/meta/proto_go/versioned.pb.go | 2 +- pkg/meta/types/types.go | 44 +- pkg/meta/version/version_test.go | 2 +- pkg/test/image-utils/images.go | 4 +- pkg/test/image-utils/multiarch.go | 6 +- pkg/test/mocks/repo_db_mock.go | 62 +-- pkg/test/oci-utils/repo.go | 6 +- test/blackbox/cloud_only.bats | 2 +- 53 files changed, 1014 insertions(+), 1012 deletions(-) diff --git a/Makefile b/Makefile index 4ca2c0ac0f..fc5e3965f5 100644 --- a/Makefile +++ b/Makefile @@ -32,21 +32,21 @@ TESTDATA := $(TOP_LEVEL)/test/data OS ?= $(shell go env GOOS) ARCH ?= $(shell go env GOARCH) +PROTOC := $(TOOLSDIR)/bin/protoc +PROTOC_VERSION := 24.4 GO_PROTOC_VERSION := 1.31.0 -PROTOC_VERSION := 3.15.8 HOST_OS := $(shell go env GOOS) HOST_ARCH := $(shell go env GOARCH) ifeq ($(HOST_OS),linux) PROTOC_OS = linux - PROTOC_ARCH = x86_64 - ifeq ($(HOST_ARCH),arm64) - PROTOC_ARCH = aarch_64 - endif else ifeq ($(HOST_OS),darwin) PROTOC_OS = osx - PROTOC_ARCH = universal_binary endif -PROTOC := $(TOOLSDIR)/bin/protoc +ifeq ($(HOST_ARCH),amd64) + PROTOC_ARCH = x86_64 +else ifeq ($(HOST_ARCH),arm64) + PROTOC_ARCH = aarch_64 +endif BENCH_OUTPUT ?= stdout ALL_EXTENSIONS = debug,imagetrust,lint,metrics,mgmt,profile,scrub,search,sync,ui,userprefs @@ -283,6 +283,7 @@ $(PROTOC): mkdir -p $(TOOLSDIR)/bin curl -Lo protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip unzip -o -d $(TOOLSDIR) protoc.zip bin/protoc + rm protoc.zip chmod +x $(PROTOC) go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(GO_PROTOC_VERSION) diff --git a/errors/errors.go b/errors/errors.go index 1960b6baae..ae06840d95 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -108,7 +108,7 @@ var ( ErrManifestConflict = errors.New("manifest: multiple manifests found") ErrManifestMetaNotFound = errors.New("metadb: image metadata not found for given manifest reference") ErrManifestDataNotFound = errors.New("metadb: image data not found for given manifest digest") - ErrImageDataNotFound = errors.New("metadb: image data not found") + ErrImageMetaNotFound = errors.New("metadb: image data not found") ErrUnexpectedMediaType = errors.New("metadb: got unexpected media type") ErrIndexDataNotFount = errors.New("metadb: index data not found for given digest") ErrRepoMetaNotFound = errors.New("metadb: repo metadata not found for given repo name") diff --git a/examples/config-all-remote.json b/examples/config-all-remote.json index c953576067..89b734a9c1 100644 --- a/examples/config-all-remote.json +++ b/examples/config-all-remote.json @@ -18,7 +18,7 @@ "region": "us-east-2", "cacheTablename": "ZotBlobTable", "repoMetaTablename": "ZotRepoMetadataTable", - "imageDataTablename": "ZotImageDataTable", + "imageMetaTablename": "ZotImageMetaTable", "repoBlobsInfoTablename": "ZotRepoBlobsInfoTable", "versionTablename": "ZotVersion" } diff --git a/examples/config-dynamodb.json b/examples/config-dynamodb.json index b60a661d14..b269a04758 100644 --- a/examples/config-dynamodb.json +++ b/examples/config-dynamodb.json @@ -19,7 +19,7 @@ "region": "us-east-2", "cacheTablename": "ZotBlobTable", "repoMetaTablename": "ZotRepoMetadataTable", - "imageDataTablename": "ZotImageDataTable", + "imageMetaTablename": "ZotImageMetaTable", "repoBlobsInfoTablename": "ZotRepoBlobsInfoTable", "userDataTablename": "ZotUserDataTable", "versionTablename": "ZotVersion" diff --git a/pkg/api/controller_test.go b/pkg/api/controller_test.go index d32af47d0a..5f2a6e1ef2 100644 --- a/pkg/api/controller_test.go +++ b/pkg/api/controller_test.go @@ -158,7 +158,7 @@ func TestCreateCacheDatabaseDriver(t *testing.T) { "region": "us-east-2", "cacheTablename": "BlobTable", "repoMetaTablename": "RepoMetadataTable", - "imageDataTablename": "ZotImageDataTable", + "imageMetaTablename": "ZotImageMetaTable", "repoBlobsInfoTablename": "ZotRepoBlobsInfoTable", "userDataTablename": "ZotUserDataTable", "versionTablename": "Version", @@ -174,7 +174,7 @@ func TestCreateCacheDatabaseDriver(t *testing.T) { "region": "us-east-2", "cacheTablename": "BlobTable", "repoMetaTablename": "RepoMetadataTable", - "imageDataTablename": "ZotImageDataTable", + "imageMetaTablename": "ZotImageMetaTable", "repoBlobsInfoTablename": "ZotRepoBlobsInfoTable", "userDataTablename": "ZotUserDataTable", "versionTablename": "Version", @@ -189,7 +189,7 @@ func TestCreateCacheDatabaseDriver(t *testing.T) { "region": "us-east-2", "cacheTablename": "BlobTable", "repoMetaTablename": "RepoMetadataTable", - "imageDataTablename": "ZotImageDataTable", + "imageMetaTablename": "ZotImageMetaTable", "repoBlobsInfoTablename": "ZotRepoBlobsInfoTable", "userDataTablename": "ZotUserDataTable", "versionTablename": "Version", @@ -223,7 +223,7 @@ func TestCreateMetaDBDriver(t *testing.T) { "region": "us-east-2", "cachetablename": "BlobTable", "repometatablename": "RepoMetadataTable", - "imageDataTablename": "ZotImageDataTable", + "imageMetaTablename": "ZotImageMetaTable", "repoBlobsInfoTablename": "ZotRepoBlobsInfoTable", "userdatatablename": "UserDatatable", } @@ -237,7 +237,7 @@ func TestCreateMetaDBDriver(t *testing.T) { "region": "us-east-2", "cachetablename": "", "repometatablename": "RepoMetadataTable", - "imageDataTablename": "ZotImageDataTable", + "imageMetaTablename": "ZotImageMetaTable", "repoBlobsInfoTablename": "ZotRepoBlobsInfoTable", "userDataTablename": "ZotUserDataTable", "versiontablename": 1, @@ -252,7 +252,7 @@ func TestCreateMetaDBDriver(t *testing.T) { "region": "us-east-2", "cachetablename": "test", "repometatablename": "RepoMetadataTable", - "imagedatatablename": "ZotImageDataTable", + "imagemetatablename": "ZotImageMetaTable", "repoblobsinfotablename": "ZotRepoBlobsInfoTable", "userdatatablename": "ZotUserDataTable", "apikeytablename": "APIKeyTable", @@ -434,7 +434,7 @@ func TestObjectStorageController(t *testing.T) { "region": "us-east-2", "cachetablename": "test", "repometatablename": "RepoMetadataTable", - "imagedatatablename": "ZotImageDataTable", + "imagemetatablename": "ZotImageMetaTable", "repoblobsinfotablename": "ZotRepoBlobsInfoTable", "userdatatablename": "ZotUserDataTable", "apikeytablename": "APIKeyTable1", @@ -7933,7 +7933,7 @@ func TestGCSignaturesAndUntaggedManifestsWithMetaDB(t *testing.T) { err = gc.CleanRepo(repoName) So(err, ShouldBeNil) - // make sure both signatures are removed from repodb and repo reference for untagged is removed + // make sure both signatures are removed from metaDB and repo reference for untagged is removed repoMeta, err = ctlr.MetaDB.GetRepoMeta(ctx, repoName) So(err, ShouldBeNil) diff --git a/pkg/cli/client/cve_cmd_test.go b/pkg/cli/client/cve_cmd_test.go index 17f6cffb9c..6c46968d9a 100644 --- a/pkg/cli/client/cve_cmd_test.go +++ b/pkg/cli/client/cve_cmd_test.go @@ -755,7 +755,7 @@ func getMockCveScanner(metaDB mTypes.MetaDB) cveinfo.Scanner { return false, err } - manifestData, err := metaDB.GetImageData(manifestDigest) + manifestData, err := metaDB.GetImageMeta(manifestDigest) if err != nil { return false, err } diff --git a/pkg/extensions/extension_image_trust_test.go b/pkg/extensions/extension_image_trust_test.go index 9d89929ed2..a0dc6d304d 100644 --- a/pkg/extensions/extension_image_trust_test.go +++ b/pkg/extensions/extension_image_trust_test.go @@ -134,7 +134,7 @@ func TestSignatureUploadAndVerificationAWS(t *testing.T) { versionTablename := "Version" + uuid.String() userDataTablename := "UserDataTable" + uuid.String() apiKeyTablename := "ApiKeyTable" + uuid.String() - imageDataTablename := "imageDataTable" + uuid.String() + imageMetaTablename := "imageMetaTable" + uuid.String() repoBlobsInfoTablename := "repoBlobsInfoTable" + uuid.String() cacheDriverParams := map[string]interface{}{ @@ -143,7 +143,7 @@ func TestSignatureUploadAndVerificationAWS(t *testing.T) { "region": "us-east-2", "cacheTablename": cacheTablename, "repoMetaTablename": repoMetaTablename, - "imageDataTablename": imageDataTablename, + "imageMetaTablename": imageMetaTablename, "repoBlobsInfoTablename": repoBlobsInfoTablename, "userDataTablename": userDataTablename, "apiKeyTablename": apiKeyTablename, diff --git a/pkg/extensions/imagetrust/image_trust.go b/pkg/extensions/imagetrust/image_trust.go index e197d1f42e..3fd06fa141 100644 --- a/pkg/extensions/imagetrust/image_trust.go +++ b/pkg/extensions/imagetrust/image_trust.go @@ -157,13 +157,13 @@ func IsResourceExistsException(err error) bool { } func (imgTrustStore *ImageTrustStore) VerifySignature( - signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageData mTypes.ImageData, + signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageMeta mTypes.ImageMeta, repo string, ) (string, time.Time, bool, error) { desc := ispec.Descriptor{ - MediaType: imageData.MediaType, - Digest: imageData.Digest, - Size: imageData.Size, + MediaType: imageMeta.MediaType, + Digest: imageMeta.Digest, + Size: imageMeta.Size, } if manifestDigest.String() == "" { diff --git a/pkg/extensions/imagetrust/image_trust_disabled.go b/pkg/extensions/imagetrust/image_trust_disabled.go index cd555d2011..9a6cf24e70 100644 --- a/pkg/extensions/imagetrust/image_trust_disabled.go +++ b/pkg/extensions/imagetrust/image_trust_disabled.go @@ -22,7 +22,7 @@ func NewAWSImageTrustStore(region, endpoint string) (*imageTrustDisabled, error) type imageTrustDisabled struct{} func (imgTrustStore *imageTrustDisabled) VerifySignature( - signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageData mTypes.ImageData, + signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageMeta mTypes.ImageMeta, repo string, ) (string, time.Time, bool, error) { return "", time.Time{}, false, nil diff --git a/pkg/extensions/imagetrust/image_trust_disabled_test.go b/pkg/extensions/imagetrust/image_trust_disabled_test.go index 6abb28a010..c146df576d 100644 --- a/pkg/extensions/imagetrust/image_trust_disabled_test.go +++ b/pkg/extensions/imagetrust/image_trust_disabled_test.go @@ -33,7 +33,7 @@ func TestImageTrust(t *testing.T) { So(err, ShouldBeNil) author, expTime, ok, err := localImgTrustStore.VerifySignature("cosign", - []byte(""), "", image.Digest(), image.AsImageData(), repo, + []byte(""), "", image.Digest(), image.AsImageMeta(), repo, ) So(author, ShouldBeEmpty) So(expTime, ShouldBeZeroValue) @@ -52,7 +52,7 @@ func TestImageTrust(t *testing.T) { So(err, ShouldBeNil) author, expTime, ok, err = cloudImgTrustStore.VerifySignature("cosign", - []byte(""), "", image.Digest(), image.AsImageData(), repo, + []byte(""), "", image.Digest(), image.AsImageMeta(), repo, ) So(author, ShouldBeEmpty) So(expTime, ShouldBeZeroValue) diff --git a/pkg/extensions/imagetrust/image_trust_test.go b/pkg/extensions/imagetrust/image_trust_test.go index c6a1d32e17..d436b05520 100644 --- a/pkg/extensions/imagetrust/image_trust_test.go +++ b/pkg/extensions/imagetrust/image_trust_test.go @@ -154,7 +154,7 @@ func TestVerifySignatures(t *testing.T) { image := CreateRandomImage() imgTrustStore := &imagetrust.ImageTrustStore{} - _, _, _, err := imgTrustStore.VerifySignature("", []byte(""), "", "", image.AsImageData(), "repo") + _, _, _, err := imgTrustStore.VerifySignature("", []byte(""), "", "", image.AsImageMeta(), "repo") So(err, ShouldNotBeNil) So(err, ShouldEqual, zerr.ErrBadManifestDigest) }) @@ -163,7 +163,7 @@ func TestVerifySignatures(t *testing.T) { image := CreateRandomImage() imgTrustStore := &imagetrust.ImageTrustStore{} - _, _, _, err := imgTrustStore.VerifySignature("wrongType", []byte(""), "", image.Digest(), image.AsImageData(), + _, _, _, err := imgTrustStore.VerifySignature("wrongType", []byte(""), "", image.Digest(), image.AsImageMeta(), "repo") So(err, ShouldNotBeNil) So(err, ShouldEqual, zerr.ErrInvalidSignatureType) @@ -180,7 +180,7 @@ func TestVerifySignatures(t *testing.T) { CosignStorage: &imagetrust.PublicKeyLocalStorage{}, } - _, _, _, err := imgTrustStore.VerifySignature("cosign", []byte(""), "", image.Digest(), image.AsImageData(), repo) + _, _, _, err := imgTrustStore.VerifySignature("cosign", []byte(""), "", image.Digest(), image.AsImageMeta(), repo) So(err, ShouldNotBeNil) So(err, ShouldEqual, zerr.ErrSignConfigDirNotSet) }) @@ -200,7 +200,7 @@ func TestVerifySignatures(t *testing.T) { CosignStorage: pubKeyStorage, } - _, _, _, err = imgTrustStore.VerifySignature("cosign", []byte(""), "", image.Digest(), image.AsImageData(), repo) + _, _, _, err = imgTrustStore.VerifySignature("cosign", []byte(""), "", image.Digest(), image.AsImageMeta(), repo) So(err, ShouldNotBeNil) }) @@ -220,7 +220,7 @@ func TestVerifySignatures(t *testing.T) { CosignStorage: pubKeyStorage, } - _, _, isTrusted, err := imgTrustStore.VerifySignature("cosign", []byte(""), "", image.Digest(), image.AsImageData(), + _, _, isTrusted, err := imgTrustStore.VerifySignature("cosign", []byte(""), "", image.Digest(), image.AsImageMeta(), repo) So(err, ShouldBeNil) So(isTrusted, ShouldBeFalse) @@ -309,7 +309,7 @@ func TestVerifySignatures(t *testing.T) { // signature is trusted author, _, isTrusted, err := imgTrustStore.VerifySignature("cosign", rawSignature, sigKey, image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldBeNil) So(isTrusted, ShouldBeTrue) So(author, ShouldNotBeEmpty) @@ -327,7 +327,7 @@ func TestVerifySignatures(t *testing.T) { } _, _, _, err := imgTrustStore.VerifySignature("notation", []byte("signature"), "", image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldNotBeNil) So(err, ShouldEqual, zerr.ErrSignConfigDirNotSet) }) @@ -343,7 +343,7 @@ func TestVerifySignatures(t *testing.T) { } _, _, isTrusted, err := imgTrustStore.VerifySignature("notation", []byte(""), "", image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldNotBeNil) So(isTrusted, ShouldBeFalse) }) @@ -364,7 +364,7 @@ func TestVerifySignatures(t *testing.T) { } _, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldNotBeNil) }) @@ -386,7 +386,7 @@ func TestVerifySignatures(t *testing.T) { } _, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldNotBeNil) }) @@ -489,7 +489,7 @@ func TestVerifySignatures(t *testing.T) { // signature is trusted author, _, isTrusted, err := imgTrustStore.VerifySignature("notation", rawSignature, sigKey, image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldBeNil) So(isTrusted, ShouldBeTrue) So(author, ShouldNotBeEmpty) @@ -499,7 +499,7 @@ func TestVerifySignatures(t *testing.T) { // signature is not trusted author, _, isTrusted, err = imgTrustStore.VerifySignature("notation", rawSignature, sigKey, image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldNotBeNil) So(isTrusted, ShouldBeFalse) So(author, ShouldNotBeEmpty) @@ -985,7 +985,7 @@ func TestAWSTrustStore(t *testing.T) { } _, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldNotBeNil) }) @@ -1015,7 +1015,7 @@ func TestAWSTrustStore(t *testing.T) { } _, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldNotBeNil) secretsManagerCacheMock = mocks.SecretsManagerCacheMock{ @@ -1032,7 +1032,7 @@ func TestAWSTrustStore(t *testing.T) { } _, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldNotBeNil) secretsManagerCacheMock = mocks.SecretsManagerCacheMock{ @@ -1049,7 +1049,7 @@ func TestAWSTrustStore(t *testing.T) { } _, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldNotBeNil) }) @@ -1063,7 +1063,7 @@ func TestAWSTrustStore(t *testing.T) { versionTablename := "Version" + uuid.String() userDataTablename := "UserDataTable" + uuid.String() apiKeyTablename := "ApiKeyTable" + uuid.String() - imageDataTablename := "imageDataTable" + uuid.String() + imageMetaTablename := "imageMetaTable" + uuid.String() repoBlobsInfoTablename := "repoBlobsInfoTable" + uuid.String() dynamoDBDriverParams := map[string]interface{}{ @@ -1071,7 +1071,7 @@ func TestAWSTrustStore(t *testing.T) { "endpoint": os.Getenv("DYNAMODBMOCK_ENDPOINT"), "region": "us-east-2", "repometatablename": repoMetaTablename, - "imagedatatablename": imageDataTablename, + "imagemetatablename": imageMetaTablename, "repoblobsinfotablename": repoBlobsInfoTablename, "userdatatablename": userDataTablename, "apikeytablename": apiKeyTablename, @@ -1287,7 +1287,7 @@ func RunVerificationTests(t *testing.T, dbDriverParams map[string]interface{}) { // signature is trusted author, _, isTrusted, err := imageTrustStore.VerifySignature("cosign", rawSignature, sigKey, image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldBeNil) So(isTrusted, ShouldBeTrue) So(author, ShouldNotBeEmpty) @@ -1377,7 +1377,7 @@ func RunVerificationTests(t *testing.T, dbDriverParams map[string]interface{}) { // signature is trusted author, _, isTrusted, err := imageTrustStore.VerifySignature("notation", rawSignature, sigKey, image.Digest(), - image.AsImageData(), repo) + image.AsImageMeta(), repo) So(err, ShouldBeNil) So(isTrusted, ShouldBeTrue) So(author, ShouldEqual, "CN=cert,O=Notary,L=Seattle,ST=WA,C=US") diff --git a/pkg/extensions/search/convert/convert_internal_test.go b/pkg/extensions/search/convert/convert_internal_test.go index 9dfb691514..17521db392 100644 --- a/pkg/extensions/search/convert/convert_internal_test.go +++ b/pkg/extensions/search/convert/convert_internal_test.go @@ -39,13 +39,13 @@ func TestCVEConvert(t *testing.T) { Blob: ispec.DescriptorEmptyJSON.Data, }}).DefaultConfig().Build() - err = metaDB.SetRepoReference("repo1", "0.1.0", image.AsImageData()) + err = metaDB.SetRepoReference("repo1", "0.1.0", image.AsImageMeta()) So(err, ShouldBeNil) repoMetaList, err := metaDB.SearchRepos(context.Background(), "") So(err, ShouldBeNil) - imageData, err := metaDB.FilterImageData(context.Background(), []string{image.DigestStr()}) + imageMeta, err := metaDB.FilterImageMeta(context.Background(), []string{image.DigestStr()}) ctx := graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, graphql.DefaultRecover) @@ -71,8 +71,8 @@ func TestCVEConvert(t *testing.T) { So(imageSummary, ShouldBeNil) So(graphql.GetErrors(ctx), ShouldBeNil) - imageSummary, _, err = ImageManifest2ImageSummary(ctx, GetImageMeta("0.1.0", repoMetaList[0], - imageData[image.DigestStr()])) + imageSummary, _, err = ImageManifest2ImageSummary(ctx, GetFullImageMeta("0.1.0", repoMetaList[0], + imageMeta[image.DigestStr()])) So(err, ShouldBeNil) So(imageSummary, ShouldNotBeNil) @@ -162,8 +162,8 @@ func TestCVEConvert(t *testing.T) { So(repoSummary, ShouldBeNil) So(graphql.GetErrors(ctx), ShouldBeNil) - imageSummary, _, err := ImageManifest2ImageSummary(ctx, GetImageMeta("0.1.0", repoMetaList[0], - imageData[image.DigestStr()])) + imageSummary, _, err := ImageManifest2ImageSummary(ctx, GetFullImageMeta("0.1.0", repoMetaList[0], + imageMeta[image.DigestStr()])) So(err, ShouldBeNil) So(imageSummary, ShouldNotBeNil) @@ -220,8 +220,8 @@ func TestCVEConvert(t *testing.T) { So(manifestSummary, ShouldBeNil) So(graphql.GetErrors(ctx), ShouldBeNil) - imageSummary, _, err := ImageManifest2ImageSummary(ctx, GetImageMeta("0.1.0", repoMetaList[0], - imageData[image.DigestStr()])) + imageSummary, _, err := ImageManifest2ImageSummary(ctx, GetFullImageMeta("0.1.0", repoMetaList[0], + imageMeta[image.DigestStr()])) So(err, ShouldBeNil) manifestSummary = imageSummary.Manifests[0] diff --git a/pkg/extensions/search/convert/convert_test.go b/pkg/extensions/search/convert/convert_test.go index 3bd7dc24a9..befc74a8b1 100644 --- a/pkg/extensions/search/convert/convert_test.go +++ b/pkg/extensions/search/convert/convert_test.go @@ -346,11 +346,11 @@ func TestPaginatedConvert(t *testing.T) { // Test different combinations of the filter repoMetaList, err := metaDB.FilterRepos(ctx, mTypes.AcceptAllRepoNames, mTypes.AcceptAllRepoMeta) So(err, ShouldBeNil) - imageData, err := metaDB.FilterImageData(ctx, mTypes.GetLatestImageDigests(repoMetaList)) + imageMeta, err := metaDB.FilterImageMeta(ctx, mTypes.GetLatestImageDigests(repoMetaList)) So(err, ShouldBeNil) reposSum, pageInfo, err := convert.PaginatedRepoMeta2RepoSummaries( - ctx, repoMetaList, imageData, + ctx, repoMetaList, imageMeta, mTypes.Filter{ Os: []*string{ref("good-os")}, Arch: []*string{ref("good-arch")}, @@ -369,7 +369,7 @@ func TestPaginatedConvert(t *testing.T) { So(pageInfo.ItemCount, ShouldEqual, 2) reposSum, pageInfo, err = convert.PaginatedRepoMeta2RepoSummaries( - ctx, repoMetaList, imageData, + ctx, repoMetaList, imageMeta, mTypes.Filter{ Os: []*string{ref("good-os")}, Arch: []*string{ref("good-arch")}, @@ -384,7 +384,7 @@ func TestPaginatedConvert(t *testing.T) { So(pageInfo.ItemCount, ShouldEqual, 0) reposSum, pageInfo, err = convert.PaginatedRepoMeta2RepoSummaries( - ctx, repoMetaList, imageData, + ctx, repoMetaList, imageMeta, mTypes.Filter{ HasToBeSigned: ref(true), }, @@ -397,7 +397,7 @@ func TestPaginatedConvert(t *testing.T) { // no filter reposSum, pageInfo, err = convert.PaginatedRepoMeta2RepoSummaries( - ctx, repoMetaList, imageData, + ctx, repoMetaList, imageMeta, mTypes.Filter{}, pagination.PageInput{SortBy: pagination.AlphabeticAsc}, mocks.CveInfoMock{}, skipCVE, ) So(err, ShouldBeNil) @@ -411,7 +411,7 @@ func TestPaginatedConvert(t *testing.T) { // no filter opposite sorting reposSum, pageInfo, err = convert.PaginatedRepoMeta2RepoSummaries( - ctx, repoMetaList, imageData, + ctx, repoMetaList, imageMeta, mTypes.Filter{}, pagination.PageInput{SortBy: pagination.AlphabeticDsc}, mocks.CveInfoMock{}, skipCVE, ) So(err, ShouldBeNil) @@ -425,7 +425,7 @@ func TestPaginatedConvert(t *testing.T) { // add pagination reposSum, pageInfo, err = convert.PaginatedRepoMeta2RepoSummaries( - ctx, repoMetaList, imageData, + ctx, repoMetaList, imageMeta, mTypes.Filter{ Os: []*string{ref("good-os")}, Arch: []*string{ref("good-arch")}, @@ -441,7 +441,7 @@ func TestPaginatedConvert(t *testing.T) { So(pageInfo.TotalCount, ShouldEqual, 2) reposSum, pageInfo, err = convert.PaginatedRepoMeta2RepoSummaries( - ctx, repoMetaList, imageData, + ctx, repoMetaList, imageMeta, mTypes.Filter{ Os: []*string{ref("good-os")}, Arch: []*string{ref("good-arch")}, @@ -458,11 +458,11 @@ func TestPaginatedConvert(t *testing.T) { }) Convey("PaginatedRepoMeta2ImageSummaries filtering and sorting", t, func() { - imageDataList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageData) + fullImageMetaList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageMeta) So(err, ShouldBeNil) - imgSum, pageInfo, err := convert.PaginatedImageMeta2ImageSummaries( - ctx, imageDataList, skipCVE, mocks.CveInfoMock{}, + imgSum, pageInfo, err := convert.PaginatedFullImageMeta2ImageSummaries( + ctx, fullImageMetaList, skipCVE, mocks.CveInfoMock{}, mTypes.Filter{ Os: []*string{ref("good-os")}, Arch: []*string{ref("good-arch")}, @@ -484,8 +484,8 @@ func TestPaginatedConvert(t *testing.T) { So(pageInfo.ItemCount, ShouldEqual, 5) // add page of size 2 - imgSum, pageInfo, err = convert.PaginatedImageMeta2ImageSummaries( - ctx, imageDataList, skipCVE, mocks.CveInfoMock{}, + imgSum, pageInfo, err = convert.PaginatedFullImageMeta2ImageSummaries( + ctx, fullImageMetaList, skipCVE, mocks.CveInfoMock{}, mTypes.Filter{ Os: []*string{ref("good-os")}, Arch: []*string{ref("good-arch")}, @@ -502,8 +502,8 @@ func TestPaginatedConvert(t *testing.T) { So(pageInfo.TotalCount, ShouldEqual, 5) // next page - imgSum, pageInfo, err = convert.PaginatedImageMeta2ImageSummaries( - ctx, imageDataList, skipCVE, mocks.CveInfoMock{}, + imgSum, pageInfo, err = convert.PaginatedFullImageMeta2ImageSummaries( + ctx, fullImageMetaList, skipCVE, mocks.CveInfoMock{}, mTypes.Filter{ Os: []*string{ref("good-os")}, Arch: []*string{ref("good-arch")}, @@ -520,8 +520,8 @@ func TestPaginatedConvert(t *testing.T) { So(pageInfo.TotalCount, ShouldEqual, 5) // last page - imgSum, pageInfo, err = convert.PaginatedImageMeta2ImageSummaries( - ctx, imageDataList, skipCVE, mocks.CveInfoMock{}, + imgSum, pageInfo, err = convert.PaginatedFullImageMeta2ImageSummaries( + ctx, fullImageMetaList, skipCVE, mocks.CveInfoMock{}, mTypes.Filter{ Os: []*string{ref("good-os")}, Arch: []*string{ref("good-arch")}, @@ -536,8 +536,8 @@ func TestPaginatedConvert(t *testing.T) { So(pageInfo.TotalCount, ShouldEqual, 5) // has to be signed - imgSum, pageInfo, err = convert.PaginatedImageMeta2ImageSummaries( - ctx, imageDataList, skipCVE, mocks.CveInfoMock{}, + imgSum, pageInfo, err = convert.PaginatedFullImageMeta2ImageSummaries( + ctx, fullImageMetaList, skipCVE, mocks.CveInfoMock{}, mTypes.Filter{ Os: []*string{ref("good-os")}, Arch: []*string{ref("good-arch")}, @@ -627,11 +627,11 @@ func TestIndexAnnotations(t *testing.T) { repoMeta, err := metaDB.GetRepoMeta(ctx, "repo") So(err, ShouldBeNil) - imageData, err := metaDB.FilterImageData(ctx, []string{indexWithAnnotations.DigestStr()}) + imageMeta, err := metaDB.FilterImageMeta(ctx, []string{indexWithAnnotations.DigestStr()}) So(err, ShouldBeNil) - imageSummary, _, err := convert.ImageIndex2ImageSummary(ctx, convert.GetImageMeta("tag", repoMeta, - imageData[indexWithAnnotations.DigestStr()])) + imageSummary, _, err := convert.ImageIndex2ImageSummary(ctx, convert.GetFullImageMeta("tag", repoMeta, + imageMeta[indexWithAnnotations.DigestStr()])) So(err, ShouldBeNil) So(*imageSummary.Description, ShouldResemble, "IndexDescription") So(*imageSummary.Licenses, ShouldResemble, "IndexLicenses") @@ -660,11 +660,11 @@ func TestIndexAnnotations(t *testing.T) { repoMeta, err = metaDB.GetRepoMeta(ctx, "repo") So(err, ShouldBeNil) - imageData, err = metaDB.FilterImageData(ctx, []string{digest}) + imageMeta, err = metaDB.FilterImageMeta(ctx, []string{digest}) So(err, ShouldBeNil) - imageSummary, _, err = convert.ImageIndex2ImageSummary(ctx, convert.GetImageMeta("tag", repoMeta, - imageData[digest])) + imageSummary, _, err = convert.ImageIndex2ImageSummary(ctx, convert.GetFullImageMeta("tag", repoMeta, + imageMeta[digest])) So(err, ShouldBeNil) So(*imageSummary.Description, ShouldResemble, "ManifestDescription") So(*imageSummary.Licenses, ShouldResemble, "ManifestLicenses") @@ -693,11 +693,11 @@ func TestIndexAnnotations(t *testing.T) { repoMeta, err = metaDB.GetRepoMeta(ctx, "repo") So(err, ShouldBeNil) - imageData, err = metaDB.FilterImageData(ctx, []string{digest}) + imageMeta, err = metaDB.FilterImageMeta(ctx, []string{digest}) So(err, ShouldBeNil) - imageSummary, _, err = convert.ImageIndex2ImageSummary(ctx, convert.GetImageMeta("tag", repoMeta, - imageData[digest])) + imageSummary, _, err = convert.ImageIndex2ImageSummary(ctx, convert.GetFullImageMeta("tag", repoMeta, + imageMeta[digest])) So(err, ShouldBeNil) So(*imageSummary.Description, ShouldResemble, "ConfigDescription") So(*imageSummary.Licenses, ShouldResemble, "ConfigLicenses") @@ -747,11 +747,11 @@ func TestIndexAnnotations(t *testing.T) { repoMeta, err = metaDB.GetRepoMeta(ctx, "repo") So(err, ShouldBeNil) - imageData, err = metaDB.FilterImageData(ctx, []string{digest}) + imageMeta, err = metaDB.FilterImageMeta(ctx, []string{digest}) So(err, ShouldBeNil) - imageSummary, _, err = convert.ImageIndex2ImageSummary(ctx, convert.GetImageMeta("tag", repoMeta, - imageData[digest])) + imageSummary, _, err = convert.ImageIndex2ImageSummary(ctx, convert.GetFullImageMeta("tag", repoMeta, + imageMeta[digest])) So(err, ShouldBeNil) So(*imageSummary.Description, ShouldResemble, "ConfigDescription") So(*imageSummary.Licenses, ShouldResemble, "ConfigLicenses") @@ -778,11 +778,11 @@ func TestIndexAnnotations(t *testing.T) { repoMeta, err = metaDB.GetRepoMeta(ctx, "repo") So(err, ShouldBeNil) - imageData, err = metaDB.FilterImageData(ctx, []string{digest}) + imageMeta, err = metaDB.FilterImageMeta(ctx, []string{digest}) So(err, ShouldBeNil) - imageSummary, _, err = convert.ImageIndex2ImageSummary(ctx, convert.GetImageMeta("tag", repoMeta, - imageData[digest])) + imageSummary, _, err = convert.ImageIndex2ImageSummary(ctx, convert.GetFullImageMeta("tag", repoMeta, + imageMeta[digest])) So(err, ShouldBeNil) So(*imageSummary.Description, ShouldBeBlank) So(*imageSummary.Licenses, ShouldBeBlank) diff --git a/pkg/extensions/search/convert/metadb.go b/pkg/extensions/search/convert/metadb.go index dea51c631c..5ee64a9031 100644 --- a/pkg/extensions/search/convert/metadb.go +++ b/pkg/extensions/search/convert/metadb.go @@ -98,7 +98,7 @@ func getImageBlobsInfo(manifestDigest string, manifestSize int64, configDigest s } func RepoMeta2ImageSummaries(ctx context.Context, repoMeta mTypes.RepoMeta, - imageData map[string]mTypes.ImageData, skip SkipQGLField, cveInfo cveinfo.CveInfo, + imageMeta map[string]mTypes.ImageMeta, skip SkipQGLField, cveInfo cveinfo.CveInfo, ) []*gql_generated.ImageSummary { imageSummaries := make([]*gql_generated.ImageSummary, 0, len(repoMeta.Tags)) @@ -116,7 +116,7 @@ func RepoMeta2ImageSummaries(ctx context.Context, repoMeta mTypes.RepoMeta, for _, tag := range tags { descriptor := repoMeta.Tags[tag] - imageSummary, _, err := ImageMeta2ImageSummary(ctx, GetImageMeta(tag, repoMeta, imageData[descriptor.Digest])) + imageSummary, _, err := FullImageMeta2ImageSummary(ctx, GetFullImageMeta(tag, repoMeta, imageMeta[descriptor.Digest])) if err != nil { continue } @@ -131,15 +131,15 @@ func RepoMeta2ImageSummaries(ctx context.Context, repoMeta mTypes.RepoMeta, } func RepoMeta2ExpandedRepoInfo(ctx context.Context, repoMeta mTypes.RepoMeta, - imageDataMap map[string]mTypes.ImageData, skip SkipQGLField, cveInfo cveinfo.CveInfo, log log.Logger, + imageMetaMap map[string]mTypes.ImageMeta, skip SkipQGLField, cveInfo cveinfo.CveInfo, log log.Logger, ) (*gql_generated.RepoSummary, []*gql_generated.ImageSummary) { repoName := repoMeta.Name imageSummaries := make([]*gql_generated.ImageSummary, 0, len(repoMeta.Tags)) for tag, descriptor := range repoMeta.Tags { - imageData := imageDataMap[descriptor.Digest] + imageMeta := imageMetaMap[descriptor.Digest] - imageSummary, _, err := ImageMeta2ImageSummary(ctx, GetImageMeta(tag, repoMeta, imageData)) + imageSummary, _, err := FullImageMeta2ImageSummary(ctx, GetFullImageMeta(tag, repoMeta, imageMeta)) if err != nil { log.Error().Str("repository", repoName).Str("reference", tag). Msg("metadb: error while converting descriptor for image") @@ -152,34 +152,34 @@ func RepoMeta2ExpandedRepoInfo(ctx context.Context, repoMeta mTypes.RepoMeta, imageSummaries = append(imageSummaries, imageSummary) } - repoSummary := RepoMeta2RepoSummary(ctx, repoMeta, imageDataMap) + repoSummary := RepoMeta2RepoSummary(ctx, repoMeta, imageMetaMap) updateRepoSummaryVulnerabilities(ctx, repoSummary, skip, cveInfo) return repoSummary, imageSummaries } -func GetImageMeta(tag string, repoMeta mTypes.RepoMeta, imageData mTypes.ImageData, -) mTypes.ImageMeta { - return mTypes.ImageMeta{ +func GetFullImageMeta(tag string, repoMeta mTypes.RepoMeta, imageMeta mTypes.ImageMeta, +) mTypes.FullImageMeta { + return mTypes.FullImageMeta{ Repo: repoMeta.Name, Tag: tag, - MediaType: imageData.MediaType, - Digest: imageData.Digest, - Size: imageData.Size, - Index: imageData.Index, - Manifests: GetManifestMeta(repoMeta, imageData.Manifests), - Referrers: repoMeta.Referrers[imageData.Digest.String()], - Statistics: repoMeta.Statistics[imageData.Digest.String()], - Signatures: repoMeta.Signatures[imageData.Digest.String()], + MediaType: imageMeta.MediaType, + Digest: imageMeta.Digest, + Size: imageMeta.Size, + Index: imageMeta.Index, + Manifests: GetFullManifestMeta(repoMeta, imageMeta.Manifests), + Referrers: repoMeta.Referrers[imageMeta.Digest.String()], + Statistics: repoMeta.Statistics[imageMeta.Digest.String()], + Signatures: repoMeta.Signatures[imageMeta.Digest.String()], } } -func GetManifestMeta(repoMeta mTypes.RepoMeta, manifests []mTypes.ManifestData) []mTypes.ManifestMeta { - results := make([]mTypes.ManifestMeta, 0, len(manifests)) +func GetFullManifestMeta(repoMeta mTypes.RepoMeta, manifests []mTypes.ManifestData) []mTypes.FullManifestMeta { + results := make([]mTypes.FullManifestMeta, 0, len(manifests)) for i := range manifests { - results = append(results, mTypes.ManifestMeta{ + results = append(results, mTypes.FullManifestMeta{ ManifestData: manifests[i], Referrers: repoMeta.Referrers[manifests[i].Digest.String()], Statistics: repoMeta.Statistics[manifests[i].Digest.String()], @@ -290,7 +290,7 @@ func GetSignaturesInfo(isSigned bool, signatures mTypes.ManifestSignatures) []*g } func PaginatedRepoMeta2RepoSummaries(ctx context.Context, repoMetaList []mTypes.RepoMeta, - imageDataMap map[string]mTypes.ImageData, filter mTypes.Filter, pageInput pagination.PageInput, + imageMetaMap map[string]mTypes.ImageMeta, 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) @@ -299,7 +299,7 @@ func PaginatedRepoMeta2RepoSummaries(ctx context.Context, repoMetaList []mTypes. } for _, repoMeta := range repoMetaList { - repoSummary := RepoMeta2RepoSummary(ctx, repoMeta, imageDataMap) + repoSummary := RepoMeta2RepoSummary(ctx, repoMeta, imageMetaMap) if RepoSumAcceptedByFilter(repoSummary, filter) { reposPageFinder.Add(repoSummary) @@ -317,7 +317,7 @@ func PaginatedRepoMeta2RepoSummaries(ctx context.Context, repoMetaList []mTypes. } func RepoMeta2RepoSummary(ctx context.Context, repoMeta mTypes.RepoMeta, - imageDataMap map[string]mTypes.ImageData, + imageMetaMap map[string]mTypes.ImageMeta, ) *gql_generated.RepoSummary { var ( repoName = repoMeta.Name @@ -329,7 +329,7 @@ func RepoMeta2RepoSummary(ctx context.Context, repoMeta mTypes.RepoMeta, repoIsUserStarred = repoMeta.IsStarred // value specific to the current user repoIsUserBookMarked = repoMeta.IsBookmarked // value specific to the current user repoSize = repoMeta.Size - lastUpdatedImageData = imageDataMap[repoMeta.LastUpdatedImage.Digest] + lastUpdatedImageMeta = imageMetaMap[repoMeta.LastUpdatedImage.Digest] lastUpdatedTag = repoMeta.LastUpdatedImage.Tag ) @@ -337,7 +337,8 @@ func RepoMeta2RepoSummary(ctx context.Context, repoMeta mTypes.RepoMeta, repoLastUpdatedTimestamp = &time.Time{} } - imageSummary, _, err := ImageMeta2ImageSummary(ctx, GetImageMeta(lastUpdatedTag, repoMeta, lastUpdatedImageData)) + imageSummary, _, err := FullImageMeta2ImageSummary(ctx, GetFullImageMeta(lastUpdatedTag, repoMeta, + lastUpdatedImageMeta)) _ = err return &gql_generated.RepoSummary{ @@ -383,42 +384,42 @@ type ( BlobDigest = string ) -func ImageMeta2ImageSummary(ctx context.Context, imageMeta mTypes.ImageMeta, +func FullImageMeta2ImageSummary(ctx context.Context, fullImageMeta mTypes.FullImageMeta, ) (*gql_generated.ImageSummary, map[BlobDigest]int64, error) { - switch imageMeta.MediaType { + switch fullImageMeta.MediaType { case ispec.MediaTypeImageManifest: - return ImageManifest2ImageSummary(ctx, imageMeta) + return ImageManifest2ImageSummary(ctx, fullImageMeta) case ispec.MediaTypeImageIndex: - return ImageIndex2ImageSummary(ctx, imageMeta) + return ImageIndex2ImageSummary(ctx, fullImageMeta) default: return nil, nil, zerr.ErrMediaTypeNotSupported } } -func ImageIndex2ImageSummary(ctx context.Context, imageMeta mTypes.ImageMeta, +func ImageIndex2ImageSummary(ctx context.Context, fullImageMeta mTypes.FullImageMeta, ) (*gql_generated.ImageSummary, map[BlobDigest]int64, error) { var ( - repo = imageMeta.Repo - tag = imageMeta.Tag + repo = fullImageMeta.Repo + tag = fullImageMeta.Tag indexLastUpdated time.Time - isSigned = isImageSigned(imageMeta.Signatures) + isSigned = isImageSigned(fullImageMeta.Signatures) indexSize = int64(0) manifestAnnotations *ImageAnnotations - manifestSummaries = make([]*gql_generated.ManifestSummary, 0, len(imageMeta.Manifests)) + manifestSummaries = make([]*gql_generated.ManifestSummary, 0, len(fullImageMeta.Manifests)) indexBlobs = map[string]int64{} - indexDigestStr = imageMeta.Digest.String() + indexDigestStr = fullImageMeta.Digest.String() indexMediaType = ispec.MediaTypeImageIndex ) - for _, imageManifest := range imageMeta.Manifests { - imageManifestSummary, manifestBlobs, err := ImageManifest2ImageSummary(ctx, mTypes.ImageMeta{ - Repo: imageMeta.Repo, - Tag: imageMeta.Tag, + for _, imageManifest := range fullImageMeta.Manifests { + imageManifestSummary, manifestBlobs, err := ImageManifest2ImageSummary(ctx, mTypes.FullImageMeta{ + Repo: fullImageMeta.Repo, + Tag: fullImageMeta.Tag, MediaType: ispec.MediaTypeImageManifest, Digest: imageManifest.Digest, Size: imageManifest.Size, - Manifests: []mTypes.ManifestMeta{imageManifest}, + Manifests: []mTypes.FullManifestMeta{imageManifest}, Referrers: imageManifest.Referrers, Statistics: imageManifest.Statistics, Signatures: imageManifest.Signatures, @@ -448,13 +449,13 @@ func ImageIndex2ImageSummary(ctx context.Context, imageMeta mTypes.ImageMeta, manifestSummaries = append(manifestSummaries, imageManifestSummary.Manifests[0]) } - signaturesInfo := GetSignaturesInfo(isSigned, imageMeta.Signatures) + signaturesInfo := GetSignaturesInfo(isSigned, fullImageMeta.Signatures) if manifestAnnotations == nil { manifestAnnotations = &ImageAnnotations{} } - annotations := GetIndexAnnotations(imageMeta.Index.Annotations, manifestAnnotations) + annotations := GetIndexAnnotations(fullImageMeta.Index.Annotations, manifestAnnotations) indexSummary := gql_generated.ImageSummary{ RepoName: &repo, @@ -466,7 +467,7 @@ func ImageIndex2ImageSummary(ctx context.Context, imageMeta mTypes.ImageMeta, IsSigned: &isSigned, SignatureInfo: signaturesInfo, Size: ref(strconv.FormatInt(indexSize, 10)), - DownloadCount: ref(imageMeta.Statistics.DownloadCount), + DownloadCount: ref(fullImageMeta.Statistics.DownloadCount), Description: &annotations.Description, Title: &annotations.Title, Documentation: &annotations.Documentation, @@ -475,29 +476,29 @@ func ImageIndex2ImageSummary(ctx context.Context, imageMeta mTypes.ImageMeta, Source: &annotations.Source, Vendor: &annotations.Vendor, Authors: &annotations.Authors, - Referrers: getReferrers(imageMeta.Referrers), + Referrers: getReferrers(fullImageMeta.Referrers), } return &indexSummary, indexBlobs, nil } -func ImageManifest2ImageSummary(ctx context.Context, imageMeta mTypes.ImageMeta, +func ImageManifest2ImageSummary(ctx context.Context, fullImageMeta mTypes.FullImageMeta, ) (*gql_generated.ImageSummary, map[BlobDigest]int64, error) { - manifest := imageMeta.Manifests[0] + manifest := fullImageMeta.Manifests[0] var ( - repoName = imageMeta.Repo - tag = imageMeta.Tag + repoName = fullImageMeta.Repo + tag = fullImageMeta.Tag configDigest = manifest.Manifest.Config.Digest.String() configSize = manifest.Manifest.Config.Size manifestDigest = manifest.Digest.String() manifestSize = manifest.Size mediaType = manifest.Manifest.MediaType - artifactType = zcommon.GetManifestArtifactType(imageMeta.Manifests[0].Manifest) + artifactType = zcommon.GetManifestArtifactType(fullImageMeta.Manifests[0].Manifest) platform = getPlatform(manifest.Config.Platform) imageLastUpdated = zcommon.GetImageLastUpdated(manifest.Config) - downloadCount = imageMeta.Statistics.DownloadCount - isSigned = isImageSigned(imageMeta.Signatures) + downloadCount = fullImageMeta.Statistics.DownloadCount + isSigned = isImageSigned(fullImageMeta.Signatures) ) imageSize, imageBlobsMap := getImageBlobsInfo(manifestDigest, manifestSize, configDigest, configSize, @@ -516,7 +517,7 @@ func ImageManifest2ImageSummary(ctx context.Context, imageMeta mTypes.ImageMeta, "manifest digest: %s, error: %s", tag, repoName, manifest.Digest, err.Error())) } - signaturesInfo := GetSignaturesInfo(isSigned, imageMeta.Signatures) + signaturesInfo := GetSignaturesInfo(isSigned, fullImageMeta.Signatures) manifestSummary := gql_generated.ManifestSummary{ Digest: &manifestDigest, @@ -529,7 +530,7 @@ func ImageManifest2ImageSummary(ctx context.Context, imageMeta mTypes.ImageMeta, DownloadCount: &downloadCount, Layers: getLayersSummaries(manifest.Manifest), History: historyEntries, - Referrers: getReferrers(imageMeta.Referrers), + Referrers: getReferrers(fullImageMeta.Referrers), ArtifactType: &artifactType, } @@ -597,7 +598,7 @@ func deref[T any](pointer *T, defaultVal T) T { return defaultVal } -func PaginatedImageMeta2ImageSummaries(ctx context.Context, imageMetaList []mTypes.ImageMeta, skip SkipQGLField, +func PaginatedFullImageMeta2ImageSummaries(ctx context.Context, imageMetaList []mTypes.FullImageMeta, skip SkipQGLField, cveInfo cveinfo.CveInfo, filter mTypes.Filter, pageInput pagination.PageInput, ) ([]*gql_generated.ImageSummary, zcommon.PageInfo, error) { imagePageFinder, err := pagination.NewImgSumPageFinder(pageInput.Limit, pageInput.Offset, pageInput.SortBy) @@ -605,8 +606,8 @@ func PaginatedImageMeta2ImageSummaries(ctx context.Context, imageMetaList []mTyp return []*gql_generated.ImageSummary{}, zcommon.PageInfo{}, err } - for _, imageData := range imageMetaList { - imageSummary, _, err := ImageMeta2ImageSummary(ctx, imageData) + for _, imageMeta := range imageMetaList { + imageSummary, _, err := FullImageMeta2ImageSummary(ctx, imageMeta) if err != nil { continue } diff --git a/pkg/extensions/search/cve/cve.go b/pkg/extensions/search/cve/cve.go index ee6c38eda3..a4acb8b459 100644 --- a/pkg/extensions/search/cve/cve.go +++ b/pkg/extensions/search/cve/cve.go @@ -288,7 +288,7 @@ func getIndexContent(metaDB mTypes.MetaDB, indexDigestStr string) (ispec.Index, return ispec.Index{}, err } - indexData, err := metaDB.GetImageData(indexDigest) + indexData, err := metaDB.GetImageMeta(indexDigest) if err != nil { return ispec.Index{}, err } @@ -306,7 +306,7 @@ func getConfigAndDigest(metaDB mTypes.MetaDB, manifestDigestStr string) (ispec.I return ispec.Image{}, "", err } - manifestData, err := metaDB.GetImageData(manifestDigest) + manifestData, err := metaDB.GetImageMeta(manifestDigest) if err != nil { return ispec.Image{}, "", err } diff --git a/pkg/extensions/search/cve/cve_test.go b/pkg/extensions/search/cve/cve_test.go index 31364b7835..065ec00332 100644 --- a/pkg/extensions/search/cve/cve_test.go +++ b/pkg/extensions/search/cve/cve_test.go @@ -401,8 +401,8 @@ func TestImageFormat(t *testing.T) { }, }, nil }, - GetImageDataFn: func(digest godigest.Digest) (mTypes.ImageData, error) { - return mTypes.ImageData{ + GetImageMetaFn: func(digest godigest.Digest) (mTypes.ImageMeta, error) { + return mTypes.ImageMeta{ MediaType: ispec.MediaTypeImageIndex, Digest: godigest.FromString("digest"), Index: &ispec.Index{}, @@ -769,32 +769,32 @@ func TestCVEStruct(t *testing.T) { //nolint:gocyclo image11 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2008, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference(repo1, "0.1.0", image11.AsImageData()) + err = metaDB.SetRepoReference(repo1, "0.1.0", image11.AsImageMeta()) So(err, ShouldBeNil) image12 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2009, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference(repo1, "1.0.0", image12.AsImageData()) + err = metaDB.SetRepoReference(repo1, "1.0.0", image12.AsImageMeta()) So(err, ShouldBeNil) image13 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2010, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference(repo1, "1.1.0", image13.AsImageData()) + err = metaDB.SetRepoReference(repo1, "1.1.0", image13.AsImageMeta()) So(err, ShouldBeNil) image14 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2011, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference(repo1, "1.0.1", image14.AsImageData()) + err = metaDB.SetRepoReference(repo1, "1.0.1", image14.AsImageMeta()) So(err, ShouldBeNil) // Create metadb data for scannable image with no vulnerabilities image61 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2016, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference(repo6, "1.0.0", image61.AsImageData()) + err = metaDB.SetRepoReference(repo6, "1.0.0", image61.AsImageMeta()) So(err, ShouldBeNil) // Create metadb data for image not supporting scanning @@ -804,22 +804,22 @@ func TestCVEStruct(t *testing.T) { //nolint:gocyclo Digest: godigest.FromBytes([]byte{10, 10, 10}), }}).ImageConfig(ispec.Image{Created: DateRef(2009, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference(repo2, "1.0.0", image21.AsImageData()) + err = metaDB.SetRepoReference(repo2, "1.0.0", image21.AsImageMeta()) So(err, ShouldBeNil) // Create metadb data for invalid images/negative tests image := CreateRandomImage() - err = metaDB.SetRepoReference(repo3, "invalid-manifest", image.AsImageData()) + err = metaDB.SetRepoReference(repo3, "invalid-manifest", image.AsImageMeta()) So(err, ShouldBeNil) image41 := CreateImageWith().DefaultLayers(). CustomConfigBlob([]byte("invalid config blob"), ispec.MediaTypeImageConfig).Build() - err = metaDB.SetRepoReference(repo4, "invalid-config", image41.AsImageData()) + err = metaDB.SetRepoReference(repo4, "invalid-config", image41.AsImageMeta()) So(err, ShouldBeNil) digest51 := godigest.FromString("abc8") - randomImgData := CreateRandomImage().AsImageData() + randomImgData := CreateRandomImage().AsImageMeta() randomImgData.Digest = digest51 randomImgData.Manifests[0].Digest = digest51 err = metaDB.SetRepoReference(repo5, "nonexitent-manifest", randomImgData) @@ -829,25 +829,25 @@ func TestCVEStruct(t *testing.T) { //nolint:gocyclo image71 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2000, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference(repo7, "1.0.0", image71.AsImageData()) + err = metaDB.SetRepoReference(repo7, "1.0.0", image71.AsImageMeta()) So(err, ShouldBeNil) // create multiarch image with vulnerabilities multiarchImage := CreateRandomMultiarch() err = metaDB.SetRepoReference(repoMultiarch, multiarchImage.Images[0].DigestStr(), - multiarchImage.Images[0].AsImageData()) + multiarchImage.Images[0].AsImageMeta()) So(err, ShouldBeNil) err = metaDB.SetRepoReference(repoMultiarch, multiarchImage.Images[1].DigestStr(), - multiarchImage.Images[1].AsImageData()) + multiarchImage.Images[1].AsImageMeta()) So(err, ShouldBeNil) err = metaDB.SetRepoReference(repoMultiarch, multiarchImage.Images[2].DigestStr(), - multiarchImage.Images[2].AsImageData()) + multiarchImage.Images[2].AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repoMultiarch, "tagIndex", multiarchImage.AsImageData()) + err = metaDB.SetRepoReference(repoMultiarch, "tagIndex", multiarchImage.AsImageMeta()) So(err, ShouldBeNil) err = metaDB.SetRepoMeta("repo-with-bad-tag-digest", mTypes.RepoMeta{ @@ -1078,7 +1078,7 @@ func TestCVEStruct(t *testing.T) { //nolint:gocyclo return false, err } - manifestData, err := metaDB.GetImageData(manifestDigest) + manifestData, err := metaDB.GetImageMeta(manifestDigest) if err != nil { return false, err } @@ -1195,7 +1195,7 @@ func TestCVEStruct(t *testing.T) { //nolint:gocyclo // Tag is not found cveList, pageInfo, err = cveInfo.GetCVEListForImage("repo-with-bad-tag-digest", "tag", "", pageInput) - So(err, ShouldEqual, zerr.ErrImageDataNotFound) + So(err, ShouldEqual, zerr.ErrImageMetaNotFound) So(len(cveList), ShouldEqual, 0) So(pageInfo.ItemCount, ShouldEqual, 0) So(pageInfo.TotalCount, ShouldEqual, 0) diff --git a/pkg/extensions/search/cve/pagination_test.go b/pkg/extensions/search/cve/pagination_test.go index df8f1d1b9e..c4d87afc5c 100644 --- a/pkg/extensions/search/cve/pagination_test.go +++ b/pkg/extensions/search/cve/pagination_test.go @@ -41,7 +41,7 @@ func TestCVEPagination(t *testing.T) { Blob: ispec.DescriptorEmptyJSON.Data, }}).ImageConfig(ispec.Image{Created: &timeStamp11}).Build() - err = metaDB.SetRepoReference("repo1", "0.1.0", image.AsImageData()) + err = metaDB.SetRepoReference("repo1", "0.1.0", image.AsImageMeta()) So(err, ShouldBeNil) timeStamp12 := time.Date(2009, 1, 1, 12, 0, 0, 0, time.UTC) @@ -53,7 +53,7 @@ func TestCVEPagination(t *testing.T) { Blob: ispec.DescriptorEmptyJSON.Data, }}).ImageConfig(ispec.Image{Created: &timeStamp12}).Build() - err = metaDB.SetRepoReference("repo1", "1.0.0", image2.AsImageData()) + err = metaDB.SetRepoReference("repo1", "1.0.0", image2.AsImageMeta()) So(err, ShouldBeNil) // MetaDB loaded with initial data, mock the scanner diff --git a/pkg/extensions/search/cve/scan.go b/pkg/extensions/search/cve/scan.go index e0a67bc8ca..3f3e1980d2 100644 --- a/pkg/extensions/search/cve/scan.go +++ b/pkg/extensions/search/cve/scan.go @@ -41,13 +41,13 @@ type scanTaskGenerator struct { } func (gen *scanTaskGenerator) getMatcherFunc() mTypes.FilterFunc { - return func(repoMeta mTypes.RepoMeta, imageData mTypes.ImageData) bool { + return func(repoMeta mTypes.RepoMeta, imageMeta mTypes.ImageMeta) bool { // Note this matcher will return information based on scan status of manifests // An index scan aggregates results of manifest scans // If at least one of its manifests can be scanned, // the index and its tag will be returned by the caller function too repoName := repoMeta.Name - manifestDigest := imageData.Digest.String() + manifestDigest := imageMeta.Digest.String() if gen.isScheduled(manifestDigest) { // We skip this manifest as it has already scheduled @@ -121,16 +121,16 @@ func (gen *scanTaskGenerator) Next() (scheduler.Task, error) { // Obtain a list of repos with un-scanned scannable manifests // We may implement a method to return just 1 match at some point - imageData, err := gen.metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, gen.getMatcherFunc()) + imageMeta, err := gen.metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, gen.getMatcherFunc()) if err != nil { // Do not crash the generator for potential metadb inconsistencies // as there may be scannable images not yet scanned gen.log.Warn().Err(err).Msg("Scheduled CVE scan: error while obtaining repo metadata") } - // no imageData are returned, all results are in already in cache + // no imageMeta are returned, all results are in already in cache // or manifests cannot be scanned - if len(imageData) == 0 { + if len(imageMeta) == 0 { gen.log.Info().Msg("Scheduled CVE scan: finished for available images") gen.done = true @@ -138,14 +138,14 @@ func (gen *scanTaskGenerator) Next() (scheduler.Task, error) { return nil, nil } - // Since imageData will always contain just un-scanned images we can pick + // Since imageMeta will always contain just un-scanned images we can pick // any image out of the resulting matches - digest := imageData[0].Digest.String() + digest := imageMeta[0].Digest.String() // Mark the digest as scheduled so it is skipped on next generator run gen.setScheduled(digest, true) - return newScanTask(gen, imageData[0].Repo, digest), nil + return newScanTask(gen, imageMeta[0].Repo, digest), nil } func (gen *scanTaskGenerator) IsDone() bool { diff --git a/pkg/extensions/search/cve/scan_test.go b/pkg/extensions/search/cve/scan_test.go index 1731f08be2..bc50a994cc 100644 --- a/pkg/extensions/search/cve/scan_test.go +++ b/pkg/extensions/search/cve/scan_test.go @@ -74,32 +74,32 @@ func TestScanGeneratorWithMockedData(t *testing.T) { //nolint: gocyclo image11 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2008, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference("repo1", "0.1.0", image11.AsImageData()) + err = metaDB.SetRepoReference("repo1", "0.1.0", image11.AsImageMeta()) So(err, ShouldBeNil) image12 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2009, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference("repo1", "1.0.0", image12.AsImageData()) + err = metaDB.SetRepoReference("repo1", "1.0.0", image12.AsImageMeta()) So(err, ShouldBeNil) image13 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2010, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference("repo1", "1.1.0", image13.AsImageData()) + err = metaDB.SetRepoReference("repo1", "1.1.0", image13.AsImageMeta()) So(err, ShouldBeNil) image14 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2011, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference("repo1", "1.0.1", image14.AsImageData()) + err = metaDB.SetRepoReference("repo1", "1.0.1", image14.AsImageMeta()) So(err, ShouldBeNil) // Create metadb data for scannable image with no vulnerabilities image61 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2016, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference("repo6", "1.0.0", image61.AsImageData()) + err = metaDB.SetRepoReference("repo6", "1.0.0", image61.AsImageMeta()) So(err, ShouldBeNil) // Create metadb data for image not supporting scanning @@ -109,49 +109,49 @@ func TestScanGeneratorWithMockedData(t *testing.T) { //nolint: gocyclo Digest: godigest.FromBytes([]byte{10, 10, 10}), }}).ImageConfig(ispec.Image{Created: DateRef(2009, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference("repo2", "1.0.0", image21.AsImageData()) + err = metaDB.SetRepoReference("repo2", "1.0.0", image21.AsImageMeta()) So(err, ShouldBeNil) // Create metadb data for invalid images/negative tests img := CreateRandomImage() digest31 := img.Digest() - err = metaDB.SetRepoReference("repo3", "invalid-manifest", img.AsImageData()) + err = metaDB.SetRepoReference("repo3", "invalid-manifest", img.AsImageMeta()) So(err, ShouldBeNil) image41 := CreateImageWith().DefaultLayers(). CustomConfigBlob([]byte("invalid config blob"), ispec.MediaTypeImageConfig).Build() - err = metaDB.SetRepoReference("repo4", "invalid-config", image41.AsImageData()) + err = metaDB.SetRepoReference("repo4", "invalid-config", image41.AsImageMeta()) So(err, ShouldBeNil) image15 := CreateRandomMultiarch() digest51 := image15.Digest() - err = metaDB.SetRepoReference("repo5", "nonexitent-manifests-for-multiarch", image15.AsImageData()) + err = metaDB.SetRepoReference("repo5", "nonexitent-manifests-for-multiarch", image15.AsImageMeta()) So(err, ShouldBeNil) // Create metadb data for scannable image which errors during scan image71 := CreateImageWith().DefaultLayers(). ImageConfig(ispec.Image{Created: DateRef(2000, 1, 1, 12, 0, 0, 0, time.UTC)}).Build() - err = metaDB.SetRepoReference("repo7", "1.0.0", image71.AsImageData()) + err = metaDB.SetRepoReference("repo7", "1.0.0", image71.AsImageMeta()) So(err, ShouldBeNil) // Create multiarch image with vulnerabilities multiarchImage := CreateRandomMultiarch() err = metaDB.SetRepoReference(repoIndex, multiarchImage.Images[0].DigestStr(), - multiarchImage.Images[0].AsImageData()) + multiarchImage.Images[0].AsImageMeta()) So(err, ShouldBeNil) err = metaDB.SetRepoReference(repoIndex, multiarchImage.Images[1].DigestStr(), - multiarchImage.Images[1].AsImageData()) + multiarchImage.Images[1].AsImageMeta()) So(err, ShouldBeNil) err = metaDB.SetRepoReference(repoIndex, multiarchImage.Images[2].DigestStr(), - multiarchImage.Images[2].AsImageData()) + multiarchImage.Images[2].AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repoIndex, "tagIndex", multiarchImage.AsImageData()) + err = metaDB.SetRepoReference(repoIndex, "tagIndex", multiarchImage.AsImageMeta()) So(err, ShouldBeNil) err = metaDB.SetRepoMeta("repo-with-bad-tag-digest", mTypes.RepoMeta{ @@ -377,7 +377,7 @@ func TestScanGeneratorWithMockedData(t *testing.T) { //nolint: gocyclo return false, err } - manifestData, err := metaDB.GetImageData(manifestDigest) + manifestData, err := metaDB.GetImageMeta(manifestDigest) if err != nil { return false, err } diff --git a/pkg/extensions/search/cve/trivy/scanner.go b/pkg/extensions/search/cve/trivy/scanner.go index 49080e8090..6ae1a74398 100644 --- a/pkg/extensions/search/cve/trivy/scanner.go +++ b/pkg/extensions/search/cve/trivy/scanner.go @@ -238,7 +238,7 @@ func (scanner Scanner) isManifestScanable(digestStr string) (bool, error) { return true, nil } - manifestData, err := scanner.metaDB.GetImageData(godigest.Digest(digestStr)) + manifestData, err := scanner.metaDB.GetImageMeta(godigest.Digest(digestStr)) if err != nil { return false, err } @@ -285,7 +285,7 @@ func (scanner Scanner) isIndexScannable(digestStr string) (bool, error) { return true, nil } - indexData, err := scanner.metaDB.GetImageData(godigest.Digest(digestStr)) + indexData, err := scanner.metaDB.GetImageMeta(godigest.Digest(digestStr)) if err != nil { return false, err } @@ -454,7 +454,7 @@ func (scanner Scanner) scanIndex(repo, digest string) (map[string]cvemodel.CVE, return cachedMap, nil } - indexData, err := scanner.metaDB.GetImageData(godigest.Digest(digest)) + indexData, err := scanner.metaDB.GetImageMeta(godigest.Digest(digest)) if err != nil { return map[string]cvemodel.CVE{}, err } @@ -594,9 +594,9 @@ func getImageDescriptor(metaDB mTypes.MetaDB, repo, tag string) (mTypes.Descript // findMediaTypeForDigest will look into the buckets for a certain digest. Depending on which bucket that // digest is found the corresponding mediatype is returned. func findMediaTypeForDigest(metaDB mTypes.MetaDB, digest godigest.Digest) (bool, string) { - imageData, err := metaDB.GetImageData(digest) + imageMeta, err := metaDB.GetImageMeta(digest) if err == nil { - return true, imageData.MediaType + return true, imageMeta.MediaType } return false, "" diff --git a/pkg/extensions/search/cve/trivy/scanner_internal_test.go b/pkg/extensions/search/cve/trivy/scanner_internal_test.go index 63dc232c30..5801c5bbff 100644 --- a/pkg/extensions/search/cve/trivy/scanner_internal_test.go +++ b/pkg/extensions/search/cve/trivy/scanner_internal_test.go @@ -299,7 +299,7 @@ func TestImageScannable(t *testing.T) { Blob: ispec.DescriptorEmptyJSON.Data, }}).ImageConfig(validConfig).Build() - err = metaDB.SetRepoReference("repo1", "valid", validImage.AsImageData()) + err = metaDB.SetRepoReference("repo1", "valid", validImage.AsImageMeta()) if err != nil { panic(err) } @@ -312,7 +312,7 @@ func TestImageScannable(t *testing.T) { Blob: ispec.DescriptorEmptyJSON.Data, }}).ImageConfig(validConfig).Build() - err = metaDB.SetRepoReference("repo1", "unscannable-layer", imageWithUnscannableLayer.AsImageData()) + err = metaDB.SetRepoReference("repo1", "unscannable-layer", imageWithUnscannableLayer.AsImageMeta()) if err != nil { panic(err) } @@ -449,11 +449,11 @@ func TestIsIndexScannableErrors(t *testing.T) { img2 := CreateImageWith().Layers(unscannableLayer).RandomConfig().Build() multiarch := CreateMultiarchWith().Images([]Image{img1, img2}).Build() - metaDB.GetImageDataFn = func(digest godigest.Digest) (types.ImageData, error) { - return map[string]types.ImageData{ - img1.DigestStr(): img1.AsImageData(), - img2.DigestStr(): img2.AsImageData(), - multiarch.DigestStr(): multiarch.AsImageData(), + metaDB.GetImageMetaFn = func(digest godigest.Digest) (types.ImageMeta, error) { + return map[string]types.ImageMeta{ + img1.DigestStr(): img1.AsImageMeta(), + img2.DigestStr(): img2.AsImageMeta(), + multiarch.DigestStr(): multiarch.AsImageMeta(), }[digest.String()], nil } diff --git a/pkg/extensions/search/resolver.go b/pkg/extensions/search/resolver.go index 9c31ece946..a6949ac814 100644 --- a/pkg/extensions/search/resolver.go +++ b/pkg/extensions/search/resolver.go @@ -73,12 +73,12 @@ func NewResolver(log log.Logger, storeController storage.StoreController, } func FilterByDigest(digest string) mTypes.FilterFunc { - // imageData will always contain 1 manifest - return func(repoMeta mTypes.RepoMeta, imageData mTypes.ImageData) bool { + // imageMeta will always contain 1 manifest + return func(repoMeta mTypes.RepoMeta, imageMeta mTypes.ImageMeta) bool { lookupDigest := digest contains := false - manifest := imageData.Manifests[0] + manifest := imageMeta.Manifests[0] manifestDigest := manifest.Digest.String() @@ -125,12 +125,12 @@ func getImageListForDigest(ctx context.Context, digest string, metaDB mTypes.Met ), } - imageDataList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, FilterByDigest(digest)) + fullImageMetaList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, FilterByDigest(digest)) if err != nil { return &gql_generated.PaginatedImagesResult{}, err } - imageSummaries, pageInfo, err := convert.PaginatedImageMeta2ImageSummaries(ctx, imageDataList, skip, + imageSummaries, pageInfo, err := convert.PaginatedFullImageMeta2ImageSummaries(ctx, fullImageMetaList, skip, cveInfo, mTypes.Filter{}, pageInput) if err != nil { return &gql_generated.PaginatedImagesResult{}, err @@ -171,12 +171,12 @@ func getImageSummary(ctx context.Context, repo, tag string, digest *string, skip } } - imageDataMap, err := metaDB.FilterImageData(ctx, []string{imageDigest}) + imageMetaMap, err := metaDB.FilterImageMeta(ctx, []string{imageDigest}) if err != nil { return &gql_generated.ImageSummary{}, err } - imageSummaries := convert.RepoMeta2ImageSummaries(ctx, repoMeta, imageDataMap, skipCVE, cveInfo) + imageSummaries := convert.RepoMeta2ImageSummaries(ctx, repoMeta, imageMetaMap, skipCVE, cveInfo) if len(imageSummaries) == 0 { return &gql_generated.ImageSummary{}, nil @@ -260,8 +260,8 @@ func getCVEListForImage( } func FilterByTagInfo(tagsInfo []cvemodel.TagInfo) mTypes.FilterFunc { - return func(repoMeta mTypes.RepoMeta, imageData mTypes.ImageData) bool { - manifestDigest := imageData.Manifests[0].Digest.String() + return func(repoMeta mTypes.RepoMeta, imageMeta mTypes.ImageMeta) bool { + manifestDigest := imageMeta.Manifests[0].Digest.String() for _, tagInfo := range tagsInfo { switch tagInfo.Descriptor.MediaType { @@ -283,12 +283,12 @@ func FilterByTagInfo(tagsInfo []cvemodel.TagInfo) mTypes.FilterFunc { } func FilterByRepoAndTagInfo(repo string, tagsInfo []cvemodel.TagInfo) mTypes.FilterFunc { - return func(repoMeta mTypes.RepoMeta, imageData mTypes.ImageData) bool { + return func(repoMeta mTypes.RepoMeta, imageMeta mTypes.ImageMeta) bool { if repoMeta.Name != repo { return false } - manifestDigest := imageData.Manifests[0].Digest.String() + manifestDigest := imageMeta.Manifests[0].Digest.String() for _, tagInfo := range tagsInfo { switch tagInfo.Descriptor.MediaType { @@ -373,12 +373,12 @@ func getImageListForCVE( } // get all repos - imageDataList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, FilterByTagInfo(affectedImages)) + fullImageMetaList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, FilterByTagInfo(affectedImages)) if err != nil { return &gql_generated.PaginatedImagesResult{}, err } - imageSummaries, pageInfo, err := convert.PaginatedImageMeta2ImageSummaries(ctx, imageDataList, + imageSummaries, pageInfo, err := convert.PaginatedFullImageMeta2ImageSummaries(ctx, fullImageMetaList, skip, cveInfo, localFilter, pageInput) if err != nil { return &gql_generated.PaginatedImagesResult{}, err @@ -446,12 +446,12 @@ func getImageListWithCVEFixed( } // get all repos - imageDataList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, FilterByRepoAndTagInfo(repo, tagsInfo)) + fullImageMetaList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, FilterByRepoAndTagInfo(repo, tagsInfo)) if err != nil { return &gql_generated.PaginatedImagesResult{}, err } - imageSummaries, pageInfo, err := convert.PaginatedImageMeta2ImageSummaries(ctx, imageDataList, + imageSummaries, pageInfo, err := convert.PaginatedFullImageMeta2ImageSummaries(ctx, fullImageMetaList, skip, cveInfo, localFilter, pageInput) if err != nil { return &gql_generated.PaginatedImagesResult{}, err @@ -496,12 +496,12 @@ func repoListWithNewestImage( return &gql_generated.PaginatedReposResult{}, err } - imageDataMap, err := metaDB.FilterImageData(ctx, mTypes.GetLatestImageDigests(repoMetaList)) + imageMetaMap, err := metaDB.FilterImageMeta(ctx, mTypes.GetLatestImageDigests(repoMetaList)) if err != nil { return &gql_generated.PaginatedReposResult{}, err } - repos, pageInfo, err := convert.PaginatedRepoMeta2RepoSummaries(ctx, repoMetaList, imageDataMap, + repos, pageInfo, err := convert.PaginatedRepoMeta2RepoSummaries(ctx, repoMetaList, imageMetaMap, mTypes.Filter{}, pageInput, cveInfo, skip) if err != nil { return &gql_generated.PaginatedReposResult{}, err @@ -584,12 +584,12 @@ func getFilteredPaginatedRepos( return &gql_generated.PaginatedReposResult{}, err } - latestImageData, err := metaDB.FilterImageData(ctx, mTypes.GetLatestImageDigests(repoMetaList)) + latestImageMeta, err := metaDB.FilterImageMeta(ctx, mTypes.GetLatestImageDigests(repoMetaList)) if err != nil { return &gql_generated.PaginatedReposResult{}, err } - repos, pageInfo, err := convert.PaginatedRepoMeta2RepoSummaries(ctx, repoMetaList, latestImageData, + repos, pageInfo, err := convert.PaginatedRepoMeta2RepoSummaries(ctx, repoMetaList, latestImageMeta, mTypes.Filter{}, pageInput, cveInfo, skip) if err != nil { return &gql_generated.PaginatedReposResult{}, err @@ -647,13 +647,13 @@ func globalSearch(ctx context.Context, query string, metaDB mTypes.MetaDB, filte []*gql_generated.LayerSummary{}, err } - imageDataMap, err := metaDB.FilterImageData(ctx, mTypes.GetLatestImageDigests(repoMetaList)) + imageMetaMap, err := metaDB.FilterImageMeta(ctx, mTypes.GetLatestImageDigests(repoMetaList)) if err != nil { return &gql_generated.PaginatedReposResult{}, []*gql_generated.ImageSummary{}, []*gql_generated.LayerSummary{}, err } - repos, pageInfo, err := convert.PaginatedRepoMeta2RepoSummaries(ctx, repoMetaList, imageDataMap, localFilter, + repos, pageInfo, err := convert.PaginatedRepoMeta2RepoSummaries(ctx, repoMetaList, imageMetaMap, localFilter, pageInput, cveInfo, skip) if err != nil { @@ -680,12 +680,12 @@ func globalSearch(ctx context.Context, query string, metaDB mTypes.MetaDB, filte ), } - imageDataList, err := metaDB.SearchTags(ctx, query) + fullImageMetaList, err := metaDB.SearchTags(ctx, query) if err != nil { return &gql_generated.PaginatedReposResult{}, []*gql_generated.ImageSummary{}, []*gql_generated.LayerSummary{}, err } - imageSummaries, pageInfo, err := convert.PaginatedImageMeta2ImageSummaries(ctx, imageDataList, skip, cveInfo, + imageSummaries, pageInfo, err := convert.PaginatedFullImageMeta2ImageSummaries(ctx, fullImageMetaList, skip, cveInfo, localFilter, pageInput) if err != nil { return &gql_generated.PaginatedReposResult{}, []*gql_generated.ImageSummary{}, []*gql_generated.LayerSummary{}, err @@ -747,12 +747,12 @@ func derivedImageList(ctx context.Context, image string, digest *string, metaDB } // we need all available tags - imageDataList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, filterDerivedImages(searchedImage)) + fullImageMetaList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, filterDerivedImages(searchedImage)) if err != nil { return &gql_generated.PaginatedImagesResult{}, err } - derivedList, pageInfo, err := convert.PaginatedImageMeta2ImageSummaries(ctx, imageDataList, skip, cveInfo, + derivedList, pageInfo, err := convert.PaginatedFullImageMeta2ImageSummaries(ctx, fullImageMetaList, skip, cveInfo, mTypes.Filter{}, pageInput) if err != nil { return &gql_generated.PaginatedImagesResult{}, err @@ -768,10 +768,10 @@ func derivedImageList(ctx context.Context, image string, digest *string, metaDB } func filterDerivedImages(image *gql_generated.ImageSummary) mTypes.FilterFunc { - return func(repoMeta mTypes.RepoMeta, imageData mTypes.ImageData) bool { + return func(repoMeta mTypes.RepoMeta, imageMeta mTypes.ImageMeta) bool { var addImageToList bool - imageManifest := imageData.Manifests[0] + imageManifest := imageMeta.Manifests[0] for i := range image.Manifests { manifestDigest := imageManifest.Digest.String() @@ -848,12 +848,12 @@ func baseImageList(ctx context.Context, image string, digest *string, metaDB mTy } // we need all available tags - imageDataList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, filterBaseImages(searchedImage)) + fullImageMetaList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, filterBaseImages(searchedImage)) if err != nil { return &gql_generated.PaginatedImagesResult{}, err } - baseList, pageInfo, err := convert.PaginatedImageMeta2ImageSummaries(ctx, imageDataList, + baseList, pageInfo, err := convert.PaginatedFullImageMeta2ImageSummaries(ctx, fullImageMetaList, skip, cveInfo, mTypes.Filter{}, pageInput) if err != nil { return &gql_generated.PaginatedImagesResult{}, err @@ -869,10 +869,10 @@ func baseImageList(ctx context.Context, image string, digest *string, metaDB mTy } func filterBaseImages(image *gql_generated.ImageSummary) mTypes.FilterFunc { - return func(repoMeta mTypes.RepoMeta, imageData mTypes.ImageData) bool { + return func(repoMeta mTypes.RepoMeta, imageMeta mTypes.ImageMeta) bool { var addImageToList bool - manifest := imageData.Manifests[0] + manifest := imageMeta.Manifests[0] for i := range image.Manifests { manifestDigest := manifest.Digest.String() @@ -1053,9 +1053,9 @@ func expandedRepoInfo(ctx context.Context, repo string, metaDB mTypes.MetaDB, cv tagsDigests = append(tagsDigests, repoMeta.Tags[i].Digest) } - imageDataMap, err := metaDB.FilterImageData(ctx, tagsDigests) + imageMetaMap, err := metaDB.FilterImageMeta(ctx, tagsDigests) if err != nil { - log.Error().Err(err).Str("repository", repo).Msg("resolver: can't retrieve imageData for repo") + log.Error().Err(err).Str("repository", repo).Msg("resolver: can't retrieve imageMeta for repo") return &gql_generated.RepoInfo{}, err } @@ -1065,7 +1065,7 @@ func expandedRepoInfo(ctx context.Context, repo string, metaDB mTypes.MetaDB, cv canSkipField(convert.GetPreloads(ctx), "Images.Vulnerabilities"), } - repoSummary, imageSummaries := convert.RepoMeta2ExpandedRepoInfo(ctx, repoMeta, imageDataMap, + repoSummary, imageSummaries := convert.RepoMeta2ExpandedRepoInfo(ctx, repoMeta, imageMetaMap, skip, cveInfo, log) dateSortedImages := make(timeSlice, 0, len(imageSummaries)) @@ -1131,12 +1131,12 @@ func getImageList(ctx context.Context, repo string, metaDB mTypes.MetaDB, cveInf matchRepoName = func(repoName, tag string) bool { return repoName == repo } } - imageData, err := metaDB.FilterTags(ctx, matchRepoName, mTypes.AcceptAllImageData) + imageMeta, err := metaDB.FilterTags(ctx, matchRepoName, mTypes.AcceptAllImageMeta) if err != nil { return &gql_generated.PaginatedImagesResult{}, err } - imageList, pageInfo, err := convert.PaginatedImageMeta2ImageSummaries(ctx, imageData, skip, + imageList, pageInfo, err := convert.PaginatedFullImageMeta2ImageSummaries(ctx, imageMeta, skip, cveInfo, mTypes.Filter{}, pageInput) if err != nil { return &gql_generated.PaginatedImagesResult{}, err diff --git a/pkg/extensions/search/resolver_test.go b/pkg/extensions/search/resolver_test.go index ec33ddc0af..02d8bd5a78 100644 --- a/pkg/extensions/search/resolver_test.go +++ b/pkg/extensions/search/resolver_test.go @@ -72,8 +72,8 @@ func TestResolverGlobalSearch(t *testing.T) { Convey("MetaDB SearchTags gives error", func() { mockMetaDB := mocks.MetaDBMock{ - SearchTagsFn: func(ctx context.Context, searchText string) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, ErrTestError + SearchTagsFn: func(ctx context.Context, searchText string) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, ErrTestError }, } const query = "repo1:1.0.1" @@ -202,12 +202,12 @@ func TestRepoListWithNewestImage(t *testing.T) { return repos, nil }, - FilterImageDataFn: func(ctx context.Context, digests []string, - ) (map[string]mTypes.ImageData, error) { - return map[string]mTypes.ImageData{ - img1.DigestStr(): mConvert.GetImageManifestData(img1.Manifest, img1.Config, + FilterImageMetaFn: func(ctx context.Context, digests []string, + ) (map[string]mTypes.ImageMeta, error) { + return map[string]mTypes.ImageMeta{ + img1.DigestStr(): mConvert.GetImageManifestMeta(img1.Manifest, img1.Config, img1.ManifestDescriptor.Size, img1.ManifestDescriptor.Digest), - img2.DigestStr(): mConvert.GetImageManifestData(img2.Manifest, img2.Config, + img2.DigestStr(): mConvert.GetImageManifestMeta(img2.Manifest, img2.Config, img2.ManifestDescriptor.Size, img2.ManifestDescriptor.Digest), }, nil }, @@ -310,8 +310,8 @@ func TestImageListForDigest(t *testing.T) { mockMetaDB := mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, ErrTestError + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, ErrTestError }, } @@ -334,17 +334,17 @@ func TestImageListForDigest(t *testing.T) { mockMetaDB := mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - imageDataList := []mTypes.ImageData{img1.AsImageData(), img2.AsImageData()} + ) ([]mTypes.FullImageMeta, error) { + fullImageMetaList := []mTypes.ImageMeta{img1.AsImageMeta(), img2.AsImageMeta()} repoMeta := getTestRepoMetaWithImages("repo", []Image{img1, img2}) tags := []string{"tag1", "tag2"} - acceptedImages := []mTypes.ImageMeta{} + acceptedImages := []mTypes.FullImageMeta{} - for i := range imageDataList { - if filterFunc(repoMeta, imageDataList[i]) { + for i := range fullImageMetaList { + if filterFunc(repoMeta, fullImageMetaList[i]) { acceptedImages = append(acceptedImages, - convert.GetImageMeta(tags[i], repoMeta, imageDataList[i])) + convert.GetFullImageMeta(tags[i], repoMeta, fullImageMetaList[i])) continue } @@ -389,17 +389,17 @@ func TestImageListForDigest(t *testing.T) { mockMetaDB := mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - imageDataList := []mTypes.ImageData{img1.AsImageData()} + ) ([]mTypes.FullImageMeta, error) { + fullImageMetaList := []mTypes.ImageMeta{img1.AsImageMeta()} repoMeta := getTestRepoMetaWithImages("repo", []Image{img1, img1}) tags := []string{"tag1", "tag2"} - acceptedImages := []mTypes.ImageMeta{} + acceptedImages := []mTypes.FullImageMeta{} - for i := range imageDataList { - if filterFunc(repoMeta, imageDataList[i]) { + for i := range fullImageMetaList { + if filterFunc(repoMeta, fullImageMetaList[i]) { acceptedImages = append(acceptedImages, - convert.GetImageMeta(tags[i], repoMeta, imageDataList[i])) + convert.GetFullImageMeta(tags[i], repoMeta, fullImageMetaList[i])) continue } @@ -432,8 +432,8 @@ func TestImageListError(t *testing.T) { Convey("no page requested, SearchRepoFn returns error", func() { mockMetaDB := mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, ErrTestError + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, ErrTestError }, } @@ -457,11 +457,11 @@ func TestImageListError(t *testing.T) { Convey("valid repoList returned", func() { mockMetaDB := mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { + ) ([]mTypes.FullImageMeta, error) { repoName := "correct-repo" if !filterRepoTag(repoName, "tag") { - return []mTypes.ImageMeta{}, nil + return []mTypes.FullImageMeta{}, nil } image := CreateDefaultImage() @@ -473,7 +473,7 @@ func TestImageListError(t *testing.T) { }}, } - return []mTypes.ImageMeta{convert.GetImageMeta("tag", repoMeta, image.AsImageData())}, nil + return []mTypes.FullImageMeta{convert.GetFullImageMeta("tag", repoMeta, image.AsImageMeta())}, nil }, } @@ -617,8 +617,8 @@ func TestQueryResolverErrors(t *testing.T) { }, mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, ErrTestError + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, ErrTestError }, }, mocks.CveInfoMock{}, @@ -638,8 +638,8 @@ func TestQueryResolverErrors(t *testing.T) { }, mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, ErrTestError + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, ErrTestError }, }, mocks.CveInfoMock{}, @@ -697,8 +697,8 @@ func TestQueryResolverErrors(t *testing.T) { storage.StoreController{}, mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, ErrTestError + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, ErrTestError }, }, mocks.CveInfoMock{}, @@ -772,8 +772,8 @@ func TestQueryResolverErrors(t *testing.T) { storage.StoreController{}, mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, ErrTestError + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, ErrTestError }, GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ @@ -783,8 +783,8 @@ func TestQueryResolverErrors(t *testing.T) { }, }, nil }, - GetImageDataFn: func(digest godigest.Digest) (mTypes.ImageData, error) { - return image.AsImageData(), nil + GetImageMetaFn: func(digest godigest.Digest) (mTypes.ImageMeta, error) { + return image.AsImageMeta(), nil }, }, mocks.CveInfoMock{}, @@ -1623,14 +1623,14 @@ func TestMockedDerivedImageList(t *testing.T) { image := CreateRandomImage() mockMetaDB := mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, ErrTestError + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, ErrTestError }, GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{}, ErrTestError }, - FilterImageDataFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) { - return map[string]mTypes.ImageData{image.DigestStr(): image.AsImageData()}, nil + FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { + return map[string]mTypes.ImageMeta{image.DigestStr(): image.AsImageMeta()}, nil }, } responseContext := graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, @@ -1665,8 +1665,8 @@ func TestMockedDerivedImageList(t *testing.T) { }, }, nil }, - FilterImageDataFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) { - return map[string]mTypes.ImageData{image.DigestStr(): image.AsImageData()}, nil + FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { + return map[string]mTypes.ImageMeta{image.DigestStr(): image.AsImageMeta()}, nil }, }, pageInput, @@ -1681,8 +1681,8 @@ func TestMockedDerivedImageList(t *testing.T) { mockMetaDB := mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, nil + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, nil }, GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ @@ -1692,13 +1692,13 @@ func TestMockedDerivedImageList(t *testing.T) { }, }, nil }, - FilterImageDataFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) { - return map[string]mTypes.ImageData{ - digests[0]: image.AsImageData(), + FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { + return map[string]mTypes.ImageMeta{ + digests[0]: image.AsImageMeta(), }, nil }, - GetImageDataFn: func(digest godigest.Digest) (mTypes.ImageData, error) { - return image.AsImageData(), nil + GetImageMetaFn: func(digest godigest.Digest) (mTypes.ImageMeta, error) { + return image.AsImageMeta(), nil }, } responseContext := graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, @@ -1734,9 +1734,9 @@ func TestMockedDerivedImageList(t *testing.T) { layer4, }).DefaultConfig().Build() - imageDataMap := map[string]mTypes.ImageData{ - image.DigestStr(): image.AsImageData(), - derivedImage.DigestStr(): derivedImage.AsImageData(), + imageMetaMap := map[string]mTypes.ImageMeta{ + image.DigestStr(): image.AsImageMeta(), + derivedImage.DigestStr(): derivedImage.AsImageMeta(), } mockMetaDB := mocks.MetaDBMock{ @@ -1748,21 +1748,21 @@ func TestMockedDerivedImageList(t *testing.T) { }, }, nil }, - GetImageDataFn: func(digest godigest.Digest) (mTypes.ImageData, error) { - return imageDataMap[digest.String()], nil + GetImageMetaFn: func(digest godigest.Digest) (mTypes.ImageMeta, error) { + return imageMetaMap[digest.String()], nil }, - FilterImageDataFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) { - result := map[string]mTypes.ImageData{} + FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { + result := map[string]mTypes.ImageMeta{} for _, digest := range digests { - result[digest] = imageDataMap[digest] + result[digest] = imageMetaMap[digest] } return result, nil }, FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - fullImageDataList := []mTypes.ImageMeta{} + ) ([]mTypes.FullImageMeta, error) { + fullImageMetaList := []mTypes.FullImageMeta{} repos := []mTypes.RepoMeta{{ Name: "repo1", Tags: map[string]mTypes.Descriptor{ @@ -1774,14 +1774,14 @@ func TestMockedDerivedImageList(t *testing.T) { for _, repo := range repos { for tag, descriptor := range repo.Tags { - if filterFunc(repo, imageDataMap[descriptor.Digest]) { - fullImageDataList = append(fullImageDataList, - convert.GetImageMeta(tag, repo, imageDataMap[descriptor.Digest])) + if filterFunc(repo, imageMetaMap[descriptor.Digest]) { + fullImageMetaList = append(fullImageMetaList, + convert.GetFullImageMeta(tag, repo, imageMetaMap[descriptor.Digest])) } } } - return fullImageDataList, nil + return fullImageMetaList, nil }, } @@ -1818,14 +1818,14 @@ func TestMockedBaseImageList(t *testing.T) { Convey("MetaDB FilterTags error", t, func() { mockMetaDB := mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, ErrTestError + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, ErrTestError }, GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{}, ErrTestError }, - FilterImageDataFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) { - return map[string]mTypes.ImageData{}, ErrTestError + FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { + return map[string]mTypes.ImageMeta{}, ErrTestError }, } responseContext := graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, @@ -1856,8 +1856,8 @@ func TestMockedBaseImageList(t *testing.T) { }, }, nil }, - FilterImageDataFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) { - return map[string]mTypes.ImageData{image.DigestStr(): image.AsImageData()}, nil + FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { + return map[string]mTypes.ImageMeta{image.DigestStr(): image.AsImageMeta()}, nil }, }, pageInput, mocks.CveInfoMock{}, log.NewLogger("debug", "")) @@ -1870,8 +1870,8 @@ func TestMockedBaseImageList(t *testing.T) { mockMetaDB := mocks.MetaDBMock{ FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - return []mTypes.ImageMeta{}, nil + ) ([]mTypes.FullImageMeta, error) { + return []mTypes.FullImageMeta{}, nil }, GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ @@ -1881,8 +1881,8 @@ func TestMockedBaseImageList(t *testing.T) { }, }, nil }, - FilterImageDataFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) { - return map[string]mTypes.ImageData{image.DigestStr(): image.AsImageData()}, nil + FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { + return map[string]mTypes.ImageMeta{image.DigestStr(): image.AsImageMeta()}, nil }, } responseContext := graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, @@ -1917,9 +1917,9 @@ func TestMockedBaseImageList(t *testing.T) { layer4, }).DefaultConfig().Build() - imageDataMap := map[string]mTypes.ImageData{ - image.DigestStr(): image.AsImageData(), - derivedImage.DigestStr(): derivedImage.AsImageData(), + imageMetaMap := map[string]mTypes.ImageMeta{ + image.DigestStr(): image.AsImageMeta(), + derivedImage.DigestStr(): derivedImage.AsImageMeta(), } mockMetaDB := mocks.MetaDBMock{ @@ -1931,12 +1931,12 @@ func TestMockedBaseImageList(t *testing.T) { }, }, nil }, - FilterImageDataFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) { - return imageDataMap, nil + FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { + return imageMetaMap, nil }, FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - imageDataList := []mTypes.ImageMeta{} + ) ([]mTypes.FullImageMeta, error) { + fullImageMetaList := []mTypes.FullImageMeta{} repos := []mTypes.RepoMeta{{ Name: "repo1", Tags: map[string]mTypes.Descriptor{ @@ -1948,14 +1948,14 @@ func TestMockedBaseImageList(t *testing.T) { for _, repo := range repos { for tag, descriptor := range repo.Tags { - if filterFunc(repo, imageDataMap[descriptor.Digest]) { - imageDataList = append(imageDataList, - convert.GetImageMeta(tag, repo, imageDataMap[descriptor.Digest])) + if filterFunc(repo, imageMetaMap[descriptor.Digest]) { + fullImageMetaList = append(fullImageMetaList, + convert.GetFullImageMeta(tag, repo, imageMetaMap[descriptor.Digest])) } } } - return imageDataList, nil + return fullImageMetaList, nil }, } responseContext := graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, @@ -2012,9 +2012,9 @@ func TestMockedBaseImageList(t *testing.T) { layer4, }).DefaultConfig().Build() - imageDataMap := map[string]mTypes.ImageData{ - image.DigestStr(): image.AsImageData(), - derivedImage.DigestStr(): derivedImage.AsImageData(), + imageMetaMap := map[string]mTypes.ImageMeta{ + image.DigestStr(): image.AsImageMeta(), + derivedImage.DigestStr(): derivedImage.AsImageMeta(), } mockMetaDB := mocks.MetaDBMock{ @@ -2026,12 +2026,12 @@ func TestMockedBaseImageList(t *testing.T) { }, }, nil }, - FilterImageDataFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) { - return imageDataMap, nil + FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { + return imageMetaMap, nil }, FilterTagsFn: func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, - ) ([]mTypes.ImageMeta, error) { - imageDataList := []mTypes.ImageMeta{} + ) ([]mTypes.FullImageMeta, error) { + fullImageMetaList := []mTypes.FullImageMeta{} repos := []mTypes.RepoMeta{{ Name: "repo1", Tags: map[string]mTypes.Descriptor{ @@ -2042,14 +2042,14 @@ func TestMockedBaseImageList(t *testing.T) { for _, repo := range repos { for tag, descriptor := range repo.Tags { - if filterFunc(repo, imageDataMap[descriptor.Digest]) { - imageDataList = append(imageDataList, - convert.GetImageMeta(tag, repo, imageDataMap[descriptor.Digest])) + if filterFunc(repo, imageMetaMap[descriptor.Digest]) { + fullImageMetaList = append(fullImageMetaList, + convert.GetFullImageMeta(tag, repo, imageMetaMap[descriptor.Digest])) } } } - return imageDataList, nil + return fullImageMetaList, 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 f6b3b71b14..56b9b2b527 100644 --- a/pkg/extensions/search/search_test.go +++ b/pkg/extensions/search/search_test.go @@ -327,7 +327,7 @@ func getMockCveScanner(metaDB mTypes.MetaDB) cveinfo.Scanner { return false, err } - manifestData, err := metaDB.GetImageData(manifestDigest) + manifestData, err := metaDB.GetImageMeta(manifestDigest) if err != nil { return false, err } @@ -4484,7 +4484,7 @@ func TestMetaDBWhenPushingImages(t *testing.T) { Convey("SetManifestMeta succeeds but SetRepoReference fails", func() { ctlr.MetaDB = mocks.MetaDBMock{ - SetRepoReferenceFn: func(repo, reference string, imageData mTypes.ImageData) error { + SetRepoReferenceFn: func(repo, reference string, imageMeta mTypes.ImageMeta) error { return ErrTestError }, } diff --git a/pkg/extensions/sync/sync_internal_test.go b/pkg/extensions/sync/sync_internal_test.go index 67d54ecc69..f28d3c3e47 100644 --- a/pkg/extensions/sync/sync_internal_test.go +++ b/pkg/extensions/sync/sync_internal_test.go @@ -337,7 +337,7 @@ func TestLocalRegistry(t *testing.T) { Convey("trigger metaDB error on index manifest in CommitImage()", func() { registry := NewLocalRegistry(storage.StoreController{DefaultStore: syncImgStore}, mocks.MetaDBMock{ - SetRepoReferenceFn: func(repo string, reference string, imageData mTypes.ImageData) error { + SetRepoReferenceFn: func(repo string, reference string, imageMeta mTypes.ImageMeta) error { if reference == "1.0" { return zerr.ErrRepoMetaNotFound } @@ -352,7 +352,7 @@ func TestLocalRegistry(t *testing.T) { Convey("trigger metaDB error on image manifest in CommitImage()", func() { registry := NewLocalRegistry(storage.StoreController{DefaultStore: syncImgStore}, mocks.MetaDBMock{ - SetRepoReferenceFn: func(repo, reference string, imageData mTypes.ImageData) error { + SetRepoReferenceFn: func(repo, reference string, imageMeta mTypes.ImageMeta) error { return zerr.ErrRepoMetaNotFound }, }, log) diff --git a/pkg/extensions/sync/sync_test.go b/pkg/extensions/sync/sync_test.go index bdfef94699..d2890aafd5 100644 --- a/pkg/extensions/sync/sync_test.go +++ b/pkg/extensions/sync/sync_test.go @@ -875,7 +875,7 @@ func TestOnDemand(t *testing.T) { return nil }, - SetRepoReferenceFn: func(repo, reference string, imageData mTypes.ImageData) error { + SetRepoReferenceFn: func(repo, reference string, imageMeta mTypes.ImageMeta) error { if strings.HasPrefix(reference, "sha256-") && (strings.HasSuffix(reference, remote.SignatureTagSuffix) || strings.HasSuffix(reference, remote.SBOMTagSuffix)) || @@ -1015,8 +1015,8 @@ func TestOnDemand(t *testing.T) { // metadb fails for syncReferrersTag" dctlr.MetaDB = mocks.MetaDBMock{ - SetRepoReferenceFn: func(repo, reference string, imageData mTypes.ImageData) error { - if imageData.Digest.String() == ociRefImage.ManifestDescriptor.Digest.String() { + SetRepoReferenceFn: func(repo, reference string, imageMeta mTypes.ImageMeta) error { + if imageMeta.Digest.String() == ociRefImage.ManifestDescriptor.Digest.String() { return sync.ErrTestError } diff --git a/pkg/meta/boltdb/boltdb.go b/pkg/meta/boltdb/boltdb.go index 989d46b97a..f815e0ea4a 100644 --- a/pkg/meta/boltdb/boltdb.go +++ b/pkg/meta/boltdb/boltdb.go @@ -55,7 +55,7 @@ func New(boltDB *bbolt.DB, log log.Logger) (*BoltDB, error) { return err } - _, err = transaction.CreateBucketIfNotExists([]byte(ImageDataBuck)) + _, err = transaction.CreateBucketIfNotExists([]byte(ImageMetaBuck)) if err != nil { return err } @@ -84,28 +84,28 @@ func New(boltDB *bbolt.DB, log log.Logger) (*BoltDB, error) { }, nil } -func (bdw *BoltDB) SetImageData(digest godigest.Digest, imageData mTypes.ImageData) error { +func (bdw *BoltDB) SetImageMeta(digest godigest.Digest, imageMeta mTypes.ImageMeta) error { err := bdw.DB.Update(func(tx *bbolt.Tx) error { - buck := tx.Bucket([]byte(ImageDataBuck)) + buck := tx.Bucket([]byte(ImageMetaBuck)) - protoImageData := &proto_go.ImageData{} + protoImageMeta := &proto_go.ImageMeta{} - switch imageData.MediaType { + switch imageMeta.MediaType { case ispec.MediaTypeImageManifest: - manifest := imageData.Manifests[0] + manifest := imageMeta.Manifests[0] - protoImageData = mConvert.GetProtoImageManifestData(manifest.Manifest, manifest.Config, + protoImageMeta = mConvert.GetProtoImageManifestData(manifest.Manifest, manifest.Config, manifest.Size, manifest.Digest.String()) case ispec.MediaTypeImageIndex: - protoImageData = mConvert.GetProtoImageIndexData(*imageData.Index, imageData.Size, imageData.Digest.String()) + protoImageMeta = mConvert.GetProtoImageIndexMeta(*imageMeta.Index, imageMeta.Size, imageMeta.Digest.String()) } - pImageDataBlob, err := proto.Marshal(protoImageData) + pImageMetaBlob, err := proto.Marshal(protoImageMeta) if err != nil { return fmt.Errorf("metadb: error while calculating blob for manifest with digest %s %w", digest, err) } - err = buck.Put([]byte(digest), pImageDataBlob) + err = buck.Put([]byte(digest), pImageMetaBlob) if err != nil { return fmt.Errorf("metadb: error while setting manifest data with for digest %s %w", digest, err) } @@ -116,27 +116,27 @@ func (bdw *BoltDB) SetImageData(digest godigest.Digest, imageData mTypes.ImageDa return err } -func (bdw *BoltDB) SetRepoReference(repo string, reference string, imageData mTypes.ImageData, +func (bdw *BoltDB) SetRepoReference(repo string, reference string, imageMeta mTypes.ImageMeta, ) error { - if err := common.ValidateRepoReferenceInput(repo, reference, imageData.Digest); err != nil { + if err := common.ValidateRepoReferenceInput(repo, reference, imageMeta.Digest); err != nil { return err } err := bdw.DB.Update(func(tx *bbolt.Tx) error { repoBuck := tx.Bucket([]byte(RepoMetaBuck)) repoBlobsBuck := tx.Bucket([]byte(RepoBlobsBuck)) - imageBuck := tx.Bucket([]byte(ImageDataBuck)) + imageBuck := tx.Bucket([]byte(ImageMetaBuck)) // 1. Add image data to db if needed - protoImageData := mConvert.GetProtoImageData(imageData) + protoImageMeta := mConvert.GetProtoImageMeta(imageMeta) - imageDataBlob, err := proto.Marshal(protoImageData) + imageMetaBlob, err := proto.Marshal(protoImageMeta) if err != nil { return err } - err = imageBuck.Put([]byte(imageData.Digest), imageDataBlob) + err = imageBuck.Put([]byte(imageMeta.Digest), imageMetaBlob) if err != nil { return err } @@ -159,7 +159,7 @@ func (bdw *BoltDB) SetRepoReference(repo string, reference string, imageData mTy } // 2. Referrers - if subject := mConvert.GetImageSubject(protoImageData); subject != nil { + if subject := mConvert.GetImageSubject(protoImageMeta); subject != nil { refInfo := &proto_go.ReferrersInfo{} if protoRepoMeta.Referrers[subject.Digest.String()] != nil { refInfo = protoRepoMeta.Referrers[subject.Digest.String()] @@ -168,7 +168,7 @@ func (bdw *BoltDB) SetRepoReference(repo string, reference string, imageData mTy foundReferrer := false for i := range refInfo.List { - if refInfo.List[i].Digest == mConvert.GetImageDigestStr(protoImageData) { + if refInfo.List[i].Digest == mConvert.GetImageDigestStr(protoImageMeta) { foundReferrer = true refInfo.List[i].Count += 1 @@ -179,11 +179,11 @@ func (bdw *BoltDB) SetRepoReference(repo string, reference string, imageData mTy if !foundReferrer { refInfo.List = append(refInfo.List, &proto_go.ReferrerInfo{ Count: 1, - MediaType: protoImageData.MediaType, - Digest: mConvert.GetImageDigestStr(protoImageData), - ArtifactType: mConvert.GetImageArtifactType(protoImageData), - Size: mConvert.GetImageManifestSize(protoImageData), - Annotations: mConvert.GetImageAnnotations(protoImageData), + MediaType: protoImageMeta.MediaType, + Digest: mConvert.GetImageDigestStr(protoImageMeta), + ArtifactType: mConvert.GetImageArtifactType(protoImageMeta), + Size: mConvert.GetImageManifestSize(protoImageMeta), + Annotations: mConvert.GetImageAnnotations(protoImageMeta), }) } @@ -193,23 +193,23 @@ func (bdw *BoltDB) SetRepoReference(repo string, reference string, imageData mTy // 3. Update tag if !common.ReferenceIsDigest(reference) { protoRepoMeta.Tags[reference] = &proto_go.TagDescriptor{ - Digest: imageData.Digest.String(), - MediaType: imageData.MediaType, + Digest: imageMeta.Digest.String(), + MediaType: imageMeta.MediaType, } } - if _, ok := protoRepoMeta.Statistics[imageData.Digest.String()]; !ok { - protoRepoMeta.Statistics[imageData.Digest.String()] = &proto_go.DescriptorStatistics{DownloadCount: 0} + if _, ok := protoRepoMeta.Statistics[imageMeta.Digest.String()]; !ok { + protoRepoMeta.Statistics[imageMeta.Digest.String()] = &proto_go.DescriptorStatistics{DownloadCount: 0} } - if _, ok := protoRepoMeta.Signatures[imageData.Digest.String()]; !ok { - protoRepoMeta.Signatures[imageData.Digest.String()] = &proto_go.ManifestSignatures{ + if _, ok := protoRepoMeta.Signatures[imageMeta.Digest.String()]; !ok { + protoRepoMeta.Signatures[imageMeta.Digest.String()] = &proto_go.ManifestSignatures{ Map: map[string]*proto_go.SignaturesInfo{"": {}}, } } - if _, ok := protoRepoMeta.Referrers[imageData.Digest.String()]; !ok { - protoRepoMeta.Referrers[imageData.Digest.String()] = &proto_go.ReferrersInfo{ + if _, ok := protoRepoMeta.Referrers[imageMeta.Digest.String()]; !ok { + protoRepoMeta.Referrers[imageMeta.Digest.String()] = &proto_go.ReferrersInfo{ List: []*proto_go.ReferrerInfo{}, } } @@ -228,7 +228,7 @@ func (bdw *BoltDB) SetRepoReference(repo string, reference string, imageData mTy } } - protoRepoMeta, repoBlobs, err = common.AddImageDataToRepoMeta(protoRepoMeta, repoBlobs, reference, imageData) + protoRepoMeta, repoBlobs, err = common.AddImageMetaToRepoMeta(protoRepoMeta, repoBlobs, reference, imageMeta) if err != nil { return err } @@ -254,24 +254,24 @@ func (bdw *BoltDB) SetRepoReference(repo string, reference string, imageData mTy return err } -func (bdw *BoltDB) FilterImageData(ctx context.Context, digests []string, -) (map[string]mTypes.ImageData, error) { - imageDataMap := map[string]mTypes.ImageData{} +func (bdw *BoltDB) FilterImageMeta(ctx context.Context, digests []string, +) (map[string]mTypes.ImageMeta, error) { + imageMetaMap := map[string]mTypes.ImageMeta{} err := bdw.DB.View(func(transaction *bbolt.Tx) error { - imageBuck := transaction.Bucket([]byte(ImageDataBuck)) + imageBuck := transaction.Bucket([]byte(ImageMetaBuck)) for _, digest := range digests { - protoImageData, err := fetchProtoImageData(imageBuck, digest) + protoImageMeta, err := fetchProtoImageMeta(imageBuck, digest) if err != nil { return err } - if protoImageData.MediaType == ispec.MediaTypeImageIndex { - manifestDataList := make([]*proto_go.ManifestData, 0, len(protoImageData.Index.Index.Manifests)) + if protoImageMeta.MediaType == ispec.MediaTypeImageIndex { + manifestDataList := make([]*proto_go.ManifestMeta, 0, len(protoImageMeta.Index.Index.Manifests)) - for _, manifest := range protoImageData.Index.Index.Manifests { - imageManifestData, err := fetchProtoImageData(imageBuck, manifest.Digest) + for _, manifest := range protoImageMeta.Index.Index.Manifests { + imageManifestData, err := fetchProtoImageMeta(imageBuck, manifest.Digest) if err != nil { return err } @@ -279,16 +279,16 @@ func (bdw *BoltDB) FilterImageData(ctx context.Context, digests []string, manifestDataList = append(manifestDataList, imageManifestData.Manifests[0]) } - protoImageData.Manifests = manifestDataList + protoImageMeta.Manifests = manifestDataList } - imageDataMap[digest] = mConvert.GetImageData(protoImageData) + imageMetaMap[digest] = mConvert.GetImageMeta(protoImageMeta) } return nil }) - return imageDataMap, err + return imageMetaMap, err } func (bdw *BoltDB) SearchRepos(ctx context.Context, searchText string, @@ -336,37 +336,37 @@ func (bdw *BoltDB) SearchRepos(ctx context.Context, searchText string, return repos, err } -func fetchProtoImageData(imageBuck *bbolt.Bucket, digest string) (*proto_go.ImageData, error) { - imageDataBlob := imageBuck.Get([]byte(digest)) +func fetchProtoImageMeta(imageBuck *bbolt.Bucket, digest string) (*proto_go.ImageMeta, error) { + imageMetaBlob := imageBuck.Get([]byte(digest)) - if len(imageDataBlob) == 0 { - return nil, zerr.ErrImageDataNotFound + if len(imageMetaBlob) == 0 { + return nil, zerr.ErrImageMetaNotFound } - imageData := proto_go.ImageData{} + imageMeta := proto_go.ImageMeta{} - err := proto.Unmarshal(imageDataBlob, &imageData) + err := proto.Unmarshal(imageMetaBlob, &imageMeta) if err != nil { return nil, err } - return &imageData, nil + return &imageMeta, nil } func (bdw *BoltDB) SearchTags(ctx context.Context, searchText string, -) ([]mTypes.ImageMeta, error) { - images := []mTypes.ImageMeta{} +) ([]mTypes.FullImageMeta, error) { + images := []mTypes.FullImageMeta{} searchedRepo, searchedTag, err := common.GetRepoTag(searchText) if err != nil { - return []mTypes.ImageMeta{}, + return []mTypes.FullImageMeta{}, fmt.Errorf("metadb: error while parsing search text, invalid format %w", err) } err = bdw.DB.View(func(transaction *bbolt.Tx) error { var ( repoBuck = transaction.Bucket([]byte(RepoMetaBuck)) - imageBuck = transaction.Bucket([]byte(ImageDataBuck)) + imageBuck = transaction.Bucket([]byte(ImageMetaBuck)) userBookmarks = getUserBookmarks(ctx, transaction) userStars = getUserStars(ctx, transaction) ) @@ -398,32 +398,32 @@ func (bdw *BoltDB) SearchTags(ctx context.Context, searchText string, continue } - var protoImageData *proto_go.ImageData + var protoImageMeta *proto_go.ImageMeta switch descriptor.MediaType { case ispec.MediaTypeImageManifest: manifestDigest := descriptor.Digest - imageManifestData, err := fetchProtoImageData(imageBuck, manifestDigest) + imageManifestData, err := fetchProtoImageMeta(imageBuck, manifestDigest) if err != nil { return fmt.Errorf("metadb: error fetching manifest meta for manifest with digest %s %w", manifestDigest, err) } - protoImageData = imageManifestData + protoImageMeta = imageManifestData case ispec.MediaTypeImageIndex: indexDigest := descriptor.Digest - imageIndexData, err := fetchProtoImageData(imageBuck, indexDigest) + imageIndexData, err := fetchProtoImageMeta(imageBuck, indexDigest) if err != nil { return fmt.Errorf("metadb: error fetching manifest meta for manifest with digest %s %w", indexDigest, err) } - manifestDataList := make([]*proto_go.ManifestData, 0, len(imageIndexData.Index.Index.Manifests)) + manifestDataList := make([]*proto_go.ManifestMeta, 0, len(imageIndexData.Index.Index.Manifests)) for _, manifest := range imageIndexData.Index.Index.Manifests { - imageManifestData, err := fetchProtoImageData(imageBuck, manifest.Digest) + imageManifestData, err := fetchProtoImageMeta(imageBuck, manifest.Digest) if err != nil { return err } @@ -433,14 +433,14 @@ func (bdw *BoltDB) SearchTags(ctx context.Context, searchText string, imageIndexData.Manifests = manifestDataList - protoImageData = imageIndexData + protoImageMeta = imageIndexData default: bdw.Log.Error().Str("mediaType", descriptor.MediaType).Msg("Unsupported media type") continue } - images = append(images, mConvert.GetImageMetaFromProto(tag, protoRepoMeta, protoImageData)) + images = append(images, mConvert.GetFullImageMetaFromProto(tag, protoRepoMeta, protoImageMeta)) } return nil @@ -451,13 +451,13 @@ func (bdw *BoltDB) SearchTags(ctx context.Context, searchText string, func (bdw *BoltDB) FilterTags(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, -) ([]mTypes.ImageMeta, error) { - images := []mTypes.ImageMeta{} +) ([]mTypes.FullImageMeta, error) { + images := []mTypes.FullImageMeta{} err := bdw.DB.View(func(transaction *bbolt.Tx) error { var ( repoBuck = transaction.Bucket([]byte(RepoMetaBuck)) - imageDataBuck = transaction.Bucket([]byte(ImageDataBuck)) + imageMetaBuck = transaction.Bucket([]byte(ImageMetaBuck)) userBookmarks = getUserBookmarks(ctx, transaction) userStars = getUserStars(ctx, transaction) viewError error @@ -494,43 +494,43 @@ func (bdw *BoltDB) FilterTags(ctx context.Context, filterRepoTag mTypes.FilterRe case ispec.MediaTypeImageManifest: manifestDigest := descriptor.Digest - imageManifestData, err := fetchProtoImageData(imageDataBuck, manifestDigest) + imageManifestData, err := fetchProtoImageMeta(imageMetaBuck, manifestDigest) if err != nil { viewError = errors.Join(viewError, err) continue } - imageData := mConvert.GetImageData(imageManifestData) + imageMeta := mConvert.GetImageMeta(imageManifestData) - if filterFunc(repoMeta, imageData) { - images = append(images, mConvert.GetImageMetaFromProto(tag, protoRepoMeta, imageManifestData)) + if filterFunc(repoMeta, imageMeta) { + images = append(images, mConvert.GetFullImageMetaFromProto(tag, protoRepoMeta, imageManifestData)) } case ispec.MediaTypeImageIndex: indexDigest := descriptor.Digest - imageIndexData, err := fetchProtoImageData(imageDataBuck, indexDigest) + imageIndexData, err := fetchProtoImageMeta(imageMetaBuck, indexDigest) if err != nil { viewError = errors.Join(viewError, err) continue } - matchedManifests := []*proto_go.ManifestData{} + matchedManifests := []*proto_go.ManifestMeta{} for _, manifest := range imageIndexData.Index.Index.Manifests { manifestDigest := manifest.Digest - imageManifestData, err := fetchProtoImageData(imageDataBuck, manifestDigest) + imageManifestData, err := fetchProtoImageMeta(imageMetaBuck, manifestDigest) if err != nil { viewError = errors.Join(viewError, err) continue } - imageData := mConvert.GetImageData(imageManifestData) + imageMeta := mConvert.GetImageMeta(imageManifestData) - if filterFunc(repoMeta, imageData) { + if filterFunc(repoMeta, imageMeta) { matchedManifests = append(matchedManifests, imageManifestData.Manifests[0]) } } @@ -538,7 +538,7 @@ func (bdw *BoltDB) FilterTags(ctx context.Context, filterRepoTag mTypes.FilterRe if len(matchedManifests) > 0 { imageIndexData.Manifests = matchedManifests - images = append(images, mConvert.GetImageMetaFromProto(tag, protoRepoMeta, imageIndexData)) + images = append(images, mConvert.GetFullImageMetaFromProto(tag, protoRepoMeta, imageIndexData)) } default: bdw.Log.Error().Str("mediaType", descriptor.MediaType).Msg("Unsupported media type") @@ -633,13 +633,13 @@ func (bdw *BoltDB) GetRepoMeta(ctx context.Context, repo string) (mTypes.RepoMet return mConvert.GetRepoMeta(&protoRepoMeta), err } -func (bdw *BoltDB) GetImageMeta(ctx context.Context, repo string, tag string) (mTypes.ImageMeta, error) { +func (bdw *BoltDB) GetFullImageMeta(ctx context.Context, repo string, tag string) (mTypes.FullImageMeta, error) { protoRepoMeta := &proto_go.RepoMeta{} - protoImageData := &proto_go.ImageData{} + protoImageMeta := &proto_go.ImageMeta{} err := bdw.DB.View(func(tx *bbolt.Tx) error { buck := tx.Bucket([]byte(RepoMetaBuck)) - imageBuck := tx.Bucket([]byte(ImageDataBuck)) + imageBuck := tx.Bucket([]byte(ImageMetaBuck)) userBookmarks := getUserBookmarks(ctx, tx) userStars := getUserStars(ctx, tx) @@ -662,19 +662,19 @@ func (bdw *BoltDB) GetImageMeta(ctx context.Context, repo string, tag string) (m descriptor, ok := protoRepoMeta.Tags[tag] if !ok { - return zerr.ErrImageDataNotFound + return zerr.ErrImageMetaNotFound } - protoImageData, err = fetchProtoImageData(imageBuck, descriptor.Digest) + protoImageMeta, err = fetchProtoImageMeta(imageBuck, descriptor.Digest) if err != nil { return err } - if protoImageData.MediaType == ispec.MediaTypeImageIndex { - manifestDataList := make([]*proto_go.ManifestData, 0, len(protoImageData.Index.Index.Manifests)) + if protoImageMeta.MediaType == ispec.MediaTypeImageIndex { + manifestDataList := make([]*proto_go.ManifestMeta, 0, len(protoImageMeta.Index.Index.Manifests)) - for _, manifest := range protoImageData.Index.Index.Manifests { - imageManifestData, err := fetchProtoImageData(imageBuck, manifest.Digest) + for _, manifest := range protoImageMeta.Index.Index.Manifests { + imageManifestData, err := fetchProtoImageMeta(imageBuck, manifest.Digest) if err != nil { return err } @@ -682,31 +682,31 @@ func (bdw *BoltDB) GetImageMeta(ctx context.Context, repo string, tag string) (m manifestDataList = append(manifestDataList, imageManifestData.Manifests[0]) } - protoImageData.Manifests = manifestDataList + protoImageMeta.Manifests = manifestDataList } return nil }) - return mConvert.GetImageMetaFromProto(tag, protoRepoMeta, protoImageData), err + return mConvert.GetFullImageMetaFromProto(tag, protoRepoMeta, protoImageMeta), err } -func (bdw *BoltDB) GetImageData(digest godigest.Digest) (mTypes.ImageData, error) { - imageData := mTypes.ImageData{} +func (bdw *BoltDB) GetImageMeta(digest godigest.Digest) (mTypes.ImageMeta, error) { + imageMeta := mTypes.ImageMeta{} err := bdw.DB.View(func(tx *bbolt.Tx) error { - imageBuck := tx.Bucket([]byte(ImageDataBuck)) + imageBuck := tx.Bucket([]byte(ImageMetaBuck)) - protoImageData, err := fetchProtoImageData(imageBuck, digest.String()) + protoImageMeta, err := fetchProtoImageMeta(imageBuck, digest.String()) if err != nil { return err } - if protoImageData.MediaType == ispec.MediaTypeImageIndex { - manifestDataList := make([]*proto_go.ManifestData, 0, len(protoImageData.Index.Index.Manifests)) + if protoImageMeta.MediaType == ispec.MediaTypeImageIndex { + manifestDataList := make([]*proto_go.ManifestMeta, 0, len(protoImageMeta.Index.Index.Manifests)) - for _, manifest := range protoImageData.Index.Index.Manifests { - imageManifestData, err := fetchProtoImageData(imageBuck, manifest.Digest) + for _, manifest := range protoImageMeta.Index.Index.Manifests { + imageManifestData, err := fetchProtoImageMeta(imageBuck, manifest.Digest) if err != nil { return err } @@ -714,15 +714,15 @@ func (bdw *BoltDB) GetImageData(digest godigest.Digest) (mTypes.ImageData, error manifestDataList = append(manifestDataList, imageManifestData.Manifests[0]) } - protoImageData.Manifests = manifestDataList + protoImageMeta.Manifests = manifestDataList } - imageData = mConvert.GetImageData(protoImageData) + imageMeta = mConvert.GetImageMeta(protoImageMeta) return nil }) - return imageData, err + return imageMeta, err } func (bdw *BoltDB) GetMultipleRepoMeta(ctx context.Context, filter func(repoMeta mTypes.RepoMeta) bool, @@ -1141,17 +1141,17 @@ func (bdw *BoltDB) UpdateSignaturesValidity(repo string, manifestDigest godigest } // get ManifestData of signed manifest - imageDataBuck := transaction.Bucket([]byte(ImageDataBuck)) - idBlob := imageDataBuck.Get([]byte(manifestDigest)) + imageMetaBuck := transaction.Bucket([]byte(ImageMetaBuck)) + idBlob := imageMetaBuck.Get([]byte(manifestDigest)) if len(idBlob) == 0 { // manifest meta not found, updating signatures with details about validity and author will not be performed return nil } - protoImageData := proto_go.ImageData{} + protoImageMeta := proto_go.ImageMeta{} - err := proto.Unmarshal(idBlob, &protoImageData) + err := proto.Unmarshal(idBlob, &protoImageMeta) if err != nil { return err } @@ -1180,7 +1180,7 @@ func (bdw *BoltDB) UpdateSignaturesValidity(repo string, manifestDigest godigest for _, layerInfo := range sigInfo.LayersInfo { author, date, isTrusted, _ := imgTrustStore.VerifySignature(sigType, layerInfo.LayerContent, - layerInfo.SignatureKey, manifestDigest, mConvert.GetImageData(&protoImageData), repo) + layerInfo.SignatureKey, manifestDigest, mConvert.GetImageMeta(&protoImageMeta), repo) if isTrusted { layerInfo.Signer = author @@ -1219,7 +1219,7 @@ func (bdw *BoltDB) UpdateSignaturesValidity(repo string, manifestDigest godigest func (bdw *BoltDB) RemoveRepoReference(repo, reference string, manifestDigest godigest.Digest) error { err := bdw.DB.Update(func(tx *bbolt.Tx) error { buck := tx.Bucket([]byte(RepoMetaBuck)) - imageDataBuck := tx.Bucket([]byte(ImageDataBuck)) + imageMetaBuck := tx.Bucket([]byte(ImageMetaBuck)) repoBlobsBuck := tx.Bucket([]byte(RepoBlobsBuck)) repoMetaBlob := buck.Get([]byte(repo)) @@ -1234,9 +1234,9 @@ func (bdw *BoltDB) RemoveRepoReference(repo, reference string, manifestDigest go return err } - imageData, err := fetchProtoImageData(imageDataBuck, manifestDigest.String()) + imageMeta, err := fetchProtoImageMeta(imageMetaBuck, manifestDigest.String()) if err != nil { - if errors.Is(err, zerr.ErrImageDataNotFound) { + if errors.Is(err, zerr.ErrImageMetaNotFound) { return nil } @@ -1244,7 +1244,7 @@ func (bdw *BoltDB) RemoveRepoReference(repo, reference string, manifestDigest go } // Remove Referrers - if subject := mConvert.GetImageSubject(imageData); subject != nil { + if subject := mConvert.GetImageSubject(imageMeta); subject != nil { referredDigest := subject.Digest.String() refInfo := &proto_go.ReferrersInfo{} @@ -1945,7 +1945,7 @@ func (bdw *BoltDB) ResetDB() error { return err } - err = resetBucket(transaction, ImageDataBuck) + err = resetBucket(transaction, ImageMetaBuck) if err != nil { return err } diff --git a/pkg/meta/boltdb/boltdb_test.go b/pkg/meta/boltdb/boltdb_test.go index 665cf72451..f606df1d3f 100644 --- a/pkg/meta/boltdb/boltdb_test.go +++ b/pkg/meta/boltdb/boltdb_test.go @@ -22,7 +22,7 @@ import ( type imgTrustStore struct{} func (its imgTrustStore) VerifySignature( - signatureType string, rawSignature []byte, sigKey string, manifestDigest digest.Digest, imageData mTypes.ImageData, + signatureType string, rawSignature []byte, sigKey string, manifestDigest digest.Digest, imageMeta mTypes.ImageMeta, repo string, ) (string, time.Time, bool, error) { return "", time.Time{}, false, nil diff --git a/pkg/meta/boltdb/buckets.go b/pkg/meta/boltdb/buckets.go index e15b7059f4..90188974c8 100644 --- a/pkg/meta/boltdb/buckets.go +++ b/pkg/meta/boltdb/buckets.go @@ -2,7 +2,7 @@ package boltdb // MetadataDB. const ( - ImageDataBuck = "ImageData" + ImageMetaBuck = "ImageMeta" RepoMetaBuck = "RepoMeta" RepoBlobsBuck = "RepoBlobsMeta" UserDataBucket = "UserData" diff --git a/pkg/meta/common/common.go b/pkg/meta/common/common.go index cd8a4e62a5..0fe7bf0ceb 100644 --- a/pkg/meta/common/common.go +++ b/pkg/meta/common/common.go @@ -186,12 +186,12 @@ func CheckImageLastUpdated(repoLastUpdated time.Time, isSigned bool, noImageChec return repoLastUpdated, noImageChecked, isSigned } -func AddImageDataToRepoMeta(repoMeta *proto_go.RepoMeta, repoBlobs *proto_go.RepoBlobs, reference string, - imageData mTypes.ImageData, +func AddImageMetaToRepoMeta(repoMeta *proto_go.RepoMeta, repoBlobs *proto_go.RepoBlobs, reference string, + imageMeta mTypes.ImageMeta, ) (*proto_go.RepoMeta, *proto_go.RepoBlobs, error) { - switch imageData.MediaType { + switch imageMeta.MediaType { case ispec.MediaTypeImageManifest: - manifestData := imageData.Manifests[0] + manifestData := imageMeta.Manifests[0] vendor := GetVendor(manifestData.Manifest.Annotations) if vendor == "" { @@ -220,8 +220,8 @@ func AddImageDataToRepoMeta(repoMeta *proto_go.RepoMeta, repoBlobs *proto_go.Rep lastUpdated := zcommon.GetImageLastUpdated(manifestData.Config) - repoBlobs.Blobs[imageData.Digest.String()] = &proto_go.BlobInfo{ - Size: imageData.Size, + repoBlobs.Blobs[imageMeta.Digest.String()] = &proto_go.BlobInfo{ + Size: imageMeta.Size, Vendors: vendors, Platforms: platforms, SubBlobs: subBlobs, @@ -229,12 +229,12 @@ func AddImageDataToRepoMeta(repoMeta *proto_go.RepoMeta, repoBlobs *proto_go.Rep } case ispec.MediaTypeImageIndex: subBlobs := []string{} - for _, manifest := range imageData.Index.Manifests { + for _, manifest := range imageMeta.Index.Manifests { subBlobs = append(subBlobs, manifest.Digest.String()) } - repoBlobs.Blobs[imageData.Digest.String()] = &proto_go.BlobInfo{ - Size: imageData.Size, + repoBlobs.Blobs[imageMeta.Digest.String()] = &proto_go.BlobInfo{ + Size: imageMeta.Size, SubBlobs: subBlobs, } } @@ -249,12 +249,12 @@ func AddImageDataToRepoMeta(repoMeta *proto_go.RepoMeta, repoBlobs *proto_go.Rep repoMeta.Platforms = platforms repoMeta.Size = int32(size) - imageBlobInfo := repoBlobs.Blobs[imageData.Digest.String()] + imageBlobInfo := repoBlobs.Blobs[imageMeta.Digest.String()] repoMeta.LastUpdatedImage = mConvert.GetProtoEarlierUpdatedImage(repoMeta.LastUpdatedImage, &proto_go.RepoLastUpdatedImage{ LastUpdated: imageBlobInfo.LastUpdated, - MediaType: imageData.MediaType, - Digest: imageData.Digest.String(), + MediaType: imageMeta.MediaType, + Digest: imageMeta.Digest.String(), Tag: reference, }) diff --git a/pkg/meta/convert/convert.go b/pkg/meta/convert/convert.go index 50bb8f2b68..0a7ad985ab 100644 --- a/pkg/meta/convert/convert.go +++ b/pkg/meta/convert/convert.go @@ -33,80 +33,80 @@ func GetHistory(history []*proto_go.History) []ispec.History { return results } -func GetImageArtifactType(imageData *proto_go.ImageData) string { - switch imageData.MediaType { +func GetImageArtifactType(imageMeta *proto_go.ImageMeta) string { + switch imageMeta.MediaType { case ispec.MediaTypeImageManifest: - manifestArtifactType := deref(imageData.Manifests[0].Manifest.ArtifactType, "") + manifestArtifactType := deref(imageMeta.Manifests[0].Manifest.ArtifactType, "") if manifestArtifactType != "" { return manifestArtifactType } - return imageData.Manifests[0].Manifest.Config.MediaType + return imageMeta.Manifests[0].Manifest.Config.MediaType case ispec.MediaTypeImageIndex: - return deref(imageData.Index.Index.ArtifactType, "") + return deref(imageMeta.Index.Index.ArtifactType, "") default: return "" } } -func GetImageManifestSize(imageData *proto_go.ImageData) int64 { - switch imageData.MediaType { +func GetImageManifestSize(imageMeta *proto_go.ImageMeta) int64 { + switch imageMeta.MediaType { case ispec.MediaTypeImageManifest: - return imageData.Manifests[0].Size + return imageMeta.Manifests[0].Size case ispec.MediaTypeImageIndex: - return imageData.Index.Size + return imageMeta.Index.Size default: return 0 } } -func GetImageDigest(imageData *proto_go.ImageData) godigest.Digest { - switch imageData.MediaType { +func GetImageDigest(imageMeta *proto_go.ImageMeta) godigest.Digest { + switch imageMeta.MediaType { case ispec.MediaTypeImageManifest: - return godigest.Digest(imageData.Manifests[0].Digest) + return godigest.Digest(imageMeta.Manifests[0].Digest) case ispec.MediaTypeImageIndex: - return godigest.Digest(imageData.Index.Digest) + return godigest.Digest(imageMeta.Index.Digest) default: return "" } } -func GetImageDigestStr(imageData *proto_go.ImageData) string { - switch imageData.MediaType { +func GetImageDigestStr(imageMeta *proto_go.ImageMeta) string { + switch imageMeta.MediaType { case ispec.MediaTypeImageManifest: - return imageData.Manifests[0].Digest + return imageMeta.Manifests[0].Digest case ispec.MediaTypeImageIndex: - return imageData.Index.Digest + return imageMeta.Index.Digest default: return "" } } -func GetImageAnnotations(imageData *proto_go.ImageData) map[string]string { - switch imageData.MediaType { +func GetImageAnnotations(imageMeta *proto_go.ImageMeta) map[string]string { + switch imageMeta.MediaType { case ispec.MediaTypeImageManifest: - return imageData.Manifests[0].Manifest.Annotations + return imageMeta.Manifests[0].Manifest.Annotations case ispec.MediaTypeImageIndex: - return imageData.Index.Index.Annotations + return imageMeta.Index.Index.Annotations default: return map[string]string{} } } -func GetImageSubject(imageData *proto_go.ImageData) *ispec.Descriptor { - switch imageData.MediaType { +func GetImageSubject(imageMeta *proto_go.ImageMeta) *ispec.Descriptor { + switch imageMeta.MediaType { case ispec.MediaTypeImageManifest: - if imageData.Manifests[0].Manifest.Subject == nil { + if imageMeta.Manifests[0].Manifest.Subject == nil { return nil } - return GetDescriptorRef(imageData.Manifests[0].Manifest.Subject) + return GetDescriptorRef(imageMeta.Manifests[0].Manifest.Subject) case ispec.MediaTypeImageIndex: - if imageData.Index.Index.Subject == nil { + if imageMeta.Index.Index.Subject == nil { return nil } - return GetDescriptorRef(imageData.Index.Index.Subject) + return GetDescriptorRef(imageMeta.Index.Index.Subject) default: return &ispec.Descriptor{} } @@ -300,10 +300,10 @@ func GetImageStatistics(stats *proto_go.DescriptorStatistics) mTypes.DescriptorS } } -func GetImageManifestData(manifestContent ispec.Manifest, configContent ispec.Image, size int64, +func GetImageManifestMeta(manifestContent ispec.Manifest, configContent ispec.Image, size int64, digest godigest.Digest, -) mTypes.ImageData { - return mTypes.ImageData{ +) mTypes.ImageMeta { + return mTypes.ImageMeta{ MediaType: ispec.MediaTypeImageManifest, Digest: digest, Size: size, @@ -318,8 +318,8 @@ func GetImageManifestData(manifestContent ispec.Manifest, configContent ispec.Im } } -func GetImageIndexData(indexContent ispec.Index, size int64, digest godigest.Digest) mTypes.ImageData { - return mTypes.ImageData{ +func GetImageIndexMeta(indexContent ispec.Index, size int64, digest godigest.Digest) mTypes.ImageMeta { + return mTypes.ImageMeta{ MediaType: ispec.MediaTypeImageIndex, Index: &indexContent, Manifests: GetManifests(indexContent.Manifests), @@ -370,19 +370,19 @@ func GetTime(time *timestamppb.Timestamp) *time.Time { return ref(time.AsTime()) } -func GetImageMetaFromProto(tag string, protoRepoMeta *proto_go.RepoMeta, protoImageData *proto_go.ImageData, -) mTypes.ImageMeta { - imageData := GetImageData(protoImageData) - imageDigest := imageData.Digest.String() +func GetFullImageMetaFromProto(tag string, protoRepoMeta *proto_go.RepoMeta, protoImageMeta *proto_go.ImageMeta, +) mTypes.FullImageMeta { + imageMeta := GetImageMeta(protoImageMeta) + imageDigest := imageMeta.Digest.String() - return mTypes.ImageMeta{ + return mTypes.FullImageMeta{ Repo: protoRepoMeta.Name, Tag: tag, - MediaType: imageData.MediaType, - Digest: imageData.Digest, - Size: imageData.Size, - Index: imageData.Index, - Manifests: GetFullManifestData(protoRepoMeta, imageData.Manifests), + MediaType: imageMeta.MediaType, + Digest: imageMeta.Digest, + Size: imageMeta.Size, + Index: imageMeta.Index, + Manifests: GetFullManifestData(protoRepoMeta, imageMeta.Manifests), IsStarred: protoRepoMeta.IsStarred, IsBookmarked: protoRepoMeta.IsBookmarked, @@ -393,11 +393,11 @@ func GetImageMetaFromProto(tag string, protoRepoMeta *proto_go.RepoMeta, protoIm } func GetFullManifestData(protoRepoMeta *proto_go.RepoMeta, manifestData []mTypes.ManifestData, -) []mTypes.ManifestMeta { - results := []mTypes.ManifestMeta{} +) []mTypes.FullManifestMeta { + results := []mTypes.FullManifestMeta{} for i := range manifestData { - results = append(results, mTypes.ManifestMeta{ + results = append(results, mTypes.FullManifestMeta{ ManifestData: manifestData[i], Referrers: GetImageReferrers(protoRepoMeta.Referrers[manifestData[i].Digest.String()]), Statistics: GetImageStatistics(protoRepoMeta.Statistics[manifestData[i].Digest.String()]), @@ -501,19 +501,19 @@ func GetLastUpdatedImage(protoLastUpdated *proto_go.RepoLastUpdatedImage) *mType } } -func GetImageData(dbImageData *proto_go.ImageData) mTypes.ImageData { - imageData := mTypes.ImageData{ - MediaType: dbImageData.MediaType, - Size: GetImageManifestSize(dbImageData), - Digest: GetImageDigest(dbImageData), +func GetImageMeta(dbImageMeta *proto_go.ImageMeta) mTypes.ImageMeta { + imageMeta := mTypes.ImageMeta{ + MediaType: dbImageMeta.MediaType, + Size: GetImageManifestSize(dbImageMeta), + Digest: GetImageDigest(dbImageMeta), } - if dbImageData.MediaType == ispec.MediaTypeImageIndex { + if dbImageMeta.MediaType == ispec.MediaTypeImageIndex { var subject *ispec.Descriptor - manifests := make([]ispec.Descriptor, 0, len(dbImageData.Manifests)) + manifests := make([]ispec.Descriptor, 0, len(dbImageMeta.Manifests)) - for _, manifest := range dbImageData.Manifests { + for _, manifest := range dbImageMeta.Manifests { manifests = append(manifests, ispec.Descriptor{ MediaType: deref(manifest.Manifest.MediaType, ""), Digest: godigest.Digest(manifest.Digest), @@ -521,7 +521,7 @@ func GetImageData(dbImageData *proto_go.ImageData) mTypes.ImageData { }) } - if imgSubject := GetImageSubject(dbImageData); imgSubject != nil { + if imgSubject := GetImageSubject(dbImageMeta); imgSubject != nil { subject = &ispec.Descriptor{ MediaType: imgSubject.MediaType, Digest: imgSubject.Digest, @@ -529,19 +529,19 @@ func GetImageData(dbImageData *proto_go.ImageData) mTypes.ImageData { } } - imageData.Index = &ispec.Index{ - Versioned: specs.Versioned{SchemaVersion: int(dbImageData.Index.Index.Versioned.GetSchemaVersion())}, + imageMeta.Index = &ispec.Index{ + Versioned: specs.Versioned{SchemaVersion: int(dbImageMeta.Index.Index.Versioned.GetSchemaVersion())}, MediaType: ispec.MediaTypeImageIndex, Manifests: manifests, Subject: subject, - ArtifactType: GetImageArtifactType(dbImageData), - Annotations: GetImageAnnotations(dbImageData), + ArtifactType: GetImageArtifactType(dbImageMeta), + Annotations: GetImageAnnotations(dbImageMeta), } } - manifestDataList := make([]mTypes.ManifestData, 0, len(dbImageData.Manifests)) + manifestDataList := make([]mTypes.ManifestData, 0, len(dbImageMeta.Manifests)) - for _, manifest := range dbImageData.Manifests { + for _, manifest := range dbImageMeta.Manifests { manifestDataList = append(manifestDataList, mTypes.ManifestData{ Size: manifest.Size, Digest: godigest.Digest(manifest.Digest), @@ -582,9 +582,9 @@ func GetImageData(dbImageData *proto_go.ImageData) mTypes.ImageData { }) } - imageData.Manifests = manifestDataList + imageMeta.Manifests = manifestDataList - return imageData + return imageMeta } func GetExposedPorts(exposedPorts map[string]*proto_go.EmptyMessage) map[string]struct{} { diff --git a/pkg/meta/convert/convert_proto.go b/pkg/meta/convert/convert_proto.go index 59c3be8720..8bb784441d 100644 --- a/pkg/meta/convert/convert_proto.go +++ b/pkg/meta/convert/convert_proto.go @@ -26,39 +26,39 @@ func GetProtoRepoMeta(repo mTypes.RepoMeta) *proto_go.RepoMeta { } } -func GetProtoImageData(imageData mTypes.ImageData) *proto_go.ImageData { - switch imageData.MediaType { +func GetProtoImageMeta(imageMeta mTypes.ImageMeta) *proto_go.ImageMeta { + switch imageMeta.MediaType { case ispec.MediaTypeImageManifest: - if len(imageData.Manifests) == 0 { + if len(imageMeta.Manifests) == 0 { return nil } - manifestData := imageData.Manifests[0] + manifestData := imageMeta.Manifests[0] return GetProtoImageManifestData(manifestData.Manifest, manifestData.Config, manifestData.Size, manifestData.Digest.String()) case ispec.MediaTypeImageIndex: - if imageData.Index == nil { + if imageMeta.Index == nil { return nil } - return GetProtoImageIndexData(*imageData.Index, imageData.Size, imageData.Digest.String()) + return GetProtoImageIndexMeta(*imageMeta.Index, imageMeta.Size, imageMeta.Digest.String()) default: return nil } } func GetProtoImageManifestData(manifestContent ispec.Manifest, configContent ispec.Image, size int64, digest string, -) *proto_go.ImageData { - return &proto_go.ImageData{ +) *proto_go.ImageMeta { + return &proto_go.ImageMeta{ MediaType: ispec.MediaTypeImageManifest, - Manifests: []*proto_go.ManifestData{GetProtoManifestData(manifestContent, configContent, size, digest)}, + Manifests: []*proto_go.ManifestMeta{GetProtoManifestMeta(manifestContent, configContent, size, digest)}, Index: nil, } } -func GetProtoManifestData(manifestContent ispec.Manifest, configContent ispec.Image, size int64, digest string, -) *proto_go.ManifestData { - return &proto_go.ManifestData{ +func GetProtoManifestMeta(manifestContent ispec.Manifest, configContent ispec.Image, size int64, digest string, +) *proto_go.ManifestMeta { + return &proto_go.ManifestMeta{ Digest: digest, Size: size, Manifest: &proto_go.Manifest{ @@ -101,10 +101,10 @@ func GetProtoManifestData(manifestContent ispec.Manifest, configContent ispec.Im } } -func GetProtoImageIndexData(indexContent ispec.Index, size int64, digest string) *proto_go.ImageData { - return &proto_go.ImageData{ +func GetProtoImageIndexMeta(indexContent ispec.Index, size int64, digest string) *proto_go.ImageMeta { + return &proto_go.ImageMeta{ MediaType: ispec.MediaTypeImageIndex, - Index: &proto_go.IndexData{ + Index: &proto_go.IndexMeta{ Size: size, Digest: digest, Index: &proto_go.Index{ diff --git a/pkg/meta/dynamodb/dynamodb.go b/pkg/meta/dynamodb/dynamodb.go index 042fe06727..3a9614e84e 100644 --- a/pkg/meta/dynamodb/dynamodb.go +++ b/pkg/meta/dynamodb/dynamodb.go @@ -33,7 +33,7 @@ type DynamoDB struct { APIKeyTablename string RepoMetaTablename string RepoBlobsTablename string - ImageDataTablename string + ImageMetaTablename string UserDataTablename string VersionTablename string Patches []func(client *dynamodb.Client, tableNames map[string]string) error @@ -50,7 +50,7 @@ func New( UserDataTablename: params.UserDataTablename, APIKeyTablename: params.APIKeyTablename, RepoMetaTablename: params.RepoMetaTablename, - ImageDataTablename: params.ImageDataTablename, + ImageMetaTablename: params.ImageMetaTablename, RepoBlobsTablename: params.RepoBlobsInfoTablename, Patches: version.GetDynamoDBPatches(), imgTrustStore: nil, @@ -72,7 +72,7 @@ func New( return nil, err } - err = dynamoWrapper.createTable(dynamoWrapper.ImageDataTablename) + err = dynamoWrapper.createTable(dynamoWrapper.ImageMetaTablename) if err != nil { return nil, err } @@ -99,8 +99,8 @@ func (dwr *DynamoDB) SetImageTrustStore(imgTrustStore mTypes.ImageTrustStore) { dwr.imgTrustStore = imgTrustStore } -func (dwr *DynamoDB) SetProtoImageData(digest godigest.Digest, protoImageData *proto_go.ImageData) error { - bytes, err := proto.Marshal(protoImageData) +func (dwr *DynamoDB) SetProtoImageMeta(digest godigest.Digest, protoImageMeta *proto_go.ImageMeta) error { + bytes, err := proto.Marshal(protoImageMeta) if err != nil { return err } @@ -112,30 +112,30 @@ func (dwr *DynamoDB) SetProtoImageData(digest godigest.Digest, protoImageData *p _, err = dwr.Client.UpdateItem(context.TODO(), &dynamodb.UpdateItemInput{ ExpressionAttributeNames: map[string]string{ - "#ID": "ImageData", + "#ID": "ImageMeta", }, ExpressionAttributeValues: map[string]types.AttributeValue{ - ":ImageData": mdAttributeValue, + ":ImageMeta": mdAttributeValue, }, Key: map[string]types.AttributeValue{ "Key": &types.AttributeValueMemberS{ - Value: mConvert.GetImageDigestStr(protoImageData), + Value: mConvert.GetImageDigestStr(protoImageMeta), }, }, - TableName: aws.String(dwr.ImageDataTablename), - UpdateExpression: aws.String("SET #ID = :ImageData"), + TableName: aws.String(dwr.ImageMetaTablename), + UpdateExpression: aws.String("SET #ID = :ImageMeta"), }) return err } -func (dwr *DynamoDB) SetImageData(digest godigest.Digest, imageData mTypes.ImageData) error { - return dwr.SetProtoImageData(imageData.Digest, mConvert.GetProtoImageData(imageData)) +func (dwr *DynamoDB) SetImageMeta(digest godigest.Digest, imageMeta mTypes.ImageMeta) error { + return dwr.SetProtoImageMeta(imageMeta.Digest, mConvert.GetProtoImageMeta(imageMeta)) } -func (dwr *DynamoDB) GetProtoImageData(ctx context.Context, digest godigest.Digest) (*proto_go.ImageData, error) { +func (dwr *DynamoDB) GetProtoImageMeta(ctx context.Context, digest godigest.Digest) (*proto_go.ImageMeta, error) { resp, err := dwr.Client.GetItem(ctx, &dynamodb.GetItemInput{ - TableName: aws.String(dwr.ImageDataTablename), + TableName: aws.String(dwr.ImageMetaTablename), Key: map[string]types.AttributeValue{ "Key": &types.AttributeValueMemberS{Value: digest.String()}, }, @@ -147,22 +147,22 @@ func (dwr *DynamoDB) GetProtoImageData(ctx context.Context, digest godigest.Dige blob := []byte{} if resp.Item == nil { - return nil, zerr.ErrImageDataNotFound + return nil, zerr.ErrImageMetaNotFound } - err = attributevalue.Unmarshal(resp.Item["ImageData"], &blob) + err = attributevalue.Unmarshal(resp.Item["ImageMeta"], &blob) if err != nil { return nil, err } - imageData := &proto_go.ImageData{} + imageMeta := &proto_go.ImageMeta{} - err = proto.Unmarshal(blob, imageData) + err = proto.Unmarshal(blob, imageMeta) if err != nil { return nil, err } - return imageData, nil + return imageMeta, nil } func (dwr *DynamoDB) setProtoRepoMeta(repo string, repoMeta *proto_go.RepoMeta) error { @@ -229,15 +229,15 @@ func (dwr *DynamoDB) getProtoRepoMeta(ctx context.Context, repo string) (*proto_ return repoMeta, nil } -func (dwr *DynamoDB) SetRepoReference(repo string, reference string, imageData mTypes.ImageData) error { - if err := common.ValidateRepoReferenceInput(repo, reference, imageData.Digest); err != nil { +func (dwr *DynamoDB) SetRepoReference(repo string, reference string, imageMeta mTypes.ImageMeta) error { + if err := common.ValidateRepoReferenceInput(repo, reference, imageMeta.Digest); err != nil { return err } // 1. Add image data to db if needed - protoImageData := mConvert.GetProtoImageData(imageData) + protoImageMeta := mConvert.GetProtoImageMeta(imageMeta) - err := dwr.SetProtoImageData(imageData.Digest, protoImageData) + err := dwr.SetProtoImageMeta(imageMeta.Digest, protoImageMeta) if err != nil { return err } @@ -258,7 +258,7 @@ func (dwr *DynamoDB) SetRepoReference(repo string, reference string, imageData m } // 2. Referrers - if subject := mConvert.GetImageSubject(protoImageData); subject != nil { + if subject := mConvert.GetImageSubject(protoImageMeta); subject != nil { refInfo := &proto_go.ReferrersInfo{} if repoMeta.Referrers[subject.Digest.String()] != nil { refInfo = repoMeta.Referrers[subject.Digest.String()] @@ -267,7 +267,7 @@ func (dwr *DynamoDB) SetRepoReference(repo string, reference string, imageData m foundReferrer := false for i := range refInfo.List { - if refInfo.List[i].Digest == mConvert.GetImageDigestStr(protoImageData) { + if refInfo.List[i].Digest == mConvert.GetImageDigestStr(protoImageMeta) { foundReferrer = true refInfo.List[i].Count += 1 @@ -278,11 +278,11 @@ func (dwr *DynamoDB) SetRepoReference(repo string, reference string, imageData m if !foundReferrer { refInfo.List = append(refInfo.List, &proto_go.ReferrerInfo{ Count: 1, - MediaType: protoImageData.MediaType, - Digest: mConvert.GetImageDigestStr(protoImageData), - ArtifactType: mConvert.GetImageArtifactType(protoImageData), - Size: mConvert.GetImageManifestSize(protoImageData), - Annotations: mConvert.GetImageAnnotations(protoImageData), + MediaType: protoImageMeta.MediaType, + Digest: mConvert.GetImageDigestStr(protoImageMeta), + ArtifactType: mConvert.GetImageArtifactType(protoImageMeta), + Size: mConvert.GetImageManifestSize(protoImageMeta), + Annotations: mConvert.GetImageAnnotations(protoImageMeta), }) } @@ -292,23 +292,23 @@ func (dwr *DynamoDB) SetRepoReference(repo string, reference string, imageData m // 3. Update tag if !common.ReferenceIsDigest(reference) { repoMeta.Tags[reference] = &proto_go.TagDescriptor{ - Digest: imageData.Digest.String(), - MediaType: imageData.MediaType, + Digest: imageMeta.Digest.String(), + MediaType: imageMeta.MediaType, } } - if _, ok := repoMeta.Statistics[imageData.Digest.String()]; !ok { - repoMeta.Statistics[imageData.Digest.String()] = &proto_go.DescriptorStatistics{DownloadCount: 0} + if _, ok := repoMeta.Statistics[imageMeta.Digest.String()]; !ok { + repoMeta.Statistics[imageMeta.Digest.String()] = &proto_go.DescriptorStatistics{DownloadCount: 0} } - if _, ok := repoMeta.Signatures[imageData.Digest.String()]; !ok { - repoMeta.Signatures[imageData.Digest.String()] = &proto_go.ManifestSignatures{ + if _, ok := repoMeta.Signatures[imageMeta.Digest.String()]; !ok { + repoMeta.Signatures[imageMeta.Digest.String()] = &proto_go.ManifestSignatures{ Map: map[string]*proto_go.SignaturesInfo{"": {}}, } } - if _, ok := repoMeta.Referrers[imageData.Digest.String()]; !ok { - repoMeta.Referrers[imageData.Digest.String()] = &proto_go.ReferrersInfo{ + if _, ok := repoMeta.Referrers[imageMeta.Digest.String()]; !ok { + repoMeta.Referrers[imageMeta.Digest.String()] = &proto_go.ReferrersInfo{ List: []*proto_go.ReferrerInfo{}, } } @@ -319,7 +319,7 @@ func (dwr *DynamoDB) SetRepoReference(repo string, reference string, imageData m return err } - repoMeta, repoBlobs, err = common.AddImageDataToRepoMeta(repoMeta, repoBlobs, reference, imageData) + repoMeta, repoBlobs, err = common.AddImageMetaToRepoMeta(repoMeta, repoBlobs, reference, imageMeta) if err != nil { return err } @@ -447,25 +447,25 @@ func (dwr *DynamoDB) SearchRepos(ctx context.Context, searchText string) ([]mTyp return repos, nil } -func (dwr *DynamoDB) SearchTags(ctx context.Context, searchText string) ([]mTypes.ImageMeta, error) { - images := []mTypes.ImageMeta{} +func (dwr *DynamoDB) SearchTags(ctx context.Context, searchText string) ([]mTypes.FullImageMeta, error) { + images := []mTypes.FullImageMeta{} userBookmarks := getUserBookmarks(ctx, dwr) userStars := getUserStars(ctx, dwr) searchedRepo, searchedTag, err := common.GetRepoTag(searchText) if err != nil { - return []mTypes.ImageMeta{}, + return []mTypes.FullImageMeta{}, fmt.Errorf("metadb: error while parsing search text, invalid format %w", err) } if ok, err := reqCtx.RepoIsUserAvailable(ctx, searchedRepo); !ok || err != nil { - return []mTypes.ImageMeta{}, err + return []mTypes.FullImageMeta{}, err } protoRepoMeta, err := dwr.getProtoRepoMeta(ctx, searchedRepo) if err != nil { if errors.Is(err, zerr.ErrRepoMetaNotFound) { - return []mTypes.ImageMeta{}, nil + return []mTypes.FullImageMeta{}, nil } return nil, err @@ -481,36 +481,36 @@ func (dwr *DynamoDB) SearchTags(ctx context.Context, searchText string) ([]mType continue } - var protoImageData *proto_go.ImageData + var protoImageMeta *proto_go.ImageMeta switch descriptor.MediaType { case ispec.MediaTypeImageManifest: manifestDigest := descriptor.Digest - imageManifestData, err := dwr.GetProtoImageData(ctx, godigest.Digest(manifestDigest)) + imageManifestData, err := dwr.GetProtoImageMeta(ctx, godigest.Digest(manifestDigest)) if err != nil { - return []mTypes.ImageMeta{}, + return []mTypes.FullImageMeta{}, fmt.Errorf("metadb: error fetching manifest meta for manifest with digest %s %w", manifestDigest, err) } - protoImageData = imageManifestData + protoImageMeta = imageManifestData case ispec.MediaTypeImageIndex: indexDigest := godigest.Digest(descriptor.Digest) - imageIndexData, err := dwr.GetProtoImageData(ctx, indexDigest) + imageIndexData, err := dwr.GetProtoImageMeta(ctx, indexDigest) if err != nil { - return []mTypes.ImageMeta{}, + return []mTypes.FullImageMeta{}, fmt.Errorf("metadb: error fetching manifest meta for manifest with digest %s %w", indexDigest, err) } - manifestDataList := make([]*proto_go.ManifestData, 0, len(imageIndexData.Index.Index.Manifests)) + manifestDataList := make([]*proto_go.ManifestMeta, 0, len(imageIndexData.Index.Index.Manifests)) for _, manifest := range imageIndexData.Index.Index.Manifests { manifestDigest := godigest.Digest(manifest.Digest) - imageManifestData, err := dwr.GetProtoImageData(ctx, manifestDigest) + imageManifestData, err := dwr.GetProtoImageMeta(ctx, manifestDigest) if err != nil { - return []mTypes.ImageMeta{}, err + return []mTypes.FullImageMeta{}, err } manifestDataList = append(manifestDataList, imageManifestData.Manifests[0]) @@ -518,14 +518,14 @@ func (dwr *DynamoDB) SearchTags(ctx context.Context, searchText string) ([]mType imageIndexData.Manifests = manifestDataList - protoImageData = imageIndexData + protoImageMeta = imageIndexData default: dwr.Log.Error().Str("mediaType", descriptor.MediaType).Msg("Unsupported media type") continue } - images = append(images, mConvert.GetImageMetaFromProto(tag, protoRepoMeta, protoImageData)) + images = append(images, mConvert.GetFullImageMetaFromProto(tag, protoRepoMeta, protoImageMeta)) } return images, err @@ -533,8 +533,8 @@ func (dwr *DynamoDB) SearchTags(ctx context.Context, searchText string) ([]mType func (dwr *DynamoDB) FilterTags(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, -) ([]mTypes.ImageMeta, error) { - images := []mTypes.ImageMeta{} +) ([]mTypes.FullImageMeta, error) { + images := []mTypes.FullImageMeta{} userBookmarks := getUserBookmarks(ctx, dwr) userStars := getUserStars(ctx, dwr) @@ -577,43 +577,43 @@ func (dwr *DynamoDB) FilterTags(ctx context.Context, filterRepoTag mTypes.Filter case ispec.MediaTypeImageManifest: manifestDigest := descriptor.Digest - imageManifestData, err := dwr.GetProtoImageData(ctx, godigest.Digest(manifestDigest)) + imageManifestData, err := dwr.GetProtoImageMeta(ctx, godigest.Digest(manifestDigest)) if err != nil { viewError = errors.Join(viewError, err) continue } - imageData := mConvert.GetImageData(imageManifestData) + imageMeta := mConvert.GetImageMeta(imageManifestData) - if filterFunc(repoMeta, imageData) { - images = append(images, mConvert.GetImageMetaFromProto(tag, protoRepoMeta, imageManifestData)) + if filterFunc(repoMeta, imageMeta) { + images = append(images, mConvert.GetFullImageMetaFromProto(tag, protoRepoMeta, imageManifestData)) } case ispec.MediaTypeImageIndex: indexDigest := descriptor.Digest - imageIndexData, err := dwr.GetProtoImageData(ctx, godigest.Digest(indexDigest)) + imageIndexData, err := dwr.GetProtoImageMeta(ctx, godigest.Digest(indexDigest)) if err != nil { viewError = errors.Join(viewError, err) continue } - matchedManifests := []*proto_go.ManifestData{} + matchedManifests := []*proto_go.ManifestMeta{} for _, manifest := range imageIndexData.Index.Index.Manifests { manifestDigest := manifest.Digest - imageManifestData, err := dwr.GetProtoImageData(ctx, godigest.Digest(manifestDigest)) + imageManifestData, err := dwr.GetProtoImageMeta(ctx, godigest.Digest(manifestDigest)) if err != nil { viewError = errors.Join(viewError, err) continue } - imageData := mConvert.GetImageData(imageManifestData) + imageMeta := mConvert.GetImageMeta(imageManifestData) - if filterFunc(repoMeta, imageData) { + if filterFunc(repoMeta, imageMeta) { matchedManifests = append(matchedManifests, imageManifestData.Manifests[0]) } } @@ -621,7 +621,7 @@ func (dwr *DynamoDB) FilterTags(ctx context.Context, filterRepoTag mTypes.Filter if len(matchedManifests) > 0 { imageIndexData.Manifests = matchedManifests - images = append(images, mConvert.GetImageMetaFromProto(tag, protoRepoMeta, imageIndexData)) + images = append(images, mConvert.GetFullImageMetaFromProto(tag, protoRepoMeta, imageIndexData)) } default: dwr.Log.Error().Str("mediaType", descriptor.MediaType).Msg("Unsupported media type") @@ -654,22 +654,22 @@ func getProtoRepoMetaFromAttribute(repoMetaAttribute types.AttributeValue) (*pro return protoRepoMeta, nil } -func getProtoImageDataFromAttribute(imageDataAttribute types.AttributeValue) (*proto_go.ImageData, error) { +func getProtoImageMetaFromAttribute(imageMetaAttribute types.AttributeValue) (*proto_go.ImageMeta, error) { blob := []byte{} - err := attributevalue.Unmarshal(imageDataAttribute, &blob) + err := attributevalue.Unmarshal(imageMetaAttribute, &blob) if err != nil { return nil, err } - protoImageData := &proto_go.ImageData{} + protoImageMeta := &proto_go.ImageMeta{} - err = proto.Unmarshal(blob, protoImageData) + err = proto.Unmarshal(blob, protoImageMeta) if err != nil { return nil, err } - return protoImageData, nil + return protoImageMeta, nil } func (dwr *DynamoDB) ResetRepoReferences(repo string) error { @@ -705,10 +705,10 @@ func (dwr *DynamoDB) GetRepoMeta(ctx context.Context, repo string) (mTypes.RepoM return mConvert.GetRepoMeta(protoRepoMeta), nil } -func (dwr *DynamoDB) GetImageMeta(ctx context.Context, repo string, tag string) (mTypes.ImageMeta, error) { +func (dwr *DynamoDB) GetFullImageMeta(ctx context.Context, repo string, tag string) (mTypes.FullImageMeta, error) { protoRepoMeta, err := dwr.getProtoRepoMeta(ctx, repo) if err != nil { - return mTypes.ImageMeta{}, err + return mTypes.FullImageMeta{}, err } delete(protoRepoMeta.Tags, "") @@ -720,30 +720,30 @@ func (dwr *DynamoDB) GetImageMeta(ctx context.Context, repo string, tag string) descriptor, ok := protoRepoMeta.Tags[tag] if !ok { - return mTypes.ImageMeta{}, zerr.ErrImageDataNotFound + return mTypes.FullImageMeta{}, zerr.ErrImageMetaNotFound } - protoImageData, err := dwr.GetProtoImageData(ctx, godigest.Digest(descriptor.Digest)) + protoImageMeta, err := dwr.GetProtoImageMeta(ctx, godigest.Digest(descriptor.Digest)) if err != nil { - return mTypes.ImageMeta{}, err + return mTypes.FullImageMeta{}, err } - if protoImageData.MediaType == ispec.MediaTypeImageIndex { - manifestDataList := make([]*proto_go.ManifestData, 0, len(protoImageData.Index.Index.Manifests)) + if protoImageMeta.MediaType == ispec.MediaTypeImageIndex { + manifestDataList := make([]*proto_go.ManifestMeta, 0, len(protoImageMeta.Index.Index.Manifests)) - for _, manifest := range protoImageData.Index.Index.Manifests { - imageManifestData, err := dwr.GetProtoImageData(ctx, godigest.Digest(manifest.Digest)) + for _, manifest := range protoImageMeta.Index.Index.Manifests { + imageManifestData, err := dwr.GetProtoImageMeta(ctx, godigest.Digest(manifest.Digest)) if err != nil { - return mTypes.ImageMeta{}, err + return mTypes.FullImageMeta{}, err } manifestDataList = append(manifestDataList, imageManifestData.Manifests[0]) } - protoImageData.Manifests = manifestDataList + protoImageMeta.Manifests = manifestDataList } - return mConvert.GetImageMetaFromProto(tag, protoRepoMeta, protoImageData), nil + return mConvert.GetFullImageMetaFromProto(tag, protoRepoMeta, protoImageMeta), nil } func (dwr *DynamoDB) getUserBookmarksAndStars(ctx context.Context) ([]string, []string) { @@ -755,30 +755,30 @@ func (dwr *DynamoDB) getUserBookmarksAndStars(ctx context.Context) ([]string, [] return userData.BookmarkedRepos, userData.StarredRepos } -func (dwr *DynamoDB) GetImageData(digest godigest.Digest) (mTypes.ImageData, error) { - protoImageData, err := dwr.GetProtoImageData(context.Background(), digest) +func (dwr *DynamoDB) GetImageMeta(digest godigest.Digest) (mTypes.ImageMeta, error) { + protoImageMeta, err := dwr.GetProtoImageMeta(context.Background(), digest) if err != nil { - return mTypes.ImageData{}, err + return mTypes.ImageMeta{}, err } - if protoImageData.MediaType == ispec.MediaTypeImageIndex { - manifestDataList := make([]*proto_go.ManifestData, 0, len(protoImageData.Index.Index.Manifests)) + if protoImageMeta.MediaType == ispec.MediaTypeImageIndex { + manifestDataList := make([]*proto_go.ManifestMeta, 0, len(protoImageMeta.Index.Index.Manifests)) - for _, manifest := range protoImageData.Index.Index.Manifests { + for _, manifest := range protoImageMeta.Index.Index.Manifests { manifestDigest := godigest.Digest(manifest.Digest) - imageManifestData, err := dwr.GetProtoImageData(context.Background(), manifestDigest) + imageManifestData, err := dwr.GetProtoImageMeta(context.Background(), manifestDigest) if err != nil { - return mTypes.ImageData{}, err + return mTypes.ImageMeta{}, err } manifestDataList = append(manifestDataList, imageManifestData.Manifests[0]) } - protoImageData.Manifests = manifestDataList + protoImageMeta.Manifests = manifestDataList } - return mConvert.GetImageData(protoImageData), nil + return mConvert.GetImageMeta(protoImageMeta), nil } func (dwr *DynamoDB) GetMultipleRepoMeta(ctx context.Context, filter func(repoMeta mTypes.RepoMeta) bool, @@ -977,7 +977,7 @@ func (dwr *DynamoDB) UpdateSignaturesValidity(repo string, manifestDigest godige return nil } - protoImageData, err := dwr.GetProtoImageData(context.Background(), manifestDigest) + protoImageMeta, err := dwr.GetProtoImageMeta(context.Background(), manifestDigest) if err != nil { return err } @@ -998,7 +998,7 @@ func (dwr *DynamoDB) UpdateSignaturesValidity(repo string, manifestDigest godige for _, layerInfo := range sigInfo.LayersInfo { author, date, isTrusted, _ := imgTrustStore.VerifySignature(sigType, layerInfo.LayerContent, - layerInfo.SignatureKey, manifestDigest, mConvert.GetImageData(protoImageData), repo) + layerInfo.SignatureKey, manifestDigest, mConvert.GetImageMeta(protoImageMeta), repo) if isTrusted { layerInfo.Signer = author @@ -1130,36 +1130,36 @@ func (dwr *DynamoDB) DeleteSignature(repo string, signedManifestDigest godigest. return dwr.setProtoRepoMeta(protoRepoMeta.Name, protoRepoMeta) } -func (dwr *DynamoDB) FilterImageData(ctx context.Context, digests []string, -) (map[string]mTypes.ImageData, error) { - imageDataAttributes, err := dwr.fetchImageDataAttributesByDigest(ctx, digests) +func (dwr *DynamoDB) FilterImageMeta(ctx context.Context, digests []string, +) (map[string]mTypes.ImageMeta, error) { + imageMetaAttributes, err := dwr.fetchImageMetaAttributesByDigest(ctx, digests) if err != nil { return nil, err } - results := map[string]mTypes.ImageData{} + results := map[string]mTypes.ImageMeta{} - for _, attributes := range imageDataAttributes { - protoImageData, err := getProtoImageDataFromAttribute(attributes["ImageData"]) + for _, attributes := range imageMetaAttributes { + protoImageMeta, err := getProtoImageMetaFromAttribute(attributes["ImageMeta"]) if err != nil { return nil, err } - if protoImageData.MediaType == ispec.MediaTypeImageIndex { - manifestDataList := make([]*proto_go.ManifestData, 0, len(protoImageData.Index.Index.Manifests)) + if protoImageMeta.MediaType == ispec.MediaTypeImageIndex { + manifestDataList := make([]*proto_go.ManifestMeta, 0, len(protoImageMeta.Index.Index.Manifests)) - indexDigests := make([]string, 0, len(protoImageData.Index.Index.Manifests)) - for i := range protoImageData.Index.Index.Manifests { - indexDigests = append(indexDigests, protoImageData.Index.Index.Manifests[i].Digest) + indexDigests := make([]string, 0, len(protoImageMeta.Index.Index.Manifests)) + for i := range protoImageMeta.Index.Index.Manifests { + indexDigests = append(indexDigests, protoImageMeta.Index.Index.Manifests[i].Digest) } - manifestsAttributes, err := dwr.fetchImageDataAttributesByDigest(ctx, indexDigests) + manifestsAttributes, err := dwr.fetchImageMetaAttributesByDigest(ctx, indexDigests) if err != nil { return nil, err } for _, manifestAttribute := range manifestsAttributes { - imageManifestData, err := getProtoImageDataFromAttribute(manifestAttribute["ImageData"]) + imageManifestData, err := getProtoImageMetaFromAttribute(manifestAttribute["ImageMeta"]) if err != nil { return nil, err } @@ -1167,10 +1167,10 @@ func (dwr *DynamoDB) FilterImageData(ctx context.Context, digests []string, manifestDataList = append(manifestDataList, imageManifestData.Manifests[0]) } - protoImageData.Manifests = manifestDataList + protoImageMeta.Manifests = manifestDataList } - results[mConvert.GetImageDigestStr(protoImageData)] = mConvert.GetImageData(protoImageData) + results[mConvert.GetImageDigestStr(protoImageMeta)] = mConvert.GetImageMeta(protoImageMeta) } return results, nil @@ -1187,9 +1187,9 @@ func (dwr *DynamoDB) RemoveRepoReference(repo, reference string, manifestDigest return err } - protoImageData, err := dwr.GetProtoImageData(context.TODO(), manifestDigest) + protoImageMeta, err := dwr.GetProtoImageMeta(context.TODO(), manifestDigest) if err != nil { - if errors.Is(err, zerr.ErrImageDataNotFound) { + if errors.Is(err, zerr.ErrImageMetaNotFound) { return nil } @@ -1197,7 +1197,7 @@ func (dwr *DynamoDB) RemoveRepoReference(repo, reference string, manifestDigest } // Remove Referrers - if subject := mConvert.GetImageSubject(protoImageData); subject != nil { + if subject := mConvert.GetImageSubject(protoImageMeta); subject != nil { referredDigest := subject.Digest.String() refInfo := &proto_go.ReferrersInfo{} @@ -1787,11 +1787,11 @@ func (dwr DynamoDB) DeleteUserData(ctx context.Context) error { return err } -func (dwr *DynamoDB) fetchImageDataAttributesByDigest(ctx context.Context, digests []string, +func (dwr *DynamoDB) fetchImageMetaAttributesByDigest(ctx context.Context, digests []string, ) ([]map[string]types.AttributeValue, error) { resp, err := dwr.Client.BatchGetItem(ctx, &dynamodb.BatchGetItemInput{ RequestItems: map[string]types.KeysAndAttributes{ - dwr.ImageDataTablename: { + dwr.ImageMetaTablename: { Keys: getBatchImageKeys(digests), }, }, @@ -1800,11 +1800,11 @@ func (dwr *DynamoDB) fetchImageDataAttributesByDigest(ctx context.Context, diges return nil, err } - if len(resp.Responses[dwr.ImageDataTablename]) != len(digests) { - return nil, zerr.ErrImageDataNotFound + if len(resp.Responses[dwr.ImageMetaTablename]) != len(digests) { + return nil, zerr.ErrImageMetaNotFound } - return resp.Responses[dwr.ImageDataTablename], nil + return resp.Responses[dwr.ImageMetaTablename], nil } func getBatchImageKeys(digests []string) []map[string]types.AttributeValue { @@ -1856,7 +1856,7 @@ func (dwr *DynamoDB) ResetDB() error { return err } - err = dwr.ResetTable(dwr.ImageDataTablename) + err = dwr.ResetTable(dwr.ImageMetaTablename) if err != nil { return err } diff --git a/pkg/meta/dynamodb/dynamodb_test.go b/pkg/meta/dynamodb/dynamodb_test.go index c4bf71bf82..4d3b4c6e7e 100644 --- a/pkg/meta/dynamodb/dynamodb_test.go +++ b/pkg/meta/dynamodb/dynamodb_test.go @@ -38,7 +38,7 @@ func TestIterator(t *testing.T) { repoMetaTablename := "RepoMetadataTable" + uuid.String() versionTablename := "Version" + uuid.String() - imageDataTablename := "ImageData" + uuid.String() + imageMetaTablename := "ImageMeta" + uuid.String() repoBlobsTablename := "RepoBlobs" + uuid.String() userDataTablename := "UserDataTable" + uuid.String() apiKeyTablename := "ApiKeyTable" + uuid.String() @@ -50,7 +50,7 @@ func TestIterator(t *testing.T) { Endpoint: endpoint, Region: region, RepoMetaTablename: repoMetaTablename, - ImageDataTablename: imageDataTablename, + ImageMetaTablename: imageMetaTablename, RepoBlobsInfoTablename: repoBlobsTablename, VersionTablename: versionTablename, APIKeyTablename: apiKeyTablename, @@ -62,16 +62,16 @@ func TestIterator(t *testing.T) { dynamoWrapper, err := mdynamodb.New(client, params, log) So(err, ShouldBeNil) - So(dynamoWrapper.ResetTable(dynamoWrapper.ImageDataTablename), ShouldBeNil) + So(dynamoWrapper.ResetTable(dynamoWrapper.ImageMetaTablename), ShouldBeNil) So(dynamoWrapper.ResetTable(dynamoWrapper.RepoMetaTablename), ShouldBeNil) - err = dynamoWrapper.SetRepoReference("repo1", "tag1", CreateRandomImage().AsImageData()) + err = dynamoWrapper.SetRepoReference("repo1", "tag1", CreateRandomImage().AsImageMeta()) So(err, ShouldBeNil) - err = dynamoWrapper.SetRepoReference("repo2", "tag2", CreateRandomImage().AsImageData()) + err = dynamoWrapper.SetRepoReference("repo2", "tag2", CreateRandomImage().AsImageMeta()) So(err, ShouldBeNil) - err = dynamoWrapper.SetRepoReference("repo3", "tag3", CreateRandomImage().AsImageData()) + err = dynamoWrapper.SetRepoReference("repo3", "tag3", CreateRandomImage().AsImageMeta()) So(err, ShouldBeNil) repoMetaAttributeIterator := mdynamodb.NewBaseDynamoAttributesIterator( @@ -144,7 +144,7 @@ func TestWrapperErrors(t *testing.T) { userDataTablename := "UserDataTable" + uuid.String() apiKeyTablename := "ApiKeyTable" + uuid.String() wrongTableName := "WRONG Tables" - imageDataTablename := "ImageData" + uuid.String() + imageMetaTablename := "ImageMeta" + uuid.String() repoBlobsTablename := "RepoBlobs" + uuid.String() log := log.NewLogger("debug", "") @@ -154,7 +154,7 @@ func TestWrapperErrors(t *testing.T) { Endpoint: endpoint, Region: region, RepoMetaTablename: repoMetaTablename, - ImageDataTablename: imageDataTablename, + ImageMetaTablename: imageMetaTablename, RepoBlobsInfoTablename: repoBlobsTablename, UserDataTablename: userDataTablename, APIKeyTablename: apiKeyTablename, @@ -172,7 +172,7 @@ func TestWrapperErrors(t *testing.T) { dynamoWrapper.SetImageTrustStore(imgTrustStore) So(dynamoWrapper.ResetTable(dynamoWrapper.RepoMetaTablename), ShouldBeNil) //nolint:contextcheck - So(dynamoWrapper.ResetTable(dynamoWrapper.ImageDataTablename), ShouldBeNil) //nolint:contextcheck + So(dynamoWrapper.ResetTable(dynamoWrapper.ImageMetaTablename), ShouldBeNil) //nolint:contextcheck So(dynamoWrapper.ResetTable(dynamoWrapper.UserDataTablename), ShouldBeNil) //nolint:contextcheck userAc := reqCtx.NewUserAccessControl() @@ -515,7 +515,7 @@ func TestWrapperErrors(t *testing.T) { Endpoint: endpoint, Region: region, RepoMetaTablename: "", - ImageDataTablename: imageDataTablename, + ImageMetaTablename: imageMetaTablename, RepoBlobsInfoTablename: repoBlobsTablename, UserDataTablename: userDataTablename, APIKeyTablename: apiKeyTablename, @@ -531,7 +531,7 @@ func TestWrapperErrors(t *testing.T) { Endpoint: endpoint, Region: region, RepoMetaTablename: repoMetaTablename, - ImageDataTablename: imageDataTablename, + ImageMetaTablename: imageMetaTablename, RepoBlobsInfoTablename: repoBlobsTablename, UserDataTablename: userDataTablename, APIKeyTablename: apiKeyTablename, @@ -547,7 +547,7 @@ func TestWrapperErrors(t *testing.T) { Endpoint: endpoint, Region: region, RepoMetaTablename: repoMetaTablename, - ImageDataTablename: imageDataTablename, + ImageMetaTablename: imageMetaTablename, RepoBlobsInfoTablename: repoBlobsTablename, VersionTablename: versionTablename, UserDataTablename: "", @@ -563,7 +563,7 @@ func TestWrapperErrors(t *testing.T) { Endpoint: endpoint, Region: region, RepoMetaTablename: repoMetaTablename, - ImageDataTablename: imageDataTablename, + ImageMetaTablename: imageMetaTablename, RepoBlobsInfoTablename: repoBlobsTablename, VersionTablename: versionTablename, UserDataTablename: userDataTablename, diff --git a/pkg/meta/dynamodb/parameters.go b/pkg/meta/dynamodb/parameters.go index 573df3df5d..48ecacd142 100644 --- a/pkg/meta/dynamodb/parameters.go +++ b/pkg/meta/dynamodb/parameters.go @@ -9,7 +9,7 @@ import ( ) type DBDriverParameters struct { - Endpoint, Region, RepoMetaTablename, RepoBlobsInfoTablename, ImageDataTablename, + Endpoint, Region, RepoMetaTablename, RepoBlobsInfoTablename, ImageMetaTablename, UserDataTablename, APIKeyTablename, VersionTablename string } diff --git a/pkg/meta/meta.go b/pkg/meta/meta.go index ab1619352c..ef685676e8 100644 --- a/pkg/meta/meta.go +++ b/pkg/meta/meta.go @@ -84,7 +84,7 @@ func getDynamoParams(cacheDriverConfig map[string]interface{}, log log.Logger) m repoBlobsInfoTablename, ok := toStringIfOk(cacheDriverConfig, "repoblobsinfotablename", log) allParametersOk = allParametersOk && ok - imageDataTablename, ok := toStringIfOk(cacheDriverConfig, "imagedatatablename", log) + imageMetaTablename, ok := toStringIfOk(cacheDriverConfig, "imagemetatablename", log) allParametersOk = allParametersOk && ok apiKeyTablename, ok := toStringIfOk(cacheDriverConfig, "apikeytablename", log) @@ -105,7 +105,7 @@ func getDynamoParams(cacheDriverConfig map[string]interface{}, log log.Logger) m Region: region, RepoMetaTablename: repoMetaTablename, RepoBlobsInfoTablename: repoBlobsInfoTablename, - ImageDataTablename: imageDataTablename, + ImageMetaTablename: imageMetaTablename, UserDataTablename: userDataTablename, APIKeyTablename: apiKeyTablename, VersionTablename: versionTablename, diff --git a/pkg/meta/meta_test.go b/pkg/meta/meta_test.go index 67ed97e4e9..527995653d 100644 --- a/pkg/meta/meta_test.go +++ b/pkg/meta/meta_test.go @@ -109,7 +109,7 @@ func TestDynamoDBWrapper(t *testing.T) { versionTablename := "Version" + uuid.String() userDataTablename := "UserDataTable" + uuid.String() apiKeyTablename := "ApiKeyTable" + uuid.String() - imageDataTablename := "ImageData" + uuid.String() + imageMetaTablename := "ImageMeta" + uuid.String() repoBlobsTablename := "RepoBlobs" + uuid.String() Convey("DynamoDB Wrapper", t, func() { @@ -117,7 +117,7 @@ func TestDynamoDBWrapper(t *testing.T) { Endpoint: os.Getenv("DYNAMODBMOCK_ENDPOINT"), RepoMetaTablename: repoMetaTablename, RepoBlobsInfoTablename: repoBlobsTablename, - ImageDataTablename: imageDataTablename, + ImageMetaTablename: imageMetaTablename, VersionTablename: versionTablename, UserDataTablename: userDataTablename, APIKeyTablename: apiKeyTablename, @@ -144,7 +144,7 @@ func TestDynamoDBWrapper(t *testing.T) { return err } - err = dynamoDriver.ResetTable(dynamoDriver.ImageDataTablename) + err = dynamoDriver.ResetTable(dynamoDriver.ImageMetaTablename) if err != nil { return err } @@ -462,28 +462,28 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Test Setting an image by tag and retrieving data", func() { - imgData := CreateDefaultImage().AsImageData() + imgData := CreateDefaultImage().AsImageMeta() - err := metaDB.SetImageData(imgData.Digest, imgData) + err := metaDB.SetImageMeta(imgData.Digest, imgData) So(err, ShouldBeNil) - retrievedImgData, err := metaDB.GetImageData(imgData.Digest) + retrievedImgData, err := metaDB.GetImageMeta(imgData.Digest) So(err, ShouldBeNil) So(imgData, ShouldResemble, retrievedImgData) imgMulti := CreateRandomMultiarch() for i := range imgMulti.Images { - err = metaDB.SetImageData(imgMulti.Images[i].Digest(), imgMulti.Images[i].AsImageData()) + err = metaDB.SetImageMeta(imgMulti.Images[i].Digest(), imgMulti.Images[i].AsImageMeta()) So(err, ShouldBeNil) } - err = metaDB.SetImageData(imgMulti.Digest(), imgMulti.AsImageData()) + err = metaDB.SetImageMeta(imgMulti.Digest(), imgMulti.AsImageMeta()) So(err, ShouldBeNil) - retrievedImgMultiData, err := metaDB.GetImageData(imgMulti.Digest()) + retrievedImgMultiData, err := metaDB.GetImageMeta(imgMulti.Digest()) So(err, ShouldBeNil) - So(imgMulti.AsImageData(), ShouldEqual, retrievedImgMultiData) + So(imgMulti.AsImageMeta(), ShouldEqual, retrievedImgMultiData) }) Convey("Test SetRepoReference", func() { @@ -496,12 +496,12 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func img1 := CreateImageWith().RandomLayers(2, 10).RandomConfig(). Annotations(map[string]string{"test": "annotation"}).Build() - imgData1 := img1.AsImageData() + imgData1 := img1.AsImageMeta() img1Size := img1.ConfigDescriptor.Size + img1.ManifestDescriptor.Size + 2*10 img2 := CreateImageWith().LayerBlobs(img1.Layers).RandomConfig(). Annotations(map[string]string{"test": "annotation"}).Build() - imgData2 := img2.AsImageData() + imgData2 := img2.AsImageMeta() img2Size := img2.ConfigDescriptor.Size + img2.ManifestDescriptor.Size + 2*10 multiImages := []Image{ @@ -535,11 +535,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func for i := range imgMulti.Images { err := metaDB.SetRepoReference(repo1, imgMulti.Images[i].DigestStr(), - imgMulti.Images[i].AsImageData()) + imgMulti.Images[i].AsImageMeta()) So(err, ShouldBeNil) } - err = metaDB.SetRepoReference(repo1, tag1, imgMulti.AsImageData()) + err = metaDB.SetRepoReference(repo1, tag1, imgMulti.AsImageMeta()) So(err, ShouldBeNil) image1TotalSize := multiImages[0].ManifestDescriptor.Size + multiImages[0].ConfigDescriptor.Size + 2*10 @@ -578,12 +578,12 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ImageConfig(ispec.Image{Platform: ispec.Platform{OS: "os1", Architecture: "arch1"}}). Annotations(map[string]string{ispec.AnnotationVendor: "vendor1"}). Build() - imageData1 := image1.AsImageData() + imageMeta1 := image1.AsImageMeta() layersSize := int64(2 * 10) - image1Size := imageData1.Manifests[0].Size + imageData1.Manifests[0].Manifest.Config.Size + layersSize + image1Size := imageMeta1.Manifests[0].Size + imageMeta1.Manifests[0].Manifest.Config.Size + layersSize - err := metaDB.SetRepoReference(repo1, tag1, imageData1) + err := metaDB.SetRepoReference(repo1, tag1, imageMeta1) So(err, ShouldBeNil) repoMeta, err := metaDB.GetRepoMeta(ctx, repo1) @@ -597,12 +597,12 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ImageConfig(ispec.Image{Platform: ispec.Platform{OS: "os2", Architecture: "arch2"}}). Annotations(map[string]string{ispec.AnnotationVendor: "vendor2"}). Build() - imageData2 := image2.AsImageData() + imageMeta2 := image2.AsImageMeta() // the layers are the same so we add them once repoSize := image1Size + image2.ManifestDescriptor.Size + image2.ConfigDescriptor.Size - err = metaDB.SetRepoReference(repo1, tag2, imageData2) + err = metaDB.SetRepoReference(repo1, tag2, imageMeta2) So(err, ShouldBeNil) repoMeta, err = metaDB.GetRepoMeta(ctx, repo1) @@ -629,27 +629,27 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ImageConfig(ispec.Image{Platform: ispec.Platform{OS: "os1", Architecture: "arch1"}}). Annotations(map[string]string{ispec.AnnotationVendor: "vendor1"}). Build() - imageData1 := image1.AsImageData() - image1Size := imageData1.Manifests[0].Size + imageData1.Manifests[0].Manifest.Config.Size + layersSize + imageMeta1 := image1.AsImageMeta() + image1Size := imageMeta1.Manifests[0].Size + imageMeta1.Manifests[0].Manifest.Config.Size + layersSize image2 := CreateImageWith(). LayerBlobs(image1.Layers). ImageConfig(ispec.Image{Platform: ispec.Platform{OS: "os2", Architecture: "arch2"}}). Annotations(map[string]string{ispec.AnnotationVendor: "vendor2", "annotation": "test"}). Build() - imageData2 := image2.AsImageData() - image2Size := imageData2.Manifests[0].Size + imageData2.Manifests[0].Manifest.Config.Size + layersSize + imageMeta2 := image2.AsImageMeta() + image2Size := imageMeta2.Manifests[0].Size + imageMeta2.Manifests[0].Manifest.Config.Size + layersSize totalRepoSize := image1Size + image2Size - layersSize - err := metaDB.SetRepoReference(repo, tag1, imageData1) + err := metaDB.SetRepoReference(repo, tag1, imageMeta1) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo, tag2, imageData2) + err = metaDB.SetRepoReference(repo, tag2, imageMeta2) So(err, ShouldBeNil) Convey("Delete reference from repo", func() { - err = metaDB.RemoveRepoReference(repo, tag1, imageData1.Digest) + err = metaDB.RemoveRepoReference(repo, tag1, imageMeta1.Digest) So(err, ShouldBeNil) repoMeta, err := metaDB.GetRepoMeta(ctx, repo) @@ -663,7 +663,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Delete a digest from repo", func() { - err = metaDB.RemoveRepoReference(repo, tag2, imageData2.Digest) + err = metaDB.RemoveRepoReference(repo, tag2, imageMeta2.Digest) So(err, ShouldBeNil) repoMeta, err := metaDB.GetRepoMeta(ctx, repo) @@ -684,8 +684,8 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func repoMeta, err := metaDB.GetRepoMeta(ctx, repo) So(err, ShouldBeNil) - So(repoMeta.Tags[tag1].Digest, ShouldResemble, imageData1.Digest.String()) - So(repoMeta.Tags[tag2].Digest, ShouldResemble, imageData2.Digest.String()) + So(repoMeta.Tags[tag1].Digest, ShouldResemble, imageMeta1.Digest.String()) + So(repoMeta.Tags[tag2].Digest, ShouldResemble, imageMeta2.Digest.String()) So(repoMeta.Size, ShouldEqual, totalRepoSize) }) @@ -698,8 +698,8 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func repoMeta, err := metaDB.GetRepoMeta(ctx, repo) So(err, ShouldBeNil) - So(repoMeta.Tags[tag1].Digest, ShouldResemble, imageData1.Digest.String()) - So(repoMeta.Tags[tag2].Digest, ShouldResemble, imageData2.Digest.String()) + So(repoMeta.Tags[tag1].Digest, ShouldResemble, imageMeta1.Digest.String()) + So(repoMeta.Tags[tag2].Digest, ShouldResemble, imageMeta2.Digest.String()) So(repoMeta.Size, ShouldEqual, totalRepoSize) }) }) @@ -717,22 +717,22 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ImageConfig(ispec.Image{Platform: ispec.Platform{OS: "os1", Architecture: "arch1"}}). Annotations(map[string]string{ispec.AnnotationVendor: "vendor1"}). Build() - imageData1 := image1.AsImageData() + imageMeta1 := image1.AsImageMeta() image2 := CreateImageWith(). LayerBlobs(image1.Layers). ImageConfig(ispec.Image{Platform: ispec.Platform{OS: "os2", Architecture: "arch2"}}). Annotations(map[string]string{ispec.AnnotationVendor: "vendor2"}). Build() - imageData2 := image2.AsImageData() + imageMeta2 := image2.AsImageMeta() - err := metaDB.SetRepoReference(repo1, tag1, imageData1) + err := metaDB.SetRepoReference(repo1, tag1, imageMeta1) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, tag2, imageData2) + err = metaDB.SetRepoReference(repo1, tag2, imageMeta2) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo2, tag2, imageData2) + err = metaDB.SetRepoReference(repo2, tag2, imageMeta2) So(err, ShouldBeNil) Convey("Get all RepoMeta", func() { @@ -755,7 +755,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) So(err, ShouldBeNil) So(len(repoMetaSlice), ShouldEqual, 1) - So(repoMetaSlice[0].Tags[tag1].Digest == imageData1.Digest.String(), ShouldBeTrue) + So(repoMetaSlice[0].Tags[tag1].Digest == imageMeta1.Digest.String(), ShouldBeTrue) }) }) @@ -763,10 +763,10 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func var ( repo1 = "repo1" tag1 = "0.0.1" - imageData = CreateDefaultImage().AsImageData() + imageMeta = CreateDefaultImage().AsImageMeta() ) - err := metaDB.SetRepoReference(repo1, tag1, imageData) + err := metaDB.SetRepoReference(repo1, tag1, imageMeta) So(err, ShouldBeNil) err = metaDB.IncrementRepoStars(repo1) @@ -795,10 +795,10 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func var ( repo1 = "repo1" tag1 = "0.0.1" - imageData = CreateDefaultImage().AsImageData() + imageMeta = CreateDefaultImage().AsImageMeta() ) - err := metaDB.SetRepoReference(repo1, tag1, imageData) + err := metaDB.SetRepoReference(repo1, tag1, imageMeta) So(err, ShouldBeNil) err = metaDB.IncrementRepoStars(repo1) @@ -832,7 +832,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func tag1 = "0.0.1" ) - err := metaDB.SetRepoReference(repo1, tag1, CreateDefaultImage().AsImageData()) + err := metaDB.SetRepoReference(repo1, tag1, CreateDefaultImage().AsImageMeta()) So(err, ShouldBeNil) err = metaDB.IncrementRepoStars(repo1) @@ -890,10 +890,10 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func // anonymous user ctx3 := userAc.DeriveContext(ctx) - err := metaDB.SetRepoReference(repo1, tag1, CreateDefaultImage().AsImageData()) + err := metaDB.SetRepoReference(repo1, tag1, CreateDefaultImage().AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo2, tag1, CreateDefaultImage().AsImageData()) + err = metaDB.SetRepoReference(repo2, tag1, CreateDefaultImage().AsImageMeta()) So(err, ShouldBeNil) repos, err := metaDB.GetStarredRepos(ctx1) @@ -1055,7 +1055,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func repo1 = "repo1" tag1 = "0.0.1" repo2 = "repo2" - image1 = CreateRandomImage().AsImageData() + image1 = CreateRandomImage().AsImageMeta() ) userAc := reqCtx.NewUserAccessControl() @@ -1198,7 +1198,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func var ( repo1 = "repo1" tag1 = "0.0.1" - image1 = CreateRandomImage().AsImageData() + image1 = CreateRandomImage().AsImageMeta() ) err := metaDB.SetRepoReference(repo1, tag1, image1) @@ -1225,7 +1225,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func var ( repo1 = "repo1" tag1 = "0.0.1" - image1 = CreateRandomImage().AsImageData() + image1 = CreateRandomImage().AsImageMeta() ) err := metaDB.SetRepoReference(repo1, tag1, image1) @@ -1243,13 +1243,13 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func So(repoMeta.Signatures[image1.Digest.String()]["cosign"][0].SignatureManifestDigest, ShouldResemble, "digest") - imageData, err := metaDB.GetImageData(image1.Digest) + imageMeta, err := metaDB.GetImageMeta(image1.Digest) - imageMeta := convert.GetImageMeta(tag1, repoMeta, imageData) + fullImageMeta := convert.GetFullImageMeta(tag1, repoMeta, imageMeta) So(err, ShouldBeNil) - So(imageMeta.Signatures["cosign"][0].SignatureManifestDigest, ShouldResemble, "digest") - So(imageMeta.Signatures["cosign"][0].LayersInfo[0].LayerDigest, ShouldResemble, "layer-digest") - So(imageMeta.Signatures["cosign"][0].LayersInfo[0].LayerContent[0], ShouldEqual, 10) + So(fullImageMeta.Signatures["cosign"][0].SignatureManifestDigest, ShouldResemble, "digest") + So(fullImageMeta.Signatures["cosign"][0].LayersInfo[0].LayerDigest, ShouldResemble, "layer-digest") + So(fullImageMeta.Signatures["cosign"][0].LayersInfo[0].LayerContent[0], ShouldEqual, 10) }) Convey("Test UpdateSignaturesValidity", func() { @@ -1260,7 +1260,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func image1 = CreateRandomImage() ) - err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageData()) + err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageMeta()) So(err, ShouldBeNil) layerInfo := mTypes.LayerInfo{LayerDigest: "", LayerContent: []byte{}, SignatureKey: ""} @@ -1287,7 +1287,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func repo := "repo1" tag := "0.0.1" - err := metaDB.SetRepoReference(repo, tag, image1.AsImageData()) + err := metaDB.SetRepoReference(repo, tag, image1.AsImageMeta()) So(err, ShouldBeNil) mediaType := jws.MediaTypeEnvelope @@ -1392,7 +1392,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, tag1, image1.AsImageData()) + err = metaDB.SetRepoReference(repo1, tag1, image1.AsImageMeta()) So(err, ShouldBeNil) repoMeta, err := metaDB.GetRepoMeta(ctx, repo1) @@ -1408,7 +1408,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func image1 = CreateRandomImage() ) - err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageData()) + err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageMeta()) So(err, ShouldBeNil) err = metaDB.AddManifestSignature(repo1, image1.Digest(), mTypes.SignatureMetadata{ @@ -1454,11 +1454,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ) _ = repo3 Convey("Search all repos", func() { - err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageData()) + err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, tag2, image2.AsImageData()) + err = metaDB.SetRepoReference(repo1, tag2, image2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo2, tag3, image3.AsImageData()) + err = metaDB.SetRepoReference(repo2, tag3, image3.AsImageMeta()) So(err, ShouldBeNil) repoMetaList, err := metaDB.SearchRepos(ctx, "") @@ -1471,7 +1471,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Search a repo by name", func() { - err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageData()) + err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageMeta()) So(err, ShouldBeNil) repoMetaList, err := metaDB.SearchRepos(ctx, repo1) @@ -1481,10 +1481,10 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Search non-existing repo by name", func() { - err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageData()) + err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, tag2, image2.AsImageData()) + err = metaDB.SetRepoReference(repo1, tag2, image2.AsImageMeta()) So(err, ShouldBeNil) repoMetaList, err := metaDB.SearchRepos(ctx, "RepoThatDoesntExist") @@ -1493,11 +1493,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Search with partial match", func() { - err := metaDB.SetRepoReference("alpine", tag1, image1.AsImageData()) + err := metaDB.SetRepoReference("alpine", tag1, image1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("pine", tag2, image2.AsImageData()) + err = metaDB.SetRepoReference("pine", tag2, image2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("golang", tag3, image3.AsImageData()) + err = metaDB.SetRepoReference("golang", tag3, image3.AsImageMeta()) So(err, ShouldBeNil) repoMetaList, err := metaDB.SearchRepos(ctx, "pine") @@ -1506,11 +1506,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Search multiple repos that share manifests", func() { - err := metaDB.SetRepoReference("alpine", tag1, image1.AsImageData()) + err := metaDB.SetRepoReference("alpine", tag1, image1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("pine", tag2, image1.AsImageData()) + err = metaDB.SetRepoReference("pine", tag2, image1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("golang", tag3, image1.AsImageData()) + err = metaDB.SetRepoReference("golang", tag3, image1.AsImageMeta()) So(err, ShouldBeNil) repoMetaList, err := metaDB.SearchRepos(ctx, "") @@ -1519,11 +1519,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Search repos with access control", func() { - err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageData()) + err := metaDB.SetRepoReference(repo1, tag1, image1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo2, tag2, image2.AsImageData()) + err = metaDB.SetRepoReference(repo2, tag2, image2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo3, tag3, image3.AsImageData()) + err = metaDB.SetRepoReference(repo3, tag3, image3.AsImageMeta()) So(err, ShouldBeNil) userAc := reqCtx.NewUserAccessControl() @@ -1554,14 +1554,14 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func image1 = CreateRandomImage() ) - err := metaDB.SetRepoReference("repo", subImage1.DigestStr(), subImage1.AsImageData()) + err := metaDB.SetRepoReference("repo", subImage1.DigestStr(), subImage1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", subImage2.DigestStr(), subImage2.AsImageData()) + err = metaDB.SetRepoReference("repo", subImage2.DigestStr(), subImage2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", tag4, multiarch.AsImageData()) + err = metaDB.SetRepoReference("repo", tag4, multiarch.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", tag5, image1.AsImageData()) + err = metaDB.SetRepoReference("repo", tag5, image1.AsImageMeta()) So(err, ShouldBeNil) repoMetaList, err := metaDB.SearchRepos(ctx, "repo") @@ -1586,30 +1586,30 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ctx = context.Background() ) - err := metaDB.SetRepoReference(repo1, "0.0.1", image1.AsImageData()) + err := metaDB.SetRepoReference(repo1, "0.0.1", image1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "0.0.2", image3.AsImageData()) + err = metaDB.SetRepoReference(repo1, "0.0.2", image3.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "0.1.0", image2.AsImageData()) + err = metaDB.SetRepoReference(repo1, "0.1.0", image2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "1.0.0", image2.AsImageData()) + err = metaDB.SetRepoReference(repo1, "1.0.0", image2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "1.0.1", image2.AsImageData()) + err = metaDB.SetRepoReference(repo1, "1.0.1", image2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo2, "0.0.1", image3.AsImageData()) + err = metaDB.SetRepoReference(repo2, "0.0.1", image3.AsImageMeta()) So(err, ShouldBeNil) Convey("With exact match", func() { - imageDataList, err := metaDB.SearchTags(ctx, "repo1:0.0.1") + fullImageMetaList, err := metaDB.SearchTags(ctx, "repo1:0.0.1") So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 1) - So(imageDataList[0].Digest.String(), ShouldResemble, image1.DigestStr()) + So(len(fullImageMetaList), ShouldEqual, 1) + So(fullImageMetaList[0].Digest.String(), ShouldResemble, image1.DigestStr()) }) Convey("With no match", func() { - imageDataList, err := metaDB.SearchTags(ctx, "repo1:badtag") + fullImageMetaList, err := metaDB.SearchTags(ctx, "repo1:badtag") So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 0) + So(len(fullImageMetaList), ShouldEqual, 0) }) Convey("With no permission", func() { @@ -1623,37 +1623,37 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ) ctx1 := userAc.DeriveContext(context.Background()) - imageDataList, err := metaDB.SearchTags(ctx1, "repo1:0.0.1") + fullImageMetaList, err := metaDB.SearchTags(ctx1, "repo1:0.0.1") So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 0) + So(len(fullImageMetaList), ShouldEqual, 0) }) Convey("With partial repo path", func() { - imageDataList, err := metaDB.SearchTags(ctx, "repo:0.0.1") + fullImageMetaList, err := metaDB.SearchTags(ctx, "repo:0.0.1") So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 0) + So(len(fullImageMetaList), ShouldEqual, 0) }) Convey("With partial tag", func() { - imageDataList, err := metaDB.SearchTags(ctx, "repo1:0.0") + fullImageMetaList, err := metaDB.SearchTags(ctx, "repo1:0.0") So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 2) + So(len(fullImageMetaList), ShouldEqual, 2) tags := map[string]struct{}{} - for _, imageData := range imageDataList { - tags[imageData.Tag] = struct{}{} + for _, imageMeta := range fullImageMetaList { + tags[imageMeta.Tag] = struct{}{} } So(tags, ShouldContainKey, "0.0.2") So(tags, ShouldContainKey, "0.0.1") - imageDataList, err = metaDB.SearchTags(ctx, "repo1:0.") + fullImageMetaList, err = metaDB.SearchTags(ctx, "repo1:0.") So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 3) + So(len(fullImageMetaList), ShouldEqual, 3) tags = map[string]struct{}{} - for _, imageData := range imageDataList { - tags[imageData.Tag] = struct{}{} + for _, imageMeta := range fullImageMetaList { + tags[imageMeta.Tag] = struct{}{} } So(tags, ShouldContainKey, "0.0.1") @@ -1662,9 +1662,9 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("With bad query", func() { - imageDataList, err := metaDB.SearchTags(ctx, "repo:0.0.1:test") + fullImageMetaList, err := metaDB.SearchTags(ctx, "repo:0.0.1:test") So(err, ShouldNotBeNil) - So(len(imageDataList), ShouldEqual, 0) + So(len(fullImageMetaList), ShouldEqual, 0) }) Convey("Search with access control", func() { @@ -1677,14 +1677,14 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ctx := userAc.DeriveContext(context.Background()) - imageDataList, err := metaDB.SearchTags(ctx, "repo1:") + fullImageMetaList, err := metaDB.SearchTags(ctx, "repo1:") So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 5) - So(imageDataList[0].Repo, ShouldResemble, repo1) + So(len(fullImageMetaList), ShouldEqual, 5) + So(fullImageMetaList[0].Repo, ShouldResemble, repo1) - imageDataList, err = metaDB.SearchTags(ctx, "repo2:") + fullImageMetaList, err = metaDB.SearchTags(ctx, "repo2:") So(err, ShouldBeNil) - So(imageDataList, ShouldBeEmpty) + So(fullImageMetaList, ShouldBeEmpty) }) Convey("Search Tags with Indexes", func() { @@ -1701,47 +1701,47 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func image6 = CreateRandomImage() ) - err = metaDB.SetRepoReference("repo", subImage1.DigestStr(), subImage1.AsImageData()) + err = metaDB.SetRepoReference("repo", subImage1.DigestStr(), subImage1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", subImage2.DigestStr(), subImage2.AsImageData()) + err = metaDB.SetRepoReference("repo", subImage2.DigestStr(), subImage2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", tag4, multiarch.AsImageData()) + err = metaDB.SetRepoReference("repo", tag4, multiarch.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", tag5, image5.AsImageData()) + err = metaDB.SetRepoReference("repo", tag5, image5.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", tag6, image6.AsImageData()) + err = metaDB.SetRepoReference("repo", tag6, image6.AsImageMeta()) So(err, ShouldBeNil) - imageDataList, err := metaDB.SearchTags(ctx, "repo:0.0") + fullImageMetaList, err := metaDB.SearchTags(ctx, "repo:0.0") So(err, ShouldBeNil) tags := map[string]struct{}{} - for _, imageData := range imageDataList { - tags[imageData.Tag] = struct{}{} + for _, imageMeta := range fullImageMetaList { + tags[imageMeta.Tag] = struct{}{} } - So(len(imageDataList), ShouldEqual, 2) + So(len(fullImageMetaList), ShouldEqual, 2) So(tags, ShouldContainKey, tag4) So(tags, ShouldContainKey, tag5) So(tags, ShouldNotContainKey, tag6) - multiarchImageData := mTypes.ImageMeta{} + multiarchImageMeta := mTypes.FullImageMeta{} found := false - for _, imageData := range imageDataList { - if imageData.MediaType == ispec.MediaTypeImageIndex { - multiarchImageData = imageData + for _, imageMeta := range fullImageMetaList { + if imageMeta.MediaType == ispec.MediaTypeImageIndex { + multiarchImageMeta = imageMeta found = true } } So(found, ShouldBeTrue) - So(len(multiarchImageData.Manifests), ShouldEqual, 2) + So(len(multiarchImageMeta.Manifests), ShouldEqual, 2) digests := []string{} - for _, manifest := range multiarchImageData.Manifests { + for _, manifest := range multiarchImageMeta.Manifests { digests = append(digests, manifest.Digest.String()) } @@ -1764,40 +1764,40 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ctx = context.Background() ) - err := metaDB.SetRepoReference(repo1, subImage1.DigestStr(), subImage1.AsImageData()) + err := metaDB.SetRepoReference(repo1, subImage1.DigestStr(), subImage1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, subImage2.DigestStr(), subImage2.AsImageData()) + err = metaDB.SetRepoReference(repo1, subImage2.DigestStr(), subImage2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "2.0.0", multiarch.AsImageData()) + err = metaDB.SetRepoReference(repo1, "2.0.0", multiarch.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "0.0.1", image1.AsImageData()) + err = metaDB.SetRepoReference(repo1, "0.0.1", image1.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "0.0.2", image3.AsImageData()) + err = metaDB.SetRepoReference(repo1, "0.0.2", image3.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "0.1.0", image2.AsImageData()) + err = metaDB.SetRepoReference(repo1, "0.1.0", image2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "1.0.0", image2.AsImageData()) + err = metaDB.SetRepoReference(repo1, "1.0.0", image2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo1, "1.0.1", image2.AsImageData()) + err = metaDB.SetRepoReference(repo1, "1.0.1", image2.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo2, "0.0.1", image3.AsImageData()) + err = metaDB.SetRepoReference(repo2, "0.0.1", image3.AsImageMeta()) So(err, ShouldBeNil) Convey("Return all tags", func() { - imageDataList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageData) + fullImageMetaList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageMeta) So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 7) + So(len(fullImageMetaList), ShouldEqual, 7) tags := []string{} - indexImage := mTypes.ImageMeta{} + indexImage := mTypes.FullImageMeta{} - for _, imageData := range imageDataList { - tags = append(tags, imageData.Tag) + for _, imageMeta := range fullImageMetaList { + tags = append(tags, imageMeta.Tag) - if imageData.MediaType == ispec.MediaTypeImageIndex { - indexImage = imageData + if imageMeta.MediaType == ispec.MediaTypeImageIndex { + indexImage = imageMeta } } @@ -1821,20 +1821,20 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Return all tags in a specific repo", func() { - imageDataList, err := metaDB.FilterTags(ctx, func(repo, tag string) bool { return repo == repo1 }, - mTypes.AcceptAllImageData) + fullImageMetaList, err := metaDB.FilterTags(ctx, func(repo, tag string) bool { return repo == repo1 }, + mTypes.AcceptAllImageMeta) So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 6) + So(len(fullImageMetaList), ShouldEqual, 6) tags := map[string]struct{}{} - indexImage := mTypes.ImageMeta{} + indexImage := mTypes.FullImageMeta{} - for _, imageData := range imageDataList { - tags[imageData.Tag] = struct{}{} + for _, imageMeta := range fullImageMetaList { + tags[imageMeta.Tag] = struct{}{} - if imageData.MediaType == ispec.MediaTypeImageIndex { - indexImage = imageData + if imageMeta.MediaType == ispec.MediaTypeImageIndex { + indexImage = imageMeta } } @@ -1857,13 +1857,13 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Filter everything out", func() { - imageDataList, err := metaDB.FilterTags(ctx, + fullImageMetaList, err := metaDB.FilterTags(ctx, func(repo, tag string) bool { return false }, - func(repoMeta mTypes.RepoMeta, imageData mTypes.ImageData) bool { return false }, + func(repoMeta mTypes.RepoMeta, imageMeta mTypes.ImageMeta) bool { return false }, ) So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 0) + So(len(fullImageMetaList), ShouldEqual, 0) }) Convey("Search with access control", func() { @@ -1876,19 +1876,19 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ctx := userAc.DeriveContext(context.Background()) - imageDataList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageData) + fullImageMetaList, err := metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageMeta) So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 1) - So(imageDataList[0].Repo, ShouldResemble, repo2) - So(imageDataList[0].Tag, ShouldResemble, "0.0.1") + So(len(fullImageMetaList), ShouldEqual, 1) + So(fullImageMetaList[0].Repo, ShouldResemble, repo2) + So(fullImageMetaList[0].Tag, ShouldResemble, "0.0.1") }) }) Convey("Test Referrers", func() { image1 := CreateRandomImage() - err := metaDB.SetRepoReference("repo", "tag", image1.AsImageData()) + err := metaDB.SetRepoReference("repo", "tag", image1.AsImageMeta()) So(err, ShouldBeNil) // Artifact 1 with artifact type in Manifest @@ -1898,7 +1898,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func Subject(image1.DescriptorRef()). Build() - err = metaDB.SetRepoReference("repo", artifact1.DigestStr(), artifact1.AsImageData()) + err = metaDB.SetRepoReference("repo", artifact1.DigestStr(), artifact1.AsImageMeta()) So(err, ShouldBeNil) // Artifact 2 with artifact type in Config media type @@ -1908,7 +1908,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func Subject(image1.DescriptorRef()). Build() - err = metaDB.SetRepoReference("repo", artifact2.DigestStr(), artifact2.AsImageData()) + err = metaDB.SetRepoReference("repo", artifact2.DigestStr(), artifact2.AsImageMeta()) So(err, ShouldBeNil) // GetReferrers @@ -1953,13 +1953,13 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func image := CreateRandomImage() referrer := CreateRandomImageWith().Subject(image.DescriptorRef()).Build() - err = metaDB.SetRepoReference("repo", tag, image.AsImageData()) + err = metaDB.SetRepoReference("repo", tag, image.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", refTag, referrer.AsImageData()) + err = metaDB.SetRepoReference("repo", refTag, referrer.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", referrer.DigestStr(), referrer.AsImageData()) + err = metaDB.SetRepoReference("repo", referrer.DigestStr(), referrer.AsImageMeta()) So(err, ShouldBeNil) repoMeta, err := metaDB.GetRepoMeta(ctx, "repo") @@ -1991,13 +1991,13 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func image := CreateRandomImage() referrer := CreateRandomImageWith().Subject(image.DescriptorRef()).Build() - err = metaDB.SetRepoReference("repo", tag, image.AsImageData()) + err = metaDB.SetRepoReference("repo", tag, image.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", refTag, referrer.AsImageData()) + err = metaDB.SetRepoReference("repo", refTag, referrer.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", referrer.DigestStr(), referrer.AsImageData()) + err = metaDB.SetRepoReference("repo", referrer.DigestStr(), referrer.AsImageMeta()) So(err, ShouldBeNil) repoMeta, err := metaDB.GetRepoMeta(ctx, "repo") @@ -2021,13 +2021,13 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func image := CreateRandomImage() referrer := CreateRandomImageWith().Subject(image.DescriptorRef()).Build() - err = metaDB.SetRepoReference("repo", tag, image.AsImageData()) + err = metaDB.SetRepoReference("repo", tag, image.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", referrer.DigestStr(), referrer.AsImageData()) + err = metaDB.SetRepoReference("repo", referrer.DigestStr(), referrer.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", referrer.DigestStr(), referrer.AsImageData()) + err = metaDB.SetRepoReference("repo", referrer.DigestStr(), referrer.AsImageMeta()) So(err, ShouldBeNil) repoMeta, err := metaDB.GetRepoMeta(ctx, "repo") @@ -2040,7 +2040,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func tag := "tag" image := CreateRandomImage() - err := metaDB.SetRepoReference(repo, tag, image.AsImageData()) + err := metaDB.SetRepoReference(repo, tag, image.AsImageMeta()) So(err, ShouldBeNil) referrerWantedType := CreateRandomImageWith(). @@ -2051,9 +2051,9 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ArtifactType("not-wanted-type"). Subject(image.DescriptorRef()).Build() - err = metaDB.SetRepoReference(repo, referrerWantedType.DigestStr(), referrerWantedType.AsImageData()) + err = metaDB.SetRepoReference(repo, referrerWantedType.DigestStr(), referrerWantedType.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo, referrerNotWantedType.DigestStr(), referrerNotWantedType.AsImageData()) + err = metaDB.SetRepoReference(repo, referrerNotWantedType.DigestStr(), referrerNotWantedType.AsImageMeta()) So(err, ShouldBeNil) referrerInfo, err := metaDB.GetReferrersInfo("repo", image.Digest(), []string{"wanted-type"}) @@ -2063,20 +2063,20 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func So(referrerInfo[0].Digest, ShouldResemble, referrerWantedType.DigestStr()) }) - Convey("FilterImageData", func() { + Convey("FilterImageMeta", func() { repo := "repo" tag := "tag" Convey("Just manifests", func() { image := CreateRandomImage() - err := metaDB.SetRepoReference(repo, tag, image.AsImageData()) + err := metaDB.SetRepoReference(repo, tag, image.AsImageMeta()) So(err, ShouldBeNil) - imageData, err := metaDB.FilterImageData(ctx, []string{image.DigestStr()}) + imageMeta, err := metaDB.FilterImageMeta(ctx, []string{image.DigestStr()}) So(err, ShouldBeNil) - So(imageData, ShouldContainKey, image.DigestStr()) + So(imageMeta, ShouldContainKey, image.DigestStr()) - _, err = metaDB.FilterImageData(ctx, []string{image.DigestStr(), "bad-digest"}) + _, err = metaDB.FilterImageMeta(ctx, []string{image.DigestStr(), "bad-digest"}) So(err, ShouldNotBeNil) }) @@ -2085,20 +2085,20 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func digests := []string{} for i := range multi.Images { - err := metaDB.SetRepoReference(repo, multi.Images[i].DigestStr(), multi.Images[i].AsImageData()) + err := metaDB.SetRepoReference(repo, multi.Images[i].DigestStr(), multi.Images[i].AsImageMeta()) So(err, ShouldBeNil) digests = append(digests, multi.Images[i].DigestStr()) } - err := metaDB.SetRepoReference(repo, tag, multi.AsImageData()) + err := metaDB.SetRepoReference(repo, tag, multi.AsImageMeta()) So(err, ShouldBeNil) - imageData, err := metaDB.FilterImageData(ctx, []string{multi.DigestStr()}) + imageMeta, err := metaDB.FilterImageMeta(ctx, []string{multi.DigestStr()}) So(err, ShouldBeNil) - So(imageData, ShouldContainKey, multi.DigestStr()) + So(imageMeta, ShouldContainKey, multi.DigestStr()) - actualDigests := tCommon.AccumulateField(imageData[multi.DigestStr()].Manifests, getManifestDigest) + actualDigests := tCommon.AccumulateField(imageMeta[multi.DigestStr()].Manifests, getManifestDigest) So(tCommon.ContainSameElements(actualDigests, digests), ShouldBeTrue) }) }) @@ -2109,9 +2109,9 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func image := CreateRandomImage() referrer := CreateRandomImageWith().Subject(image.DescriptorRef()).Build() - err := metaDB.SetRepoReference(repo, tag, image.AsImageData()) + err := metaDB.SetRepoReference(repo, tag, image.AsImageMeta()) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo, tag, referrer.AsImageData()) + err = metaDB.SetRepoReference(repo, tag, referrer.AsImageMeta()) So(err, ShouldBeNil) repoMeta, err := metaDB.GetRepoMeta(ctx, repo) @@ -2133,7 +2133,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func tag2 := "tag2" image := CreateImageWith().DefaultLayers().PlatformConfig("image-platform", "image-os").Build() - err := metaDB.SetRepoReference(repo, tag1, image.AsImageData()) + err := metaDB.SetRepoReference(repo, tag1, image.AsImageMeta()) So(err, ShouldBeNil) multiarch := CreateMultiarchWith(). @@ -2143,11 +2143,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }).Build() for _, img := range multiarch.Images { - err := metaDB.SetRepoReference(repo, img.DigestStr(), img.AsImageData()) + err := metaDB.SetRepoReference(repo, img.DigestStr(), img.AsImageMeta()) So(err, ShouldBeNil) } - err = metaDB.SetRepoReference(repo, tag2, multiarch.AsImageData()) + err = metaDB.SetRepoReference(repo, tag2, multiarch.AsImageMeta()) So(err, ShouldBeNil) repoMetaList, err := metaDB.FilterRepos(context.Background(), mTypes.AcceptAllRepoNames, @@ -2172,7 +2172,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func image := CreateRandomImage() - err := metaDB.SetRepoReference(repo99, "tag", image.AsImageData()) + err := metaDB.SetRepoReference(repo99, "tag", image.AsImageMeta()) So(err, ShouldBeNil) repoMetaList, err := metaDB.SearchRepos(ctx, repo99) @@ -2181,11 +2181,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func So(repoMetaList[0].IsBookmarked, ShouldBeFalse) So(repoMetaList[0].IsStarred, ShouldBeFalse) - imageDataList, err := metaDB.SearchTags(ctx, repo99+":") + fullImageMetaList, err := metaDB.SearchTags(ctx, repo99+":") So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 1) - So(imageDataList[0].IsBookmarked, ShouldBeFalse) - So(imageDataList[0].IsStarred, ShouldBeFalse) + So(len(fullImageMetaList), ShouldEqual, 1) + So(fullImageMetaList[0].IsBookmarked, ShouldBeFalse) + So(fullImageMetaList[0].IsStarred, ShouldBeFalse) repoMetaList, err = metaDB.FilterRepos(ctx, mTypes.AcceptAllRepoNames, mTypes.AcceptAllRepoMeta) So(err, ShouldBeNil) @@ -2193,11 +2193,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func So(repoMetaList[0].IsBookmarked, ShouldBeFalse) So(repoMetaList[0].IsStarred, ShouldBeFalse) - imageDataList, err = metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageData) + fullImageMetaList, err = metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageMeta) So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 1) - So(imageDataList[0].IsBookmarked, ShouldBeFalse) - So(imageDataList[0].IsStarred, ShouldBeFalse) + So(len(fullImageMetaList), ShouldEqual, 1) + So(fullImageMetaList[0].IsBookmarked, ShouldBeFalse) + So(fullImageMetaList[0].IsStarred, ShouldBeFalse) _, err = metaDB.ToggleBookmarkRepo(ctx, repo99) So(err, ShouldBeNil) @@ -2211,11 +2211,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func So(repoMetaList[0].IsBookmarked, ShouldBeTrue) So(repoMetaList[0].IsStarred, ShouldBeTrue) - imageDataList, err = metaDB.SearchTags(ctx, repo99+":") + fullImageMetaList, err = metaDB.SearchTags(ctx, repo99+":") So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 1) - So(imageDataList[0].IsBookmarked, ShouldBeTrue) - So(imageDataList[0].IsStarred, ShouldBeTrue) + So(len(fullImageMetaList), ShouldEqual, 1) + So(fullImageMetaList[0].IsBookmarked, ShouldBeTrue) + So(fullImageMetaList[0].IsStarred, ShouldBeTrue) repoMetaList, err = metaDB.FilterRepos(ctx, mTypes.AcceptAllRepoNames, mTypes.AcceptAllRepoMeta) So(err, ShouldBeNil) @@ -2223,11 +2223,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func So(repoMetaList[0].IsBookmarked, ShouldBeTrue) So(repoMetaList[0].IsStarred, ShouldBeTrue) - imageDataList, err = metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageData) + fullImageMetaList, err = metaDB.FilterTags(ctx, mTypes.AcceptAllRepoTag, mTypes.AcceptAllImageMeta) So(err, ShouldBeNil) - So(len(imageDataList), ShouldEqual, 1) - So(imageDataList[0].IsBookmarked, ShouldBeTrue) - So(imageDataList[0].IsStarred, ShouldBeTrue) + So(len(fullImageMetaList), ShouldEqual, 1) + So(fullImageMetaList[0].IsBookmarked, ShouldBeTrue) + So(fullImageMetaList[0].IsStarred, ShouldBeTrue) }) Convey("Test GetUserRepoMeta", func() { @@ -2242,7 +2242,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func ctx := userAc.DeriveContext(context.Background()) - err = metaDB.SetRepoReference("repo", "tag", CreateDefaultImage().AsImageData()) + err = metaDB.SetRepoReference("repo", "tag", CreateDefaultImage().AsImageMeta()) So(err, ShouldBeNil) _, err = metaDB.ToggleBookmarkRepo(ctx, "repo") @@ -2289,7 +2289,7 @@ func TestCreateDynamo(t *testing.T) { Endpoint: os.Getenv("DYNAMODBMOCK_ENDPOINT"), RepoMetaTablename: "RepoMetadataTable", RepoBlobsInfoTablename: "RepoBlobs", - ImageDataTablename: "ImageData", + ImageMetaTablename: "ImageMeta", UserDataTablename: "UserDataTable", APIKeyTablename: "ApiKeyTable", VersionTablename: "Version", diff --git a/pkg/meta/parse.go b/pkg/meta/parse.go index a1ab4688d1..cd824de8a5 100644 --- a/pkg/meta/parse.go +++ b/pkg/meta/parse.go @@ -252,7 +252,7 @@ func getNotationSignatureLayersInfo( func SetImageMetaFromInput(repo, reference, mediaType string, digest godigest.Digest, blob []byte, imageStore storageTypes.ImageStore, metaDB mTypes.MetaDB, log log.Logger, ) error { - var imageData mTypes.ImageData + var imageMeta mTypes.ImageMeta switch mediaType { case ispec.MediaTypeImageManifest: @@ -308,7 +308,7 @@ func SetImageMetaFromInput(repo, reference, mediaType string, digest godigest.Di return nil } - imageData = convert.GetImageManifestData(manifestContent, configContent, int64(len(blob)), digest) + imageMeta = convert.GetImageManifestMeta(manifestContent, configContent, int64(len(blob)), digest) case ispec.MediaTypeImageIndex: indexContent := ispec.Index{} @@ -317,12 +317,12 @@ func SetImageMetaFromInput(repo, reference, mediaType string, digest godigest.Di return err } - imageData = convert.GetImageIndexData(indexContent, int64(len(blob)), digest) + imageMeta = convert.GetImageIndexMeta(indexContent, int64(len(blob)), digest) default: return nil } - err := metaDB.SetRepoReference(repo, reference, imageData) + err := metaDB.SetRepoReference(repo, reference, imageMeta) if err != nil { log.Error().Err(err).Msg("metadb: error while putting repo meta") diff --git a/pkg/meta/parse_test.go b/pkg/meta/parse_test.go index b290bdb965..3cce6d77ee 100644 --- a/pkg/meta/parse_test.go +++ b/pkg/meta/parse_test.go @@ -116,7 +116,7 @@ func TestParseStorageErrors(t *testing.T) { } Convey("metaDB.SetRepoReference", func() { - metaDB.SetRepoReferenceFn = func(repo, reference string, imageData mTypes.ImageData) error { + metaDB.SetRepoReferenceFn = func(repo, reference string, imageMeta mTypes.ImageMeta) error { return ErrTestError } @@ -154,7 +154,7 @@ func TestParseStorageDynamoWrapper(t *testing.T) { Region: "us-east-2", RepoMetaTablename: "RepoMetadataTable", RepoBlobsInfoTablename: "RepoBlobsInfoTablename", - ImageDataTablename: "ImageDataTablename", + ImageMetaTablename: "ImageMetaTablename", UserDataTablename: "UserDataTable", APIKeyTablename: "ApiKeyTable", VersionTablename: "Version", @@ -172,7 +172,7 @@ func TestParseStorageDynamoWrapper(t *testing.T) { err = dynamoWrapper.ResetTable(dynamoWrapper.RepoBlobsTablename) So(err, ShouldBeNil) - err = dynamoWrapper.ResetTable(dynamoWrapper.ImageDataTablename) + err = dynamoWrapper.ResetTable(dynamoWrapper.ImageMetaTablename) So(err, ShouldBeNil) RunParseStorageTests(rootDir, dynamoWrapper) @@ -257,7 +257,7 @@ func RunParseStorageTests(rootDir string, metaDB mTypes.MetaDB) { ctx := context.Background() for tag, descriptor := range repos[0].Tags { - imageManifestData, err := metaDB.GetImageMeta(ctx, repo, tag) + imageManifestData, err := metaDB.GetFullImageMeta(ctx, repo, tag) So(err, ShouldBeNil) if descriptor.Digest == signedManifestDigest.String() { @@ -332,7 +332,7 @@ func RunParseStorageTests(rootDir string, metaDB mTypes.MetaDB) { err := WriteImageToFileSystem(image, repo, "tag", storeController) So(err, ShouldBeNil) - err = metaDB.SetRepoReference(repo, "tag", image.AsImageData()) + err = metaDB.SetRepoReference(repo, "tag", image.AsImageMeta()) So(err, ShouldBeNil) err = metaDB.IncrementRepoStars(repo) diff --git a/pkg/meta/proto/meta.proto b/pkg/meta/proto/meta.proto index e959413527..a62c8c88dc 100644 --- a/pkg/meta/proto/meta.proto +++ b/pkg/meta/proto/meta.proto @@ -12,20 +12,20 @@ message TagDescriptor { string Digest = 2; } -message ImageData { +message ImageMeta { string MediaType = 1; - repeated ManifestData Manifests = 2; - optional IndexData Index = 3; + repeated ManifestMeta Manifests = 2; + optional IndexMeta Index = 3; } -message ManifestData { +message ManifestMeta { string Digest = 1; int64 Size = 2; Manifest Manifest = 3; Image Config = 4; } -message IndexData { +message IndexMeta { string Digest = 1; int64 Size = 2; Index Index = 3; diff --git a/pkg/meta/proto_go/config.pb.go b/pkg/meta/proto_go/config.pb.go index df42ec154e..6af260d25b 100644 --- a/pkg/meta/proto_go/config.pb.go +++ b/pkg/meta/proto_go/config.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v3.15.8 +// protoc v4.24.4 // source: config.proto package proto_go diff --git a/pkg/meta/proto_go/descriptor.pb.go b/pkg/meta/proto_go/descriptor.pb.go index 8a39bc8105..ef1a8eabeb 100644 --- a/pkg/meta/proto_go/descriptor.pb.go +++ b/pkg/meta/proto_go/descriptor.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v3.15.8 +// protoc v4.24.4 // source: descriptor.proto package proto_go diff --git a/pkg/meta/proto_go/index.pb.go b/pkg/meta/proto_go/index.pb.go index 34dafa637d..5b2d2d3aad 100644 --- a/pkg/meta/proto_go/index.pb.go +++ b/pkg/meta/proto_go/index.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v3.15.8 +// protoc v4.24.4 // source: index.proto package proto_go diff --git a/pkg/meta/proto_go/manifest.pb.go b/pkg/meta/proto_go/manifest.pb.go index 628c5b809b..18aba395e7 100644 --- a/pkg/meta/proto_go/manifest.pb.go +++ b/pkg/meta/proto_go/manifest.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v3.15.8 +// protoc v4.24.4 // source: manifest.proto package proto_go diff --git a/pkg/meta/proto_go/meta.pb.go b/pkg/meta/proto_go/meta.pb.go index fffff3995f..42c0b60f05 100644 --- a/pkg/meta/proto_go/meta.pb.go +++ b/pkg/meta/proto_go/meta.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v3.15.8 +// protoc v4.24.4 // source: meta.proto package proto_go @@ -76,18 +76,18 @@ func (x *TagDescriptor) GetDigest() string { return "" } -type ImageData struct { +type ImageMeta struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields MediaType string `protobuf:"bytes,1,opt,name=MediaType,proto3" json:"MediaType,omitempty"` - Manifests []*ManifestData `protobuf:"bytes,2,rep,name=Manifests,proto3" json:"Manifests,omitempty"` - Index *IndexData `protobuf:"bytes,3,opt,name=Index,proto3,oneof" json:"Index,omitempty"` + Manifests []*ManifestMeta `protobuf:"bytes,2,rep,name=Manifests,proto3" json:"Manifests,omitempty"` + Index *IndexMeta `protobuf:"bytes,3,opt,name=Index,proto3,oneof" json:"Index,omitempty"` } -func (x *ImageData) Reset() { - *x = ImageData{} +func (x *ImageMeta) Reset() { + *x = ImageMeta{} if protoimpl.UnsafeEnabled { mi := &file_meta_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -95,13 +95,13 @@ func (x *ImageData) Reset() { } } -func (x *ImageData) String() string { +func (x *ImageMeta) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ImageData) ProtoMessage() {} +func (*ImageMeta) ProtoMessage() {} -func (x *ImageData) ProtoReflect() protoreflect.Message { +func (x *ImageMeta) ProtoReflect() protoreflect.Message { mi := &file_meta_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -113,33 +113,33 @@ func (x *ImageData) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ImageData.ProtoReflect.Descriptor instead. -func (*ImageData) Descriptor() ([]byte, []int) { +// Deprecated: Use ImageMeta.ProtoReflect.Descriptor instead. +func (*ImageMeta) Descriptor() ([]byte, []int) { return file_meta_proto_rawDescGZIP(), []int{1} } -func (x *ImageData) GetMediaType() string { +func (x *ImageMeta) GetMediaType() string { if x != nil { return x.MediaType } return "" } -func (x *ImageData) GetManifests() []*ManifestData { +func (x *ImageMeta) GetManifests() []*ManifestMeta { if x != nil { return x.Manifests } return nil } -func (x *ImageData) GetIndex() *IndexData { +func (x *ImageMeta) GetIndex() *IndexMeta { if x != nil { return x.Index } return nil } -type ManifestData struct { +type ManifestMeta struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -150,8 +150,8 @@ type ManifestData struct { Config *Image `protobuf:"bytes,4,opt,name=Config,proto3" json:"Config,omitempty"` } -func (x *ManifestData) Reset() { - *x = ManifestData{} +func (x *ManifestMeta) Reset() { + *x = ManifestMeta{} if protoimpl.UnsafeEnabled { mi := &file_meta_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -159,13 +159,13 @@ func (x *ManifestData) Reset() { } } -func (x *ManifestData) String() string { +func (x *ManifestMeta) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ManifestData) ProtoMessage() {} +func (*ManifestMeta) ProtoMessage() {} -func (x *ManifestData) ProtoReflect() protoreflect.Message { +func (x *ManifestMeta) ProtoReflect() protoreflect.Message { mi := &file_meta_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -177,40 +177,40 @@ func (x *ManifestData) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ManifestData.ProtoReflect.Descriptor instead. -func (*ManifestData) Descriptor() ([]byte, []int) { +// Deprecated: Use ManifestMeta.ProtoReflect.Descriptor instead. +func (*ManifestMeta) Descriptor() ([]byte, []int) { return file_meta_proto_rawDescGZIP(), []int{2} } -func (x *ManifestData) GetDigest() string { +func (x *ManifestMeta) GetDigest() string { if x != nil { return x.Digest } return "" } -func (x *ManifestData) GetSize() int64 { +func (x *ManifestMeta) GetSize() int64 { if x != nil { return x.Size } return 0 } -func (x *ManifestData) GetManifest() *Manifest { +func (x *ManifestMeta) GetManifest() *Manifest { if x != nil { return x.Manifest } return nil } -func (x *ManifestData) GetConfig() *Image { +func (x *ManifestMeta) GetConfig() *Image { if x != nil { return x.Config } return nil } -type IndexData struct { +type IndexMeta struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -220,8 +220,8 @@ type IndexData struct { Index *Index `protobuf:"bytes,3,opt,name=Index,proto3" json:"Index,omitempty"` } -func (x *IndexData) Reset() { - *x = IndexData{} +func (x *IndexMeta) Reset() { + *x = IndexMeta{} if protoimpl.UnsafeEnabled { mi := &file_meta_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -229,13 +229,13 @@ func (x *IndexData) Reset() { } } -func (x *IndexData) String() string { +func (x *IndexMeta) String() string { return protoimpl.X.MessageStringOf(x) } -func (*IndexData) ProtoMessage() {} +func (*IndexMeta) ProtoMessage() {} -func (x *IndexData) ProtoReflect() protoreflect.Message { +func (x *IndexMeta) ProtoReflect() protoreflect.Message { mi := &file_meta_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -247,26 +247,26 @@ func (x *IndexData) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use IndexData.ProtoReflect.Descriptor instead. -func (*IndexData) Descriptor() ([]byte, []int) { +// Deprecated: Use IndexMeta.ProtoReflect.Descriptor instead. +func (*IndexMeta) Descriptor() ([]byte, []int) { return file_meta_proto_rawDescGZIP(), []int{3} } -func (x *IndexData) GetDigest() string { +func (x *IndexMeta) GetDigest() string { if x != nil { return x.Digest } return "" } -func (x *IndexData) GetSize() int64 { +func (x *IndexMeta) GetSize() int64 { if x != nil { return x.Size } return 0 } -func (x *IndexData) GetIndex() *Index { +func (x *IndexMeta) GetIndex() *Index { if x != nil { return x.Index } @@ -1045,17 +1045,17 @@ var file_meta_proto_rawDesc = []byte{ 0x1c, 0x0a, 0x09, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x44, - 0x69, 0x67, 0x65, 0x73, 0x74, 0x22, 0x8d, 0x01, 0x0a, 0x09, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x44, - 0x61, 0x74, 0x61, 0x12, 0x1c, 0x0a, 0x09, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x54, 0x79, 0x70, 0x65, + 0x69, 0x67, 0x65, 0x73, 0x74, 0x22, 0x8d, 0x01, 0x0a, 0x09, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x4d, + 0x65, 0x74, 0x61, 0x12, 0x1c, 0x0a, 0x09, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x54, 0x79, 0x70, 0x65, 0x12, 0x2e, 0x0a, 0x09, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, - 0x73, 0x74, 0x44, 0x61, 0x74, 0x61, 0x52, 0x09, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, + 0x73, 0x74, 0x4d, 0x65, 0x74, 0x61, 0x52, 0x09, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x73, 0x12, 0x28, 0x0a, 0x05, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x0d, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x44, 0x61, 0x74, 0x61, 0x48, + 0x32, 0x0d, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x65, 0x74, 0x61, 0x48, 0x00, 0x52, 0x05, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x88, 0x01, 0x01, 0x42, 0x08, 0x0a, 0x06, 0x5f, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x22, 0x87, 0x01, 0x0a, 0x0c, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, - 0x73, 0x74, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, + 0x73, 0x74, 0x4d, 0x65, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x28, 0x0a, 0x08, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x18, 0x03, @@ -1063,7 +1063,7 @@ var file_meta_proto_rawDesc = []byte{ 0x73, 0x74, 0x52, 0x08, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x52, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x22, - 0x58, 0x0a, 0x09, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, + 0x58, 0x0a, 0x09, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x65, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1f, 0x0a, 0x05, 0x49, 0x6e, 0x64, 0x65, @@ -1234,9 +1234,9 @@ func file_meta_proto_rawDescGZIP() []byte { var file_meta_proto_msgTypes = make([]protoimpl.MessageInfo, 22) var file_meta_proto_goTypes = []interface{}{ (*TagDescriptor)(nil), // 0: v1.TagDescriptor - (*ImageData)(nil), // 1: v1.ImageData - (*ManifestData)(nil), // 2: v1.ManifestData - (*IndexData)(nil), // 3: v1.IndexData + (*ImageMeta)(nil), // 1: v1.ImageMeta + (*ManifestMeta)(nil), // 2: v1.ManifestMeta + (*IndexMeta)(nil), // 3: v1.IndexMeta (*RepoLastUpdatedImage)(nil), // 4: v1.RepoLastUpdatedImage (*RepoMeta)(nil), // 5: v1.RepoMeta (*RepoBlobs)(nil), // 6: v1.RepoBlobs @@ -1262,11 +1262,11 @@ var file_meta_proto_goTypes = []interface{}{ (*Platform)(nil), // 26: v1.Platform } var file_meta_proto_depIdxs = []int32{ - 2, // 0: v1.ImageData.Manifests:type_name -> v1.ManifestData - 3, // 1: v1.ImageData.Index:type_name -> v1.IndexData - 22, // 2: v1.ManifestData.Manifest:type_name -> v1.Manifest - 23, // 3: v1.ManifestData.Config:type_name -> v1.Image - 24, // 4: v1.IndexData.Index:type_name -> v1.Index + 2, // 0: v1.ImageMeta.Manifests:type_name -> v1.ManifestMeta + 3, // 1: v1.ImageMeta.Index:type_name -> v1.IndexMeta + 22, // 2: v1.ManifestMeta.Manifest:type_name -> v1.Manifest + 23, // 3: v1.ManifestMeta.Config:type_name -> v1.Image + 24, // 4: v1.IndexMeta.Index:type_name -> v1.Index 25, // 5: v1.RepoLastUpdatedImage.LastUpdated:type_name -> google.protobuf.Timestamp 15, // 6: v1.RepoMeta.Tags:type_name -> v1.RepoMeta.TagsEntry 16, // 7: v1.RepoMeta.Statistics:type_name -> v1.RepoMeta.StatisticsEntry @@ -1319,7 +1319,7 @@ func file_meta_proto_init() { } } file_meta_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ImageData); i { + switch v := v.(*ImageMeta); i { case 0: return &v.state case 1: @@ -1331,7 +1331,7 @@ func file_meta_proto_init() { } } file_meta_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ManifestData); i { + switch v := v.(*ManifestMeta); i { case 0: return &v.state case 1: @@ -1343,7 +1343,7 @@ func file_meta_proto_init() { } } file_meta_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*IndexData); i { + switch v := v.(*IndexMeta); i { case 0: return &v.state case 1: diff --git a/pkg/meta/proto_go/versioned.pb.go b/pkg/meta/proto_go/versioned.pb.go index e7adcd681d..1d93cf4c67 100644 --- a/pkg/meta/proto_go/versioned.pb.go +++ b/pkg/meta/proto_go/versioned.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v3.15.8 +// protoc v4.24.4 // source: versioned.proto package proto_go diff --git a/pkg/meta/types/types.go b/pkg/meta/types/types.go index ad5e0bd3a5..34d3cd5bbd 100644 --- a/pkg/meta/types/types.go +++ b/pkg/meta/types/types.go @@ -18,9 +18,9 @@ const ( ) type ( - // Currently imageData applied for indexes is applied for each manifest individually so imageData.manifests + // Currently imageMeta applied for indexes is applied for each manifest individually so imageMeta.manifests // contains just 1 manifest. - FilterFunc func(repoMeta RepoMeta, imageData ImageData) bool + FilterFunc func(repoMeta RepoMeta, imageMeta ImageMeta) bool FilterRepoNameFunc func(repo string) bool FilterFullRepoFunc func(repoMeta RepoMeta) bool FilterRepoTagFunc func(repo, tag string) bool @@ -38,7 +38,7 @@ func AcceptAllRepoTag(repo, tag string) bool { return true } -func AcceptAllImageData(repoMeta RepoMeta, imageData ImageData) bool { +func AcceptAllImageMeta(repoMeta RepoMeta, imageMeta ImageMeta) bool { return true } @@ -61,20 +61,20 @@ type ( type MetaDB interface { //nolint:interfacebloat UserDB - SetImageData(digest godigest.Digest, imageData ImageData) error + SetImageMeta(digest godigest.Digest, imageMeta ImageMeta) error // SetRepoReference sets the given image data to the repo metadata. - SetRepoReference(repo string, reference string, imageData ImageData) error + SetRepoReference(repo string, reference string, imageMeta ImageMeta) error // SearchRepos searches for repos given a search string SearchRepos(ctx context.Context, searchText string) ([]RepoMeta, error) // SearchTags searches for images(repo:tag) given a search string - SearchTags(ctx context.Context, searchText string) ([]ImageMeta, error) + SearchTags(ctx context.Context, searchText string) ([]FullImageMeta, error) // FilterTags filters for images given a filter function FilterTags(ctx context.Context, filterRepoTag FilterRepoTagFunc, filterFunc FilterFunc, - ) ([]ImageMeta, error) + ) ([]FullImageMeta, error) // FilterRepos filters for repos given a filter function FilterRepos(ctx context.Context, rankName FilterRepoNameFunc, filterFunc FilterFullRepoFunc, @@ -83,11 +83,11 @@ type MetaDB interface { //nolint:interfacebloat // GetRepoMeta return the full information about a repo GetRepoMeta(ctx context.Context, repo string) (RepoMeta, error) - // GetImageMeta return the full information about an image - GetImageMeta(ctx context.Context, repo string, tag string) (ImageMeta, error) + // GetFullImageMeta return the full information about an image + GetFullImageMeta(ctx context.Context, repo string, tag string) (FullImageMeta, error) - // GetImageData returns the raw information about an image - GetImageData(digest godigest.Digest) (ImageData, error) + // GetImageMeta returns the raw information about an image + GetImageMeta(digest godigest.Digest) (ImageMeta, error) // GetMultipleRepoMeta returns information about all repositories as map[string]RepoMetadata filtered by the filter // function @@ -119,8 +119,8 @@ type MetaDB interface { //nolint:interfacebloat // IncrementImageDownloads adds 1 to the download count of an image IncrementImageDownloads(repo string, reference string) error - // FilterImageData returns the image data for the given digests - FilterImageData(ctx context.Context, digests []string) (map[string]ImageData, error) + // FilterImageMeta returns the image data for the given digests + FilterImageMeta(ctx context.Context, digests []string) (map[string]ImageMeta, error) /* RemoveRepoReference removes the tag from RepoMetadata if the reference is a tag, @@ -132,8 +132,8 @@ type MetaDB interface { //nolint:interfacebloat */ RemoveRepoReference(repo, reference string, manifestDigest godigest.Digest) error - // ResetRepoReferences resets all layout specific data (tags, signatures, referrers, etc.) but keep user specific - // data such as star count and other statistics + // ResetRepoReferences resets all layout specific data (tags, signatures, referrers, etc.) but keep user and image + // specific metadata such as star count, downloads other statistics ResetRepoReferences(repo string) error // ResetDB will delete all data in the DB @@ -185,13 +185,13 @@ type UserDB interface { //nolint:interfacebloat type ImageTrustStore interface { VerifySignature( - signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageData ImageData, + signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageMeta ImageMeta, repo string, ) (string, time.Time, bool, error) } -// ImageData can store all data related to a image, multiarch or simple. Used for writing imaged to MetaDB. -type ImageData struct { +// ImageMeta can store all data related to a image, multiarch or simple. Used for writing imaged to MetaDB. +type ImageMeta struct { MediaType string // MediaType refers to the image descriptor, a manifest or a index (if multiarch) Digest godigest.Digest // Digest refers to the image descriptor, a manifest or a index (if multiarch) Size int64 // Size refers to the image descriptor, a manifest or a index (if multiarch) @@ -228,15 +228,15 @@ type RepoMeta struct { DownloadCount int } -// ImageMeta is a condensed structure of all information needed about an image when searching MetaDB. -type ImageMeta struct { +// FullImageMeta is a condensed structure of all information needed about an image when searching MetaDB. +type FullImageMeta struct { Repo string Tag string MediaType string Digest godigest.Digest Size int64 Index *ispec.Index - Manifests []ManifestMeta + Manifests []FullManifestMeta IsStarred bool IsBookmarked bool @@ -245,7 +245,7 @@ type ImageMeta struct { Signatures ManifestSignatures } -type ManifestMeta struct { +type FullManifestMeta struct { ManifestData Referrers []ReferrerInfo diff --git a/pkg/meta/version/version_test.go b/pkg/meta/version/version_test.go index 8aebee9fc2..e56918d20d 100644 --- a/pkg/meta/version/version_test.go +++ b/pkg/meta/version/version_test.go @@ -128,7 +128,7 @@ func TestVersioningDynamoDB(t *testing.T) { Region: "us-east-2", RepoMetaTablename: "RepoMetadataTable" + uuid.String(), RepoBlobsInfoTablename: "RepoBlobsInfoTablename" + uuid.String(), - ImageDataTablename: "ImageDataTablename" + uuid.String(), + ImageMetaTablename: "ImageMetaTablename" + uuid.String(), UserDataTablename: "UserDataTable" + uuid.String(), APIKeyTablename: "ApiKeyTable" + uuid.String(), VersionTablename: "Version" + uuid.String(), diff --git a/pkg/test/image-utils/images.go b/pkg/test/image-utils/images.go index 2d1e5436a8..3e46ba2d6a 100644 --- a/pkg/test/image-utils/images.go +++ b/pkg/test/image-utils/images.go @@ -140,8 +140,8 @@ func (img Image) DescriptorRef() *ispec.Descriptor { } } -func (img Image) AsImageData() mTypes.ImageData { - return mTypes.ImageData{ +func (img Image) AsImageMeta() mTypes.ImageMeta { + return mTypes.ImageMeta{ MediaType: img.Manifest.MediaType, Digest: img.ManifestDescriptor.Digest, Size: img.ManifestDescriptor.Size, diff --git a/pkg/test/image-utils/multiarch.go b/pkg/test/image-utils/multiarch.go index b4ae59c492..a5926ba7d7 100644 --- a/pkg/test/image-utils/multiarch.go +++ b/pkg/test/image-utils/multiarch.go @@ -30,16 +30,16 @@ func (mi *MultiarchImage) DigestStr() string { return mi.Digest().String() } -func (mi MultiarchImage) AsImageData() mTypes.ImageData { +func (mi MultiarchImage) AsImageMeta() mTypes.ImageMeta { index := mi.Index manifests := make([]mTypes.ManifestData, 0, len(index.Manifests)) for _, image := range mi.Images { - manifests = append(manifests, image.AsImageData().Manifests...) + manifests = append(manifests, image.AsImageMeta().Manifests...) } - return mTypes.ImageData{ + return mTypes.ImageMeta{ MediaType: ispec.MediaTypeImageIndex, Digest: mi.IndexDescriptor.Digest, Size: mi.IndexDescriptor.Size, diff --git a/pkg/test/mocks/repo_db_mock.go b/pkg/test/mocks/repo_db_mock.go index 1a95eb5194..2e1ef0195c 100644 --- a/pkg/test/mocks/repo_db_mock.go +++ b/pkg/test/mocks/repo_db_mock.go @@ -45,17 +45,17 @@ type MetaDBMock struct { SetImageTrustStoreFn func(mTypes.ImageTrustStore) - SetRepoReferenceFn func(repo string, reference string, imageData mTypes.ImageData) error + SetRepoReferenceFn func(repo string, reference string, imageMeta mTypes.ImageMeta) error SearchReposFn func(ctx context.Context, searchText string, ) ([]mTypes.RepoMeta, error) - SearchTagsFn func(ctx context.Context, searchText string) ([]mTypes.ImageMeta, error) + SearchTagsFn func(ctx context.Context, searchText string) ([]mTypes.FullImageMeta, error) FilterTagFn func(ctx context.Context, filterFunc mTypes.FilterFunc, - ) ([]mTypes.RepoMeta, map[string]mTypes.ImageData, error) + ) ([]mTypes.RepoMeta, map[string]mTypes.ImageMeta, error) - GetImageDataFn func(digest godigest.Digest) (mTypes.ImageData, error) + GetImageMetaFn func(digest godigest.Digest) (mTypes.ImageMeta, error) GetMultipleRepoMetaFn func(ctx context.Context, filter func(repoMeta mTypes.RepoMeta) bool, ) ([]mTypes.RepoMeta, error) @@ -85,18 +85,18 @@ type MetaDBMock struct { DeleteSignatureFn func(repo string, signedManifestDigest godigest.Digest, sigMeta mTypes.SignatureMetadata) error - SetImageDataFn func(digest godigest.Digest, imageData mTypes.ImageData) error + SetImageMetaFn func(digest godigest.Digest, imageMeta mTypes.ImageMeta) error FilterTagsFn func(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, - filterFunc mTypes.FilterFunc) ([]mTypes.ImageMeta, error) + filterFunc mTypes.FilterFunc) ([]mTypes.FullImageMeta, error) GetRepoMetaFn func(ctx context.Context, repo string) (mTypes.RepoMeta, error) - FilterImageDataFn func(ctx context.Context, digests []string) (map[string]mTypes.ImageData, error) + FilterImageMetaFn func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) RemoveRepoReferenceFn func(repo, reference string, manifestDigest godigest.Digest) error - GetImageMetaFn func(ctx context.Context, repo string, tag string) (mTypes.ImageMeta, error) + GetFullImageMetaFn func(ctx context.Context, repo string, tag string) (mTypes.FullImageMeta, error) ResetRepoReferencesFn func(repo string) error @@ -253,17 +253,17 @@ func (sdm MetaDBMock) DeleteUserAPIKey(ctx context.Context, id string) error { return nil } -func (sdm MetaDBMock) SetImageData(digest godigest.Digest, imageData mTypes.ImageData) error { - if sdm.SetImageDataFn != nil { - return sdm.SetImageDataFn(digest, imageData) +func (sdm MetaDBMock) SetImageMeta(digest godigest.Digest, imageMeta mTypes.ImageMeta) error { + if sdm.SetImageMetaFn != nil { + return sdm.SetImageMetaFn(digest, imageMeta) } return nil } -func (sdm MetaDBMock) SetRepoReference(repo string, reference string, imageData mTypes.ImageData) error { +func (sdm MetaDBMock) SetRepoReference(repo string, reference string, imageMeta mTypes.ImageMeta) error { if sdm.SetRepoReferenceFn != nil { - return sdm.SetRepoReferenceFn(repo, reference, imageData) + return sdm.SetRepoReferenceFn(repo, reference, imageMeta) } return nil @@ -277,22 +277,22 @@ func (sdm MetaDBMock) SearchRepos(ctx context.Context, searchText string) ([]mTy return []mTypes.RepoMeta{}, nil } -func (sdm MetaDBMock) SearchTags(ctx context.Context, searchText string) ([]mTypes.ImageMeta, error) { +func (sdm MetaDBMock) SearchTags(ctx context.Context, searchText string) ([]mTypes.FullImageMeta, error) { if sdm.SearchTagsFn != nil { return sdm.SearchTagsFn(ctx, searchText) } - return []mTypes.ImageMeta{}, nil + return []mTypes.FullImageMeta{}, nil } func (sdm MetaDBMock) FilterTags(ctx context.Context, filterRepoTag mTypes.FilterRepoTagFunc, filterFunc mTypes.FilterFunc, -) ([]mTypes.ImageMeta, error) { +) ([]mTypes.FullImageMeta, error) { if sdm.FilterTagsFn != nil { return sdm.FilterTagsFn(ctx, filterRepoTag, filterFunc) } - return []mTypes.ImageMeta{}, nil + return []mTypes.FullImageMeta{}, nil } func (sdm MetaDBMock) GetRepoMeta(ctx context.Context, repo string) (mTypes.RepoMeta, error) { @@ -303,12 +303,12 @@ func (sdm MetaDBMock) GetRepoMeta(ctx context.Context, repo string) (mTypes.Repo return mTypes.RepoMeta{}, nil } -func (sdm MetaDBMock) GetImageData(digest godigest.Digest) (mTypes.ImageData, error) { - if sdm.GetImageDataFn != nil { - return sdm.GetImageDataFn(digest) +func (sdm MetaDBMock) GetImageMeta(digest godigest.Digest) (mTypes.ImageMeta, error) { + if sdm.GetImageMetaFn != nil { + return sdm.GetImageMetaFn(digest) } - return mTypes.ImageData{}, nil + return mTypes.ImageMeta{}, nil } func (sdm MetaDBMock) GetMultipleRepoMeta(ctx context.Context, filter func(repoMeta mTypes.RepoMeta) bool, @@ -408,13 +408,13 @@ func (sdm MetaDBMock) DeleteSignature(repo string, signedManifestDigest godigest return nil } -func (sdm MetaDBMock) FilterImageData(ctx context.Context, digests []string, -) (map[string]mTypes.ImageData, error) { - if sdm.FilterImageDataFn != nil { - return sdm.FilterImageDataFn(ctx, digests) +func (sdm MetaDBMock) FilterImageMeta(ctx context.Context, digests []string, +) (map[string]mTypes.ImageMeta, error) { + if sdm.FilterImageMetaFn != nil { + return sdm.FilterImageMetaFn(ctx, digests) } - return map[string]mTypes.ImageData{}, nil + return map[string]mTypes.ImageMeta{}, nil } func (sdm MetaDBMock) RemoveRepoReference(repo, reference string, manifestDigest godigest.Digest) error { @@ -425,13 +425,13 @@ func (sdm MetaDBMock) RemoveRepoReference(repo, reference string, manifestDigest return nil } -func (sdm MetaDBMock) GetImageMeta(ctx context.Context, repo string, tag string, -) (mTypes.ImageMeta, error) { - if sdm.GetImageMetaFn != nil { - return sdm.GetImageMetaFn(ctx, repo, tag) +func (sdm MetaDBMock) GetFullImageMeta(ctx context.Context, repo string, tag string, +) (mTypes.FullImageMeta, error) { + if sdm.GetFullImageMetaFn != nil { + return sdm.GetFullImageMetaFn(ctx, repo, tag) } - return mTypes.ImageMeta{}, nil + return mTypes.FullImageMeta{}, nil } func (sdm MetaDBMock) ResetRepoReferences(repo string) error { diff --git a/pkg/test/oci-utils/repo.go b/pkg/test/oci-utils/repo.go index 5b6b490015..6c726f22a5 100644 --- a/pkg/test/oci-utils/repo.go +++ b/pkg/test/oci-utils/repo.go @@ -46,7 +46,7 @@ func InitializeTestMetaDB(ctx context.Context, metaDB mTypes.MetaDB, repos ...Re statistics := map[string]mTypes.DescriptorStatistics{"": {}} for _, image := range repo.Images { - err := metaDB.SetRepoReference(repo.Name, image.Reference, image.AsImageData()) + err := metaDB.SetRepoReference(repo.Name, image.Reference, image.AsImageMeta()) if err != nil { return uacContext, err } @@ -56,7 +56,7 @@ func InitializeTestMetaDB(ctx context.Context, metaDB mTypes.MetaDB, repos ...Re for _, multiArch := range repo.MultiArchImages { for _, image := range multiArch.Images { - err := metaDB.SetRepoReference(repo.Name, image.DigestStr(), image.AsImageData()) + err := metaDB.SetRepoReference(repo.Name, image.DigestStr(), image.AsImageMeta()) if err != nil { return uacContext, err } @@ -64,7 +64,7 @@ func InitializeTestMetaDB(ctx context.Context, metaDB mTypes.MetaDB, repos ...Re statistics[image.DigestStr()] = multiArch.ImageStatistics[image.DigestStr()] } - err := metaDB.SetRepoReference(repo.Name, multiArch.Reference, multiArch.AsImageData()) + err := metaDB.SetRepoReference(repo.Name, multiArch.Reference, multiArch.AsImageMeta()) if err != nil { return uacContext, err } diff --git a/test/blackbox/cloud_only.bats b/test/blackbox/cloud_only.bats index c4351092d4..2c8e38d472 100644 --- a/test/blackbox/cloud_only.bats +++ b/test/blackbox/cloud_only.bats @@ -41,7 +41,7 @@ function setup() { "region": "us-east-2", "cacheTablename": "BlobTable", "repoMetaTablename": "RepoMetadataTable", - "imageDataTablename": "ImageDataTable", + "imageMetaTablename": "ImageMetaTable", "repoBlobsInfoTablename": "RepoBlobsInfoTable", "userDataTablename": "UserDataTable", "apiKeyTablename":"ApiKeyTable",