chore: update golangci-lint and fix all issues (#3575)

* chore: Update golangci-lint

Signed-off-by: Lars Francke <git@lars-francke.de>

* chore: fix all golangci-lint issues

- Remove deprecated `// +build` tags
- Fix godoclint, modernize, wsl_v5, govet, lll, gci, noctx issues
- Update linter configuration
- Modernize code to use Go 1.22+ features (for range N, slices.Contains, etc.)
- Update make check lint the privileged tests

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

---------

Signed-off-by: Lars Francke <git@lars-francke.de>
Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
Co-authored-by: Lars Francke <git@lars-francke.de>
This commit is contained in:
Andrei Aaron
2025-11-22 23:36:48 +02:00
committed by GitHub
parent 566286ae42
commit da426850e7
242 changed files with 811 additions and 1010 deletions
+15 -14
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
"time"
@@ -464,8 +465,8 @@ func (bdw *BoltDB) SearchRepos(ctx context.Context, searchText string,
}
protoRepoMeta.Rank = int32(rank) //nolint:gosec // ignore overflow
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
repos = append(repos, mConvert.GetRepoMeta(protoRepoMeta))
}
@@ -574,8 +575,8 @@ func (bdw *BoltDB) SearchTags(ctx context.Context, searchText string,
delete(protoRepoMeta.Tags, "")
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
for tag, descriptor := range protoRepoMeta.Tags {
if !strings.HasPrefix(tag, searchedTag) || tag == "" {
@@ -658,8 +659,8 @@ func (bdw *BoltDB) FilterTags(ctx context.Context, filterRepoTag mTypes.FilterRe
}
delete(protoRepoMeta.Tags, "")
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
repoMeta := mConvert.GetRepoMeta(protoRepoMeta)
for tag, descriptor := range protoRepoMeta.Tags {
@@ -759,8 +760,8 @@ func (bdw *BoltDB) FilterRepos(ctx context.Context, acceptName mTypes.FilterRepo
return err
}
repoMeta.IsBookmarked = zcommon.Contains(userBookmarks, repoMeta.Name)
repoMeta.IsStarred = zcommon.Contains(userStars, repoMeta.Name)
repoMeta.IsBookmarked = slices.Contains(userBookmarks, repoMeta.Name)
repoMeta.IsStarred = slices.Contains(userStars, repoMeta.Name)
fullRepoMeta := mConvert.GetRepoMeta(repoMeta)
@@ -796,8 +797,8 @@ func (bdw *BoltDB) GetRepoMeta(ctx context.Context, repo string) (mTypes.RepoMet
}
delete(protoRepoMeta.Tags, "")
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, repo)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = slices.Contains(userStars, repo)
return nil
})
@@ -830,8 +831,8 @@ func (bdw *BoltDB) GetFullImageMeta(ctx context.Context, repo string, tag string
}
delete(protoRepoMeta.Tags, "")
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, repo)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = slices.Contains(userStars, repo)
descriptor, ok := protoRepoMeta.Tags[tag]
if !ok {
@@ -1518,7 +1519,7 @@ func (bdw *BoltDB) ToggleStarRepo(ctx context.Context, repo string) (mTypes.Togg
return err
}
isRepoStarred := zcommon.Contains(userData.StarredRepos, repo)
isRepoStarred := slices.Contains(userData.StarredRepos, repo)
if isRepoStarred {
res = mTypes.Removed
@@ -1591,7 +1592,7 @@ func (bdw *BoltDB) ToggleBookmarkRepo(ctx context.Context, repo string) (mTypes.
return err
}
isRepoBookmarked := zcommon.Contains(userData.BookmarkedRepos, repo)
isRepoBookmarked := slices.Contains(userData.BookmarkedRepos, repo)
if isRepoBookmarked {
res = mTypes.Removed
+10 -27
View File
@@ -1,6 +1,7 @@
package common
import (
"slices"
"strings"
"time"
@@ -15,23 +16,15 @@ import (
)
func SignatureAlreadyExists(signatureSlice []mTypes.SignatureInfo, sm mTypes.SignatureMetadata) bool {
for _, sigInfo := range signatureSlice {
if sm.SignatureDigest == sigInfo.SignatureManifestDigest {
return true
}
}
return false
return slices.ContainsFunc(signatureSlice, func(sigInfo mTypes.SignatureInfo) bool {
return sm.SignatureDigest == sigInfo.SignatureManifestDigest
})
}
func ProtoSignatureAlreadyExists(signatureSlice []*proto_go.SignatureInfo, sm mTypes.SignatureMetadata) bool {
for _, sigInfo := range signatureSlice {
if sm.SignatureDigest == sigInfo.SignatureManifestDigest {
return true
}
}
return false
return slices.ContainsFunc(signatureSlice, func(sigInfo *proto_go.SignatureInfo) bool {
return sm.SignatureDigest == sigInfo.SignatureManifestDigest
})
}
func ReferenceIsDigest(reference string) bool {
@@ -159,19 +152,9 @@ func MatchesArtifactTypes(descriptorMediaType string, artifactTypes []string) bo
return true
}
found := false
for _, artifactType := range artifactTypes {
if artifactType != "" && descriptorMediaType != artifactType {
continue
}
found = true
break
}
return found
return slices.ContainsFunc(artifactTypes, func(artifactType string) bool {
return artifactType == "" || descriptorMediaType == artifactType
})
}
// CheckImageLastUpdated check if the given image is updated earlier than the current repoLastUpdated value
+5 -9
View File
@@ -1,6 +1,7 @@
package convert
import (
"slices"
"time"
godigest "github.com/opencontainers/go-digest"
@@ -8,7 +9,6 @@ import (
ispec "github.com/opencontainers/image-spec/specs-go/v1"
"google.golang.org/protobuf/types/known/timestamppb"
"zotregistry.dev/zot/v2/pkg/common"
"zotregistry.dev/zot/v2/pkg/compat"
proto_go "zotregistry.dev/zot/v2/pkg/meta/proto/gen"
mTypes "zotregistry.dev/zot/v2/pkg/meta/types"
@@ -497,18 +497,14 @@ func AddProtoPlatforms(platforms []*proto_go.Platform, newPlatforms []*proto_go.
}
func ContainsProtoPlatform(platforms []*proto_go.Platform, platform *proto_go.Platform) bool {
for i := range platforms {
if platforms[i].GetOS() == platform.GetOS() && platforms[i].GetArchitecture() == platform.GetArchitecture() {
return true
}
}
return false
return slices.ContainsFunc(platforms, func(p *proto_go.Platform) bool {
return p.GetOS() == platform.GetOS() && p.GetArchitecture() == platform.GetArchitecture()
})
}
func AddVendors(vendors []string, newVendors []string) []string {
for _, newVendor := range newVendors {
if !common.Contains(vendors, newVendor) {
if !slices.Contains(vendors, newVendor) {
vendors = append(vendors, newVendor)
}
}
-4
View File
@@ -213,8 +213,6 @@ func getProtoManifestLayers(layers []ispec.Descriptor) []*proto_go.Descriptor {
protoLayers := []*proto_go.Descriptor{}
for _, layer := range layers {
layer := layer
protoLayers = append(protoLayers, getProtoDesc(&layer))
}
@@ -275,8 +273,6 @@ func getProtoHistory(historySlice []ispec.History) []*proto_go.History {
protoHistory := []*proto_go.History{}
for _, history := range historySlice {
history := history
protoHistory = append(protoHistory, &proto_go.History{
Created: GetProtoTime(history.Created),
CreatedBy: &history.CreatedBy,
+15 -14
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"strings"
"time"
@@ -635,8 +636,8 @@ func (dwr *DynamoDB) SearchRepos(ctx context.Context, searchText string) ([]mTyp
}
protoRepoMeta.Rank = int32(rank) //nolint:gosec // ignore overflow
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
repos = append(repos, mConvert.GetRepoMeta(protoRepoMeta))
}
@@ -670,8 +671,8 @@ func (dwr *DynamoDB) SearchTags(ctx context.Context, searchText string) ([]mType
delete(protoRepoMeta.Tags, "")
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, searchedRepo)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, searchedRepo)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, searchedRepo)
protoRepoMeta.IsStarred = slices.Contains(userStars, searchedRepo)
for tag, descriptor := range protoRepoMeta.Tags {
if !strings.HasPrefix(tag, searchedTag) {
@@ -754,8 +755,8 @@ func (dwr *DynamoDB) FilterTags(ctx context.Context, filterRepoTag mTypes.Filter
continue
}
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
repoMeta := mConvert.GetRepoMeta(protoRepoMeta)
for tag, descriptor := range repoMeta.Tags {
@@ -890,8 +891,8 @@ func (dwr *DynamoDB) GetRepoMeta(ctx context.Context, repo string) (mTypes.RepoM
userBookmarks := getUserBookmarks(ctx, dwr)
userStars := getUserStars(ctx, dwr)
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, repo)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = slices.Contains(userStars, repo)
return mConvert.GetRepoMeta(protoRepoMeta), nil
}
@@ -906,8 +907,8 @@ func (dwr *DynamoDB) GetFullImageMeta(ctx context.Context, repo string, tag stri
bookmarks, stars := dwr.getUserBookmarksAndStars(ctx)
protoRepoMeta.IsBookmarked = zcommon.Contains(bookmarks, repo)
protoRepoMeta.IsStarred = zcommon.Contains(stars, repo)
protoRepoMeta.IsBookmarked = slices.Contains(bookmarks, repo)
protoRepoMeta.IsStarred = slices.Contains(stars, repo)
descriptor, ok := protoRepoMeta.Tags[tag]
if !ok {
@@ -1040,8 +1041,8 @@ func (dwr *DynamoDB) FilterRepos(ctx context.Context, acceptName mTypes.FilterRe
continue
}
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
fullRepoMeta := mConvert.GetRepoMeta(protoRepoMeta)
@@ -1574,7 +1575,7 @@ func (dwr *DynamoDB) ToggleBookmarkRepo(ctx context.Context, repo string) (
return res, err
}
if !zcommon.Contains(userData.BookmarkedRepos, repo) {
if !slices.Contains(userData.BookmarkedRepos, repo) {
userData.BookmarkedRepos = append(userData.BookmarkedRepos, repo)
res = mTypes.Added
} else {
@@ -1625,7 +1626,7 @@ func (dwr *DynamoDB) ToggleStarRepo(ctx context.Context, repo string) (
return res, err
}
if !zcommon.Contains(userData.StarredRepos, repo) {
if !slices.Contains(userData.StarredRepos, repo) {
userData.StarredRepos = append(userData.StarredRepos, repo)
res = mTypes.Added
} else {
+2 -2
View File
@@ -38,7 +38,7 @@ func TestWrapperErrors(t *testing.T) {
badEndpoint := endpoint + "1"
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
func(service, region string, options ...any) (aws.Endpoint, error) {
return aws.Endpoint{ //nolint: staticcheck
PartitionID: "aws",
URL: badEndpoint,
@@ -74,7 +74,7 @@ func TestWrapperErrors(t *testing.T) {
Convey("Delete table errors", t, func() {
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
func(service, region string, options ...any) (aws.Endpoint, error) {
return aws.Endpoint{ //nolint: staticcheck
PartitionID: "aws",
URL: endpoint,
+1 -1
View File
@@ -106,7 +106,7 @@ func TestIterator(t *testing.T) {
func TestIteratorErrors(t *testing.T) {
Convey("errors", t, func() {
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
func(service, region string, options ...any) (aws.Endpoint, error) {
return aws.Endpoint{ //nolint: staticcheck
PartitionID: "aws",
URL: "endpoint",
+1 -1
View File
@@ -15,7 +15,7 @@ type DBDriverParameters struct {
func GetDynamoClient(params DBDriverParameters) (*dynamodb.Client, error) {
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
func(service, region string, options ...any) (aws.Endpoint, error) {
return aws.Endpoint{ //nolint: staticcheck
PartitionID: "aws",
URL: params.Endpoint,
+3 -3
View File
@@ -60,7 +60,7 @@ func New(storageConfig config.StorageConfig, log log.Logger) (mTypes.MetaDB, err
return boltdb.New(driver, log) //nolint:contextcheck
}
func getDynamoParams(cacheDriverConfig map[string]interface{}, log log.Logger) mdynamodb.DBDriverParameters {
func getDynamoParams(cacheDriverConfig map[string]any, log log.Logger) mdynamodb.DBDriverParameters {
allParametersOk := true
endpoint, ok := toStringIfOk(cacheDriverConfig, "endpoint", "", log)
@@ -103,7 +103,7 @@ func getDynamoParams(cacheDriverConfig map[string]interface{}, log log.Logger) m
}
}
func getRedisParams(cacheDriverConfig map[string]interface{}, log log.Logger) redis.DBDriverParameters {
func getRedisParams(cacheDriverConfig map[string]any, log log.Logger) redis.DBDriverParameters {
keyPrefix, ok := toStringIfOk(cacheDriverConfig, "keyprefix", "zot", log)
if !ok {
log.Panic().Msg("redis parameters are not specified correctly, can't proceed")
@@ -114,7 +114,7 @@ func getRedisParams(cacheDriverConfig map[string]interface{}, log log.Logger) re
}
}
func toStringIfOk(cacheDriverConfig map[string]interface{},
func toStringIfOk(cacheDriverConfig map[string]any,
param string,
defaultVal string,
log log.Logger,
+18 -18
View File
@@ -1,5 +1,4 @@
//go:build imagetrust
// +build imagetrust
package meta_test
@@ -9,6 +8,7 @@ import (
"fmt"
"os"
"path"
"slices"
"testing"
"time"
@@ -178,7 +178,7 @@ func TestRedisDB(t *testing.T) {
log := log.NewTestLogger()
params := redis.DBDriverParameters{KeyPrefix: "zot"}
driverConfig := map[string]interface{}{"url": "redis://" + miniRedis.Addr()}
driverConfig := map[string]any{"url": "redis://" + miniRedis.Addr()}
redisDriver, err := rediscfg.GetRedisClient(driverConfig, log)
So(err, ShouldBeNil)
@@ -2312,13 +2312,13 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func
}
}
So(zcommon.Contains(tags, "0.0.1"), ShouldBeTrue)
So(zcommon.Contains(tags, "0.0.2"), ShouldBeTrue)
So(zcommon.Contains(tags, "0.1.0"), ShouldBeTrue)
So(zcommon.Contains(tags, "1.0.0"), ShouldBeTrue)
So(zcommon.Contains(tags, "1.0.1"), ShouldBeTrue)
So(zcommon.Contains(tags, "2.0.0"), ShouldBeTrue)
So(zcommon.Contains(tags, "0.0.1"), ShouldBeTrue)
So(slices.Contains(tags, "0.0.1"), ShouldBeTrue)
So(slices.Contains(tags, "0.0.2"), ShouldBeTrue)
So(slices.Contains(tags, "0.1.0"), ShouldBeTrue)
So(slices.Contains(tags, "1.0.0"), ShouldBeTrue)
So(slices.Contains(tags, "1.0.1"), ShouldBeTrue)
So(slices.Contains(tags, "2.0.0"), ShouldBeTrue)
So(slices.Contains(tags, "0.0.1"), ShouldBeTrue)
So(indexImage.Digest.String(), ShouldResemble, multiarch.DigestStr())
@@ -3120,16 +3120,16 @@ func TestCreateBoltDB(t *testing.T) {
So(log, ShouldNotBeNil)
Convey("Test New() with unspecified driver", func() {
conf.Storage.CacheDriver = map[string]interface{}{}
conf.Storage.CacheDriver = map[string]any{}
})
Convey("Test New() with bad driver", func() {
// we default to bolt in case of misconfiguration
conf.Storage.CacheDriver = map[string]interface{}{"name": "somedriver"}
conf.Storage.CacheDriver = map[string]any{"name": "somedriver"}
})
Convey("Test New() with specified driver", func() {
conf.Storage.CacheDriver = map[string]interface{}{"name": "cache"}
conf.Storage.CacheDriver = map[string]any{"name": "cache"}
})
repoDBPath := path.Join(rootDir, "meta.db")
@@ -3162,7 +3162,7 @@ func TestCreateRedisDB(t *testing.T) {
Convey("Succeeds with default key prefix", func() {
miniRedis := miniredis.RunT(t)
cacheDriverParams := map[string]interface{}{
cacheDriverParams := map[string]any{
"name": "redis",
"url": "redis://" + miniRedis.Addr(),
}
@@ -3177,7 +3177,7 @@ func TestCreateRedisDB(t *testing.T) {
Convey("Succeeds with specific key prefix", func() {
miniRedis := miniredis.RunT(t)
cacheDriverParams := map[string]interface{}{
cacheDriverParams := map[string]any{
"name": "redis",
"url": "redis://" + miniRedis.Addr(),
"key": "keyPrefix",
@@ -3192,7 +3192,7 @@ func TestCreateRedisDB(t *testing.T) {
Convey("Fails on Ping()", func() {
// Redis client will not be responding
cacheDriverParams := map[string]interface{}{
cacheDriverParams := map[string]any{
"name": "redis",
"url": "redis://127.0.0.1:" + tCommon.GetFreePort(),
}
@@ -3205,7 +3205,7 @@ func TestCreateRedisDB(t *testing.T) {
Convey("Fail on invalid parameters", func() {
// Bad key types
cacheDriverParams := map[string]interface{}{
cacheDriverParams := map[string]any{
"name": "redis",
"url": "redis://127.0.0.1:" + tCommon.GetFreePort(),
"keyprefix": true,
@@ -3216,7 +3216,7 @@ func TestCreateRedisDB(t *testing.T) {
testFunc := func() { _, _ = meta.New(conf.Storage.StorageConfig, log) }
So(testFunc, ShouldPanic)
cacheDriverParams = map[string]interface{}{
cacheDriverParams = map[string]any{
"name": "redis",
"url": "redis://127.0.0.1:" + tCommon.GetFreePort(),
"keyprefix": "",
@@ -3227,7 +3227,7 @@ func TestCreateRedisDB(t *testing.T) {
testFunc = func() { _, _ = meta.New(conf.Storage.StorageConfig, log) }
So(testFunc, ShouldPanic)
cacheDriverParams = map[string]interface{}{
cacheDriverParams = map[string]any{
"name": "redis",
"url": false,
"keyprefix": "zot",
+2 -2
View File
@@ -90,7 +90,7 @@ func ParseStorage(metaDB mTypes.MetaDB, storeController stypes.StoreController,
func getReposToBeDeleted(allStorageRepos []string, allMetaDBRepos []string) []string {
toBeDeleted := []string{}
storageRepoNameSet := map[string]struct{}{}
storageRepoNameSet := make(map[string]struct{}, len(allStorageRepos))
for i := range allStorageRepos {
storageRepoNameSet[allStorageRepos[i]] = struct{}{}
@@ -313,7 +313,7 @@ func getNotationSignatureLayersInfo(
return layers, nil
}
// SetMetadataFromInput tries to set manifest metadata and update repo metadata by adding the current tag
// SetImageMetaFromInput tries to set manifest metadata and update repo metadata by adding the current tag
// (in case the reference is a tag). The function expects image manifests and indexes (multi arch images).
func SetImageMetaFromInput(ctx context.Context, repo, reference, mediaType string, digest godigest.Digest, blob []byte,
imageStore stypes.ImageStore, metaDB mTypes.MetaDB, log log.Logger,
+2 -2
View File
@@ -379,7 +379,7 @@ func TestParseStorageWithRedisDB(t *testing.T) {
log := log.NewTestLogger()
params := redis.DBDriverParameters{KeyPrefix: "zot"}
driverConfig := map[string]interface{}{"url": "redis://" + miniRedis.Addr()}
driverConfig := map[string]any{"url": "redis://" + miniRedis.Addr()}
redisDriver, err := rediscfg.GetRedisClient(driverConfig, log)
So(err, ShouldBeNil)
@@ -439,7 +439,7 @@ func RunParseStorageTests(rootDir string, metaDB mTypes.MetaDB, log log.Logger)
storeController := storage.StoreController{DefaultStore: imageStore}
manifests := []ispec.Manifest{}
for i := 0; i < 3; i++ {
for i := range 3 {
image := CreateRandomImage() //nolint:staticcheck
manifests = append(manifests, image.Manifest)
+20 -23
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
"time"
@@ -141,7 +142,7 @@ func (rc *RedisDB) ToggleStarRepo(ctx context.Context, repo string) (mTypes.Togg
return err
}
isRepoStarred := zcommon.Contains(userData.StarredRepos, repo)
isRepoStarred := slices.Contains(userData.StarredRepos, repo)
if isRepoStarred {
res = mTypes.Removed
@@ -228,7 +229,7 @@ func (rc *RedisDB) ToggleBookmarkRepo(ctx context.Context, repo string) (mTypes.
return err
}
isRepoBookmarked := zcommon.Contains(userData.BookmarkedRepos, repo)
isRepoBookmarked := slices.Contains(userData.BookmarkedRepos, repo)
if isRepoBookmarked {
res = mTypes.Removed
@@ -263,7 +264,6 @@ func (rc *RedisDB) ToggleBookmarkRepo(ctx context.Context, repo string) (mTypes.
return res, err
}
// UserDB profile/api key CRUD.
func (rc *RedisDB) GetUserData(ctx context.Context) (mTypes.UserData, error) {
userData := mTypes.UserData{}
userData.APIKeys = make(map[string]mTypes.APIKeyDetails)
@@ -943,8 +943,8 @@ func (rc *RedisDB) SearchRepos(ctx context.Context, searchText string) ([]mTypes
}
protoRepoMeta.Rank = int32(rank) //nolint:gosec // ignore overflow
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
repoMeta := mConvert.GetRepoMeta(protoRepoMeta)
foundRepos = append(foundRepos, repoMeta)
@@ -987,8 +987,8 @@ func (rc *RedisDB) SearchTags(ctx context.Context, searchText string) ([]mTypes.
delete(protoRepoMeta.Tags, "")
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
for tag, descriptor := range protoRepoMeta.Tags {
if !strings.HasPrefix(tag, searchedTag) || tag == "" {
@@ -1069,8 +1069,8 @@ func (rc *RedisDB) FilterTags(ctx context.Context, filterRepoTag mTypes.FilterRe
}
delete(protoRepoMeta.Tags, "")
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
repoMeta := mConvert.GetRepoMeta(protoRepoMeta)
for tag, descriptor := range protoRepoMeta.Tags {
@@ -1170,8 +1170,8 @@ func (rc *RedisDB) FilterRepos(ctx context.Context, acceptName mTypes.FilterRepo
return []mTypes.RepoMeta{}, err
}
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, protoRepoMeta.Name)
protoRepoMeta.IsStarred = slices.Contains(userStars, protoRepoMeta.Name)
repoMeta := mConvert.GetRepoMeta(protoRepoMeta)
@@ -1193,8 +1193,8 @@ func (rc *RedisDB) GetRepoMeta(ctx context.Context, repo string) (mTypes.RepoMet
userBookmarks, userStars := rc.getUserBookmarksAndStarsNoError(ctx)
delete(protoRepoMeta.Tags, "")
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, repo)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = slices.Contains(userStars, repo)
return mConvert.GetRepoMeta(protoRepoMeta), err
}
@@ -1211,8 +1211,8 @@ func (rc *RedisDB) GetFullImageMeta(ctx context.Context, repo string, tag string
userBookmarks, userStars := rc.getUserBookmarksAndStarsNoError(ctx)
delete(protoRepoMeta.Tags, "")
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = zcommon.Contains(userStars, repo)
protoRepoMeta.IsBookmarked = slices.Contains(userBookmarks, repo)
protoRepoMeta.IsStarred = slices.Contains(userStars, repo)
descriptor, ok := protoRepoMeta.Tags[tag]
if !ok {
@@ -1840,14 +1840,11 @@ func (rc *RedisDB) FilterImageMeta(ctx context.Context,
return imageMetaMap, nil
}
/*
RemoveRepoReference removes the tag from RepoMetadata if the reference is a tag,
it also removes its corresponding digest from Statistics, Signatures and Referrers if there are no tags
pointing to it.
If the reference is a digest then it will remove the digest from Statistics, Signatures and Referrers only
if there are no tags pointing to the digest, otherwise it's noop.
*/
// RemoveRepoReference removes the tag from RepoMetadata if the reference is a tag.
// It also removes its corresponding digest from Statistics, Signatures and Referrers if there are no tags
// pointing to it.
// If the reference is a digest then it will remove the digest from Statistics, Signatures and Referrers only
// if there are no tags pointing to the digest, otherwise it's noop.
func (rc *RedisDB) RemoveRepoReference(repo, reference string, manifestDigest godigest.Digest) error {
ctx := context.Background()
+3 -1
View File
@@ -8,7 +8,7 @@ import (
ispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// Used to model changes to an object after a call to the DB.
// ToggleState is used to model changes to an object after a call to the DB.
type ToggleState int
const (
@@ -18,6 +18,7 @@ const (
)
type (
// FilterFunc is a filter function.
// Currently imageMeta applied for indexes is applied for each manifest individually so imageMeta.manifests
// contains just 1 manifest.
FilterFunc func(repoMeta RepoMeta, imageMeta ImageMeta) bool
@@ -284,6 +285,7 @@ type FullManifestMeta struct {
type LastUpdatedImage struct {
Descriptor
Tag string
LastUpdated *time.Time
}