Просмотр исходного кода

chore(deps): bump golangci/golangci-lint-action from 6.5.2 to 8.0.0 (#4734)

* chore(deps): bump golangci/golangci-lint-action from 6.5.2 to 8.0.0

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 6.5.2 to 8.0.0.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/55c2c1448f86e01eaae002a5a3a9624417608d84...4afd733a84b1f43292c63897423277bb7f4313a9)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-version: 8.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: update the linter and fix some of the linter issues

Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
dependabot[bot] 11 месяцев назад
Родитель
Сommit
84fd748a0d
34 измененных файлов с 228 добавлено и 145 удалено
  1. 2 2
      .github/workflows/ci.yml
  2. 89 85
      .golangci.yaml
  3. 2 2
      Makefile
  4. 6 5
      cmd/esoctl/template.go
  5. 3 1
      e2e/framework/addon/eso_argocd_application.go
  6. 3 1
      e2e/framework/addon/eso_flux_helm.go
  7. 6 2
      e2e/framework/addon/vault.go
  8. 3 1
      e2e/framework/util/util.go
  9. 3 1
      e2e/suites/provider/cases/akeyless/provider.go
  10. 3 1
      pkg/common/webhook/webhook.go
  11. 6 4
      pkg/controllers/crds/crds_controller_test.go
  12. 3 1
      pkg/controllers/externalsecret/externalsecret_controller_secret.go
  13. 3 1
      pkg/controllers/pushsecret/pushsecret_controller.go
  14. 1 1
      pkg/controllers/secretstore/client_manager.go
  15. 3 1
      pkg/controllers/secretstore/common.go
  16. 8 3
      pkg/generator/acr/acr.go
  17. 3 1
      pkg/generator/github/github.go
  18. 3 1
      pkg/generator/quay/quay.go
  19. 33 11
      pkg/provider/akeyless/akeyless_api.go
  20. 3 1
      pkg/provider/akeyless/utils.go
  21. 3 1
      pkg/provider/alibaba/client.go
  22. 2 1
      pkg/provider/azure/keyvault/keyvault.go
  23. 3 1
      pkg/provider/bitwarden/bitwarden_sdk.go
  24. 3 1
      pkg/provider/cloudru/secretmanager/endpoints.go
  25. 3 1
      pkg/provider/doppler/client/client.go
  26. 3 1
      pkg/provider/gcp/secretmanager/auth.go
  27. 3 1
      pkg/provider/gcp/secretmanager/workload_identity.go
  28. 3 1
      pkg/provider/infisical/api/api.go
  29. 3 1
      pkg/provider/onboardbase/client/client.go
  30. 2 3
      pkg/provider/passworddepot/passworddepot_api.go
  31. 3 1
      pkg/provider/senhasegura/auth/iso.go
  32. 3 1
      pkg/provider/senhasegura/dsm/dsm.go
  33. 5 4
      pkg/provider/vault/auth_iam.go
  34. 3 1
      pkg/utils/utils.go

+ 2 - 2
.github/workflows/ci.yml

@@ -9,7 +9,7 @@ on:
 
 
 env:
 env:
   # Common versions
   # Common versions
-  GOLANGCI_VERSION: 'v1.64.6'
+  GOLANGCI_VERSION: 'v2.1.6'
   KUBERNETES_VERSION: '1.31.x'
   KUBERNETES_VERSION: '1.31.x'
 
 
   # Sonar
   # Sonar
@@ -65,7 +65,7 @@ jobs:
         run: go mod download
         run: go mod download
 
 
       - name: Lint
       - name: Lint
-        uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
+        uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
         with:
         with:
           version: ${{ env.GOLANGCI_VERSION }}
           version: ${{ env.GOLANGCI_VERSION }}
           skip-pkg-cache: true
           skip-pkg-cache: true

+ 89 - 85
.golangci.yaml

@@ -1,54 +1,11 @@
+version: "2"
+
 run:
 run:
   timeout: 10m
   timeout: 10m
-
-linters-settings:
-  gci:
-    sections:
-      - "standard"
-      - "default"
-      - "prefix(github.com/external-secrets/external-secrets)"
-      - "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
-  govet:
-    disable:
-      - shadow
-  lll:
-    line-length: 300
-  misspell:
-    locale: US
+  allow-parallel-runners: true
 
 
 linters:
 linters:
-  disable-all: true
+  default: none
   enable:
   enable:
     - asciicheck
     - asciicheck
     - bodyclose
     - bodyclose
@@ -58,65 +15,112 @@ linters:
     - errorlint
     - errorlint
     - exhaustive
     - exhaustive
     - copyloopvar
     - copyloopvar
-    - gci
     - goheader
     - goheader
     - goconst
     - goconst
     - gocritic
     - gocritic
     - godot
     - godot
-    - gofmt
     - goprintffuncname
     - goprintffuncname
     - gosec
     - gosec
-    - gosimple
     - govet
     - govet
     - ineffassign
     - ineffassign
