Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 46 additions & 58 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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$
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/webhooks/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 16 additions & 16 deletions pkg/credentials/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down