0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

fix: various lint issues (#2571)

Originally found by @jkroepke in: https://github.com/project-zot/zot/actions/runs/10056774230/job/27796324933?pr=2556
And https://github.com/project-zot/zot/pull/2556 in general

This commit covers:
- (canonicalheader) capitalization of Docker-Content-Digest header
- (protogetter) the proto getters were not used, they check for nil pointers, we should switch to using them
- (zerologlint) fix the false positive

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
Andrei Aaron 2024-07-25 20:14:22 +03:00 committed by GitHub
parent 048e59186f
commit 7d87558b7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 156 additions and 168 deletions

View file

@ -89,7 +89,7 @@ func SessionLogger(ctlr *Controller) mux.MiddlewareFunc {
clientIP := request.RemoteAddr clientIP := request.RemoteAddr
method := request.Method method := request.Method
headers := map[string][]string{} headers := map[string][]string{}
log := logger.Info() log := logger.Info() //nolint: zerologlint // false positive, the Msg call is below
for key, value := range request.Header { for key, value := range request.Header {
if key == "Authorization" { // anonymize from logs if key == "Authorization" { // anonymize from logs
s := strings.SplitN(value[0], " ", 2) //nolint:gomnd s := strings.SplitN(value[0], " ", 2) //nolint:gomnd

View file

@ -307,7 +307,7 @@ func fetchImageIndexStruct(ctx context.Context, job *httpJob) (*imageStruct, err
return nil, err return nil, err
} }
indexDigest := header.Get("docker-content-digest") indexDigest := header.Get("Docker-Content-Digest")
indexSize, err := strconv.ParseInt(header.Get("Content-Length"), 10, 64) indexSize, err := strconv.ParseInt(header.Get("Content-Length"), 10, 64)
if err != nil { if err != nil {
@ -398,7 +398,7 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se
return common.ManifestSummary{}, err return common.ManifestSummary{}, err
} }
manifestDigest := header.Get("docker-content-digest") manifestDigest := header.Get("Docker-Content-Digest")
configDigest := manifestResp.Config.Digest.String() configDigest := manifestResp.Config.Digest.String()
configContent, err := fetchConfig(ctx, repo, configDigest, searchConf, username, password) configContent, err := fetchConfig(ctx, repo, configDigest, searchConf, username, password)

View file

@ -265,7 +265,7 @@ func TestDoHTTPRequest(t *testing.T) {
vars := mux.Vars(req) vars := mux.Vars(req)
if vars["reference"] == "indexRef" { if vars["reference"] == "indexRef" {
writer.Header().Add("docker-content-digest", godigest.FromString("t").String()) writer.Header().Add("Docker-Content-Digest", godigest.FromString("t").String())
_, err := writer.Write([]byte(` _, err := writer.Write([]byte(`
{ {
"manifests": [ "manifests": [
@ -594,7 +594,7 @@ func TestDoJobErrors(t *testing.T) {
Route: "/v2/{name}/manifests/{reference}", Route: "/v2/{name}/manifests/{reference}",
HandlerFunc: func(w http.ResponseWriter, r *http.Request) { HandlerFunc: func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", ispec.MediaTypeImageIndex) w.Header().Add("Content-Type", ispec.MediaTypeImageIndex)
w.Header().Add("docker-content-digest", godigest.FromString("t").String()) w.Header().Add("Docker-Content-Digest", godigest.FromString("t").String())
_, err := w.Write([]byte("")) _, err := w.Write([]byte(""))
if err != nil { if err != nil {
@ -609,7 +609,7 @@ func TestDoJobErrors(t *testing.T) {
vars := mux.Vars(req) vars := mux.Vars(req)
if vars["reference"] == "indexRef" { if vars["reference"] == "indexRef" {
writer.Header().Add("docker-content-digest", godigest.FromString("t").String()) writer.Header().Add("Docker-Content-Digest", godigest.FromString("t").String())
_, err := writer.Write([]byte(`{"manifests": [{"digest": "manifestRef"}]}`)) _, err := writer.Write([]byte(`{"manifests": [{"digest": "manifestRef"}]}`))
if err != nil { if err != nil {
@ -618,7 +618,7 @@ func TestDoJobErrors(t *testing.T) {
} }
if vars["reference"] == "manifestRef" { if vars["reference"] == "manifestRef" {
writer.Header().Add("docker-content-digest", godigest.FromString("t").String()) writer.Header().Add("Docker-Content-Digest", godigest.FromString("t").String())
_, err := writer.Write([]byte(`{"config": {"digest": "confDigest"}}`)) _, err := writer.Write([]byte(`{"config": {"digest": "confDigest"}}`))
if err != nil { if err != nil {

View file

@ -22,11 +22,11 @@ func GetHistory(history []*proto_go.History) []ispec.History {
for _, his := range history { for _, his := range history {
results = append(results, ispec.History{ results = append(results, ispec.History{
Created: ref(his.Created.AsTime()), Created: ref(his.GetCreated().AsTime()),
CreatedBy: deref(his.CreatedBy, ""), CreatedBy: his.GetCreatedBy(),
Author: deref(his.Author, ""), Author: his.GetAuthor(),
Comment: deref(his.Comment, ""), Comment: his.GetComment(),
EmptyLayer: deref(his.EmptyLayer, false), EmptyLayer: his.GetEmptyLayer(),
}) })
} }
@ -34,79 +34,75 @@ func GetHistory(history []*proto_go.History) []ispec.History {
} }
func GetImageArtifactType(imageMeta *proto_go.ImageMeta) string { func GetImageArtifactType(imageMeta *proto_go.ImageMeta) string {
switch imageMeta.MediaType { switch imageMeta.GetMediaType() {
case ispec.MediaTypeImageManifest: case ispec.MediaTypeImageManifest:
manifestArtifactType := deref(imageMeta.Manifests[0].Manifest.ArtifactType, "") manifestArtifactType := imageMeta.GetManifests()[0].GetManifest().GetArtifactType()
if manifestArtifactType != "" { if manifestArtifactType != "" {
return manifestArtifactType return manifestArtifactType
} }
return imageMeta.Manifests[0].Manifest.Config.MediaType return imageMeta.GetManifests()[0].GetManifest().GetConfig().GetMediaType()
case ispec.MediaTypeImageIndex: case ispec.MediaTypeImageIndex:
return deref(imageMeta.Index.Index.ArtifactType, "") return imageMeta.GetIndex().GetIndex().GetArtifactType()
default: default:
return "" return ""
} }
} }
func GetImageManifestSize(imageMeta *proto_go.ImageMeta) int64 { func GetImageManifestSize(imageMeta *proto_go.ImageMeta) int64 {
switch imageMeta.MediaType { switch imageMeta.GetMediaType() {
case ispec.MediaTypeImageManifest: case ispec.MediaTypeImageManifest:
return imageMeta.Manifests[0].Size return imageMeta.GetManifests()[0].GetSize()
case ispec.MediaTypeImageIndex: case ispec.MediaTypeImageIndex:
return imageMeta.Index.Size return imageMeta.GetIndex().GetSize()
default: default:
return 0 return 0
} }
} }
func GetImageDigest(imageMeta *proto_go.ImageMeta) godigest.Digest { func GetImageDigest(imageMeta *proto_go.ImageMeta) godigest.Digest {
switch imageMeta.MediaType { switch imageMeta.GetMediaType() {
case ispec.MediaTypeImageManifest: case ispec.MediaTypeImageManifest:
return godigest.Digest(imageMeta.Manifests[0].Digest) return godigest.Digest(imageMeta.GetManifests()[0].GetDigest())
case ispec.MediaTypeImageIndex: case ispec.MediaTypeImageIndex:
return godigest.Digest(imageMeta.Index.Digest) return godigest.Digest(imageMeta.GetIndex().GetDigest())
default: default:
return "" return ""
} }
} }
func GetImageDigestStr(imageMeta *proto_go.ImageMeta) string { func GetImageDigestStr(imageMeta *proto_go.ImageMeta) string {
switch imageMeta.MediaType { switch imageMeta.GetMediaType() {
case ispec.MediaTypeImageManifest: case ispec.MediaTypeImageManifest:
return imageMeta.Manifests[0].Digest return imageMeta.GetManifests()[0].GetDigest()
case ispec.MediaTypeImageIndex: case ispec.MediaTypeImageIndex:
return imageMeta.Index.Digest return imageMeta.GetIndex().GetDigest()
default: default:
return "" return ""
} }
} }
func GetImageAnnotations(imageMeta *proto_go.ImageMeta) map[string]string { func GetImageAnnotations(imageMeta *proto_go.ImageMeta) map[string]string {
switch imageMeta.MediaType { switch imageMeta.GetMediaType() {
case ispec.MediaTypeImageManifest: case ispec.MediaTypeImageManifest:
return imageMeta.Manifests[0].Manifest.Annotations return imageMeta.GetManifests()[0].GetManifest().GetAnnotations()
case ispec.MediaTypeImageIndex: case ispec.MediaTypeImageIndex:
return imageMeta.Index.Index.Annotations return imageMeta.GetIndex().GetIndex().GetAnnotations()
default: default:
return map[string]string{} return map[string]string{}
} }
} }
func GetImageSubject(imageMeta *proto_go.ImageMeta) *ispec.Descriptor { func GetImageSubject(imageMeta *proto_go.ImageMeta) *ispec.Descriptor {
switch imageMeta.MediaType { switch imageMeta.GetMediaType() {
case ispec.MediaTypeImageManifest: case ispec.MediaTypeImageManifest:
if imageMeta.Manifests[0].Manifest.Subject == nil { if imageMeta.GetManifests()[0].GetManifest().GetSubject() == nil {
return nil return nil
} }
return GetDescriptorRef(imageMeta.Manifests[0].Manifest.Subject) return GetDescriptorRef(imageMeta.GetManifests()[0].GetManifest().GetSubject())
case ispec.MediaTypeImageIndex: case ispec.MediaTypeImageIndex:
if imageMeta.Index.Index.Subject == nil { return GetDescriptorRef(imageMeta.GetIndex().GetIndex().GetSubject())
return nil
}
return GetDescriptorRef(imageMeta.Index.Index.Subject)
default: default:
return nil return nil
} }
@ -117,17 +113,17 @@ func GetDescriptorRef(descriptor *proto_go.Descriptor) *ispec.Descriptor {
return nil return nil
} }
platform := GetPlatformRef(descriptor.Platform) platform := GetPlatformRef(descriptor.GetPlatform())
return &ispec.Descriptor{ return &ispec.Descriptor{
MediaType: descriptor.MediaType, MediaType: descriptor.GetMediaType(),
Digest: godigest.Digest(descriptor.Digest), Digest: godigest.Digest(descriptor.GetDigest()),
Size: descriptor.Size, Size: descriptor.GetSize(),
URLs: descriptor.URLs, URLs: descriptor.GetURLs(),
Data: descriptor.Data, Data: descriptor.GetData(),
Platform: platform, Platform: platform,
ArtifactType: deref(descriptor.ArtifactType, ""), ArtifactType: descriptor.GetArtifactType(),
Annotations: descriptor.Annotations, Annotations: descriptor.GetAnnotations(),
} }
} }
@ -137,11 +133,11 @@ func GetPlatform(platform *proto_go.Platform) ispec.Platform {
} }
return ispec.Platform{ return ispec.Platform{
Architecture: platform.Architecture, Architecture: platform.GetArchitecture(),
OS: platform.OS, OS: platform.GetOS(),
OSVersion: deref(platform.OSVersion, ""), OSVersion: platform.GetOSVersion(),
OSFeatures: platform.OSFeatures, OSFeatures: platform.GetOSFeatures(),
Variant: deref(platform.Variant, ""), Variant: platform.GetVariant(),
} }
} }
@ -151,11 +147,11 @@ func GetPlatformRef(platform *proto_go.Platform) *ispec.Platform {
} }
return &ispec.Platform{ return &ispec.Platform{
Architecture: platform.Architecture, Architecture: platform.GetArchitecture(),
OS: platform.OS, OS: platform.GetOS(),
OSVersion: deref(platform.OSVersion, ""), OSVersion: platform.GetOSVersion(),
OSFeatures: platform.OSFeatures, OSFeatures: platform.GetOSFeatures(),
Variant: deref(platform.Variant, ""), Variant: platform.GetVariant(),
} }
} }
@ -164,9 +160,9 @@ func GetLayers(descriptors []*proto_go.Descriptor) []ispec.Descriptor {
for _, desc := range descriptors { for _, desc := range descriptors {
results = append(results, ispec.Descriptor{ results = append(results, ispec.Descriptor{
MediaType: desc.MediaType, MediaType: desc.GetMediaType(),
Digest: godigest.Digest(desc.Digest), Digest: godigest.Digest(desc.GetDigest()),
Size: desc.Size, Size: desc.GetSize(),
}) })
} }
@ -179,9 +175,9 @@ func GetSubject(subj *proto_go.Descriptor) *ispec.Descriptor {
} }
return &ispec.Descriptor{ return &ispec.Descriptor{
MediaType: subj.MediaType, MediaType: subj.GetMediaType(),
Digest: godigest.Digest(subj.Digest), Digest: godigest.Digest(subj.GetDigest()),
Size: subj.Size, Size: subj.GetSize(),
} }
} }
@ -191,13 +187,13 @@ func GetReferrers(refs map[string]*proto_go.ReferrersInfo) map[string][]mTypes.R
for digest, ref := range refs { for digest, ref := range refs {
referrers := []mTypes.ReferrerInfo{} referrers := []mTypes.ReferrerInfo{}
for _, dbRef := range ref.List { for _, dbRef := range ref.GetList() {
referrers = append(referrers, mTypes.ReferrerInfo{ referrers = append(referrers, mTypes.ReferrerInfo{
Digest: dbRef.Digest, Digest: dbRef.GetDigest(),
MediaType: dbRef.MediaType, MediaType: dbRef.GetMediaType(),
ArtifactType: dbRef.ArtifactType, ArtifactType: dbRef.GetArtifactType(),
Size: int(dbRef.Size), Size: int(dbRef.GetSize()), // int64 to int32, need to review this later
Annotations: dbRef.Annotations, Annotations: dbRef.GetAnnotations(),
}) })
} }
@ -214,13 +210,13 @@ func GetImageReferrers(refs *proto_go.ReferrersInfo) []mTypes.ReferrerInfo {
results := []mTypes.ReferrerInfo{} results := []mTypes.ReferrerInfo{}
for _, dbRef := range refs.List { for _, dbRef := range refs.GetList() {
results = append(results, mTypes.ReferrerInfo{ results = append(results, mTypes.ReferrerInfo{
Digest: dbRef.Digest, Digest: dbRef.GetDigest(),
MediaType: dbRef.MediaType, MediaType: dbRef.GetMediaType(),
ArtifactType: dbRef.ArtifactType, ArtifactType: dbRef.GetArtifactType(),
Size: int(dbRef.Size), Size: int(dbRef.GetSize()), // int64 to int32, need to review this later
Annotations: dbRef.Annotations, Annotations: dbRef.GetAnnotations(),
}) })
} }
@ -233,8 +229,8 @@ func GetSignatures(sigs map[string]*proto_go.ManifestSignatures) map[string]mTyp
for digest, dbSignatures := range sigs { for digest, dbSignatures := range sigs {
imageSignatures := mTypes.ManifestSignatures{} imageSignatures := mTypes.ManifestSignatures{}
for signatureName, signatureInfo := range dbSignatures.Map { for signatureName, signatureInfo := range dbSignatures.GetMap() {
imageSignatures[signatureName] = GetSignaturesInfo(signatureInfo.List) imageSignatures[signatureName] = GetSignaturesInfo(signatureInfo.GetList())
} }
results[digest] = imageSignatures results[digest] = imageSignatures
@ -250,8 +246,8 @@ func GetImageSignatures(sigs *proto_go.ManifestSignatures) mTypes.ManifestSignat
results := mTypes.ManifestSignatures{} results := mTypes.ManifestSignatures{}
for signatureName, signatureInfo := range sigs.Map { for signatureName, signatureInfo := range sigs.GetMap() {
results[signatureName] = GetSignaturesInfo(signatureInfo.List) results[signatureName] = GetSignaturesInfo(signatureInfo.GetList())
} }
return results return results
@ -262,8 +258,8 @@ func GetSignaturesInfo(sigsInfo []*proto_go.SignatureInfo) []mTypes.SignatureInf
for _, siginfo := range sigsInfo { for _, siginfo := range sigsInfo {
results = append(results, mTypes.SignatureInfo{ results = append(results, mTypes.SignatureInfo{
SignatureManifestDigest: siginfo.SignatureManifestDigest, SignatureManifestDigest: siginfo.GetSignatureManifestDigest(),
LayersInfo: GetLayersInfo(siginfo.LayersInfo), LayersInfo: GetLayersInfo(siginfo.GetLayersInfo()),
}) })
} }
@ -276,15 +272,15 @@ func GetLayersInfo(layersInfo []*proto_go.LayersInfo) []mTypes.LayerInfo {
for _, layerInfo := range layersInfo { for _, layerInfo := range layersInfo {
date := time.Time{} date := time.Time{}
if layerInfo.Date != nil { if layerInfo.GetDate() != nil {
date = layerInfo.Date.AsTime() date = layerInfo.GetDate().AsTime()
} }
results = append(results, mTypes.LayerInfo{ results = append(results, mTypes.LayerInfo{
LayerDigest: layerInfo.LayerDigest, LayerDigest: layerInfo.GetLayerDigest(),
LayerContent: layerInfo.LayerContent, LayerContent: layerInfo.GetLayerContent(),
SignatureKey: layerInfo.SignatureKey, SignatureKey: layerInfo.GetSignatureKey(),
Signer: layerInfo.Signer, Signer: layerInfo.GetSigner(),
Date: date, Date: date,
}) })
} }
@ -298,10 +294,10 @@ func GetStatisticsMap(stats map[mTypes.ImageDigest]*proto_go.DescriptorStatistic
for digest, stat := range stats { for digest, stat := range stats {
results[digest] = mTypes.DescriptorStatistics{ results[digest] = mTypes.DescriptorStatistics{
DownloadCount: int(stat.DownloadCount), DownloadCount: int(stat.GetDownloadCount()),
LastPullTimestamp: stat.LastPullTimestamp.AsTime(), LastPullTimestamp: stat.GetLastPullTimestamp().AsTime(),
PushTimestamp: stat.PushTimestamp.AsTime(), PushTimestamp: stat.GetPushTimestamp().AsTime(),
PushedBy: stat.PushedBy, PushedBy: stat.GetPushedBy(),
} }
} }
@ -314,10 +310,10 @@ func GetImageStatistics(stats *proto_go.DescriptorStatistics) mTypes.DescriptorS
} }
return mTypes.DescriptorStatistics{ return mTypes.DescriptorStatistics{
DownloadCount: int(stats.DownloadCount), DownloadCount: int(stats.GetDownloadCount()),
LastPullTimestamp: stats.LastPullTimestamp.AsTime(), LastPullTimestamp: stats.GetLastPullTimestamp().AsTime(),
PushTimestamp: stats.PushTimestamp.AsTime(), PushTimestamp: stats.GetPushTimestamp().AsTime(),
PushedBy: stats.PushedBy, PushedBy: stats.GetPushedBy(),
} }
} }
@ -354,8 +350,8 @@ func GetTags(tags map[mTypes.Tag]*proto_go.TagDescriptor) map[mTypes.Tag]mTypes.
for tag, tagDescriptor := range tags { for tag, tagDescriptor := range tags {
resultMap[tag] = mTypes.Descriptor{ resultMap[tag] = mTypes.Descriptor{
Digest: tagDescriptor.Digest, Digest: tagDescriptor.GetDigest(),
MediaType: tagDescriptor.MediaType, MediaType: tagDescriptor.GetMediaType(),
} }
} }
@ -393,19 +389,19 @@ func GetFullImageMetaFromProto(tag string, protoRepoMeta *proto_go.RepoMeta, pro
imageDigest := imageMeta.Digest.String() imageDigest := imageMeta.Digest.String()
return mTypes.FullImageMeta{ return mTypes.FullImageMeta{
Repo: protoRepoMeta.Name, Repo: protoRepoMeta.GetName(),
Tag: tag, Tag: tag,
MediaType: imageMeta.MediaType, MediaType: imageMeta.MediaType,
Digest: imageMeta.Digest, Digest: imageMeta.Digest,
Size: imageMeta.Size, Size: imageMeta.Size,
Index: imageMeta.Index, Index: imageMeta.Index,
Manifests: GetFullManifestData(protoRepoMeta, imageMeta.Manifests), Manifests: GetFullManifestData(protoRepoMeta, imageMeta.Manifests),
IsStarred: protoRepoMeta.IsStarred, IsStarred: protoRepoMeta.GetIsStarred(),
IsBookmarked: protoRepoMeta.IsBookmarked, IsBookmarked: protoRepoMeta.GetIsBookmarked(),
Referrers: GetImageReferrers(protoRepoMeta.Referrers[imageDigest]), Referrers: GetImageReferrers(protoRepoMeta.GetReferrers()[imageDigest]),
Statistics: GetImageStatistics(protoRepoMeta.Statistics[imageDigest]), Statistics: GetImageStatistics(protoRepoMeta.GetStatistics()[imageDigest]),
Signatures: GetImageSignatures(protoRepoMeta.Signatures[imageDigest]), Signatures: GetImageSignatures(protoRepoMeta.GetSignatures()[imageDigest]),
} }
} }
@ -420,9 +416,9 @@ func GetFullManifestData(protoRepoMeta *proto_go.RepoMeta, manifestData []mTypes
for i := range manifestData { for i := range manifestData {
results = append(results, mTypes.FullManifestMeta{ results = append(results, mTypes.FullManifestMeta{
ManifestMeta: manifestData[i], ManifestMeta: manifestData[i],
Referrers: GetImageReferrers(protoRepoMeta.Referrers[manifestData[i].Digest.String()]), Referrers: GetImageReferrers(protoRepoMeta.GetReferrers()[manifestData[i].Digest.String()]),
Statistics: GetImageStatistics(protoRepoMeta.Statistics[manifestData[i].Digest.String()]), Statistics: GetImageStatistics(protoRepoMeta.GetStatistics()[manifestData[i].Digest.String()]),
Signatures: GetImageSignatures(protoRepoMeta.Signatures[manifestData[i].Digest.String()]), Signatures: GetImageSignatures(protoRepoMeta.GetSignatures()[manifestData[i].Digest.String()]),
}) })
} }
@ -436,27 +432,27 @@ func GetRepoMeta(protoRepoMeta *proto_go.RepoMeta) mTypes.RepoMeta {
repoDownloads := int32(0) repoDownloads := int32(0)
for _, descriptor := range protoRepoMeta.Tags { for _, descriptor := range protoRepoMeta.GetTags() {
if statistic := protoRepoMeta.Statistics[descriptor.Digest]; statistic != nil { if statistic := protoRepoMeta.GetStatistics()[descriptor.GetDigest()]; statistic != nil {
repoDownloads += statistic.DownloadCount repoDownloads += statistic.GetDownloadCount()
} }
} }
return mTypes.RepoMeta{ return mTypes.RepoMeta{
Name: protoRepoMeta.Name, Name: protoRepoMeta.GetName(),
Tags: GetTags(protoRepoMeta.Tags), Tags: GetTags(protoRepoMeta.GetTags()),
Rank: int(protoRepoMeta.Rank), Rank: int(protoRepoMeta.GetRank()),
Size: protoRepoMeta.Size, Size: protoRepoMeta.GetSize(),
Platforms: GetPlatforms(protoRepoMeta.Platforms), Platforms: GetPlatforms(protoRepoMeta.GetPlatforms()),
Vendors: protoRepoMeta.Vendors, Vendors: protoRepoMeta.GetVendors(),
IsStarred: protoRepoMeta.IsStarred, IsStarred: protoRepoMeta.GetIsStarred(),
IsBookmarked: protoRepoMeta.IsBookmarked, IsBookmarked: protoRepoMeta.GetIsBookmarked(),
StarCount: int(protoRepoMeta.Stars), StarCount: int(protoRepoMeta.GetStars()),
DownloadCount: int(repoDownloads), DownloadCount: int(repoDownloads),
LastUpdatedImage: GetLastUpdatedImage(protoRepoMeta.LastUpdatedImage), LastUpdatedImage: GetLastUpdatedImage(protoRepoMeta.GetLastUpdatedImage()),
Statistics: GetStatisticsMap(protoRepoMeta.Statistics), Statistics: GetStatisticsMap(protoRepoMeta.GetStatistics()),
Signatures: GetSignatures(protoRepoMeta.Signatures), Signatures: GetSignatures(protoRepoMeta.GetSignatures()),
Referrers: GetReferrers(protoRepoMeta.Referrers), Referrers: GetReferrers(protoRepoMeta.GetReferrers()),
} }
} }
@ -482,7 +478,7 @@ func AddProtoPlatforms(platforms []*proto_go.Platform, newPlatforms []*proto_go.
func ContainsProtoPlatform(platforms []*proto_go.Platform, platform *proto_go.Platform) bool { func ContainsProtoPlatform(platforms []*proto_go.Platform, platform *proto_go.Platform) bool {
for i := range platforms { for i := range platforms {
if platforms[i].OS == platform.OS && platforms[i].Architecture == platform.Architecture { if platforms[i].GetOS() == platform.GetOS() && platforms[i].GetArchitecture() == platform.GetArchitecture() {
return true return true
} }
} }
@ -507,11 +503,11 @@ func GetLastUpdatedImage(protoLastUpdated *proto_go.RepoLastUpdatedImage) *mType
return &mTypes.LastUpdatedImage{ return &mTypes.LastUpdatedImage{
Descriptor: mTypes.Descriptor{ Descriptor: mTypes.Descriptor{
Digest: protoLastUpdated.Digest, Digest: protoLastUpdated.GetDigest(),
MediaType: protoLastUpdated.MediaType, MediaType: protoLastUpdated.GetMediaType(),
}, },
Tag: protoLastUpdated.Tag, Tag: protoLastUpdated.GetTag(),
LastUpdated: GetTime(protoLastUpdated.LastUpdated), LastUpdated: GetTime(protoLastUpdated.GetLastUpdated()),
} }
} }
@ -521,24 +517,24 @@ func GetImageMeta(dbImageMeta *proto_go.ImageMeta) mTypes.ImageMeta {
} }
imageMeta := mTypes.ImageMeta{ imageMeta := mTypes.ImageMeta{
MediaType: dbImageMeta.MediaType, MediaType: dbImageMeta.GetMediaType(),
Size: GetImageManifestSize(dbImageMeta), Size: GetImageManifestSize(dbImageMeta),
Digest: GetImageDigest(dbImageMeta), Digest: GetImageDigest(dbImageMeta),
} }
if dbImageMeta.MediaType == ispec.MediaTypeImageIndex { if dbImageMeta.GetMediaType() == ispec.MediaTypeImageIndex {
manifests := make([]ispec.Descriptor, 0, len(dbImageMeta.Manifests)) manifests := make([]ispec.Descriptor, 0, len(dbImageMeta.GetManifests()))
for _, manifest := range deref(dbImageMeta.Index, proto_go.IndexMeta{}).Index.Manifests { for _, manifest := range dbImageMeta.GetIndex().GetIndex().GetManifests() {
manifests = append(manifests, ispec.Descriptor{ manifests = append(manifests, ispec.Descriptor{
MediaType: manifest.MediaType, MediaType: manifest.GetMediaType(),
Digest: godigest.Digest(manifest.Digest), Digest: godigest.Digest(manifest.GetDigest()),
Size: manifest.Size, Size: manifest.GetSize(),
}) })
} }
imageMeta.Index = &ispec.Index{ imageMeta.Index = &ispec.Index{
Versioned: specs.Versioned{SchemaVersion: int(dbImageMeta.Index.Index.Versioned.GetSchemaVersion())}, Versioned: specs.Versioned{SchemaVersion: int(dbImageMeta.GetIndex().GetIndex().Versioned.GetSchemaVersion())},
MediaType: ispec.MediaTypeImageIndex, MediaType: ispec.MediaTypeImageIndex,
Manifests: manifests, Manifests: manifests,
Subject: GetImageSubject(dbImageMeta), Subject: GetImageSubject(dbImageMeta),
@ -547,45 +543,45 @@ func GetImageMeta(dbImageMeta *proto_go.ImageMeta) mTypes.ImageMeta {
} }
} }
manifestDataList := make([]mTypes.ManifestMeta, 0, len(dbImageMeta.Manifests)) manifestDataList := make([]mTypes.ManifestMeta, 0, len(dbImageMeta.GetManifests()))
for _, manifest := range dbImageMeta.Manifests { for _, manifest := range dbImageMeta.GetManifests() {
manifestDataList = append(manifestDataList, mTypes.ManifestMeta{ manifestDataList = append(manifestDataList, mTypes.ManifestMeta{
Size: manifest.Size, Size: manifest.GetSize(),
Digest: godigest.Digest(manifest.Digest), Digest: godigest.Digest(manifest.GetDigest()),
Manifest: ispec.Manifest{ Manifest: ispec.Manifest{
Versioned: specs.Versioned{SchemaVersion: int(manifest.Manifest.Versioned.GetSchemaVersion())}, Versioned: specs.Versioned{SchemaVersion: int(manifest.GetManifest().GetVersioned().GetSchemaVersion())},
MediaType: deref(manifest.Manifest.MediaType, ""), MediaType: manifest.GetManifest().GetMediaType(),
ArtifactType: deref(manifest.Manifest.ArtifactType, ""), ArtifactType: manifest.GetManifest().GetArtifactType(),
Config: ispec.Descriptor{ Config: ispec.Descriptor{
MediaType: manifest.Manifest.Config.MediaType, MediaType: manifest.GetManifest().GetConfig().GetMediaType(),
Size: manifest.Manifest.Config.Size, Size: manifest.GetManifest().GetConfig().GetSize(),
Digest: godigest.Digest(manifest.Manifest.Config.Digest), Digest: godigest.Digest(manifest.GetManifest().GetConfig().GetDigest()),
}, },
Layers: GetLayers(manifest.Manifest.Layers), Layers: GetLayers(manifest.GetManifest().GetLayers()),
Subject: GetSubject(manifest.Manifest.Subject), Subject: GetSubject(manifest.GetManifest().GetSubject()),
Annotations: manifest.Manifest.Annotations, Annotations: manifest.GetManifest().GetAnnotations(),
}, },
Config: ispec.Image{ Config: ispec.Image{
Created: GetTime(manifest.Config.Created), Created: GetTime(manifest.GetConfig().GetCreated()),
Author: deref(manifest.Config.Author, ""), Author: manifest.GetConfig().GetAuthor(),
Platform: GetPlatform(manifest.Config.Platform), Platform: GetPlatform(manifest.GetConfig().GetPlatform()),
Config: ispec.ImageConfig{ Config: ispec.ImageConfig{
User: manifest.Config.Config.User, User: manifest.GetConfig().GetConfig().GetUser(),
ExposedPorts: GetExposedPorts(manifest.Config.Config.ExposedPorts), ExposedPorts: GetExposedPorts(manifest.GetConfig().GetConfig().GetExposedPorts()),
Env: manifest.Config.Config.Env, Env: manifest.GetConfig().GetConfig().GetEnv(),
Entrypoint: manifest.Config.Config.Entrypoint, Entrypoint: manifest.GetConfig().GetConfig().GetEntrypoint(),
Cmd: manifest.Config.Config.Cmd, Cmd: manifest.GetConfig().GetConfig().GetCmd(),
Volumes: GetConfigVolumes(manifest.Config.Config.Volumes), Volumes: GetConfigVolumes(manifest.GetConfig().GetConfig().GetVolumes()),
WorkingDir: deref(manifest.Config.Config.WorkingDir, ""), WorkingDir: manifest.GetConfig().GetConfig().GetWorkingDir(),
Labels: manifest.Config.Config.Labels, Labels: manifest.GetConfig().GetConfig().GetLabels(),
StopSignal: deref(manifest.Config.Config.StopSignal, ""), StopSignal: manifest.GetConfig().GetConfig().GetStopSignal(),
}, },
RootFS: ispec.RootFS{ RootFS: ispec.RootFS{
Type: manifest.Config.RootFS.Type, Type: manifest.GetConfig().GetRootFS().GetType(),
DiffIDs: GetDiffIDs(manifest.Config.RootFS.DiffIDs), DiffIDs: GetDiffIDs(manifest.GetConfig().GetRootFS().GetDiffIDs()),
}, },
History: GetHistory(manifest.Config.History), History: GetHistory(manifest.GetConfig().GetHistory()),
}, },
}) })
} }

View file

@ -388,11 +388,3 @@ func ref[T any](input T) *T {
return &ref return &ref
} }
func deref[T any](pointer *T, defaultVal T) T {
if pointer != nil {
return *pointer
}
return defaultVal
}