-    - lll
     - misspell
     - misspell
     - nakedret
     - nakedret
     - nolintlint
     - nolintlint
     - prealloc
     - prealloc
-    - staticcheck
-    - stylecheck
-    - typecheck
+    - lll
     - unconvert
     - unconvert
     - unparam
     - unparam
     - unused
     - unused
     - whitespace
     - 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: ./hack/boilerplate.go.txt
+    dupl:
+      threshold: 200
+    govet:
+      disable:
+        - shadow
+    lll:
+      line-length: 300
+#    staticcheck:
+#      checks:
+#        - QF1008
+    misspell:
+      locale: US
+  exclusions:
+    rules:
+      # Exclude some linters from running on tests files.
+      - path: _test(ing)?\.go
+        linters:
+          - gocyclo
+          - errcheck
+          - dupl
+          - gosec
+          - unparam
+          - lll
 
 
-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
+      # 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
-
-    # 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.
   # Maximum issues count per one linter. Set to 0 to disable. Default is 50.
   max-issues-per-linter: 0
   max-issues-per-linter: 0
 
 
   # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
   # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
   max-same-issues: 0
   max-same-issues: 0
+
+formatters:
+  settings:
+    golines:
+      # Target maximum line length.
+      # Default: 100
+      max-len: 200
+    gci:
+      sections:
+        - "standard"
+        - "default"
+        - "prefix(github.com/external-secrets/external-secrets)"
+        - "blank"
+        - "dot"

+ 2 - 2
Makefile

@@ -353,7 +353,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
 GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
 GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
 
 
 ## Tool Versions
 ## Tool Versions
-GOLANGCI_VERSION := 1.64.6
+GOLANGCI_VERSION := 2.1.6
 KUBERNETES_VERSION := 1.30.x
 KUBERNETES_VERSION := 1.30.x
 TILT_VERSION := 0.33.21
 TILT_VERSION := 0.33.21
 CTY_VERSION := 1.1.3
 CTY_VERSION := 1.1.3
@@ -367,7 +367,7 @@ $(ENVTEST): $(LOCALBIN)
 .PHONY: $(GOLANGCI_LINT)
 .PHONY: $(GOLANGCI_LINT)
 golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
 golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
 $(GOLANGCI_LINT): $(LOCALBIN)
 $(GOLANGCI_LINT): $(LOCALBIN)
-	test -s $(LOCALBIN)/golangci-lint && $(LOCALBIN)/golangci-lint version --format short | grep -q $(GOLANGCI_VERSION) || \
+	test -s $(LOCALBIN)/golangci-lint && $(LOCALBIN)/golangci-lint version | grep -q $(GOLANGCI_VERSION) || \
 	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) v$(GOLANGCI_VERSION)
 	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) v$(GOLANGCI_VERSION)
 
 
 .PHONY: tilt
 .PHONY: tilt

+ 6 - 5
cmd/esoctl/template.go

