Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update golangci-lint to fix aws-sdk-go-v2 linting issues #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func main() {

ctx := context.Background()

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

switch splits[0] {
case "encrypt":
//nolint:staticcheck
eReq := &pb.EncryptRequest{Plain: []byte(splits[1])}
res, err := client.Encrypt(ctx, eReq)
if err != nil {
Expand All @@ -77,6 +79,7 @@ func main() {
if err != nil {
log.Fatalf("Failed to decode: %v", err)
}
//nolint:staticcheck
dReq := &pb.DecryptRequest{Cipher: b}
res, err := client.Decrypt(ctx, dReq)
if err != nil {
Expand Down
18 changes: 0 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,3 @@ require (
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/go-critic/go-critic v0.0.0-20181204210945-1df300866540 => github.com/go-critic/go-critic v0.0.0-20190526074819-1df300866540

replace github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6 => github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6

replace github.com/golangci/go-tools v0.0.0-20180109140146-af6baa5dc196 => github.com/golangci/go-tools v0.0.0-20190318060251-af6baa5dc196

replace github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98 => github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98

replace github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 => github.com/golangci/gosec v0.0.0-20190211064107-66fb7fc33547

replace github.com/golangci/ineffassign v0.0.0-20180808204949-42439a7714cc => github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc

replace github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 => github.com/golangci/lint-1 v0.0.0-20190420132249-ee948d087217

replace github.com/timakin/bodyclose => github.com/golangci/bodyclose v0.0.0-20190714144026-65da19158fa2

replace mvdan.cc/unparam v0.0.0-20190124213536-fbb59629db34 => mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34
4 changes: 2 additions & 2 deletions hack/verify-golint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ go version

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

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

echo "Congratulations! All Go source files have been linted."
11 changes: 2 additions & 9 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package connection

import (
"context"
"fmt"
"net"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

// New returns a grpc client connection for a given unix socket file path
func New(addr string) (*grpc.ClientConn, error) {
dialer := func(ctx context.Context, addr string) (net.Conn, error) {
var d net.Dialer
return d.DialContext(ctx, "unix", addr)
}

conn, err := grpc.Dial(
addr, grpc.WithContextDialer(dialer),
conn, err := grpc.NewClient(
"unix://"+addr,
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/plugin/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestMetrics(t *testing.T) {

u := ts.URL + "/metrics"

//nolint:staticcheck
_, err := p.Encrypt(context.Background(), &pb.EncryptRequest{Plain: []byte("hello")})
if err != nil {
if entry.encryptErr == nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func newPlugin(
func (p *V1Plugin) Health() error {
recent, err := p.healthCheck.isRecentlyChecked()
if !recent {
//nolint:staticcheck
_, err = p.Encrypt(context.Background(), &pb.EncryptRequest{Plain: []byte("foo")})
p.healthCheck.recordErr(err)
if err != nil {
Expand All @@ -116,7 +117,10 @@ func (p *V1Plugin) Live() error {
}

// Version returns the V1Plugin server version
//
//nolint:staticcheck
func (p *V1Plugin) Version(ctx context.Context, request *pb.VersionRequest) (*pb.VersionResponse, error) {
//nolint:staticcheck
return &pb.VersionResponse{
Version: version.APIVersion,
RuntimeName: version.Runtime,
Expand All @@ -125,6 +129,8 @@ func (p *V1Plugin) Version(ctx context.Context, request *pb.VersionRequest) (*pb
}

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

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

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

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

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

//nolint:staticcheck
_, err := client.Version(ctx, &pb.VersionRequest{}, grpc.WaitForReady(true))
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions pkg/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func TestEncrypt(t *testing.T) {
sharedHealthCheck.Stop()
}()

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

Expand Down Expand Up @@ -258,6 +259,7 @@ func TestDecrypt(t *testing.T) {
sharedHealthCheck.Stop()
}()

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

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

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

//nolint:staticcheck
_, decErr := p.Decrypt(context.Background(), &pb.DecryptRequest{Cipher: []byte("foo")})
if entry.decryptErr == nil && decErr != nil {
t.Fatalf("#%d: unexpected error from Encrypt %v", idx, decErr)
Expand Down Expand Up @@ -349,6 +353,7 @@ func TestHealthManyRequests(t *testing.T) {
for i := 0; i < 10; i++ {
errc := make(chan error)
go func() {
//nolint:staticcheck
_, err := p.Encrypt(
context.Background(),
&pb.EncryptRequest{Plain: []byte("foo")},
Expand Down
2 changes: 2 additions & 0 deletions test/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestEncrypt(t *testing.T) {
for _, tc := range tt {
mock.SetEncryptResp(tc.output, tc.err)

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

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

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

Expand Down
Loading