mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 04:48:26 +08:00
style(metadb): use type aliases for metadb types to be easier to read (#2043)
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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")
|
||||
|
||||
+28
-13
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user