Skip to content

Commit 91f20e6

Browse files
authored
Merge pull request #122 from mjlshen/golangci-lint
Update golangci-lint to fix aws-sdk-go-v2 linting issues
2 parents 916caee + b9333f0 commit 91f20e6

File tree

8 files changed

+26
-29
lines changed

8 files changed

+26
-29
lines changed

cmd/client/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func main() {
4747

4848
ctx := context.Background()
4949

50+
//nolint:staticcheck
5051
vReq := &pb.VersionRequest{}
5152
vRes, err := client.Version(ctx, vReq)
5253
if err != nil {
@@ -66,6 +67,7 @@ func main() {
6667

6768
switch splits[0] {
6869
case "encrypt":
70+
//nolint:staticcheck
6971
eReq := &pb.EncryptRequest{Plain: []byte(splits[1])}
7072
res, err := client.Encrypt(ctx, eReq)
7173
if err != nil {
@@ -77,6 +79,7 @@ func main() {
7779
if err != nil {
7880
log.Fatalf("Failed to decode: %v", err)
7981
}
82+
//nolint:staticcheck
8083
dReq := &pb.DecryptRequest{Cipher: b}
8184
res, err := client.Decrypt(ctx, dReq)
8285
if err != nil {

go.mod

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,3 @@ require (
3737
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
3838
gopkg.in/yaml.v3 v3.0.1 // indirect
3939
)
40-
41-
replace github.com/go-critic/go-critic v0.0.0-20181204210945-1df300866540 => github.com/go-critic/go-critic v0.0.0-20190526074819-1df300866540
42-
43-
replace github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6 => github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6
44-
45-
replace github.com/golangci/go-tools v0.0.0-20180109140146-af6baa5dc196 => github.com/golangci/go-tools v0.0.0-20190318060251-af6baa5dc196
46-
47-
replace github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98 => github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98
48-
49-
replace github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 => github.com/golangci/gosec v0.0.0-20190211064107-66fb7fc33547
50-
51-
replace github.com/golangci/ineffassign v0.0.0-20180808204949-42439a7714cc => github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc
52-
53-
replace github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 => github.com/golangci/lint-1 v0.0.0-20190420132249-ee948d087217
54-
55-
replace github.com/timakin/bodyclose => github.com/golangci/bodyclose v0.0.0-20190714144026-65da19158fa2
56-
57-
replace mvdan.cc/unparam v0.0.0-20190124213536-fbb59629db34 => mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34

hack/verify-golint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ go version
2222

2323
if ! which golangci-lint > /dev/null; then
2424
echo "Cannot find golangci-lint. Installing golangci-lint..."
25-
GO111MODULE=on go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.41.1
25+
GO111MODULE=on go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
2626
fi
2727

28-
$GOPATH/bin/golangci-lint run --deadline=10m
28+
$(go env GOPATH)/bin/golangci-lint run --timeout=10m
2929

3030
echo "Congratulations! All Go source files have been linted."

pkg/connection/connection.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
package connection
22

33
import (
4-
"context"
54
"fmt"
6-
"net"
75

86
"google.golang.org/grpc"
97
"google.golang.org/grpc/credentials/insecure"
108
)
119

1210
// New returns a grpc client connection for a given unix socket file path
1311
func New(addr string) (*grpc.ClientConn, error) {
14-
dialer := func(ctx context.Context, addr string) (net.Conn, error) {
15-
var d net.Dialer
16-
return d.DialContext(ctx, "unix", addr)
17-
}
18-
19-
conn, err := grpc.Dial(
20-
addr, grpc.WithContextDialer(dialer),
12+
conn, err := grpc.NewClient(
13+
"unix://"+addr,
2114
grpc.WithTransportCredentials(insecure.NewCredentials()),
2215
)
2316
if err != nil {

pkg/plugin/metrics_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func TestMetrics(t *testing.T) {
8484

8585
u := ts.URL + "/metrics"
8686

87+
//nolint:staticcheck
8788
_, err := p.Encrypt(context.Background(), &pb.EncryptRequest{Plain: []byte("hello")})
8889
if err != nil {
8990
if entry.encryptErr == nil {

pkg/plugin/plugin.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func newPlugin(
9090
func (p *V1Plugin) Health() error {
9191
recent, err := p.healthCheck.isRecentlyChecked()
9292
if !recent {
93+
//nolint:staticcheck
9394
_, err = p.Encrypt(context.Background(), &pb.EncryptRequest{Plain: []byte("foo")})
9495
p.healthCheck.recordErr(err)
9596
if err != nil {
@@ -116,7 +117,10 @@ func (p *V1Plugin) Live() error {
116117
}
117118

118119
// Version returns the V1Plugin server version
120+
//
121+
//nolint:staticcheck
119122
func (p *V1Plugin) Version(ctx context.Context, request *pb.VersionRequest) (*pb.VersionResponse, error) {
123+
//nolint:staticcheck
120124
return &pb.VersionResponse{
121125
Version: version.APIVersion,
122126
RuntimeName: version.Runtime,
@@ -125,6 +129,8 @@ func (p *V1Plugin) Version(ctx context.Context, request *pb.VersionRequest) (*pb
125129
}
126130

127131
// Encrypt executes the encryption operation using AWS KMS
132+
//
133+
//nolint:staticcheck
128134
func (p *V1Plugin) Encrypt(ctx context.Context, request *pb.EncryptRequest) (*pb.EncryptResponse, error) {
129135
zap.L().Debug("starting encrypt operation")
130136

@@ -154,10 +160,13 @@ func (p *V1Plugin) Encrypt(ctx context.Context, request *pb.EncryptRequest) (*pb
154160
zap.L().Debug("encrypt operation successful")
155161
kmsLatencyMetric.WithLabelValues(p.keyID, kmsplugin.StatusSuccess, kmsplugin.OperationEncrypt, GRPC_V1).Observe(kmsplugin.GetMillisecondsSince(startTime))
156162
kmsOperationCounter.WithLabelValues(p.keyID, kmsplugin.StatusSuccess, kmsplugin.OperationEncrypt, GRPC_V1).Inc()
163+
//nolint:staticcheck
157164
return &pb.EncryptResponse{Cipher: append([]byte(kmsplugin.StorageVersion), result.CiphertextBlob...)}, nil
158165
}
159166

160167
// Decrypt executes the decrypt operation using AWS KMS
168+
//
169+
//nolint:staticcheck
161170
func (p *V1Plugin) Decrypt(ctx context.Context, request *pb.DecryptRequest) (*pb.DecryptResponse, error) {
162171
zap.L().Debug("starting decrypt operation")
163172

@@ -189,6 +198,7 @@ func (p *V1Plugin) Decrypt(ctx context.Context, request *pb.DecryptRequest) (*pb
189198
zap.L().Debug("decrypt operation successful")
190199
kmsLatencyMetric.WithLabelValues(p.keyID, kmsplugin.StatusSuccess, kmsplugin.OperationDecrypt, GRPC_V1).Observe(kmsplugin.GetMillisecondsSince(startTime))
191200
kmsOperationCounter.WithLabelValues(p.keyID, kmsplugin.StatusSuccess, kmsplugin.OperationDecrypt, GRPC_V1).Inc()
201+
//nolint:staticcheck
192202
return &pb.DecryptResponse{Plain: result.Plaintext}, nil
193203
}
194204

@@ -204,6 +214,7 @@ func WaitForReady(client pb.KeyManagementServiceClient, duration time.Duration)
204214
ctx, cancel := context.WithTimeout(context.Background(), duration)
205215
defer cancel()
206216

217+
//nolint:staticcheck
207218
_, err := client.Version(ctx, &pb.VersionRequest{}, grpc.WaitForReady(true))
208219
if err != nil {
209220
return err

pkg/plugin/plugin_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func TestEncrypt(t *testing.T) {
180180
sharedHealthCheck.Stop()
181181
}()
182182

183+
//nolint:staticcheck
183184
eReq := &pb.EncryptRequest{Plain: []byte(tc.input)}
184185
eRes, err := p.Encrypt(ctx, eReq)
185186

@@ -258,6 +259,7 @@ func TestDecrypt(t *testing.T) {
258259
sharedHealthCheck.Stop()
259260
}()
260261

262+
//nolint:staticcheck
261263
dReq := &pb.DecryptRequest{Cipher: []byte(tc.input)}
262264
dRes, err := p.Decrypt(ctx, dReq)
263265

@@ -304,6 +306,7 @@ func TestHealth(t *testing.T) {
304306
c.SetEncryptResp("foo", entry.encryptErr)
305307
c.SetDecryptResp("foo", entry.decryptErr)
306308

309+
//nolint:staticcheck
307310
_, encErr := p.Encrypt(context.Background(), &pb.EncryptRequest{Plain: []byte("foo")})
308311
if entry.encryptErr == nil && encErr != nil {
309312
t.Fatalf("#%d: unexpected error from Encrypt %v", idx, encErr)
@@ -317,6 +320,7 @@ func TestHealth(t *testing.T) {
317320
t.Fatalf("#%d: unexpected error from Health %v", idx, herr1)
318321
}
319322

323+
//nolint:staticcheck
320324
_, decErr := p.Decrypt(context.Background(), &pb.DecryptRequest{Cipher: []byte("foo")})
321325
if entry.decryptErr == nil && decErr != nil {
322326
t.Fatalf("#%d: unexpected error from Encrypt %v", idx, decErr)
@@ -349,6 +353,7 @@ func TestHealthManyRequests(t *testing.T) {
349353
for i := 0; i < 10; i++ {
350354
errc := make(chan error)
351355
go func() {
356+
//nolint:staticcheck
352357
_, err := p.Encrypt(
353358
context.Background(),
354359
&pb.EncryptRequest{Plain: []byte("foo")},

test/integration/integration_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func TestEncrypt(t *testing.T) {
101101
for _, tc := range tt {
102102
mock.SetEncryptResp(tc.output, tc.err)
103103

104+
//nolint:staticcheck
104105
eReq := &pb.EncryptRequest{Plain: []byte(tc.input)}
105106
eRes, err := client.Encrypt(ctx, eReq)
106107

@@ -163,6 +164,7 @@ func TestDecrypt(t *testing.T) {
163164
for _, tc := range tt {
164165
mock.SetDecryptResp(tc.output, tc.err)
165166

167+
//nolint:staticcheck
166168
dReq := &pb.DecryptRequest{Cipher: []byte(tc.input)}
167169
dRes, err := client.Decrypt(ctx, dReq)
168170

0 commit comments

Comments
 (0)