Skip to content

Commit 7c5e5b2

Browse files
committed
Even more linter fixes
1 parent f3d1863 commit 7c5e5b2

23 files changed

+86
-121
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,18 @@ generate:
133133
# Test
134134
#########################################
135135
test:
136-
$Q $(GOFLAGS) go test -short -coverprofile=coverage.out ./...
136+
$Q $(GOFLAGS) gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
137+
137138

138139
testcgo:
139-
$Q go test -short -coverprofile=coverage.out ./...
140+
$Q gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
140141

141142
.PHONY: test testcgo
142143

143144
integrate: integration
144145

145146
integration: bin/$(BINNAME)
146-
$Q $(GOFLAGS) go test -tags=integration ./integration/...
147+
$Q $(GOFLAGS) gotestsum -- -tags=integration ./integration/...
147148

148149
.PHONY: integrate integration
149150

api/log/log.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ type StackTracedError interface {
2121
StackTrace() errors.StackTrace
2222
}
2323

24-
// AsStackTracedError attempts to return the input error cast to a
25-
// StackTracedError interface.
26-
func AsStackTracedError(err error) (StackTracedError, bool) {
27-
//nolint:errorlint // ignore type assertion warning. casting to interface is hard.
28-
if st, ok := err.(StackTracedError); ok {
29-
return st, ok
30-
}
31-
return nil, false
32-
}
33-
3424
// Error adds to the response writer the given error if it implements
3525
// logging.ResponseLogger. If it does not implement it, then writes the error
3626
// using the log package.
@@ -48,9 +38,8 @@ func Error(rw http.ResponseWriter, err error) {
4838
return
4939
}
5040

51-
e, ok := AsStackTracedError(err)
41+
e, ok := err.(StackTracedError)
5242
if !ok {
53-
//nolint:errorlint // ignore type assertion warning. casting to interface is hard.
5443
e, ok = errors.Cause(err).(StackTracedError)
5544
}
5645

api/render/render.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,12 @@ type RenderableError interface {
7272
Render(http.ResponseWriter)
7373
}
7474

