diff --git a/.golangci.yml b/.golangci.yml index 445e30b0..ae066ffd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,45 +1,25 @@ -linters-settings: - lll: - line-length: 120 - gci: - sections: - - standard - - default - - prefix(github.com/cloudnative-pg/barman-cloud) - - blank - - dot - nlreturn: - # Size of the block (including return statement that is still "OK") - # so no return split required. - # Default: 1 - block-size: 3 - +version: "2" linters: - disable-all: true + default: none enable: - asciicheck - bodyclose + - copyloopvar - dogsled - dupl - durationcheck - errcheck - - copyloopvar - - gci + - ginkgolinter - gocognit - goconst - gocritic - gocyclo - - gofmt - - gofumpt - goheader - - goimports - gomoddirectives - gomodguard - goprintffuncname - gosec - - gosimple - govet - - ginkgolinter - importas - ineffassign - lll @@ -53,44 +33,52 @@ linters: - rowserrcheck - sqlclosecheck - staticcheck - - stylecheck - thelper - tparallel - - typecheck - unconvert - unparam - unused - wastedassign - whitespace - # TODO: Reverse the configuration to enable all linters and disable some - #enable-all: true - #disable: - # - depguard - # - execinquery - # - exhaustruct - # - exportloopref - # - funlen - # - gomnd - # - paralleltest - # - testpackage - # - wsl - -issues: - exclude-rules: - # Allow dot imports for ginkgo and gomega - - source: ginkgo|gomega - linters: - - revive - text: "should not use dot imports" - # Exclude some linters from running on tests files. - - path: _test\.go - linters: - - goconst - # Exclude lll issues for lines with long annotations - - linters: - - lll - source: "//\\s*\\+" - exclude-use-default: false - -run: - timeout: 5m + settings: + lll: + line-length: 120 + nlreturn: + block-size: 3 + exclusions: + generated: lax + rules: + - linters: + - revive + text: should not use dot imports + source: ginkgo|gomega + - linters: + - goconst + path: _test\.go + - linters: + - lll + source: //\s*\+ + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + settings: + gci: + sections: + - standard + - default + - prefix(github.com/cloudnative-pg/barman-cloud) + - blank + - dot + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Taskfile.yml b/Taskfile.yml index 916a5d2f..c62359ac 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -34,7 +34,7 @@ tasks: # renovate: datasource=git-refs depName=golangci-lint lookupName=https://github.com/sagikazarmark/daggerverse currentValue=main DAGGER_GOLANGCI_LINT_SHA: 21f771e7e26b6e4779af3a11fa290e689a8e0239 # renovate: datasource=docker depName=golangci/golangci-lint versioning=semver - GOLANGCI_LINT_VERSION: v1.64.8 + GOLANGCI_LINT_VERSION: v2.0.2 cmds: - > GITHUB_REF= dagger -s call -m github.com/sagikazarmark/daggerverse/golangci-lint@${DAGGER_GOLANGCI_LINT_SHA} diff --git a/pkg/api/webhooks/config.go b/pkg/api/webhooks/config.go index 6692514e..0a70684c 100644 --- a/pkg/api/webhooks/config.go +++ b/pkg/api/webhooks/config.go @@ -35,21 +35,21 @@ func ValidateBackupConfiguration( } credentialsCount := 0 - if barmanObjectStore.BarmanCredentials.Azure != nil { + if barmanObjectStore.Azure != nil { credentialsCount++ - allErrors = barmanObjectStore.BarmanCredentials.Azure.ValidateAzureCredentials( + allErrors = barmanObjectStore.Azure.ValidateAzureCredentials( path.Child("azureCredentials"), ) } - if barmanObjectStore.BarmanCredentials.AWS != nil { + if barmanObjectStore.AWS != nil { credentialsCount++ - allErrors = barmanObjectStore.BarmanCredentials.AWS.ValidateAwsCredentials( + allErrors = barmanObjectStore.AWS.ValidateAwsCredentials( path.Child("awsCredentials"), ) } - if barmanObjectStore.BarmanCredentials.Google != nil { + if barmanObjectStore.Google != nil { credentialsCount++ - allErrors = barmanObjectStore.BarmanCredentials.Google.ValidateGCSCredentials( + allErrors = barmanObjectStore.Google.ValidateGCSCredentials( field.NewPath("spec", "backupConfiguration", "googleCredentials")) } if credentialsCount == 0 { diff --git a/pkg/credentials/env.go b/pkg/credentials/env.go index f92a5cfc..ffdee8f8 100644 --- a/pkg/credentials/env.go +++ b/pkg/credentials/env.go @@ -93,9 +93,9 @@ func EnvSetCloudCredentialsAndCertificates( env []string, certificatesLocation string, ) ([]string, error) { - if configuration.EndpointCA != nil && configuration.BarmanCredentials.AWS != nil { + if configuration.EndpointCA != nil && configuration.AWS != nil { env = append(env, fmt.Sprintf("AWS_CA_BUNDLE=%s", certificatesLocation)) - } else if configuration.EndpointCA != nil && configuration.BarmanCredentials.Azure != nil { + } else if configuration.EndpointCA != nil && configuration.Azure != nil { env = append(env, fmt.Sprintf("REQUESTS_CA_BUNDLE=%s", certificatesLocation)) } return envSetCloudCredentials(ctx, c, namespace, configuration, env) @@ -110,12 +110,12 @@ func envSetCloudCredentials( configuration *barmanApi.BarmanObjectStoreConfiguration, env []string, ) (envs []string, err error) { - if configuration.BarmanCredentials.AWS != nil { - return envSetAWSCredentials(ctx, c, namespace, configuration.BarmanCredentials.AWS, env) + if configuration.AWS != nil { + return envSetAWSCredentials(ctx, c, namespace, configuration.AWS, env) } - if configuration.BarmanCredentials.Google != nil { - return envSetGoogleCredentials(ctx, c, namespace, configuration.BarmanCredentials.Google, env) + if configuration.Google != nil { + return envSetGoogleCredentials(ctx, c, namespace, configuration.Google, env) } return envSetAzureCredentials(ctx, c, namespace, configuration, env) @@ -210,20 +210,20 @@ func envSetAzureCredentials( env []string, ) ([]string, error) { // check if Azure credentials are defined - if configuration.BarmanCredentials.Azure == nil { + if configuration.Azure == nil { return nil, fmt.Errorf("missing Azure credentials") } - if configuration.BarmanCredentials.Azure.InheritFromAzureAD { + if configuration.Azure.InheritFromAzureAD { return env, nil } // Get storage account name - if configuration.BarmanCredentials.Azure.StorageAccount != nil { + if configuration.Azure.StorageAccount != nil { storageAccount, err := extractValueFromSecret( ctx, c, - configuration.BarmanCredentials.Azure.StorageAccount, + configuration.Azure.StorageAccount, namespace, ) if err != nil { @@ -233,11 +233,11 @@ func envSetAzureCredentials( } // Get the storage key - if configuration.BarmanCredentials.Azure.StorageKey != nil { + if configuration.Azure.StorageKey != nil { storageKey, err := extractValueFromSecret( ctx, c, - configuration.BarmanCredentials.Azure.StorageKey, + configuration.Azure.StorageKey, namespace, ) if err != nil { @@ -247,11 +247,11 @@ func envSetAzureCredentials( } // Get the SAS token - if configuration.BarmanCredentials.Azure.StorageSasToken != nil { + if configuration.Azure.StorageSasToken != nil { storageSasToken, err := extractValueFromSecret( ctx, c, - configuration.BarmanCredentials.Azure.StorageSasToken, + configuration.Azure.StorageSasToken, namespace, ) if err != nil { @@ -260,11 +260,11 @@ func envSetAzureCredentials( env = append(env, fmt.Sprintf("AZURE_STORAGE_SAS_TOKEN=%s", storageSasToken)) } - if configuration.BarmanCredentials.Azure.ConnectionString != nil { + if configuration.Azure.ConnectionString != nil { connString, err := extractValueFromSecret( ctx, c, - configuration.BarmanCredentials.Azure.ConnectionString, + configuration.Azure.ConnectionString, namespace, ) if err != nil {