diff --git a/pkg/extensions/imagetrust/image_trust.go b/pkg/extensions/imagetrust/image_trust.go index ce992c20..e1455499 100644 --- a/pkg/extensions/imagetrust/image_trust.go +++ b/pkg/extensions/imagetrust/image_trust.go @@ -160,7 +160,7 @@ func IsResourceExistsException(err error) bool { func (imgTrustStore *ImageTrustStore) VerifySignature( signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageMeta mTypes.ImageMeta, repo string, -) (string, time.Time, bool, error) { +) (mTypes.Author, mTypes.ExpiryDate, mTypes.Validity, error) { desc := ispec.Descriptor{ MediaType: imageMeta.MediaType, Digest: imageMeta.Digest, diff --git a/pkg/extensions/search/convert/convert_test.go b/pkg/extensions/search/convert/convert_test.go index b408678a..9f5160da 100644 --- a/pkg/extensions/search/convert/convert_test.go +++ b/pkg/extensions/search/convert/convert_test.go @@ -806,7 +806,7 @@ func TestConvertErrors(t *testing.T) { Convey("RepoMeta2ExpandedRepoInfo", func() { _, imgSums := convert.RepoMeta2ExpandedRepoInfo(ctx, mTypes.RepoMeta{ - Tags: map[string]mTypes.Descriptor{"tag": {MediaType: "bad-type", Digest: "digest"}}, + Tags: map[mTypes.Tag]mTypes.Descriptor{"tag": {MediaType: "bad-type", Digest: "digest"}}, }, map[string]mTypes.ImageMeta{ "digest": {}, diff --git a/pkg/extensions/search/cve/cve_test.go b/pkg/extensions/search/cve/cve_test.go index 8c5656c8..498a824f 100644 --- a/pkg/extensions/search/cve/cve_test.go +++ b/pkg/extensions/search/cve/cve_test.go @@ -387,7 +387,7 @@ func TestImageFormat(t *testing.T) { metaDB := &mocks.MetaDBMock{ GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": { MediaType: ispec.MediaTypeImageIndex, Digest: godigest.FromString("digest").String(), @@ -860,7 +860,7 @@ func TestCVEStruct(t *testing.T) { //nolint:gocyclo err = metaDB.SetRepoMeta("repo-with-bad-tag-digest", mTypes.RepoMeta{ Name: "repo-with-bad-tag-digest", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": {MediaType: ispec.MediaTypeImageManifest, Digest: godigest.FromString("1").String()}, }, }) diff --git a/pkg/extensions/search/cve/scan_test.go b/pkg/extensions/search/cve/scan_test.go index bfac3527..bcc41978 100644 --- a/pkg/extensions/search/cve/scan_test.go +++ b/pkg/extensions/search/cve/scan_test.go @@ -158,7 +158,7 @@ func TestScanGeneratorWithMockedData(t *testing.T) { //nolint: gocyclo err = metaDB.SetRepoMeta("repo-with-bad-tag-digest", mTypes.RepoMeta{ Name: "repo-with-bad-tag-digest", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": {MediaType: ispec.MediaTypeImageManifest, Digest: godigest.FromString("1").String()}, "tag-multi-arch": {MediaType: ispec.MediaTypeImageIndex, Digest: godigest.FromString("2").String()}, }, diff --git a/pkg/extensions/search/cve/update_test.go b/pkg/extensions/search/cve/update_test.go index d556355b..cbb9a0e5 100644 --- a/pkg/extensions/search/cve/update_test.go +++ b/pkg/extensions/search/cve/update_test.go @@ -44,7 +44,7 @@ func TestCVEDBGenerator(t *testing.T) { metaDB := &mocks.MetaDBMock{ GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": {MediaType: ispec.MediaTypeImageIndex}, }, }, nil diff --git a/pkg/extensions/search/resolver.go b/pkg/extensions/search/resolver.go index aa374d1b..15814530 100644 --- a/pkg/extensions/search/resolver.go +++ b/pkg/extensions/search/resolver.go @@ -165,7 +165,7 @@ func getImageSummary(ctx context.Context, repo, tag string, digest *string, skip return nil, gqlerror.Errorf("can't find image: %s:%s", repo, tag) } - repoMeta.Tags = map[string]mTypes.Descriptor{tag: manifestDescriptor} + repoMeta.Tags = map[mTypes.Tag]mTypes.Descriptor{tag: manifestDescriptor} imageDigest := manifestDescriptor.Digest if digest != nil { diff --git a/pkg/extensions/search/resolver_test.go b/pkg/extensions/search/resolver_test.go index 239fa089..f62a8709 100644 --- a/pkg/extensions/search/resolver_test.go +++ b/pkg/extensions/search/resolver_test.go @@ -229,13 +229,13 @@ func TestRepoListWithNewestImage(t *testing.T) { repos := []mTypes.RepoMeta{ { Name: "repo1", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.1": { Digest: img1.DigestStr(), MediaType: ispec.MediaTypeImageManifest, }, }, - Signatures: map[string]mTypes.ManifestSignatures{ + Signatures: map[mTypes.ImageDigest]mTypes.ManifestSignatures{ img1.DigestStr(): { "cosign": []mTypes.SignatureInfo{ {SignatureManifestDigest: "testSignature", LayersInfo: []mTypes.LayerInfo{}}, @@ -254,13 +254,13 @@ func TestRepoListWithNewestImage(t *testing.T) { }, { Name: "repo2", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.2": { Digest: img2.DigestStr(), MediaType: ispec.MediaTypeImageManifest, }, }, - Signatures: map[string]mTypes.ManifestSignatures{ + Signatures: map[mTypes.ImageDigest]mTypes.ManifestSignatures{ img1.DigestStr(): { "cosign": []mTypes.SignatureInfo{ {SignatureManifestDigest: "testSignature", LayersInfo: []mTypes.LayerInfo{}}, @@ -395,9 +395,9 @@ func TestGetStarredRepos(t *testing.T) { } func getTestRepoMetaWithImages(repo string, images []Image) mTypes.RepoMeta { - tags := map[string]mTypes.Descriptor{"": {}} - statistics := map[string]mTypes.DescriptorStatistics{"": {}} - signatures := map[string]mTypes.ManifestSignatures{"": {}} + tags := map[mTypes.Tag]mTypes.Descriptor{"": {}} + statistics := map[mTypes.Tag]mTypes.DescriptorStatistics{"": {}} + signatures := map[mTypes.ImageDigest]mTypes.ManifestSignatures{"": {}} referrers := map[string][]mTypes.ReferrerInfo{"": {}} for i := range images { @@ -542,7 +542,7 @@ func TestGetImageSummaryError(t *testing.T) { Convey("getImageSummary", t, func() { metaDB := mocks.MetaDBMock{ GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { - return mTypes.RepoMeta{Tags: map[string]mTypes.Descriptor{"tag": {}}}, nil + return mTypes.RepoMeta{Tags: map[mTypes.Tag]mTypes.Descriptor{"tag": {}}}, nil }, FilterImageMetaFn: func(ctx context.Context, digests []string) (map[string]mTypes.ImageMeta, error) { return nil, ErrTestError @@ -597,7 +597,7 @@ func TestImageListError(t *testing.T) { image := CreateDefaultImage() repoMeta := mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{image.DigestStr(): { + Tags: map[mTypes.Tag]mTypes.Descriptor{image.DigestStr(): { Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest, }}, @@ -944,7 +944,7 @@ func TestQueryResolverErrors(t *testing.T) { GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": {Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, }, }, nil @@ -1632,7 +1632,7 @@ func TestCVEResolvers(t *testing.T) { //nolint:gocyclo pageInput, mocks.MetaDBMock{ GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.1.0": { Digest: godigest.FromString("str").String(), MediaType: ispec.MediaTypeImageManifest, @@ -1893,7 +1893,7 @@ func TestMockedDerivedImageList(t *testing.T) { mocks.MetaDBMock{ GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.1": { Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest, @@ -1923,7 +1923,7 @@ func TestMockedDerivedImageList(t *testing.T) { GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ Name: "repo1", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.1": {Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, }, }, nil @@ -1979,7 +1979,7 @@ func TestMockedDerivedImageList(t *testing.T) { GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ Name: "repo1", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.1": {Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, }, }, nil @@ -2001,7 +2001,7 @@ func TestMockedDerivedImageList(t *testing.T) { fullImageMetaList := []mTypes.FullImageMeta{} repos := []mTypes.RepoMeta{{ Name: "repo1", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.1": {Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, "1.0.2": {Digest: derivedImage.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, "1.0.3": {Digest: derivedImage.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, @@ -2084,7 +2084,7 @@ func TestMockedBaseImageList(t *testing.T) { mocks.MetaDBMock{ GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.2": { Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest, @@ -2112,7 +2112,7 @@ func TestMockedBaseImageList(t *testing.T) { GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ Name: "repo1", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.2": {Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, }, }, nil @@ -2162,7 +2162,7 @@ func TestMockedBaseImageList(t *testing.T) { GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ Name: "repo1", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.2": {Digest: derivedImage.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, }, }, nil @@ -2175,7 +2175,7 @@ func TestMockedBaseImageList(t *testing.T) { fullImageMetaList := []mTypes.FullImageMeta{} repos := []mTypes.RepoMeta{{ Name: "repo1", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.1": {Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, "1.0.3": {Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, "1.0.2": {Digest: derivedImage.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, @@ -2257,7 +2257,7 @@ func TestMockedBaseImageList(t *testing.T) { GetRepoMetaFn: func(ctx context.Context, repo string) (mTypes.RepoMeta, error) { return mTypes.RepoMeta{ Name: "repo1", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.2": {Digest: derivedImage.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, }, }, nil @@ -2270,7 +2270,7 @@ func TestMockedBaseImageList(t *testing.T) { fullImageMetaList := []mTypes.FullImageMeta{} repos := []mTypes.RepoMeta{{ Name: "repo1", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "1.0.1": {Digest: image.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, "1.0.2": {Digest: derivedImage.DigestStr(), MediaType: ispec.MediaTypeImageManifest}, }, diff --git a/pkg/meta/boltdb/boltdb_test.go b/pkg/meta/boltdb/boltdb_test.go index ca6af087..f2e8428c 100644 --- a/pkg/meta/boltdb/boltdb_test.go +++ b/pkg/meta/boltdb/boltdb_test.go @@ -28,7 +28,7 @@ type imgTrustStore struct{} func (its imgTrustStore) VerifySignature( signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageMeta mTypes.ImageMeta, repo string, -) (string, time.Time, bool, error) { +) (mTypes.Author, mTypes.ExpiryDate, mTypes.Validity, error) { return "", time.Time{}, false, nil } @@ -75,7 +75,7 @@ func TestWrapperErrors(t *testing.T) { Convey("getProtoImageMeta errors", func() { err := boltdbWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": { MediaType: ispec.MediaTypeImageManifest, Digest: imageMeta.Digest.String(), @@ -288,7 +288,7 @@ func TestWrapperErrors(t *testing.T) { Convey("getProtoImageMeta fails", func() { err := boltdbWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": { MediaType: ispec.MediaTypeImageManifest, Digest: godigest.FromString("not-found").String(), @@ -307,7 +307,7 @@ func TestWrapperErrors(t *testing.T) { err = boltdbWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": { MediaType: ispec.MediaTypeImageIndex, Digest: multiarchImageMeta.Digest.String(), @@ -344,7 +344,7 @@ func TestWrapperErrors(t *testing.T) { badImageDigest := godigest.FromString("bad-image-manifest") err := boltdbWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "bad-image-manifest": { MediaType: ispec.MediaTypeImageManifest, Digest: badImageDigest.String(), @@ -363,7 +363,7 @@ func TestWrapperErrors(t *testing.T) { badIndexDigest := godigest.FromString("bad-image-manifest") err := boltdbWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "bad-image-index": { MediaType: ispec.MediaTypeImageIndex, Digest: badIndexDigest.String(), @@ -382,7 +382,7 @@ func TestWrapperErrors(t *testing.T) { goodIndexBadManifestDigest := godigest.FromString("good-index-bad-manifests") err := boltdbWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "good-index-bad-manifests": { MediaType: ispec.MediaTypeImageIndex, Digest: goodIndexBadManifestDigest.String(), @@ -403,7 +403,7 @@ func TestWrapperErrors(t *testing.T) { Convey("bad media type", func() { err := boltdbWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "mad-media-type": { MediaType: "bad media type", Digest: godigest.FromString("dig").String(), @@ -430,7 +430,7 @@ func TestWrapperErrors(t *testing.T) { Convey("bad media Type fails", func() { err := boltdbWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "bad-repo-meta": { MediaType: "bad media type", Digest: godigest.FromString("dig").String(), diff --git a/pkg/meta/convert/convert.go b/pkg/meta/convert/convert.go index d6acaa3c..9d55f1c0 100644 --- a/pkg/meta/convert/convert.go +++ b/pkg/meta/convert/convert.go @@ -292,8 +292,9 @@ func GetLayersInfo(layersInfo []*proto_go.LayersInfo) []mTypes.LayerInfo { return results } -func GetStatisticsMap(stats map[string]*proto_go.DescriptorStatistics) map[string]mTypes.DescriptorStatistics { - results := map[string]mTypes.DescriptorStatistics{} +func GetStatisticsMap(stats map[mTypes.ImageDigest]*proto_go.DescriptorStatistics, +) map[mTypes.ImageDigest]mTypes.DescriptorStatistics { + results := map[mTypes.ImageDigest]mTypes.DescriptorStatistics{} for digest, stat := range stats { results[digest] = mTypes.DescriptorStatistics{ @@ -348,8 +349,8 @@ func GetImageIndexMeta(indexContent ispec.Index, size int64, digest godigest.Dig } } -func GetTags(tags map[string]*proto_go.TagDescriptor) map[string]mTypes.Descriptor { - resultMap := map[string]mTypes.Descriptor{} +func GetTags(tags map[mTypes.Tag]*proto_go.TagDescriptor) map[mTypes.Tag]mTypes.Descriptor { + resultMap := map[mTypes.Tag]mTypes.Descriptor{} for tag, tagDescriptor := range tags { resultMap[tag] = mTypes.Descriptor{ diff --git a/pkg/meta/convert/convert_proto.go b/pkg/meta/convert/convert_proto.go index 49381bd1..c68a2aca 100644 --- a/pkg/meta/convert/convert_proto.go +++ b/pkg/meta/convert/convert_proto.go @@ -118,8 +118,9 @@ func GetProtoImageIndexMeta(indexContent ispec.Index, size int64, digest string) } } -func GetProtoStatistics(stats map[string]mTypes.DescriptorStatistics) map[string]*proto_go.DescriptorStatistics { - results := map[string]*proto_go.DescriptorStatistics{} +func GetProtoStatistics(stats map[mTypes.ImageDigest]mTypes.DescriptorStatistics, +) map[mTypes.ImageDigest]*proto_go.DescriptorStatistics { + results := map[mTypes.ImageDigest]*proto_go.DescriptorStatistics{} for digest, stat := range stats { results[digest] = &proto_go.DescriptorStatistics{ @@ -335,8 +336,8 @@ func GetProtoTime(time *time.Time) *timestamppb.Timestamp { return timestamppb.New(*time) } -func GetProtoTags(tags map[string]mTypes.Descriptor) map[string]*proto_go.TagDescriptor { - resultMap := map[string]*proto_go.TagDescriptor{} +func GetProtoTags(tags map[mTypes.Tag]mTypes.Descriptor) map[mTypes.Tag]*proto_go.TagDescriptor { + resultMap := map[mTypes.Tag]*proto_go.TagDescriptor{} for tag, tagDescriptor := range tags { resultMap[tag] = &proto_go.TagDescriptor{ diff --git a/pkg/meta/dynamodb/dynamodb_test.go b/pkg/meta/dynamodb/dynamodb_test.go index 87a67b60..599ec4e2 100644 --- a/pkg/meta/dynamodb/dynamodb_test.go +++ b/pkg/meta/dynamodb/dynamodb_test.go @@ -208,7 +208,7 @@ func TestWrapperErrors(t *testing.T) { Convey("getProtoImageMeta errors", func() { err := dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": { MediaType: ispec.MediaTypeImageManifest, Digest: imageMeta.Digest.String(), @@ -405,7 +405,7 @@ func TestWrapperErrors(t *testing.T) { Convey("getProtoImageMeta fails", func() { err := dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": { MediaType: ispec.MediaTypeImageManifest, Digest: godigest.FromString("not-found").String(), @@ -424,7 +424,7 @@ func TestWrapperErrors(t *testing.T) { err = dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "tag": { MediaType: ispec.MediaTypeImageIndex, Digest: multiarchImageMeta.Digest.String(), @@ -457,7 +457,7 @@ func TestWrapperErrors(t *testing.T) { badImageDigest := godigest.FromString("bad-image-manifest") err := dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "bad-image-manifest": { MediaType: ispec.MediaTypeImageManifest, Digest: badImageDigest.String(), @@ -476,7 +476,7 @@ func TestWrapperErrors(t *testing.T) { badIndexDigest := godigest.FromString("bad-image-manifest") err := dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "bad-image-index": { MediaType: ispec.MediaTypeImageIndex, Digest: badIndexDigest.String(), @@ -495,7 +495,7 @@ func TestWrapperErrors(t *testing.T) { goodIndexBadManifestDigest := godigest.FromString("good-index-bad-manifests") err := dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "good-index-bad-manifests": { MediaType: ispec.MediaTypeImageIndex, Digest: goodIndexBadManifestDigest.String(), @@ -528,7 +528,7 @@ func TestWrapperErrors(t *testing.T) { badImageDigest := godigest.FromString("bad-image-manifest") err := dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "bad-image-manifest": { MediaType: ispec.MediaTypeImageManifest, Digest: badImageDigest.String(), @@ -547,7 +547,7 @@ func TestWrapperErrors(t *testing.T) { badIndexDigest := godigest.FromString("bad-image-manifest") err := dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "bad-image-index": { MediaType: ispec.MediaTypeImageIndex, Digest: badIndexDigest.String(), @@ -566,7 +566,7 @@ func TestWrapperErrors(t *testing.T) { goodIndexBadManifestDigest := godigest.FromString("good-index-bad-manifests") err := dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "good-index-bad-manifests": { MediaType: ispec.MediaTypeImageIndex, Digest: goodIndexBadManifestDigest.String(), @@ -587,7 +587,7 @@ func TestWrapperErrors(t *testing.T) { Convey("bad media type", func() { err := dynamoWrapper.SetRepoMeta("repo", mTypes.RepoMeta{ //nolint: contextcheck Name: "repo", - Tags: map[string]mTypes.Descriptor{ + Tags: map[mTypes.Tag]mTypes.Descriptor{ "mad-media-type": { MediaType: "bad media type", Digest: godigest.FromString("dig").String(), diff --git a/pkg/meta/meta_test.go b/pkg/meta/meta_test.go index 9af8db1a..7749c04d 100644 --- a/pkg/meta/meta_test.go +++ b/pkg/meta/meta_test.go @@ -526,11 +526,11 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func Convey("Set/Get RepoMeta", func() { err := metaDB.SetRepoMeta("repo", mTypes.RepoMeta{ Name: "repo", - Tags: map[string]mTypes.Descriptor{"tag": {Digest: "dig"}}, + Tags: map[mTypes.Tag]mTypes.Descriptor{"tag": {Digest: "dig"}}, - Statistics: map[string]mTypes.DescriptorStatistics{}, - Signatures: map[string]mTypes.ManifestSignatures{}, - Referrers: map[string][]mTypes.ReferrerInfo{"digest": {{Digest: "dig"}}}, + Statistics: map[mTypes.ImageDigest]mTypes.DescriptorStatistics{}, + Signatures: map[mTypes.ImageDigest]mTypes.ManifestSignatures{}, + Referrers: map[mTypes.ImageDigest][]mTypes.ReferrerInfo{"digest": {{Digest: "dig"}}}, }) So(err, ShouldBeNil) repoMeta, err := metaDB.GetRepoMeta(ctx, "repo") diff --git a/pkg/meta/types/types.go b/pkg/meta/types/types.go index 812190f3..c39b79fc 100644 --- a/pkg/meta/types/types.go +++ b/pkg/meta/types/types.go @@ -54,10 +54,6 @@ func GetLatestImageDigests(repoMetaList []RepoMeta) []string { return digests } -type ( - ImageDigest = string -) - type MetaDB interface { //nolint:interfacebloat UserDB @@ -89,7 +85,7 @@ type MetaDB interface { //nolint:interfacebloat // 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 + // GetMultipleRepoMeta returns a list of all repos that match the given filter. // function GetMultipleRepoMeta(ctx context.Context, filter func(repoMeta RepoMeta) bool) ( []RepoMeta, error) @@ -123,7 +119,7 @@ type MetaDB interface { //nolint:interfacebloat UpdateStatsOnDownload(repo string, reference string) error // FilterImageMeta returns the image data for the given digests - FilterImageMeta(ctx context.Context, digests []string) (map[string]ImageMeta, error) + FilterImageMeta(ctx context.Context, digests []string) (map[ImageDigest]ImageMeta, error) /* RemoveRepoReference removes the tag from RepoMetadata if the reference is a tag, @@ -190,11 +186,17 @@ type UserDB interface { //nolint:interfacebloat DeleteUserAPIKey(ctx context.Context, id string) error } +type ( + Author = string + ExpiryDate = time.Time + Validity = bool +) + type ImageTrustStore interface { VerifySignature( signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageMeta ImageMeta, repo string, - ) (string, time.Time, bool, error) + ) (Author, ExpiryDate, Validity, error) } // ImageMeta can store all data related to a image, multiarch or simple. Used for writing imaged to MetaDB. @@ -214,13 +216,18 @@ type ManifestMeta struct { Config ispec.Image } +type ( + Tag = string + ImageDigest = string +) + type RepoMeta struct { Name string - Tags map[string]Descriptor + Tags map[Tag]Descriptor - Statistics map[string]DescriptorStatistics - Signatures map[string]ManifestSignatures - Referrers map[string][]ReferrerInfo + Statistics map[ImageDigest]DescriptorStatistics + Signatures map[ImageDigest]ManifestSignatures + Referrers map[ImageDigest][]ReferrerInfo LastUpdatedImage *LastUpdatedImage Platforms []ispec.Platform @@ -287,7 +294,11 @@ type DescriptorStatistics struct { PushedBy string } -type ManifestSignatures map[string][]SignatureInfo +type ( + SignatureType = string +) + +type ManifestSignatures map[SignatureType][]SignatureInfo type LayerInfo struct { LayerDigest string @@ -309,11 +320,15 @@ type SignatureMetadata struct { LayersInfo []LayerInfo } +type ( + HashedAPIKey = string +) + type UserData struct { StarredRepos []string BookmarkedRepos []string Groups []string - APIKeys map[string]APIKeyDetails + APIKeys map[HashedAPIKey]APIKeyDetails } type Filter struct { diff --git a/pkg/test/oci-utils/repo.go b/pkg/test/oci-utils/repo.go index 34b0f7dd..362104b6 100644 --- a/pkg/test/oci-utils/repo.go +++ b/pkg/test/oci-utils/repo.go @@ -18,7 +18,7 @@ type RepoImage struct { type RepoMultiArchImage struct { imageUtil.MultiarchImage - ImageStatistics map[string]mTypes.DescriptorStatistics + ImageStatistics map[mTypes.ImageDigest]mTypes.DescriptorStatistics Reference string }