From 032831f69a4e52bb5cc7c10ca20d2167a4809d3e Mon Sep 17 00:00:00 2001 From: Carlo Teubner Date: Thu, 19 Dec 2024 23:08:25 +0000 Subject: [PATCH] golangci-lint: add nilerr & address issues Signed-off-by: Carlo Teubner --- .golangci.yml | 1 + pkg/common/container/process/winapi.go | 2 +- pkg/common/plugin/facade.go | 2 +- pkg/common/telemetry/statsd.go | 2 +- pkg/server/plugin/keymanager/awskms/awskms.go | 2 +- pkg/server/plugin/keymanager/awskms/awskms_test.go | 2 ++ 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9306540caf..b703f91a92 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,6 +19,7 @@ linters: - gosec - misspell - nakedret + - nilerr - unconvert - unparam - whitespace diff --git a/pkg/common/container/process/winapi.go b/pkg/common/container/process/winapi.go index 2634b319f3..232fda40f9 100644 --- a/pkg/common/container/process/winapi.go +++ b/pkg/common/container/process/winapi.go @@ -145,7 +145,7 @@ func (a *api) QuerySystemExtendedHandleInformation() ([]SystemHandleInformationE handlesList := (*SystemExtendedHandleInformation)(unsafe.Pointer(&buffer[0])) handles := unsafe.Slice(&handlesList.Handles[0], int(handlesList.NumberOfHandles)) - return handles, nil + return handles, nil //nolint:nilerr } return nil, status diff --git a/pkg/common/plugin/facade.go b/pkg/common/plugin/facade.go index 6468eb8130..f50329ef73 100644 --- a/pkg/common/plugin/facade.go +++ b/pkg/common/plugin/facade.go @@ -52,7 +52,7 @@ func (f *Facade) InitLog(log logrus.FieldLogger) { // that come out of plugin implementations. func (f *Facade) WrapErr(err error) error { if err == nil { - return err + return nil } // Embellish the gRPC status with the prefix, if necessary. diff --git a/pkg/common/telemetry/statsd.go b/pkg/common/telemetry/statsd.go index 69d1108d61..9e25cc9d13 100644 --- a/pkg/common/telemetry/statsd.go +++ b/pkg/common/telemetry/statsd.go @@ -16,7 +16,7 @@ func newStatsdRunner(c *MetricsConfig) (sinkRunner, error) { for _, sc := range c.FileConfig.Statsd { sink, err := metrics.NewStatsdSink(sc.Address) if err != nil { - return runner, nil + return nil, err } runner.loadedSinks = append(runner.loadedSinks, sink) diff --git a/pkg/server/plugin/keymanager/awskms/awskms.go b/pkg/server/plugin/keymanager/awskms/awskms.go index f2bdc74d1e..6a3b4589fc 100644 --- a/pkg/server/plugin/keymanager/awskms/awskms.go +++ b/pkg/server/plugin/keymanager/awskms/awskms.go @@ -807,7 +807,7 @@ func (p *Plugin) createDefaultPolicy(ctx context.Context) (*string, error) { roleName, err := roleNameFromARN(*result.Arn) if err != nil { // the server has not assumed any role, use default KMS policy and log a warn message - p.log.Warn("In a future version of SPIRE, it will be mandatory for the SPIRE servers to assume an AWS IAM Role when using the default AWS KMS key policy. Please assign an IAM role to this SPIRE Server instance.") + p.log.Warn("In a future version of SPIRE, it will be mandatory for the SPIRE servers to assume an AWS IAM Role when using the default AWS KMS key policy. Please assign an IAM role to this SPIRE Server instance.", reasonTag, err) return nil, nil } diff --git a/pkg/server/plugin/keymanager/awskms/awskms_test.go b/pkg/server/plugin/keymanager/awskms/awskms_test.go index 2a1d8695fb..0a2a8596df 100644 --- a/pkg/server/plugin/keymanager/awskms/awskms_test.go +++ b/pkg/server/plugin/keymanager/awskms/awskms_test.go @@ -719,6 +719,7 @@ func TestGenerateKey(t *testing.T) { { Level: logrus.WarnLevel, Message: "In a future version of SPIRE, it will be mandatory for the SPIRE servers to assume an AWS IAM Role when using the default AWS KMS key policy. Please assign an IAM role to this SPIRE Server instance.", + Data: logrus.Fields{reasonTag: `incomplete resource, expected 'resource-type/resource-id' but got "example-account-id"`}, }, }, }, @@ -734,6 +735,7 @@ func TestGenerateKey(t *testing.T) { { Level: logrus.WarnLevel, Message: "In a future version of SPIRE, it will be mandatory for the SPIRE servers to assume an AWS IAM Role when using the default AWS KMS key policy. Please assign an IAM role to this SPIRE Server instance.", + Data: logrus.Fields{reasonTag: `arn does not contain an assumed role: "arn:aws:sts::example-account-id:user/development"`}, }, }, },