diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 004971d..1541b6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,5 +30,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0 with: - version: v1.61.0 + version: v1.63.4 args: --timeout=5m diff --git a/.golangci.yml b/.golangci.yml index 9c30141..32f3b33 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,7 +10,7 @@ run: # Timeout for analysis, e.g. 30s, 5m. # Default: 1m - timeout: 3m + timeout: 5m # This file contains only configs which differ from defaults. # All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml diff --git a/Makefile b/Makefile index 321f6c7..4a9a71b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -GOLANGCI_LINT_VERSION := v1.61.0 +GOLANGCI_LINT_VERSION := v1.63.4 CONTROLLER_TOOLS_VERSION := v0.16.5 ENVTEST_VERSION := release-0.19 ENVTEST_K8S_VERSION := 1.31.0 @@ -22,7 +22,10 @@ fmt: .PHOHY: lint lint: - $(GOLANGCI_LINT) run + $(GOLANGCI_LINT) run --verbose + +lint-clean: + $(GOLANGCI_LINT) cache clean .PHOHY: vet vet: diff --git a/internal/handlers/create_catalog.go b/internal/handlers/create_catalog.go index aaf9850..d93bb5a 100644 --- a/internal/handlers/create_catalog.go +++ b/internal/handlers/create_catalog.go @@ -7,6 +7,7 @@ import ( "crypto/x509" "encoding/base64" "encoding/hex" + "errors" "fmt" "log/slog" "net/http" @@ -69,7 +70,10 @@ func (h *CreateCatalogHandler) Handle(message messaging.Message) error { h.logger.Debug("Registry found", "registry", registry) - transport := h.transportFromRegistry(registry) + transport, err := h.transportFromRegistry(registry) + if err != nil { + return fmt.Errorf("cannot create transport for registry %s: %w", registry.Name, err) + } registryClient := h.registryClientFactory(transport) repositories, err := h.discoverRepositories(ctx, registryClient, registry) @@ -235,8 +239,14 @@ func (h *CreateCatalogHandler) refToPlatforms(registryClient registryclient.Clie } // transportFromRegistry creates a new http.RoundTripper from the options specified in the Registry spec. -func (h *CreateCatalogHandler) transportFromRegistry(registry *v1alpha1.Registry) http.RoundTripper { - transport := remote.DefaultTransport.(*http.Transport).Clone() +func (h *CreateCatalogHandler) transportFromRegistry(registry *v1alpha1.Registry) (http.RoundTripper, error) { + transport, ok := remote.DefaultTransport.(*http.Transport) + if !ok { + // should not happen + return nil, errors.New("remote.DefaultTransport is not an *http.Transport") + } + transport = transport.Clone() + transport.TLSClientConfig = &tls.Config{ InsecureSkipVerify: registry.Spec.Insecure, //nolint:gosec // this a user provided option } @@ -258,7 +268,7 @@ func (h *CreateCatalogHandler) transportFromRegistry(registry *v1alpha1.Registry } } - return transport + return transport, nil } // deleteObsoleteImages deletes images that are not present in the discovered registry anymore. diff --git a/internal/handlers/scan_sbom.go b/internal/handlers/scan_sbom.go index 1ceb165..4737c5a 100644 --- a/internal/handlers/scan_sbom.go +++ b/internal/handlers/scan_sbom.go @@ -36,6 +36,7 @@ func NewScanSBOMHandler(k8sClient client.Client, scheme *runtime.Scheme, workDir } } +//nolint:funlen //right now this is 2 lines too long because of error handling, if it grows more we should refactor func (h *ScanSBOMHandler) Handle(message messaging.Message) error { scanSBOMMessage, ok := message.(*messaging.ScanSBOM) if !ok { diff --git a/internal/storage/store_test.go b/internal/storage/store_test.go index cd9734f..7d41c90 100644 --- a/internal/storage/store_test.go +++ b/internal/storage/store_test.go @@ -335,7 +335,11 @@ func (suite *storeTestSuite) TestGuaranteedUpdate() { key: keyPrefix + "/default/test1", preconditions: &storage.Preconditions{}, tryUpdate: func(input runtime.Object, _ storage.ResponseMeta) (runtime.Object, *uint64, error) { - input.(*v1alpha1.SBOM).Spec.SPDX.Raw = []byte(`{"foo":"bar"}`) + sbom, ok := input.(*v1alpha1.SBOM) + if !ok { + return nil, ptr.To(uint64(0)), errors.New("input is not of type *v1alpha1.SBOM") + } + sbom.Spec.SPDX.Raw = []byte(`{"foo":"bar"}`) return input, ptr.To(uint64(0)), nil }, sbom: &v1alpha1.SBOM{