Skip to content

Commit c03e2a8

Browse files
More linting coverage (#4213)
* Remove explicit staticcheck and unused linter enables They are enabled by default. For consistency, do not list them like others that are enabled by default (for example govet) are not explicitly listed either. Signed-off-by: Ville Skyttä <[email protected]> * Enable makezero and nilnesserr linters There are no findings from either at the moment, but they serve useful purposes. Signed-off-by: Ville Skyttä <[email protected]> * Ensure closing of TSA response body, enable bodyclose linter This was flagged by bodyclose. Signed-off-by: Ville Skyttä <[email protected]> * Vet internal ui.Infof/Warnf uses Signed-off-by: Ville Skyttä <[email protected]> * Enable usestdlibvars linter, address findings Signed-off-by: Ville Skyttä <[email protected]> * test: update e2e rekor service count #4213 (review) Signed-off-by: Ville Skyttä <[email protected]> * Update e2e_test.sh to handle different healthy service totals Rekor has healthchecks for 5 services, Fulcio currently has healthchecks for 3. Signed-off-by: Hayden B <[email protected]> --------- Signed-off-by: Ville Skyttä <[email protected]> Signed-off-by: Hayden B <[email protected]> Co-authored-by: Hayden B <[email protected]>
1 parent 56d5114 commit c03e2a8

File tree

8 files changed

+30
-15
lines changed

8 files changed

+30
-15
lines changed

.golangci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ run:
1919
linters:
2020
enable:
2121
- asciicheck
22+
- bodyclose
2223
- errorlint
2324
- forbidigo
2425
- gocritic
2526
- gosec
2627
- importas
28+
- makezero
2729
- misspell
30+
- nilnesserr
2831
- prealloc
2932
- revive
30-
- staticcheck
3133
- tparallel
3234
- unconvert
3335
- unparam
34-
- unused
36+
- usestdlibvars
3537
- whitespace
3638
settings:
3739
forbidigo:
@@ -45,6 +47,12 @@ linters:
4547
gosec:
4648
excludes:
4749
- G115 # integer overflow conversion int64 -> uint64
50+
govet:
51+
settings:
52+
printf:
53+
funcs:
54+
- github.com/sigstore/cosign/v2/internal/ui.Infof
55+
- github.com/sigstore/cosign/v2/internal/ui.Warnf
4856
exclusions:
4957
generated: lax
5058
presets:

cmd/cosign/cli/attach/attach.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ func attachAttestation(ctx context.Context, remoteOpts []ociremote.Option, signe
7878
return err
7979
}
8080
if _, ok := ref.(name.Digest); !ok {
81-
msg := fmt.Sprintf(ui.TagReferenceMessage, imageRef)
82-
ui.Warnf(ctx, msg)
81+
ui.Warnf(ctx, ui.TagReferenceMessage, imageRef)
8382
}
8483
digest, err := ociremote.ResolveDigest(ref, remoteOpts...)
8584
if err != nil {

cmd/cosign/cli/clean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Clean() *cobra.Command {
5151

5252
func CleanCmd(ctx context.Context, regOpts options.RegistryOptions, cleanType options.CleanType, imageRef string, force bool) error {
5353
if !force {
54-
ui.Warnf(ctx, prompt(cleanType))
54+
ui.Warnf(ctx, prompt(cleanType)) //nolint:govet // practically const
5555
if err := ui.ConfirmContinue(ctx); err != nil {
5656
return err
5757
}

cmd/cosign/cli/sign/sign.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ func ParseOCIReference(ctx context.Context, refStr string, opts ...name.Option)
122122
return nil, fmt.Errorf("parsing reference: %w", err)
123123
}
124124
if _, ok := ref.(name.Digest); !ok {
125-
msg := fmt.Sprintf(ui.TagReferenceMessage, refStr)
126-
ui.Warnf(ctx, msg)
125+
ui.Warnf(ctx, ui.TagReferenceMessage, refStr)
127126
}
128127
return ref, nil
129128
}

cmd/cosign/cli/verify.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ against the transparency log.`,
152152
defer cancel()
153153

154154
if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
155-
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "signature"))
155+
ui.Warnf(ctx, ignoreTLogMessage, "signature")
156156
}
157157

158158
return v.Exec(ctx, args)
@@ -256,7 +256,7 @@ against the transparency log.`,
256256
defer cancel()
257257

258258
if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
259-
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "attestation"))
259+
ui.Warnf(ctx, ignoreTLogMessage, "attestation")
260260
}
261261

262262
return v.Exec(ctx, args)
@@ -363,7 +363,7 @@ The blob may be specified as a path to a file or - for stdin.`,
363363
defer cancel()
364364

365365
if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
366-
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "blob"))
366+
ui.Warnf(ctx, ignoreTLogMessage, "blob")
367367
}
368368

369369
return verifyBlobCmd.Exec(ctx, args[0])
@@ -444,7 +444,7 @@ The blob may be specified as a path to a file.`,
444444
defer cancel()
445445

446446
if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
447-
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "blob attestation"))
447+
ui.Warnf(ctx, ignoreTLogMessage, "blob attestation")
448448
}
449449

450450
return v.Exec(ctx, path)

internal/pkg/cosign/tsa/client/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (t *TimestampAuthorityClientImpl) GetTimestampResponse(tsq []byte) ([]byte,
130130
client.Transport = tr
131131
}
132132

133-
req, err := http.NewRequest("POST", t.URL, bytes.NewReader(tsq))
133+
req, err := http.NewRequest(http.MethodPost, t.URL, bytes.NewReader(tsq))
134134
if err != nil {
135135
return nil, fmt.Errorf("error creating HTTP request: %w", err)
136136
}
@@ -140,7 +140,8 @@ func (t *TimestampAuthorityClientImpl) GetTimestampResponse(tsq []byte) ([]byte,
140140
if err != nil {
141141
return nil, fmt.Errorf("error making request to timestamp authority: %w", err)
142142
}
143-
if tsr.StatusCode != 200 && tsr.StatusCode != 201 {
143+
defer tsr.Body.Close()
144+
if tsr.StatusCode != http.StatusOK && tsr.StatusCode != http.StatusCreated {
144145
return nil, fmt.Errorf("request to timestamp authority failed with status code %d", tsr.StatusCode)
145146
}
146147

pkg/providers/github/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (ga *githubActions) Enabled(_ context.Context) bool {
5858
func (ga *githubActions) Provide(ctx context.Context, audience string) (string, error) {
5959
url := env.Getenv(env.VariableGitHubRequestURL) + "&audience=" + audience
6060

61-
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
61+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
6262
if err != nil {
6363
return "", err
6464
}

test/e2e_test.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,16 @@ for repo in rekor fulcio; do
7070
fi
7171
${docker_compose} up -d
7272
echo -n "waiting up to 60 sec for system to start"
73+
if [ "$repo" == "fulcio" ]; then
74+
healthytotal=3
75+
elif [ "$repo" == "rekor" ]; then
76+
healthytotal=5
77+
else
78+
# handle no match in case another service is added
79+
healthytotal=0
80+
fi
7381
count=0
74-
until [ $(${docker_compose} ps | grep -c "(healthy)") == 3 ];
82+
until [ $(${docker_compose} ps | grep -c "(healthy)") == $healthytotal ];
7583
do
7684
if [ $count -eq 18 ]; then
7785
echo "! timeout reached"

0 commit comments

Comments
 (0)