diff --git a/pkg/api/controller.go b/pkg/api/controller.go index d9446ba75..59ecbce64 100644 --- a/pkg/api/controller.go +++ b/pkg/api/controller.go @@ -73,7 +73,7 @@ func NewController(appConfig *config.Config) *Controller { // memberSocket is the local member's socket // the index is also fetched for quick lookups during proxying memberSocketIdx, memberSocket, err := GetLocalMemberClusterSocket(appConfig.Cluster.Members, localSockets) - if err != nil { + if err != nil || memberSocketIdx < 0 { logger.Error().Err(err).Msg("failed to get member socket") panic("failed to get member socket") } diff --git a/pkg/api/controller_test.go b/pkg/api/controller_test.go index 66da66873..d97d6b4cf 100644 --- a/pkg/api/controller_test.go +++ b/pkg/api/controller_test.go @@ -381,7 +381,7 @@ func TestAutoPortSelection(t *testing.T) { break } - t.Logf(scanner.Text()) + t.Logf("%s", scanner.Text()) } So(scanner.Err(), ShouldBeNil) diff --git a/pkg/api/ldap.go b/pkg/api/ldap.go index 9101093bd..bd9ac45dc 100644 --- a/pkg/api/ldap.go +++ b/pkg/api/ldap.go @@ -61,7 +61,7 @@ func (lc *LDAPClient) Connect() error { RootCAs: lc.ClientCAs, } - if lc.ClientCertificates != nil && len(lc.ClientCertificates) > 0 { + if len(lc.ClientCertificates) > 0 { config.Certificates = lc.ClientCertificates } @@ -78,7 +78,7 @@ func (lc *LDAPClient) Connect() error { ServerName: lc.ServerName, RootCAs: lc.ClientCAs, } - if lc.ClientCertificates != nil && len(lc.ClientCertificates) > 0 { + if len(lc.ClientCertificates) > 0 { config.Certificates = lc.ClientCertificates } diff --git a/pkg/cli/client/service.go b/pkg/cli/client/service.go index 5ddac93d9..f0d24b490 100644 --- a/pkg/cli/client/service.go +++ b/pkg/cli/client/service.go @@ -962,7 +962,7 @@ func (ref referrersResult) stringPlainText(maxArtifactTypeLen int) (string, erro for _, referrer := range ref { artifactType := ellipsize(referrer.ArtifactType, maxArtifactTypeLen, ellipsis) // digest := ellipsize(godigest.Digest(referrer.Digest).Encoded(), digestWidth, "") - size := ellipsize(humanize.Bytes(uint64(referrer.Size)), sizeWidth, ellipsis) + size := ellipsize(humanize.Bytes(uint64(referrer.Size)), sizeWidth, ellipsis) //nolint:gosec,lll // refererrer.Size should >= 0 row := make([]string, refRowWidth) row[refArtifactTypeIndex] = artifactType @@ -1042,7 +1042,7 @@ func (repo repoStruct) stringPlainText(repoMaxLen, maxTimeLen int, verbose bool) row := make([]string, repoRowWidth) row[repoNameIndex] = repoName - row[repoSizeIndex] = ellipsize(strings.ReplaceAll(humanize.Bytes(uint64(repoSize)), " ", ""), sizeWidth, ellipsis) + row[repoSizeIndex] = ellipsize(strings.ReplaceAll(humanize.Bytes(uint64(repoSize)), " ", ""), sizeWidth, ellipsis) //nolint:gosec,lll // ignore overflow row[repoLastUpdatedIndex] = repoLastUpdated.String() row[repoDownloadsIndex] = strconv.Itoa(repoDownloads) row[repoStarsIndex] = strconv.Itoa(repoStars) @@ -1335,15 +1335,15 @@ func combineServerAndEndpointURL(serverURL, endPoint string) (string, error) { return newURL.String(), nil } -func ellipsize(text string, max int, trailing string) string { +func ellipsize(text string, maxLength int, trailing string) string { text = strings.TrimSpace(text) - if len(text) <= max { + if len(text) <= maxLength { return text } chopLength := len(trailing) - return text[:max-chopLength] + trailing + return text[:maxLength-chopLength] + trailing } func getImageTableWriter(writer io.Writer) *tablewriter.Table { diff --git a/pkg/exporter/api/controller_test.go b/pkg/exporter/api/controller_test.go index 7fade4245..e56281195 100644 --- a/pkg/exporter/api/controller_test.go +++ b/pkg/exporter/api/controller_test.go @@ -30,8 +30,8 @@ import ( . "zotregistry.dev/zot/pkg/test/common" ) -func getRandomLatencyN(max int64) time.Duration { - nBig, err := rand.Int(rand.Reader, big.NewInt(max)) +func getRandomLatencyN(maxLatency int64) time.Duration { + nBig, err := rand.Int(rand.Reader, big.NewInt(maxLatency)) if err != nil { panic(err) } diff --git a/pkg/extensions/sync/sync_test.go b/pkg/extensions/sync/sync_test.go index d0fc8a79a..85c81c4bb 100644 --- a/pkg/extensions/sync/sync_test.go +++ b/pkg/extensions/sync/sync_test.go @@ -4670,7 +4670,7 @@ func TestSignatures(t *testing.T) { splittedURL := strings.SplitAfter(srcBaseURL, ":") srcPort := splittedURL[len(splittedURL)-1] - t.Logf(srcPort) + t.Logf("%s", srcPort) cwd, err := os.Getwd() So(err, ShouldBeNil) @@ -5201,7 +5201,7 @@ func TestSignatures(t *testing.T) { splittedURL := strings.SplitAfter(srcBaseURL, ":") srcPort := splittedURL[len(splittedURL)-1] - t.Logf(srcPort) + t.Logf("%s", srcPort) err := signature.SignImageUsingCosign(fmt.Sprintf("%s@%s", repoName, digest.String()), srcPort, true) So(err, ShouldBeNil) diff --git a/pkg/meta/boltdb/boltdb.go b/pkg/meta/boltdb/boltdb.go index 851ee6d79..0166bf517 100644 --- a/pkg/meta/boltdb/boltdb.go +++ b/pkg/meta/boltdb/boltdb.go @@ -451,7 +451,7 @@ func (bdw *BoltDB) SearchRepos(ctx context.Context, searchText string, continue } - protoRepoMeta.Rank = int32(rank) + protoRepoMeta.Rank = int32(rank) //nolint:gosec // ignore overflow protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name) protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name) diff --git a/pkg/meta/boltdb/boltdb_test.go b/pkg/meta/boltdb/boltdb_test.go index 60074bb35..067925f36 100644 --- a/pkg/meta/boltdb/boltdb_test.go +++ b/pkg/meta/boltdb/boltdb_test.go @@ -647,7 +647,7 @@ func TestWrapperErrors(t *testing.T) { Convey("DeleteUserData", func() { userAc = reqCtx.NewUserAccessControl() - ctx = userAc.DeriveContext(context.Background()) + ctx = userAc.DeriveContext(context.Background()) //nolint:fatcontext // test code err = boltdbWrapper.DeleteUserData(ctx) So(err, ShouldNotBeNil) @@ -667,7 +667,7 @@ func TestWrapperErrors(t *testing.T) { Convey("GetUserGroups and SetUserGroups", func() { userAc = reqCtx.NewUserAccessControl() - ctx = userAc.DeriveContext(context.Background()) + ctx = userAc.DeriveContext(context.Background()) //nolint:fatcontext // test code _, err := boltdbWrapper.GetUserGroups(ctx) So(err, ShouldNotBeNil) diff --git a/pkg/meta/convert/convert_proto.go b/pkg/meta/convert/convert_proto.go index 59ea26684..b8985be33 100644 --- a/pkg/meta/convert/convert_proto.go +++ b/pkg/meta/convert/convert_proto.go @@ -23,8 +23,8 @@ func GetProtoRepoMeta(repo mTypes.RepoMeta) *proto_go.RepoMeta { Vendors: repo.Vendors, Platforms: GetProtoPlatforms(repo.Platforms), LastUpdatedImage: GetProtoLastUpdatedImage(repo.LastUpdatedImage), - Stars: int32(repo.StarCount), - Downloads: int32(repo.DownloadCount), + Stars: int32(repo.StarCount), //nolint:gosec // ignore overflow + Downloads: int32(repo.DownloadCount), //nolint:gosec // ignore overflow } } @@ -65,7 +65,7 @@ func GetProtoManifestMeta(manifestContent ispec.Manifest, configContent ispec.Im Digest: digest, Size: size, Manifest: &proto_go.Manifest{ - Versioned: &proto_go.Versioned{SchemaVersion: int32(manifestContent.SchemaVersion)}, + Versioned: &proto_go.Versioned{SchemaVersion: int32(manifestContent.SchemaVersion)}, //nolint:gosec,lll // ignore overflow Config: &proto_go.Descriptor{ Digest: manifestContent.Config.Digest.String(), Size: manifestContent.Config.Size, @@ -108,7 +108,7 @@ func GetProtoImageIndexMeta(indexContent ispec.Index, size int64, digest string) Size: size, Digest: digest, Index: &proto_go.Index{ - Versioned: &proto_go.Versioned{SchemaVersion: int32(indexContent.Versioned.SchemaVersion)}, + Versioned: &proto_go.Versioned{SchemaVersion: int32(indexContent.Versioned.SchemaVersion)}, //nolint:gosec,lll // ignore overflow MediaType: ref(ispec.MediaTypeImageIndex), ArtifactType: ref(common.GetIndexArtifactType(indexContent)), Manifests: getProtoManifestList(indexContent.Manifests), @@ -125,7 +125,7 @@ func GetProtoStatistics(stats map[mTypes.ImageDigest]mTypes.DescriptorStatistics for digest, stat := range stats { results[digest] = &proto_go.DescriptorStatistics{ - DownloadCount: int32(stat.DownloadCount), + DownloadCount: int32(stat.DownloadCount), //nolint:gosec // ignore overflow LastPullTimestamp: timestamppb.New(stat.LastPullTimestamp), PushTimestamp: timestamppb.New(stat.PushTimestamp), PushedBy: stat.PushedBy, diff --git a/pkg/meta/dynamodb/dynamodb.go b/pkg/meta/dynamodb/dynamodb.go index f375e7687..8488c78eb 100644 --- a/pkg/meta/dynamodb/dynamodb.go +++ b/pkg/meta/dynamodb/dynamodb.go @@ -613,7 +613,7 @@ func (dwr *DynamoDB) SearchRepos(ctx context.Context, searchText string) ([]mTyp continue } - protoRepoMeta.Rank = int32(rank) + protoRepoMeta.Rank = int32(rank) //nolint:gosec // ignore overflow protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name) protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name) diff --git a/pkg/test/image-utils/utils.go b/pkg/test/image-utils/utils.go index 580180117..aa39e5a46 100644 --- a/pkg/test/image-utils/utils.go +++ b/pkg/test/image-utils/utils.go @@ -92,36 +92,36 @@ func GetDefaultConfig() ispec.Image { func DefaultTimeRef() *time.Time { var ( - year = 2010 - month = time.Month(1) - day = 1 - hour = 1 - min = 1 - sec = 1 - nsec = 0 + year = 2010 + month = time.Month(1) + day = 1 + hour = 1 + minute = 1 + sec = 1 + nsec = 0 ) - return DateRef(year, month, day, hour, min, sec, nsec, time.UTC) + return DateRef(year, month, day, hour, minute, sec, nsec, time.UTC) } -func DateRef(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) *time.Time { - date := time.Date(year, month, day, hour, min, sec, nsec, loc) +func DateRef(year int, month time.Month, day, hour, minute, sec, nsec int, loc *time.Location) *time.Time { + date := time.Date(year, month, day, hour, minute, sec, nsec, loc) return &date } func RandomDateRef(loc *time.Location) *time.Time { var ( - year = 1990 + mathRand.Intn(30) //nolint: gosec,mnd - month = time.Month(1 + mathRand.Intn(10)) //nolint: gosec,mnd - day = 1 + mathRand.Intn(5) //nolint: gosec,mnd - hour = 1 + mathRand.Intn(22) //nolint: gosec,mnd - min = 1 + mathRand.Intn(58) //nolint: gosec,mnd - sec = 1 + mathRand.Intn(58) //nolint: gosec,mnd - nsec = 1 + year = 1990 + mathRand.Intn(30) //nolint: gosec,mnd + month = time.Month(1 + mathRand.Intn(10)) //nolint: gosec,mnd + day = 1 + mathRand.Intn(5) //nolint: gosec,mnd + hour = 1 + mathRand.Intn(22) //nolint: gosec,mnd + minute = 1 + mathRand.Intn(58) //nolint: gosec,mnd + sec = 1 + mathRand.Intn(58) //nolint: gosec,mnd + nsec = 1 ) - return DateRef(year, month, day, hour, min, sec, nsec, time.UTC) + return DateRef(year, month, day, hour, minute, sec, nsec, time.UTC) } func GetDefaultVulnConfig() ispec.Image { diff --git a/pkg/test/oci-utils/oci_layout.go b/pkg/test/oci-utils/oci_layout.go index f2a1cc54a..43bead734 100644 --- a/pkg/test/oci-utils/oci_layout.go +++ b/pkg/test/oci-utils/oci_layout.go @@ -107,7 +107,7 @@ func (olu BaseOciLayoutUtils) GetImageManifests(repo string) ([]ispec.Descriptor buf, err := imageStore.GetIndexContent(repo) if err != nil { - if goerrors.Is(zerr.ErrRepoNotFound, err) { + if goerrors.Is(err, zerr.ErrRepoNotFound) { olu.Log.Error().Err(err).Msg("failed to get index.json contents because the file is missing") return nil, zerr.ErrRepoNotFound