Skip to content

Commit bb6b5e2

Browse files
committed
Use golangci-lint to manage lints
1 parent d1bed54 commit bb6b5e2

22 files changed

+50
-86
lines changed

.github/workflows/CI.yml

+2-11
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,8 @@ jobs:
3030
name: Run static analysis and linting
3131
steps:
3232
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
33-
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753
34-
with:
35-
go-version: '^1.20.0'
36-
- name: Go fmt
37-
run: diff -u <(echo -n) <(gofmt -d -s *.go gpg/)
38-
- name: Go vet
39-
run: env GO111MODULE=on go vet ./...
40-
- name: Staticcheck
41-
run: go run honnef.co/go/tools/cmd/staticcheck -checks 'all,-ST1000' ./...
42-
- name: Gosec
43-
run: go run github.com/securego/gosec/cmd/gosec -exclude=G104 ./...
33+
- uses: cachix/install-nix-action@4b933aa7ebcc94a6174cf1364864e957b4910265
34+
- run: nix-shell --run 'golangci-lint run --timeout=5m'
4435
test_release:
4536
runs-on: ubuntu-22.04
4637
permissions:

.golangci.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- gosimple
5+
- govet
6+
- ineffassign
7+
- staticcheck
8+
- typecheck
9+
- unused
10+
- gosec
11+
- stylecheck
12+
- goimports
13+
- gofmt
14+
- tparallel
15+
- prealloc
16+
- misspell
17+
- unconvert
18+
- unparam
19+
- whitespace

go.mod

-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ require (
66
github.com/ProtonMail/go-crypto v0.0.0-20230528122434-6f98819771a1
77
github.com/hashicorp/vault/api v1.9.2
88
github.com/hashicorp/vault/sdk v0.9.1
9-
github.com/securego/gosec v0.0.0-20200401082031-e946c8c39989
109
github.com/sigstore/rekor v1.2.1
11-
honnef.co/go/tools v0.4.3
1210
)
1311

