Skip to content

Commit 54e52ce

Browse files
author
Ramkumar Chinchani
committed
fix: golangci-lint reported errors
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
1 parent 58cd28c commit 54e52ce

10 files changed

Lines changed: 38 additions & 38 deletions

File tree

pkg/api/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewController(appConfig *config.Config) *Controller {
7373
// memberSocket is the local member's socket
7474
// the index is also fetched for quick lookups during proxying
7575
memberSocketIdx, memberSocket, err := GetLocalMemberClusterSocket(appConfig.Cluster.Members, localSockets)
76-
if err != nil {
76+
if err != nil || memberSocketIdx < 0 {
7777
logger.Error().Err(err).Msg("failed to get member socket")
7878
panic("failed to get member socket")
7979
}

pkg/api/ldap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (lc *LDAPClient) Connect() error {
6161
RootCAs: lc.ClientCAs,
6262
}
6363

64-
if lc.ClientCertificates != nil && len(lc.ClientCertificates) > 0 {
64+
if len(lc.ClientCertificates) > 0 {
6565
config.Certificates = lc.ClientCertificates
6666
}
6767

@@ -78,7 +78,7 @@ func (lc *LDAPClient) Connect() error {
7878
ServerName: lc.ServerName,
7979
RootCAs: lc.ClientCAs,
8080
}
81-
if lc.ClientCertificates != nil && len(lc.ClientCertificates) > 0 {
81+
if len(lc.ClientCertificates) > 0 {
8282
config.Certificates = lc.ClientCertificates
8383
}
8484

pkg/cli/client/service.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ func (ref referrersResult) stringPlainText(maxArtifactTypeLen int) (string, erro
962962
for _, referrer := range ref {
963963
artifactType := ellipsize(referrer.ArtifactType, maxArtifactTypeLen, ellipsis)
964964
// digest := ellipsize(godigest.Digest(referrer.Digest).Encoded(), digestWidth, "")
965-
size := ellipsize(humanize.Bytes(uint64(referrer.Size)), sizeWidth, ellipsis)
965+
size := ellipsize(humanize.Bytes(uint64(referrer.Size)), sizeWidth, ellipsis) //nolint:gosec,lll // refererrer.Size should >= 0
966966

967967
row := make([]string, refRowWidth)
968968
row[refArtifactTypeIndex] = artifactType
@@ -1042,7 +1042,7 @@ func (repo repoStruct) stringPlainText(repoMaxLen, maxTimeLen int, verbose bool)
10421042

10431043
row := make([]string, repoRowWidth)
10441044
row[repoNameIndex] = repoName
1045-
row[repoSizeIndex] = ellipsize(strings.ReplaceAll(humanize.Bytes(uint64(repoSize)), " ", ""), sizeWidth, ellipsis)
1045+
row[repoSizeIndex] = ellipsize(strings.ReplaceAll(humanize.Bytes(uint64(repoSize)), " ", ""), sizeWidth, ellipsis) //nolint:gosec,lll // ignore overflow
10461046
row[repoLastUpdatedIndex] = repoLastUpdated.String()
10471047
row[repoDownloadsIndex] = strconv.Itoa(repoDownloads)
10481048
row[repoStarsIndex] = strconv.Itoa(repoStars)
@@ -1335,15 +1335,15 @@ func combineServerAndEndpointURL(serverURL, endPoint string) (string, error) {
13351335
return newURL.String(), nil
13361336
}
13371337

1338-
func ellipsize(text string, max int, trailing string) string {
1338+
func ellipsize(text string, maxLength int, trailing string) string {
13391339
text = strings.TrimSpace(text)
1340-
if len(text) <= max {
1340+
if len(text) <= maxLength {
13411341
return text
13421342
}
13431343

13441344
chopLength := len(trailing)
13451345

1346-
return text[:max-chopLength] + trailing
1346+
return text[:maxLength-chopLength] + trailing
13471347
}
13481348

13491349
func getImageTableWriter(writer io.Writer) *tablewriter.Table {

pkg/extensions/sync/sync_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,7 +4670,7 @@ func TestSignatures(t *testing.T) {
46704670

46714671
splittedURL := strings.SplitAfter(srcBaseURL, ":")
46724672
srcPort := splittedURL[len(splittedURL)-1]
4673-
t.Logf(srcPort)
4673+
t.Logf("%s", srcPort)
46744674
cwd, err := os.Getwd()
46754675
So(err, ShouldBeNil)
46764676

@@ -5201,7 +5201,7 @@ func TestSignatures(t *testing.T) {
52015201

52025202
splittedURL := strings.SplitAfter(srcBaseURL, ":")
52035203
srcPort := splittedURL[len(splittedURL)-1]
5204-
t.Logf(srcPort)
5204+
t.Logf("%s", srcPort)
52055205

52065206
err := signature.SignImageUsingCosign(fmt.Sprintf("%s@%s", repoName, digest.String()), srcPort, true)
52075207
So(err, ShouldBeNil)

pkg/meta/boltdb/boltdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func (bdw *BoltDB) SearchRepos(ctx context.Context, searchText string,
451451
continue
452452
}
453453

454-
protoRepoMeta.Rank = int32(rank)
454+
protoRepoMeta.Rank = int32(rank) //nolint:gosec // ignore overflow
455455
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
456456
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
457457

pkg/meta/boltdb/boltdb_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ func TestWrapperErrors(t *testing.T) {
647647

648648
Convey("DeleteUserData", func() {
649649
userAc = reqCtx.NewUserAccessControl()
650-
ctx = userAc.DeriveContext(context.Background())
650+
ctx = userAc.DeriveContext(context.Background()) //nolint:fatcontext // test code
651651

652652
err = boltdbWrapper.DeleteUserData(ctx)
653653
So(err, ShouldNotBeNil)
@@ -667,7 +667,7 @@ func TestWrapperErrors(t *testing.T) {
667667

668668
Convey("GetUserGroups and SetUserGroups", func() {
669669
userAc = reqCtx.NewUserAccessControl()
670-
ctx = userAc.DeriveContext(context.Background())
670+
ctx = userAc.DeriveContext(context.Background()) //nolint:fatcontext // test code
671671

672672
_, err := boltdbWrapper.GetUserGroups(ctx)
673673
So(err, ShouldNotBeNil)

pkg/meta/convert/convert_proto.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func GetProtoRepoMeta(repo mTypes.RepoMeta) *proto_go.RepoMeta {
2323
Vendors: repo.Vendors,
2424
Platforms: GetProtoPlatforms(repo.Platforms),
2525
LastUpdatedImage: GetProtoLastUpdatedImage(repo.LastUpdatedImage),
26-
Stars: int32(repo.StarCount),
27-
Downloads: int32(repo.DownloadCount),
26+
Stars: int32(repo.StarCount), //nolint:gosec // ignore overflow
27+
Downloads: int32(repo.DownloadCount), //nolint:gosec // ignore overflow
2828
}
2929
}
3030

@@ -65,7 +65,7 @@ func GetProtoManifestMeta(manifestContent ispec.Manifest, configContent ispec.Im
6565
Digest: digest,
6666
Size: size,
6767
Manifest: &proto_go.Manifest{
68-
Versioned: &proto_go.Versioned{SchemaVersion: int32(manifestContent.SchemaVersion)},
68+
Versioned: &proto_go.Versioned{SchemaVersion: int32(manifestContent.SchemaVersion)}, //nolint:gosec,lll // ignore overflow
6969
Config: &proto_go.Descriptor{
7070
Digest: manifestContent.Config.Digest.String(),
7171
Size: manifestContent.Config.Size,
@@ -108,7 +108,7 @@ func GetProtoImageIndexMeta(indexContent ispec.Index, size int64, digest string)
108108
Size: size,
109109
Digest: digest,
110110
Index: &proto_go.Index{
111-
Versioned: &proto_go.Versioned{SchemaVersion: int32(indexContent.Versioned.SchemaVersion)},
111+
Versioned: &proto_go.Versioned{SchemaVersion: int32(indexContent.Versioned.SchemaVersion)}, //nolint:gosec,lll // ignore overflow
112112
MediaType: ref(ispec.MediaTypeImageIndex),
113113
ArtifactType: ref(common.GetIndexArtifactType(indexContent)),
114114
Manifests: getProtoManifestList(indexContent.Manifests),
@@ -125,7 +125,7 @@ func GetProtoStatistics(stats map[mTypes.ImageDigest]mTypes.DescriptorStatistics
125125

126126
for digest, stat := range stats {
127127
results[digest] = &proto_go.DescriptorStatistics{
128-
DownloadCount: int32(stat.DownloadCount),
128+
DownloadCount: int32(stat.DownloadCount), //nolint:gosec // ignore overflow
129129
LastPullTimestamp: timestamppb.New(stat.LastPullTimestamp),
130130
PushTimestamp: timestamppb.New(stat.PushTimestamp),
131131
PushedBy: stat.PushedBy,

pkg/meta/dynamodb/dynamodb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ func (dwr *DynamoDB) SearchRepos(ctx context.Context, searchText string) ([]mTyp
613613
continue
614614
}
615615

616-
protoRepoMeta.Rank = int32(rank)
616+
protoRepoMeta.Rank = int32(rank) //nolint:gosec // ignore overflow
617617
protoRepoMeta.IsStarred = zcommon.Contains(userStars, protoRepoMeta.Name)
618618
protoRepoMeta.IsBookmarked = zcommon.Contains(userBookmarks, protoRepoMeta.Name)
619619

pkg/test/image-utils/utils.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,36 +92,36 @@ func GetDefaultConfig() ispec.Image {
9292

9393
func DefaultTimeRef() *time.Time {
9494
var (
95-
year = 2010
96-
month = time.Month(1)
97-
day = 1
98-
hour = 1
99-
min = 1
100-
sec = 1
101-
nsec = 0
95+
year = 2010
96+
month = time.Month(1)
97+
day = 1
98+
hour = 1
99+
minute = 1
100+
sec = 1
101+
nsec = 0
102102
)
103103

104-
return DateRef(year, month, day, hour, min, sec, nsec, time.UTC)
104+
return DateRef(year, month, day, hour, minute, sec, nsec, time.UTC)
105105
}
106106

107-
func DateRef(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) *time.Time {
108-
date := time.Date(year, month, day, hour, min, sec, nsec, loc)
107+
func DateRef(year int, month time.Month, day, hour, minute, sec, nsec int, loc *time.Location) *time.Time {
108+
date := time.Date(year, month, day, hour, minute, sec, nsec, loc)
109109

110110
return &date
111111
}
112112

113113
func RandomDateRef(loc *time.Location) *time.Time {
114114
var (
115-
year = 1990 + mathRand.Intn(30) //nolint: gosec,mnd
116-
month = time.Month(1 + mathRand.Intn(10)) //nolint: gosec,mnd
117-
day = 1 + mathRand.Intn(5) //nolint: gosec,mnd
118-
hour = 1 + mathRand.Intn(22) //nolint: gosec,mnd
119-
min = 1 + mathRand.Intn(58) //nolint: gosec,mnd
120-
sec = 1 + mathRand.Intn(58) //nolint: gosec,mnd
121-
nsec = 1
115+
year = 1990 + mathRand.Intn(30) //nolint: gosec,mnd
116+
month = time.Month(1 + mathRand.Intn(10)) //nolint: gosec,mnd
117+
day = 1 + mathRand.Intn(5) //nolint: gosec,mnd
118+
hour = 1 + mathRand.Intn(22) //nolint: gosec,mnd
119+
minute = 1 + mathRand.Intn(58) //nolint: gosec,mnd
120+
sec = 1 + mathRand.Intn(58) //nolint: gosec,mnd
121+
nsec = 1
122122
)
123123

124-
return DateRef(year, month, day, hour, min, sec, nsec, time.UTC)
124+
return DateRef(year, month, day, hour, minute, sec, nsec, time.UTC)
125125
}
126126

127127
func GetDefaultVulnConfig() ispec.Image {

pkg/test/oci-utils/oci_layout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (olu BaseOciLayoutUtils) GetImageManifests(repo string) ([]ispec.Descriptor
107107

108108
buf, err := imageStore.GetIndexContent(repo)
109109
if err != nil {
110-
if goerrors.Is(zerr.ErrRepoNotFound, err) {
110+
if goerrors.Is(err, zerr.ErrRepoNotFound) {
111111
olu.Log.Error().Err(err).Msg("failed to get index.json contents because the file is missing")
112112

113113
return nil, zerr.ErrRepoNotFound

0 commit comments

Comments
 (0)