75-
// AsRenderableError attempts to return an error type that implements the
76-
// RenderableError interface.
77-
func AsRenderableError(err error) (RenderableError, bool) {
78-
//nolint:errorlint // ignore type assertion warning. casting to interface is hard.
79-
if r, ok := err.(RenderableError); ok {
80-
return r, true
81-
}
82-
return nil, false
83-
}
84-
8575
// Error marshals the JSON representation of err to w. In case err implements
8676
// RenderableError its own Render method will be called instead.
8777
func Error(w http.ResponseWriter, err error) {
8878
log.Error(w, err)
8979

90-
if e, ok := AsRenderableError(err); ok {
80+
if e, ok := err.(RenderableError); ok {
9181
e.Render(w)
9282

9383
return
@@ -107,16 +97,6 @@ type StatusCodedError interface {
10797
StatusCode() int
10898
}
10999

110-
// AsStatusCodedError attempts to return an error type that implements the
111-
// StatusCodedError interface.
112-
func AsStatusCodedError(err error) (StatusCodedError, bool) {
113-
//nolint:errorlint // ignore type assertion warning. casting to interface is hard.
114-
if sc, ok := err.(StatusCodedError); ok {
115-
return sc, true
116-
}
117-
return nil, false
118-
}
119-
120100
func statusCodeFromError(err error) (code int) {
121101
code = http.StatusInternalServerError
122102

@@ -125,13 +105,12 @@ func statusCodeFromError(err error) (code int) {
125105
}
126106

127107
for err != nil {
128-
if sc, ok := AsStatusCodedError(err); ok {
108+
if sc, ok := err.(StatusCodedError); ok {
129109
code = sc.StatusCode()
130110

131111
break
132112
}
133113

134-
//nolint:errorlint // ignore type assertion warning. casting to interface is hard.
135114
cause, ok := err.(causer)
136115
if !ok {
137116
break

authority/authorize_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func TestAuthority_authorizeToken(t *testing.T) {
313313
p, err := tc.auth.authorizeToken(context.Background(), tc.token)
314314
if err != nil {
315315
if assert.NotNil(t, tc.err) {
316-
sc, ok := render.AsStatusCodedError(err)
316+
sc, ok := err.(render.StatusCodedError)
317317
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
318318
assert.Equals(t, sc.StatusCode(), tc.code)
319319
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -399,7 +399,7 @@ func TestAuthority_authorizeRevoke(t *testing.T) {
399399

400400
if err := tc.auth.authorizeRevoke(context.Background(), tc.token); err != nil {
401401
if assert.NotNil(t, tc.err) {
402-
sc, ok := render.AsStatusCodedError(err)
402+
sc, ok := err.(render.StatusCodedError)
403403
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
404404
assert.Equals(t, sc.StatusCode(), tc.code)
405405
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -484,7 +484,7 @@ func TestAuthority_authorizeSign(t *testing.T) {
484484
got, err := tc.auth.authorizeSign(context.Background(), tc.token)
485485
if err != nil {
486486
if assert.NotNil(t, tc.err) {
487-
sc, ok := render.AsStatusCodedError(err)
487+
sc, ok := err.(render.StatusCodedError)
488488
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
489489
assert.Equals(t, sc.StatusCode(), tc.code)
490490
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -743,7 +743,7 @@ func TestAuthority_Authorize(t *testing.T) {
743743
if err != nil {
744744
if assert.NotNil(t, tc.err, fmt.Sprintf("unexpected error: %s", err)) {
745745
assert.Nil(t, got)
746-
sc, ok := render.AsStatusCodedError(err)
746+
sc, ok := err.(render.StatusCodedError)
747747
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
748748
assert.Equals(t, sc.StatusCode(), tc.code)
749749
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -879,7 +879,7 @@ func TestAuthority_authorizeRenew(t *testing.T) {
879879
err := tc.auth.authorizeRenew(tc.cert)
880880
if err != nil {
881881
if assert.NotNil(t, tc.err) {
882-
sc, ok := render.AsStatusCodedError(err)
882+
sc, ok := err.(render.StatusCodedError)
883883
assert.Fatal(t, ok, "error does not implement StatusCoder interface")
884884
assert.Equals(t, sc.StatusCode(), tc.code)
885885
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -1027,7 +1027,7 @@ func TestAuthority_authorizeSSHSign(t *testing.T) {
10271027
got, err := tc.auth.authorizeSSHSign(context.Background(), tc.token)
10281028
if err != nil {
10291029
if assert.NotNil(t, tc.err) {
1030-
sc, ok := render.AsStatusCodedError(err)
1030+
sc, ok := err.(render.StatusCodedError)
10311031
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
10321032
assert.Equals(t, sc.StatusCode(), tc.code)
10331033
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -1144,7 +1144,7 @@ func TestAuthority_authorizeSSHRenew(t *testing.T) {
11441144
got, err := tc.auth.authorizeSSHRenew(context.Background(), tc.token)
11451145
if err != nil {
11461146
if assert.NotNil(t, tc.err) {
1147-
sc, ok := render.AsStatusCodedError(err)
1147+
sc, ok := err.(render.StatusCodedError)
11481148
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
11491149
assert.Equals(t, sc.StatusCode(), tc.code)
11501150
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -1244,7 +1244,7 @@ func TestAuthority_authorizeSSHRevoke(t *testing.T) {
12441244

12451245
if err := tc.auth.authorizeSSHRevoke(context.Background(), tc.token); err != nil {
12461246
if assert.NotNil(t, tc.err) {
1247-
sc, ok := render.AsStatusCodedError(err)
1247+
sc, ok := err.(render.StatusCodedError)
12481248
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
12491249
assert.Equals(t, sc.StatusCode(), tc.code)
12501250
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -1337,7 +1337,7 @@ func TestAuthority_authorizeSSHRekey(t *testing.T) {
13371337
cert, signOpts, err := tc.auth.authorizeSSHRekey(context.Background(), tc.token)
13381338
if err != nil {
13391339
if assert.NotNil(t, tc.err) {
1340-
sc, ok := render.AsStatusCodedError(err)
1340+
sc, ok := err.(render.StatusCodedError)
13411341
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
13421342
assert.Equals(t, sc.StatusCode(), tc.code)
13431343
assert.HasPrefix(t, err.Error(), tc.err.Error())

authority/provisioner/acme_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func TestACME_AuthorizeRenew(t *testing.T) {
224224
t.Run(name, func(t *testing.T) {
225225
tc := tt(t)
226226
if err := tc.p.AuthorizeRenew(context.Background(), tc.cert); err != nil {
227-
sc, ok := render.AsStatusCodedError(err)
227+
sc, ok := err.(render.StatusCodedError)
228228
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
229229
assert.Equals(t, sc.StatusCode(), tc.code)
230230
if assert.NotNil(t, tc.err) {
@@ -259,7 +259,7 @@ func TestACME_AuthorizeSign(t *testing.T) {
259259
tc := tt(t)
260260
if opts, err := tc.p.AuthorizeSign(context.Background(), tc.token); err != nil {
261261
if assert.NotNil(t, tc.err) {
262-
sc, ok := render.AsStatusCodedError(err)
262+
sc, ok := err.(render.StatusCodedError)
263263
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
264264
assert.Equals(t, sc.StatusCode(), tc.code)
265265
assert.HasPrefix(t, err.Error(), tc.err.Error())

authority/provisioner/aws.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,17 @@ const awsIdentityURL = "http://169.254.169.254/latest/dynamic/instance-identity/
3535
const awsSignatureURL = "http://169.254.169.254/latest/dynamic/instance-identity/signature"
3636

3737
// awsAPITokenURL is the url used to get the IMDSv2 API token
38-
//nolint:gosec,goimports // no credentials here
39-
const awsAPITokenURL = "http://169.254.169.254/latest/api/token"
38+
const awsAPITokenURL = "http://169.254.169.254/latest/api/token" //nolint:gosec // no credentials here
4039

4140
// awsAPITokenTTL is the default TTL to use when requesting IMDSv2 API tokens
4241
// -- we keep this short-lived since we get a new token with every call to readURL()
4342
const awsAPITokenTTL = "30"
4443

4544
// awsMetadataTokenHeader is the header that must be passed with every IMDSv2 request
46-
//nolint:gosec,goimports // no credentials here
47-
const awsMetadataTokenHeader = "X-aws-ec2-metadata-token"
45+
const awsMetadataTokenHeader = "X-aws-ec2-metadata-token" //nolint:gosec // no credentials here
4846

4947
// awsMetadataTokenTTLHeader is the header used to indicate the token TTL requested
50-
//nolint:gosec,goimports // no credentials here
51-
const awsMetadataTokenTTLHeader = "X-aws-ec2-metadata-token-ttl-seconds"
48+
const awsMetadataTokenTTLHeader = "X-aws-ec2-metadata-token-ttl-seconds" //nolint:gosec // no credentials here
5249

5350
// awsCertificate is the certificate used to validate the instance identity
5451
// signature.

authority/provisioner/aws_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func TestAWS_authorizeToken(t *testing.T) {
522522
tc := tt(t)
523523
if claims, err := tc.p.authorizeToken(tc.token); err != nil {
524524
if assert.NotNil(t, tc.err) {
525-
sc, ok := render.AsStatusCodedError(err)
525+
sc, ok := err.(render.StatusCodedError)
526526
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
527527
assert.Equals(t, sc.StatusCode(), tc.code)
528528
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -669,7 +669,7 @@ func TestAWS_AuthorizeSign(t *testing.T) {
669669
t.Errorf("AWS.AuthorizeSign() error = %v, wantErr %v", err, tt.wantErr)
670670
return
671671
case err != nil:
672-
sc, ok := render.AsStatusCodedError(err)
672+
sc, ok := err.(render.StatusCodedError)
673673
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
674674
assert.Equals(t, sc.StatusCode(), tt.code)
675675
default:
@@ -807,7 +807,7 @@ func TestAWS_AuthorizeSSHSign(t *testing.T) {
807807
return
808808
}
809809
if err != nil {
810-
sc, ok := render.AsStatusCodedError(err)
810+
sc, ok := err.(render.StatusCodedError)
811811
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
812812
assert.Equals(t, sc.StatusCode(), tt.code)
813813
assert.Nil(t, got)
@@ -864,7 +864,7 @@ func TestAWS_AuthorizeRenew(t *testing.T) {
864864
if err := tt.aws.AuthorizeRenew(context.Background(), tt.args.cert); (err != nil) != tt.wantErr {
865865
t.Errorf("AWS.AuthorizeRenew() error = %v, wantErr %v", err, tt.wantErr)
866866
} else if err != nil {
867-
sc, ok := render.AsStatusCodedError(err)
867+
sc, ok := err.(render.StatusCodedError)
868868
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
869869
assert.Equals(t, sc.StatusCode(), tt.code)
870870
}

authority/provisioner/azure_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func TestAzure_authorizeToken(t *testing.T) {
336336
tc := tt(t)
337337
if claims, name, group, subscriptionID, objectID, err := tc.p.authorizeToken(tc.token); err != nil {
338338
if assert.NotNil(t, tc.err) {
339-
sc, ok := render.AsStatusCodedError(err)
339+
sc, ok := err.(render.StatusCodedError)
340340
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
341341
assert.Equals(t, sc.StatusCode(), tc.code)
342342
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -498,7 +498,7 @@ func TestAzure_AuthorizeSign(t *testing.T) {
498498
t.Errorf("Azure.AuthorizeSign() error = %v, wantErr %v", err, tt.wantErr)
499499
return
500500
case err != nil:
501-
sc, ok := render.AsStatusCodedError(err)
501+
sc, ok := err.(render.StatusCodedError)
502502
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
503503
assert.Equals(t, sc.StatusCode(), tt.code)
504504
default:
@@ -576,7 +576,7 @@ func TestAzure_AuthorizeRenew(t *testing.T) {
576576
if err := tt.azure.AuthorizeRenew(context.Background(), tt.args.cert); (err != nil) != tt.wantErr {
577577
t.Errorf("Azure.AuthorizeRenew() error = %v, wantErr %v", err, tt.wantErr)
578578
} else if err != nil {
579-
sc, ok := render.AsStatusCodedError(err)
579+
sc, ok := err.(render.StatusCodedError)
580580
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
581581
assert.Equals(t, sc.StatusCode(), tt.code)
582582
}
@@ -673,7 +673,7 @@ func TestAzure_AuthorizeSSHSign(t *testing.T) {
673673
return
674674
}
675675
if err != nil {
676-
sc, ok := render.AsStatusCodedError(err)
676+
sc, ok := err.(render.StatusCodedError)
677677
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
678678
assert.Equals(t, sc.StatusCode(), tt.code)
679679
assert.Nil(t, got)

authority/provisioner/gcp_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func TestGCP_authorizeToken(t *testing.T) {
391391
tc := tt(t)
392392
if claims, err := tc.p.authorizeToken(tc.token); err != nil {
393393
if assert.NotNil(t, tc.err) {
394-
sc, ok := render.AsStatusCodedError(err)
394+
sc, ok := err.(render.StatusCodedError)
395395
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
396396
assert.Equals(t, sc.StatusCode(), tc.code)
397397
assert.HasPrefix(t, err.Error(), tc.err.Error())
@@ -541,7 +541,7 @@ func TestGCP_AuthorizeSign(t *testing.T) {
541541
t.Errorf("GCP.AuthorizeSign() error = %v, wantErr %v", err, tt.wantErr)
542542
return
543543
case err != nil:
544-
sc, ok := render.AsStatusCodedError(err)
544+
sc, ok := err.(render.StatusCodedError)
545545
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
546546
assert.Equals(t, sc.StatusCode(), tt.code)
547547
default:
@@ -682,7 +682,7 @@ func TestGCP_AuthorizeSSHSign(t *testing.T) {
682682
return
683683
}
684684
if err != nil {
685-
sc, ok := render.AsStatusCodedError(err)
685+
sc, ok := err.(render.StatusCodedError)
686686
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
687687
assert.Equals(t, sc.StatusCode(), tt.code)
688688
assert.Nil(t, got)
@@ -739,7 +739,7 @@ func TestGCP_AuthorizeRenew(t *testing.T) {
739739
if err := tt.prov.AuthorizeRenew(context.Background(), tt.args.cert); (err != nil) != tt.wantErr {
740740
t.Errorf("GCP.AuthorizeRenew() error = %v, wantErr %v", err, tt.wantErr)
741741
} else if err != nil {
742-
sc, ok := render.AsStatusCodedError(err)
742+
sc, ok := err.(render.StatusCodedError)
743743
assert.Fatal(t, ok, "error does not implement StatusCoder interface")
744744
assert.Equals(t, sc.StatusCode(), tt.code)
745745
}

authority/provisioner/jwk_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func TestJWK_authorizeToken(t *testing.T) {
185185
t.Run(tt.name, func(t *testing.T) {
186186
if got, err := tt.prov.authorizeToken(tt.args.token, testAudiences.Sign); err != nil {
187187
if assert.NotNil(t, tt.err) {
188-
sc, ok := render.AsStatusCodedError(err)
188+
sc, ok := err.(render.StatusCodedError)
189189
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
190190
assert.Equals(t, sc.StatusCode(), tt.code)
191191
assert.HasPrefix(t, err.Error(), tt.err.Error())
@@ -225,7 +225,7 @@ func TestJWK_AuthorizeRevoke(t *testing.T) {
225225
t.Run(tt.name, func(t *testing.T) {
226226
if err := tt.prov.AuthorizeRevoke(context.Background(), tt.args.token); err != nil {
227227
if assert.NotNil(t, tt.err) {
228-
sc, ok := render.AsStatusCodedError(err)
228+
sc, ok := err.(render.StatusCodedError)
229229
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
230230
assert.Equals(t, sc.StatusCode(), tt.code)
231231
assert.HasPrefix(t, err.Error(), tt.err.Error())
@@ -290,7 +290,7 @@ func TestJWK_AuthorizeSign(t *testing.T) {
290290
ctx := NewContextWithMethod(context.Background(), SignMethod)
291291
if got, err := tt.prov.AuthorizeSign(ctx, tt.args.token); err != nil {
292292
if assert.NotNil(t, tt.err) {
293-
sc, ok := render.AsStatusCodedError(err)
293+
sc, ok := err.(render.StatusCodedError)
294294
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
295295
assert.Equals(t, sc.StatusCode(), tt.code)
296296
assert.HasPrefix(t, err.Error(), tt.err.Error())
@@ -366,7 +366,7 @@ func TestJWK_AuthorizeRenew(t *testing.T) {
366366
if err := tt.prov.AuthorizeRenew(context.Background(), tt.args.cert); (err != nil) != tt.wantErr {
367367
t.Errorf("JWK.AuthorizeRenew() error = %v, wantErr %v", err, tt.wantErr)
368368
} else if err != nil {
369-
sc, ok := render.AsStatusCodedError(err)
369+
sc, ok := err.(render.StatusCodedError)
370370
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
371371
assert.Equals(t, sc.StatusCode(), tt.code)
372372
}
@@ -461,7 +461,7 @@ func TestJWK_AuthorizeSSHSign(t *testing.T) {
461461
return
462462
}
463463
if err != nil {
464-
sc, ok := render.AsStatusCodedError(err)
464+
sc, ok := err.(render.StatusCodedError)
465465
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
466466
assert.Equals(t, sc.StatusCode(), tt.code)
467467
assert.Nil(t, got)
@@ -626,7 +626,7 @@ func TestJWK_AuthorizeSSHRevoke(t *testing.T) {
626626
tc := tt(t)
627627
if err := tc.p.AuthorizeSSHRevoke(context.Background(), tc.token); err != nil {
628628
if assert.NotNil(t, tc.err) {
629-
sc, ok := render.AsStatusCodedError(err)
629+
sc, ok := err.(render.StatusCodedError)
630630
assert.Fatal(t, ok, "error does not implement StatusCodedError interface")
631631
assert.Equals(t, sc.StatusCode(), tc.code)
632632
assert.HasPrefix(t, err.Error(), tc.err.Error())

0 commit comments

Comments
 (0)