1412
require (
15-
github.com/BurntSushi/toml v1.2.1 // indirect
1613
github.com/armon/go-metrics v0.4.1 // indirect
1714
github.com/armon/go-radix v1.0.0 // indirect
1815
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
@@ -77,7 +74,6 @@ require (
7774
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
7875
github.com/mitchellh/mapstructure v1.5.0 // indirect
7976
github.com/mitchellh/reflectwalk v1.0.2 // indirect
80-
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d // indirect
8177
github.com/oklog/run v1.1.0 // indirect
8278
github.com/oklog/ulid v1.3.1 // indirect
8379
github.com/opencontainers/go-digest v1.0.0 // indirect
@@ -101,15 +97,13 @@ require (
10197
go.uber.org/zap v1.24.0 // indirect
10298
golang.org/x/crypto v0.9.0 // indirect
10399
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
104-
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
105100
golang.org/x/mod v0.10.0 // indirect
106101
golang.org/x/net v0.10.0 // indirect
107102
golang.org/x/sync v0.2.0 // indirect
108103
golang.org/x/sys v0.8.0 // indirect
109104
golang.org/x/term v0.8.0 // indirect
110105
golang.org/x/text v0.9.0 // indirect
111106
golang.org/x/time v0.3.0 // indirect
112-
golang.org/x/tools v0.8.0 // indirect
113107
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
114108
google.golang.org/grpc v1.55.0 // indirect
115109
google.golang.org/protobuf v1.30.0 // indirect

go.sum

-44
Large diffs are not rendered by default.

gpg/backend.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gpg
22

33
import (
44
"context"
5+
56
"github.com/hashicorp/vault/sdk/helper/locksutil"
67

78
"github.com/hashicorp/vault/sdk/framework"

gpg/backend_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package gpg
33
import (
44
"context"
55
"encoding/hex"
6-
"github.com/ProtonMail/go-crypto/openpgp"
7-
"github.com/hashicorp/vault/sdk/logical"
86
"reflect"
97
"strings"
108
"testing"
9+
10+
"github.com/ProtonMail/go-crypto/openpgp"
11+
"github.com/hashicorp/vault/sdk/logical"
1112
)
1213

1314
func TestBackend_CRUD(t *testing.T) {
@@ -28,6 +29,7 @@ func TestBackend_CRUD(t *testing.T) {
2829
testAccStepDeleteKey(t, b, storage, "test")
2930
testAccStepListKey(t, b, storage, []string{"test2", "test3"})
3031
testAccStepReadKey(t, b, storage, "test", nil)
32+
testAccStepReadKey(t, b, storage, "test2", keyData)
3133
}
3234

3335
func TestBackend_CRUDImportedKey(t *testing.T) {

gpg/path_config.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gpg
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/hashicorp/vault/sdk/framework"
78
"github.com/hashicorp/vault/sdk/helper/locksutil"
89
"github.com/hashicorp/vault/sdk/logical"

gpg/path_config_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package gpg
22

33
import (
44
"context"
5-
"github.com/hashicorp/vault/sdk/logical"
65
"testing"
6+
7+
"github.com/hashicorp/vault/sdk/logical"
78
)
89

910
func TestGPG_SetKeyConfig(t *testing.T) {

gpg/path_decrypt.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"context"
66
"encoding/base64"
77
"fmt"
8+
"io"
9+
"strings"
10+
811
"github.com/ProtonMail/go-crypto/openpgp"
912
"github.com/ProtonMail/go-crypto/openpgp/armor"
1013
"github.com/hashicorp/vault/sdk/framework"
1114
"github.com/hashicorp/vault/sdk/logical"
12-
"io"
13-
"strings"
1415
)
1516

1617
func pathDecrypt(b *backend) *framework.Path {

gpg/path_decrypt_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package gpg
22

33
import (
44
"context"
5-
"github.com/hashicorp/vault/sdk/logical"
65
"testing"
6+
7+
"github.com/hashicorp/vault/sdk/logical"
78
)
89

910
func TestGPG_Decrypt(t *testing.T) {
@@ -131,7 +132,6 @@ func TestGPG_DecryptError(t *testing.T) {
131132

132133
// Message is signed but signature does not match the signer key
133134
decryptMustFail("test", encryptedAndSignedMessageASCIIArmored, "ascii-armor", privateDecryptKey)
134-
135135
}
136136

137137
const privateDecryptKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----

gpg/path_export.go

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gpg
33
import (
44
"bytes"
55
"context"
6+
67
"github.com/ProtonMail/go-crypto/openpgp"
78
"github.com/ProtonMail/go-crypto/openpgp/armor"
89
"github.com/hashicorp/vault/sdk/framework"

gpg/path_export_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package gpg
22

33
import (
44
"context"
5-
"github.com/hashicorp/vault/sdk/logical"
65
"testing"
6+
7+
"github.com/hashicorp/vault/sdk/logical"
78
)
89

910
func TestGPG_ExportNotExistingKeyReturnsNotFound(t *testing.T) {

gpg/path_keys.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"context"
66
"encoding/hex"
77
"fmt"
8-
"github.com/hashicorp/vault/sdk/helper/locksutil"
98
"io"
109
"strings"
1110

11+
"github.com/hashicorp/vault/sdk/helper/locksutil"
12+
1213
"github.com/ProtonMail/go-crypto/openpgp"
1314
"github.com/ProtonMail/go-crypto/openpgp/packet"
1415
"github.com/hashicorp/vault/sdk/framework"

gpg/path_show_session_key.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (b *backend) pathShowSessionKeyWrite(ctx context.Context, req *logical.Requ
105105
}
106106
switch p := p.(type) {
107107
case *packet.EncryptedKey:
108-
encryptedKey := packet.EncryptedKey(*p)
108+
encryptedKey := *p
109109
keys := keyring.KeysById(encryptedKey.KeyId)
110110
for _, key := range keys {
111111
encryptedKey.Decrypt(key.PrivateKey, nil)

gpg/path_show_session_key_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ func TestGPG_ShowSessionKeyError(t *testing.T) {
133133

134134
// Signer key is not properly ASCII-armored
135135
showSessionKeyMustFail("test", encryptedSessionMessageASCIIArmored, "ascii-armor", "Signer key is not ASCII armored")
136-
137136
}
138137

139138
const privateSessionDecryptKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----

gpg/path_sign_verify.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"crypto"
77
"encoding/base64"
88
"fmt"
9+
"strings"
10+
911
"github.com/ProtonMail/go-crypto/openpgp"
1012
"github.com/ProtonMail/go-crypto/openpgp/armor"
1113
"github.com/ProtonMail/go-crypto/openpgp/packet"
1214
"github.com/hashicorp/vault/sdk/framework"
1315
"github.com/hashicorp/vault/sdk/logical"
14-
"strings"
1516
)
1617

1718
func pathSign(b *backend) *framework.Path {

gpg/path_sign_verify_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package gpg
22

33
import (
44
"context"
5-
"github.com/hashicorp/vault/sdk/logical"
6-
"github.com/sigstore/rekor/pkg/generated/client/entries"
75
"reflect"
86
"testing"
7+
8+
"github.com/hashicorp/vault/sdk/logical"
9+
"github.com/sigstore/rekor/pkg/generated/client/entries"
910
)
1011

1112
func TestGPG_SignVerify(t *testing.T) {
@@ -15,7 +16,6 @@ func TestGPG_SignVerify(t *testing.T) {
1516
b = Backend()
1617
mockClient := &ClientMock{
1718
CreateLogEntryFunc: func(rekorServerUrl string, params *entries.CreateLogEntryParams) (*entries.CreateLogEntryCreated, error) {
18-
1919
return &entries.CreateLogEntryCreated{
2020
ETag: "some-uuid",
2121
Location: "/path/to/entry",

gpg/public_key.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gpg
22

33
import (
44
"bytes"
5+
56
"github.com/ProtonMail/go-crypto/openpgp"
67
"github.com/ProtonMail/go-crypto/openpgp/armor"
78
)

gpg/transparency_log.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gpg
22

33
import (
44
"context"
5+
56
"github.com/sigstore/rekor/pkg/client"
67
"github.com/sigstore/rekor/pkg/generated/client/entries"
78
"github.com/sigstore/rekor/pkg/types"

gpg/transparency_log_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package gpg
22

33
import (
44
"context"
5-
"github.com/sigstore/rekor/pkg/generated/client/entries"
65
"testing"
6+
7+
"github.com/sigstore/rekor/pkg/generated/client/entries"
78
)
89

910
type ClientMock struct {

shell.nix

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ pkgs.mkShell {
1212
pkgs.goreleaser
1313
pkgs.syft
1414
pkgs.cosign
15+
pkgs.golangci-lint
1516
];
1617
}

tools.go

-9
This file was deleted.

0 commit comments

Comments
 (0)