@@ -20,6 +20,7 @@ import (
 	"context"
 	"context"
 	"fmt"
 	"fmt"
 	"os"
 	"os"
+	"path/filepath"
 
 
 	"github.com/spf13/cobra"
 	"github.com/spf13/cobra"
 	corev1 "k8s.io/api/core/v1"
 	corev1 "k8s.io/api/core/v1"
@@ -75,7 +76,7 @@ func templateRun(_ *cobra.Command, _ []string) error {
 
 
 	ctx := context.Background()
 	ctx := context.Background()
 	obj := &unstructured.Unstructured{}
 	obj := &unstructured.Unstructured{}
-	content, err := os.ReadFile(templateFile)
+	content, err := os.ReadFile(filepath.Clean(templateFile))
 	if err != nil {
 	if err != nil {
 		return fmt.Errorf("could not read template file: %w", err)
 		return fmt.Errorf("could not read template file: %w", err)
 	}
 	}
@@ -90,7 +91,7 @@ func templateRun(_ *cobra.Command, _ []string) error {
 	}
 	}
 
 
 	data := map[string][]byte{}
 	data := map[string][]byte{}
-	sourceDataContent, err := os.ReadFile(secretDataFile)
+	sourceDataContent, err := os.ReadFile(filepath.Clean(secretDataFile))
 	if err != nil {
 	if err != nil {
 		return fmt.Errorf("could not read source secret file: %w", err)
 		return fmt.Errorf("could not read source secret file: %w", err)
 	}
 	}
@@ -121,7 +122,7 @@ func templateRun(_ *cobra.Command, _ []string) error {
 
 
 	out := os.Stdout
 	out := os.Stdout
 	if outputFile != "" {
 	if outputFile != "" {
-		f, err := os.Create(outputFile)
+		f, err := os.Create(filepath.Clean(outputFile))
 		if err != nil {
 		if err != nil {
 			return fmt.Errorf("could not create output file: %w", err)
 			return fmt.Errorf("could not create output file: %w", err)
 		}
 		}
@@ -201,7 +202,7 @@ func executeTemplate(p *templating.Parser, ctx context.Context, tmpl *esv1.Exter
 func setupFromConfigAndFromSecret(p *templating.Parser) error {
 func setupFromConfigAndFromSecret(p *templating.Parser) error {
 	if templateFromConfigMapFile != "" {
 	if templateFromConfigMapFile != "" {
 		var configMap corev1.ConfigMap
 		var configMap corev1.ConfigMap
-		configMapContent, err := os.ReadFile(templateFromConfigMapFile)
+		configMapContent, err := os.ReadFile(filepath.Clean(templateFromConfigMapFile))
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
@@ -215,7 +216,7 @@ func setupFromConfigAndFromSecret(p *templating.Parser) error {
 
 
 	if templateFromSecretFile != "" {
 	if templateFromSecretFile != "" {
 		var secret corev1.Secret
 		var secret corev1.Secret
-		secretContent, err := os.ReadFile(templateFromSecretFile)
+		secretContent, err := os.ReadFile(filepath.Clean(templateFromSecretFile))
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}

+ 3 - 1
e2e/framework/addon/eso_argocd_application.go

@@ -150,7 +150,9 @@ func (c *ArgoCDApplication) Install() error {
 		if err != nil {
 		if err != nil {
 			return false, nil
 			return false, nil
 		}
 		}
-		defer res.Body.Close()
+		defer func() {
+			_ = res.Body.Close()
+		}()
 		ginkgo.GinkgoWriter.Printf("webhook res: %d", res.StatusCode)
 		ginkgo.GinkgoWriter.Printf("webhook res: %d", res.StatusCode)
 		return res.StatusCode == http.StatusOK, nil
 		return res.StatusCode == http.StatusOK, nil
 	})
 	})

+ 3 - 1
e2e/framework/addon/eso_flux_helm.go

@@ -137,7 +137,9 @@ func (c *FluxHelmRelease) Install() error {
 		if err != nil {
 		if err != nil {
 			return false, nil
 			return false, nil
 		}
 		}
-		defer res.Body.Close()
+		defer func() {
+			_ = res.Body.Close()
+		}()
 		ginkgo.GinkgoWriter.Printf("webhook res: %d", res.StatusCode)
 		ginkgo.GinkgoWriter.Printf("webhook res: %d", res.StatusCode)
 		return res.StatusCode == http.StatusOK, nil
 		return res.StatusCode == http.StatusOK, nil
 	})
 	})

+ 6 - 2
e2e/framework/addon/vault.go

@@ -275,7 +275,9 @@ func (l *Vault) configureVault() error {
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	sec, err := vault.ParseSecret(res.Body)
 	sec, err := vault.ParseSecret(res.Body)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
@@ -289,7 +291,9 @@ func (l *Vault) configureVault() error {
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	sec, err = vault.ParseSecret(res.Body)
 	sec, err = vault.ParseSecret(res.Body)
 	if err != nil {
 	if err != nil {
 		return err
 		return err

+ 3 - 1
e2e/framework/util/util.go

@@ -244,7 +244,9 @@ func WaitForURL(url string) error {
 		if err != nil {
 		if err != nil {
 			return false, nil
 			return false, nil
 		}
 		}
-		defer res.Body.Close()
+		defer func() {
+			_ = res.Body.Close()
+		}()
 		if res.StatusCode == http.StatusOK {
 		if res.StatusCode == http.StatusOK {
 			return true, nil
 			return true, nil
 		}
 		}

+ 3 - 1
e2e/suites/provider/cases/akeyless/provider.go

@@ -221,7 +221,9 @@ func readK8SServiceAccountJWT() (string, error) {
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
 	}
 	}
-	defer data.Close()
+	defer func() {
+		_ = data.Close()
+	}()
 
 
 	contentBytes, err := io.ReadAll(data)
 	contentBytes, err := io.ReadAll(data)
 	if err != nil {
 	if err != nil {

+ 3 - 1
pkg/common/webhook/webhook.go

@@ -276,7 +276,9 @@ func (w *Webhook) executeRequest(ctx context.Context, provider *Spec, data []byt
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("failed to call endpoint: %w", err)
 		return nil, fmt.Errorf("failed to call endpoint: %w", err)
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 	if resp.StatusCode == 404 {
 	if resp.StatusCode == 404 {
 		return nil, esv1.NoSecretError{}
 		return nil, esv1.NoSecretError{}
 	}
 	}

+ 6 - 4
pkg/controllers/crds/crds_controller_test.go

@@ -340,14 +340,16 @@ func TestCheckCertChain(t *testing.T) {
 	if err != nil {
 	if err != nil {
 		t.Errorf(failedCreateServerCerts, err)
 		t.Errorf(failedCreateServerCerts, err)
 	}
 	}
-	os.WriteFile(cacrt, caArtifacts.CertPEM, 0644)
-	os.WriteFile(tlscrt, certPEM, 0644)
+	_ = os.WriteFile(cacrt, caArtifacts.CertPEM, 0644)
+	_ = os.WriteFile(tlscrt, certPEM, 0644)
 	f, _ := os.OpenFile(tlscrt, os.O_APPEND|os.O_WRONLY, 0644)
 	f, _ := os.OpenFile(tlscrt, os.O_APPEND|os.O_WRONLY, 0644)
-	defer f.Close()
+	defer func() {
+		_ = f.Close()
+	}()
 	if _, err = f.Write(chainArtifacts.CertPEM); err != nil {
 	if _, err = f.Write(chainArtifacts.CertPEM); err != nil {
 		t.Errorf(failedCreateCaChain, err)
 		t.Errorf(failedCreateCaChain, err)
 	}
 	}
-	os.WriteFile(tlskey, keyPEM, 0644)
+	_ = os.WriteFile(tlskey, keyPEM, 0644)
 	cert := CertInfo{
 	cert := CertInfo{
 		CertDir:  "/tmp",
 		CertDir:  "/tmp",
 		CertName: "tls",
 		CertName: "tls",

+ 3 - 1
pkg/controllers/externalsecret/externalsecret_controller_secret.go

@@ -43,7 +43,9 @@ func (r *Reconciler) getProviderSecretData(ctx context.Context, externalSecret *
 	// that are created during the fetching process and closes clients
 	// that are created during the fetching process and closes clients
 	// if needed.
 	// if needed.
 	mgr := secretstore.NewManager(r.Client, r.ControllerClass, r.EnableFloodGate)
 	mgr := secretstore.NewManager(r.Client, r.ControllerClass, r.EnableFloodGate)
-	defer mgr.Close(ctx)
+	defer func() {
+		_ = mgr.Close(ctx)
+	}()
 
 
 	// statemanager takes care of managing the state of the generators.
 	// statemanager takes care of managing the state of the generators.
 	// Since ExternalSecrets can have multiple generators, we need to keep track of the state of each generator
 	// Since ExternalSecrets can have multiple generators, we need to keep track of the state of each generator

+ 3 - 1
pkg/controllers/pushsecret/pushsecret_controller.go

@@ -91,7 +91,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
 
 
 	var ps esapi.PushSecret
 	var ps esapi.PushSecret
 	mgr := secretstore.NewManager(r.Client, r.ControllerClass, false)
 	mgr := secretstore.NewManager(r.Client, r.ControllerClass, false)
-	defer mgr.Close(ctx)
+	defer func() {
+		_ = mgr.Close(ctx)
+	}()
 
 
 	if err := r.Get(ctx, req.NamespacedName, &ps); err != nil {
 	if err := r.Get(ctx, req.NamespacedName, &ps); err != nil {
 		if apierrors.IsNotFound(err) {
 		if apierrors.IsNotFound(err) {

+ 1 - 1
pkg/controllers/secretstore/client_manager.go

@@ -160,7 +160,7 @@ func (m *Manager) getStoredClient(ctx context.Context, storeProvider esv1.Provid
 		"store", storeName)
 		"store", storeName)
 	// if we have a client, but it points to a different store
 	// if we have a client, but it points to a different store
 	// we must clean it up
 	// we must clean it up
-	val.client.Close(ctx)
+	_ = val.client.Close(ctx)
 	delete(m.clientMap, idx)
 	delete(m.clientMap, idx)
 	return nil
 	return nil
 }
 }

+ 3 - 1
pkg/controllers/secretstore/common.go

@@ -112,7 +112,9 @@ func reconcile(ctx context.Context, req ctrl.Request, ss esapi.GenericStore, cl
 func validateStore(ctx context.Context, namespace, controllerClass string, store esapi.GenericStore,
 func validateStore(ctx context.Context, namespace, controllerClass string, store esapi.GenericStore,
 	client client.Client, gaugeVecGetter metrics.GaugeVevGetter, recorder record.EventRecorder) error {
 	client client.Client, gaugeVecGetter metrics.GaugeVevGetter, recorder record.EventRecorder) error {
 	mgr := NewManager(client, controllerClass, false)
 	mgr := NewManager(client, controllerClass, false)
-	defer mgr.Close(ctx)
+	defer func() {
+		_ = mgr.Close(ctx)
+	}()
 	cl, err := mgr.GetFromStore(ctx, store, namespace)
 	cl, err := mgr.GetFromStore(ctx, store, namespace)
 	if err != nil {
 	if err != nil {
 		cond := NewSecretStoreCondition(esapi.SecretStoreReady, v1.ConditionFalse, esapi.ReasonInvalidProviderConfig, errUnableCreateClient)
 		cond := NewSecretStoreCondition(esapi.SecretStoreReady, v1.ConditionFalse, esapi.ReasonInvalidProviderConfig, errUnableCreateClient)

+ 8 - 3
pkg/generator/acr/acr.go

@@ -22,6 +22,7 @@ import (
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
 	"os"
 	"os"
+	"path/filepath"
 	"strings"
 	"strings"
 
 
 	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
 	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
@@ -176,7 +177,9 @@ func fetchACRAccessToken(acrRefreshToken, _, registryURL, scope string) (string,
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	if res.StatusCode != http.StatusOK {
 	if res.StatusCode != http.StatusOK {
 		return "", fmt.Errorf("could not generate access token, unexpected status code: %d", res.StatusCode)
 		return "", fmt.Errorf("could not generate access token, unexpected status code: %d", res.StatusCode)
 	}
 	}
@@ -211,7 +214,9 @@ func fetchACRRefreshToken(aadAccessToken, tenantID, registryURL string) (string,
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	if res.StatusCode != http.StatusOK {
 	if res.StatusCode != http.StatusOK {
 		return "", fmt.Errorf("count not generate refresh token, unexpected status code %d, expected %d", res.StatusCode, http.StatusOK)
 		return "", fmt.Errorf("count not generate refresh token, unexpected status code %d, expected %d", res.StatusCode, http.StatusOK)
 	}
 	}
@@ -244,7 +249,7 @@ func accessTokenForWorkloadIdentity(ctx context.Context, crClient client.Client,
 		if clientID == "" || tenantID == "" || tokenFilePath == "" {
 		if clientID == "" || tenantID == "" || tokenFilePath == "" {
 			return "", errors.New("missing environment variables")
 			return "", errors.New("missing environment variables")
 		}
 		}
-		token, err := os.ReadFile(tokenFilePath)
+		token, err := os.ReadFile(filepath.Clean(tokenFilePath))
 		if err != nil {
 		if err != nil {
 			return "", fmt.Errorf("unable to read token file %s: %w", tokenFilePath, err)
 			return "", fmt.Errorf("unable to read token file %s: %w", tokenFilePath, err)
 		}
 		}

+ 3 - 1
pkg/generator/github/github.go

@@ -119,7 +119,9 @@ func (g *Generator) generate(
 	if err != nil {
 	if err != nil {
 		return nil, nil, fmt.Errorf("error performing request: %w", err)
 		return nil, nil, fmt.Errorf("error performing request: %w", err)
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 
 
 	// git access token
 	// git access token
 	var gat map[string]any
 	var gat map[string]any

+ 3 - 1
pkg/generator/quay/quay.go

@@ -154,7 +154,9 @@ func getQuayRobotToken(ctx context.Context, fedToken, robotAccount, url string,
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 
 
 	if resp.StatusCode != 200 {
 	if resp.StatusCode != 200 {
 		return "", fmt.Errorf("request failed do to unexpected status: %s", resp.Status)
 		return "", fmt.Errorf("request failed do to unexpected status: %s", resp.Status)

+ 33 - 11
pkg/provider/akeyless/akeyless_api.go

@@ -85,7 +85,9 @@ func (a *akeylessBase) GetToken(ctx context.Context, accessID, accType, accTypeP
 	if err != nil {
 	if err != nil {
 		return "", fmt.Errorf("authentication failed: %w", err)
 		return "", fmt.Errorf("authentication failed: %w", err)
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	token := authOut.GetToken()
 	token := authOut.GetToken()
 	return token, nil
 	return token, nil
 }
 }
@@ -145,7 +147,9 @@ func (a *akeylessBase) DescribeItem(ctx context.Context, itemName string) (*akey
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("can't describe item: %w", err)
 		return nil, fmt.Errorf("can't describe item: %w", err)
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 
 
 	return &gsvOut, nil
 	return &gsvOut, nil
 }
 }
@@ -166,7 +170,9 @@ func (a *akeylessBase) GetCertificate(ctx context.Context, certificateName strin
 	if err != nil {
 	if err != nil {
 		return "", fmt.Errorf("can't get certificate value: %w", err)
 		return "", fmt.Errorf("can't get certificate value: %w", err)
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 
 
 	out, err := json.Marshal(gcvOut)
 	out, err := json.Marshal(gcvOut)
 	if err != nil {
 	if err != nil {
@@ -192,7 +198,9 @@ func (a *akeylessBase) GetRotatedSecrets(ctx context.Context, secretName string,
 	if err != nil {
 	if err != nil {
 		return "", fmt.Errorf("can't get rotated secret value: %w", err)
 		return "", fmt.Errorf("can't get rotated secret value: %w", err)
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	valI, ok := gsvOut["value"]
 	valI, ok := gsvOut["value"]
 	var out []byte
 	var out []byte
 	if ok {
 	if ok {
@@ -231,7 +239,9 @@ func (a *akeylessBase) GetDynamicSecrets(ctx context.Context, secretName string)
 	if err != nil {
 	if err != nil {
 		return "", fmt.Errorf("can't get dynamic secret value: %w", err)
 		return "", fmt.Errorf("can't get dynamic secret value: %w", err)
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	out, err := json.Marshal(gsvOut)
 	out, err := json.Marshal(gsvOut)
 	if err != nil {
 	if err != nil {
 		return "", fmt.Errorf("can't marshal dynamic secret value: %w", err)
 		return "", fmt.Errorf("can't marshal dynamic secret value: %w", err)
@@ -255,7 +265,9 @@ func (a *akeylessBase) GetStaticSecret(ctx context.Context, secretName string, v
 	if err != nil {
 	if err != nil {
 		return "", fmt.Errorf("can't get secret value: %w", err)
 		return "", fmt.Errorf("can't get secret value: %w", err)
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	val, ok := gsvOut[secretName]
 	val, ok := gsvOut[secretName]
 	if !ok {
 	if !ok {
 		return "", fmt.Errorf("can't get secret: %v", secretName)
 		return "", fmt.Errorf("can't get secret: %v", secretName)
@@ -303,7 +315,9 @@ func (a *akeylessBase) ListSecrets(ctx context.Context, path, tag string) ([]str
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("error on get secrets list: %w", err)
 		return nil, fmt.Errorf("error on get secrets list: %w", err)
 	}
 	}
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	if lipOut.Items == nil {
 	if lipOut.Items == nil {
 		return nil, nil
 		return nil, nil
 	}
 	}
@@ -327,7 +341,9 @@ func (a *akeylessBase) CreateSecret(ctx context.Context, remoteKey, data string)
 		return err
 		return err
 	}
 	}
 	_, res, err := a.RestAPI.CreateSecret(ctx).Body(body).Execute()
 	_, res, err := a.RestAPI.CreateSecret(ctx).Body(body).Execute()
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	metrics.ObserveAPICall(constants.ProviderAKEYLESSSM, constants.CallAKEYLESSSMCreateSecret, err)
 	metrics.ObserveAPICall(constants.ProviderAKEYLESSSM, constants.CallAKEYLESSSMCreateSecret, err)
 	return err
 	return err
 }
 }
@@ -341,7 +357,9 @@ func (a *akeylessBase) UpdateSecret(ctx context.Context, remoteKey, data string)
 		return err
 		return err
 	}
 	}
 	_, res, err := a.RestAPI.UpdateSecretVal(ctx).Body(body).Execute()
 	_, res, err := a.RestAPI.UpdateSecretVal(ctx).Body(body).Execute()
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	metrics.ObserveAPICall(constants.ProviderAKEYLESSSM, constants.CallAKEYLESSSMUpdateSecretVal, err)
 	metrics.ObserveAPICall(constants.ProviderAKEYLESSSM, constants.CallAKEYLESSSMUpdateSecretVal, err)
 	return err
 	return err
 }
 }
@@ -354,7 +372,9 @@ func (a *akeylessBase) DeleteSecret(ctx context.Context, remoteKey string) error
 		return err
 		return err
 	}
 	}
 	_, res, err := a.RestAPI.DeleteItem(ctx).Body(body).Execute()
 	_, res, err := a.RestAPI.DeleteItem(ctx).Body(body).Execute()
-	defer res.Body.Close()
+	defer func() {
+		_ = res.Body.Close()
+	}()
 	metrics.ObserveAPICall(constants.ProviderAKEYLESSSM, constants.CallAKEYLESSSMDeleteItem, err)
 	metrics.ObserveAPICall(constants.ProviderAKEYLESSSM, constants.CallAKEYLESSSMDeleteItem, err)
 	return err
 	return err
 }
 }
@@ -455,7 +475,9 @@ func readK8SServiceAccountJWT() (string, error) {
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
 	}
 	}
-	defer data.Close()
+	defer func() {
+		_ = data.Close()
+	}()
 
 
 	contentBytes, err := io.ReadAll(data)
 	contentBytes, err := io.ReadAll(data)
 	if err != nil {
 	if err != nil {

+ 3 - 1
pkg/provider/akeyless/utils.go

@@ -104,7 +104,9 @@ func sendReq(url string) string {
 	if err != nil {
 	if err != nil {
 		return ""
 		return ""
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 
 
 	body, _ := io.ReadAll(resp.Body)
 	body, _ := io.ReadAll(resp.Body)
 	return string(body)
 	return string(body)

+ 3 - 1
pkg/provider/alibaba/client.go

@@ -147,7 +147,9 @@ func (s *secretsManagerClient) doAPICall(ctx context.Context,
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("error invoking http request: %w", err)
 		return nil, fmt.Errorf("error invoking http request: %w", err)
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 
 
 	return s.parseResponse(resp)
 	return s.parseResponse(resp)
 }
 }

+ 2 - 1
pkg/provider/azure/keyvault/keyvault.go

@@ -24,6 +24,7 @@ import (
 	"fmt"
 	"fmt"
 	"os"
 	"os"
 	"path"
 	"path"
+	"path/filepath"
 	"regexp"
 	"regexp"
 	"strings"
 	"strings"
 	"time"
 	"time"
@@ -888,7 +889,7 @@ func (a *Azure) authorizerForWorkloadIdentity(ctx context.Context, tokenProvider
 		if clientID == "" || tenantID == "" || tokenFilePath == "" {
 		if clientID == "" || tenantID == "" || tokenFilePath == "" {
 			return nil, errors.New(errMissingWorkloadEnvVars)
 			return nil, errors.New(errMissingWorkloadEnvVars)
 		}
 		}
-		token, err := os.ReadFile(tokenFilePath)
+		token, err := os.ReadFile(filepath.Clean(tokenFilePath))
 		if err != nil {
 		if err != nil {
 			return nil, fmt.Errorf(errReadTokenFile, tokenFilePath, err)
 			return nil, fmt.Errorf(errReadTokenFile, tokenFilePath, err)
 		}
 		}

+ 3 - 1
pkg/provider/bitwarden/bitwarden_sdk.go

@@ -244,7 +244,9 @@ func (s *SdkClient) performHTTPRequestOperation(ctx context.Context, params para
 	if err != nil {
 	if err != nil {
 		return fmt.Errorf("failed to do request: %w", err)
 		return fmt.Errorf("failed to do request: %w", err)
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 
 
 	if resp.StatusCode != http.StatusOK {
 	if resp.StatusCode != http.StatusOK {
 		content, _ := io.ReadAll(resp.Body)
 		content, _ := io.ReadAll(resp.Body)

+ 3 - 1
pkg/provider/cloudru/secretmanager/endpoints.go

@@ -46,7 +46,9 @@ func GetEndpoints(url string) (*EndpointsResponse, error) {
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("get cloud.ru endpoints: %w", err)
 		return nil, fmt.Errorf("get cloud.ru endpoints: %w", err)
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 
 
 	if resp.StatusCode != http.StatusOK {
 	if resp.StatusCode != http.StatusOK {
 		return nil, fmt.Errorf("get cloud.ru endpoints: unexpected status code %d", resp.StatusCode)
 		return nil, fmt.Errorf("get cloud.ru endpoints: unexpected status code %d", resp.StatusCode)

+ 3 - 1
pkg/provider/doppler/client/client.go

@@ -310,7 +310,9 @@ func (c *DopplerClient) performRequest(path, method string, headers headers, par
 	if err != nil {
 	if err != nil {
 		return nil, &APIError{Err: err, Message: "unable to load response"}
 		return nil, &APIError{Err: err, Message: "unable to load response"}
 	}
 	}
-	defer r.Body.Close()
+	defer func() {
+		_ = r.Body.Close()
+	}()
 
 
 	bodyResponse, err := io.ReadAll(r.Body)
 	bodyResponse, err := io.ReadAll(r.Body)
 	if err != nil {
 	if err != nil {

+ 3 - 1
pkg/provider/gcp/secretmanager/auth.go

@@ -36,7 +36,9 @@ func NewTokenSource(ctx context.Context, auth esv1.GCPSMAuth, projectID, storeKi
 	if err != nil {
 	if err != nil {
 		return nil, errors.New("unable to initialize workload identity")
 		return nil, errors.New("unable to initialize workload identity")
 	}
 	}
-	defer wi.Close()
+	defer func() {
+		_ = wi.Close()
+	}()
 	isClusterKind := storeKind == esv1.ClusterSecretStoreKind
 	isClusterKind := storeKind == esv1.ClusterSecretStoreKind
 	ts, err = wi.TokenSource(ctx, auth, isClusterKind, kube, namespace)
 	ts, err = wi.TokenSource(ctx, auth, isClusterKind, kube, namespace)
 	if ts != nil || err != nil {
 	if ts != nil || err != nil {

+ 3 - 1
pkg/provider/gcp/secretmanager/workload_identity.go

@@ -302,7 +302,9 @@ func (g *gcpIDBindTokenGenerator) Generate(ctx context.Context, client *http.Cli
 		return nil, fmt.Errorf("could not get idbindtoken token, status: %v", resp.StatusCode)
 		return nil, fmt.Errorf("could not get idbindtoken token, status: %v", resp.StatusCode)
 	}
 	}
 
 
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 	respBody, err := io.ReadAll(resp.Body)
 	respBody, err := io.ReadAll(resp.Body)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err

+ 3 - 1
pkg/provider/infisical/api/api.go

@@ -208,7 +208,9 @@ func (a *InfisicalClient) do(endpoint, method string, params map[string]string,
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 
 
 	if err := checkError(resp); err != nil {
 	if err := checkError(resp); err != nil {
 		return err
 		return err

+ 3 - 1
pkg/provider/onboardbase/client/client.go

@@ -388,7 +388,9 @@ func (c *OnboardbaseClient) performRequest(config *performRequestConfig) (*apiRe
 	if err != nil {
 	if err != nil {
 		return nil, &APIError{Err: err, Message: "unable to load response"}
 		return nil, &APIError{Err: err, Message: "unable to load response"}
 	}
 	}
-	defer r.Body.Close()
+	defer func() {
+		_ = r.Body.Close()
+	}()
 
 
 	bodyResponse, err := io.ReadAll(r.Body)
 	bodyResponse, err := io.ReadAll(r.Body)
 	if err != nil {
 	if err != nil {

+ 2 - 3
pkg/provider/passworddepot/passworddepot_api.go

@@ -11,6 +11,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 See the License for the specific language governing permissions and
 limitations under the License.
 limitations under the License.
 */
 */
+
 package passworddepot
 package passworddepot
 
 
 import (
 import (
@@ -229,9 +230,7 @@ func (api *API) ListSecrets(dbFingerprint, folder string) (DatabaseEntries, erro
 func ReadAndUnmarshal(resp *http.Response, target any) error {
 func ReadAndUnmarshal(resp *http.Response, target any) error {
 	var buf bytes.Buffer
 	var buf bytes.Buffer
 	defer func() {
 	defer func() {
-		if resp.Body != nil {
-			resp.Body.Close()
-		}
+		_ = resp.Body.Close()
 	}()
 	}()
 	if resp.StatusCode < 200 || resp.StatusCode > 299 {
 	if resp.StatusCode < 200 || resp.StatusCode > 299 {
 		return fmt.Errorf("failed to authenticate with the given credentials: %d %s", resp.StatusCode, buf.String())
 		return fmt.Errorf("failed to authenticate with the given credentials: %d %s", resp.StatusCode, buf.String())

+ 3 - 1
pkg/provider/senhasegura/auth/iso.go

@@ -132,7 +132,9 @@ func (s *SenhaseguraIsoSession) GetIsoToken(clientID, clientSecret, systemURL st
 	if err != nil {
 	if err != nil {
 		return "", errCannotDoRequest
 		return "", errCannotDoRequest
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 
 
 	if resp.StatusCode != 200 {
 	if resp.StatusCode != 200 {
 		return "", errInvalidHTTPCode
 		return "", errInvalidHTTPCode

+ 3 - 1
pkg/provider/senhasegura/dsm/dsm.go

@@ -199,7 +199,9 @@ func (dsm *DSM) FetchSecrets() (respObj IsoDappResponse, err error) {
 	if err != nil {
 	if err != nil {
 		return respObj, errCannotDoRequest
 		return respObj, errCannotDoRequest
 	}
 	}
-	defer resp.Body.Close()
+	defer func() {
+		_ = resp.Body.Close()
+	}()
 
 
 	if resp.StatusCode != 200 {
 	if resp.StatusCode != 200 {
 		return respObj, errInvalidHTTPCode
 		return respObj, errInvalidHTTPCode

+ 5 - 4
pkg/provider/vault/auth_iam.go

@@ -18,6 +18,7 @@ import (
 	"context"
 	"context"
 	"fmt"
 	"fmt"
 	"os"
 	"os"
+	"path/filepath"
 
 
 	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/aws/credentials"
 	"github.com/aws/aws-sdk-go/aws/credentials"
@@ -97,7 +98,7 @@ func (c *client) requestTokenWithIamAuth(ctx context.Context, iamAuth *esv1.Vaul
 		}
 		}
 
 
 		// everything looks good so far, let's fetch the jwt token from AWS_WEB_IDENTITY_TOKEN_FILE
 		// everything looks good so far, let's fetch the jwt token from AWS_WEB_IDENTITY_TOKEN_FILE
-		jwtByte, err := os.ReadFile(tokenFile)
+		jwtByte, err := os.ReadFile(filepath.Clean(tokenFile))
 		if err != nil {
 		if err != nil {
 			return fmt.Errorf(errIrsaTokenFileNotReadable, tokenFile, err)
 			return fmt.Errorf(errIrsaTokenFileNotReadable, tokenFile, err)
 		}
 		}
@@ -157,9 +158,9 @@ func (c *client) requestTokenWithIamAuth(ctx context.Context, iamAuth *esv1.Vaul
 		return err
 		return err
 	}
 	}
 	// Set environment variables. These would be fetched by Login
 	// Set environment variables. These would be fetched by Login
-	os.Setenv("AWS_ACCESS_KEY_ID", getCreds.AccessKeyID)
-	os.Setenv("AWS_SECRET_ACCESS_KEY", getCreds.SecretAccessKey)
-	os.Setenv("AWS_SESSION_TOKEN", getCreds.SessionToken)
+	_ = os.Setenv("AWS_ACCESS_KEY_ID", getCreds.AccessKeyID)
+	_ = os.Setenv("AWS_SECRET_ACCESS_KEY", getCreds.SecretAccessKey)
+	_ = os.Setenv("AWS_SESSION_TOKEN", getCreds.SessionToken)
 
 
 	var awsAuthClient *authaws.AWSAuth
 	var awsAuthClient *authaws.AWSAuth
 
 

+ 3 - 1
pkg/utils/utils.go

@@ -450,7 +450,9 @@ func NetworkValidate(endpoint string, timeout time.Duration) error {
 	if err != nil {
 	if err != nil {
 		return fmt.Errorf("error accessing external store: %w", err)
 		return fmt.Errorf("error accessing external store: %w", err)
 	}
 	}
-	defer conn.Close()
+	defer func() {
+		_ = conn.Close()
+	}()
 	return nil
 	return nil
 }
 }