diff --git a/.golangci.yaml b/.golangci.yaml index 289ef1c..561678e 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,51 +1,11 @@ +version: "2" + run: timeout: 10m - -linters-settings: - gci: - sections: - - "standard" - - "default" - - "prefix(github.com/external-secrets/bitwarden-sdk-server)" - - "blank" - - "dot" - goconst: - min-len: 3 - min-occurrences: 3 - gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - disabled-checks: - - dupImport - - ifElseChain - - octalLiteral - - whyNoLint - - wrapperFunc - - importShadow - - unnamedResult - - unnecessaryBlock - settings: - rangeValCopy: - sizeThreshold: 512 - hugeParam: - sizeThreshold: 512 - gocyclo: - min-complexity: 16 - goheader: - template-path: ./hack/boilerplate.go.txt - dupl: - threshold: 200 - lll: - line-length: 300 - misspell: - locale: US + allow-parallel-runners: true linters: - disable-all: true + default: none enable: - asciicheck - bodyclose @@ -54,68 +14,136 @@ linters: - errcheck - errorlint - exhaustive - - exportloopref - - gci + - copyloopvar - goheader - goconst - gocritic - godot - - gofmt - goprintffuncname - gosec - - gosimple - govet - ineffassign - - lll - misspell + - modernize # A suite of analyzers that suggest simplifications to Go code, using modern language and library features. https://golangci-lint.run/docs/linters/configuration/#modernize - nakedret - nolintlint - prealloc - - staticcheck - - stylecheck - - typecheck + - lll - unconvert - unparam - unused - whitespace + settings: + goconst: + min-len: 3 + min-occurrences: 3 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - dupImport + - ifElseChain + - octalLiteral + - whyNoLint + - wrapperFunc + - importShadow + - unnamedResult + - unnecessaryBlock + settings: + rangeValCopy: + sizeThreshold: 512 + hugeParam: + sizeThreshold: 512 + gocyclo: + min-complexity: 16 + goheader: + template-path: ${config-path}/hack/boilerplate.go.txt + dupl: + threshold: 200 + govet: + disable: + - shadow + lll: + line-length: 300 + misspell: + locale: US + modernize: + disable: + - omitzero + exclusions: + paths: + - runtime/template/v2/sprig + rules: + # Exclude some linters from running on tests files. + - path: _test(ing)?\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + - unparam + - lll + - revive -issues: - # Excluding configuration per-path and per-linter - exclude-rules: - # Exclude some linters from running on tests files. - - path: _test(ing)?\.go - linters: - - gocyclo - - errcheck - - dupl - - gosec - - unparam - - lll + # Allow dot imports for Ginkgo and Gomega in test files + - path: _test\.go + text: "dot-imports:" + linters: + - revive - # Ease some gocritic warnings on test files. - - path: _test\.go - text: "(unnamedResult|exitAfterDefer)" - linters: - - gocritic + # Ease some gocritic warnings on test files. + - path: _test\.go + text: "(unnamedResult|exitAfterDefer)" + linters: + - gocritic - # This is a "potential hardcoded credentials" warning. It's triggered by - # any variable with 'secret' in the same, and thus hits a lot of false - # positives in Kubernetes land where a Secret is an object type. - - text: "G101:" - linters: - - gosec + # Exclude fake or mock packages from revive linter + - path: /(fake|mock)/ + linters: + - revive - # The header check doesn't correctly parse the header as a code comment and is - # triggered by the perceived diff. The header check still correctly detects missing - # license headers and is useful for some cases. - - text: "Actual:" - linters: - - goheader + # This is a "potential hardcoded credentials" warning. It's triggered by + # any variable with 'secret' in the same, and thus hits a lot of false + # positives in Kubernetes land where a Secret is an object type. + - text: "G101:" + linters: + - gosec + + # The header check doesn't correctly parse the header as a code comment and is + # triggered by the perceived diff. The header check still correctly detects missing + # license headers and is useful for some cases. + - text: "Actual:" + linters: + - goheader +issues: + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 - # excluding deprecation check introduced on purpose in #2884 - - path: pkg/provider/fake/fake.go - text: 'SA1019: data.ValueMap is deprecated: ValueMap is deprecated and is intended to be removed in the future, use the `value` field instead.' - - path: pkg/provider/fake/fake_test.go - text: 'SA1019: data.ValueMap is deprecated: ValueMap is deprecated and is intended to be removed in the future, use the `value` field instead.' # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. max-same-issues: 0 + +formatters: + enable: + - gci + - gofmt + - goimports + - golines + settings: + goimports: + local-prefixes: + - github.com/external-secrets/bitwarden-sdk-server + golines: + # Target maximum line length. + # Default: 100 + max-len: 200 + gci: + sections: + - "standard" + - "default" + - "prefix(github.com/external-secrets/bitwarden-sdk-server)" + - "blank" + - "dot" diff --git a/Makefile b/Makefile index 7fad099..2acf333 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ endif # List the GOOS and GOARCH to build GO_LDFLAGS_STATIC="-s -w $(CTIMEVAR) -extldflags -static" -GOLANGCI_LINT_VERSION ?= v1.57.2 +GOLANGCI_LINT_VERSION ?= v2.11.3 MKCERT_VERSION ?= v1.4.4 .DEFAULT_GOAL := help diff --git a/go.mod b/go.mod index dedee79..7037e98 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module github.com/external-secrets/bitwarden-sdk-server -go 1.22 +go 1.23 replace github.com/bitwarden/sdk-go/v2 => github.com/Skarlso/sdk-go/v2 v2.0.0 require ( github.com/bitwarden/sdk-go/v2 v2.0.0 - github.com/go-chi/chi/v5 v5.2.5 + github.com/go-chi/chi/v5 v5.3.0 github.com/spf13/cobra v1.10.2 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index b2dc495..95bb86b 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,8 @@ github.com/Skarlso/sdk-go/v2 v2.0.0/go.mod h1:6Sfb4IdZ9tnggeFj8Ty4MLkWUyC2pNlFUo github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug= -github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0= +github.com/go-chi/chi/v5 v5.3.0 h1:halUjDxhshgXHMrao5bB8eNBXo/rnzwr8m5m36glehM= +github.com/go-chi/chi/v5 v5.3.0/go.mod h1:R+tYY2hNuVUUjxoPtqUdgBqevM9s9njzkTLutVsOCto= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/pkg/server/server.go b/pkg/server/server.go index 40acf16..45f1100 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -211,7 +211,9 @@ func (s *Server) getClient(r *http.Request, response any) (sdk.BitwardenClientIn if err != nil { return nil, err } - defer r.Body.Close() + defer func() { + _ = r.Body.Close() + }() if err := json.Unmarshal(content, response); err != nil { return nil, err