Skip to content

Commit

Permalink
🧹 Bumping GolangciLint version and fixing lint issues (external-secre…
Browse files Browse the repository at this point in the history
…ts#2304)

Signed-off-by: Gustavo Carvalho <[email protected]>
  • Loading branch information
gusfcarvalho authored May 12, 2023
1 parent c886568 commit 1cf7c3a
Show file tree
Hide file tree
Showing 52 changed files with 183 additions and 195 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
# Common versions
GOLANGCI_VERSION: 'v1.49.0'
GOLANGCI_VERSION: 'v1.52.2'
KUBERNETES_VERSION: '1.24.x'

# Sonar
Expand Down
6 changes: 3 additions & 3 deletions apis/externalsecrets/v1beta1/externalsecret_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (

type ExternalSecretValidator struct{}

func (esv *ExternalSecretValidator) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (esv *ExternalSecretValidator) ValidateCreate(_ context.Context, obj runtime.Object) error {
return validateExternalSecret(obj)
}

func (esv *ExternalSecretValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (esv *ExternalSecretValidator) ValidateUpdate(_ context.Context, _, newObj runtime.Object) error {
return validateExternalSecret(newObj)
}

func (esv *ExternalSecretValidator) ValidateDelete(ctx context.Context, obj runtime.Object) error {
func (esv *ExternalSecretValidator) ValidateDelete(_ context.Context, _ runtime.Object) error {
return nil
}

Expand Down
16 changes: 8 additions & 8 deletions apis/externalsecrets/v1beta1/provider_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,45 @@ func (p *PP) Capabilities() SecretStoreCapabilities {
}

// New constructs a SecretsManager Provider.
func (p *PP) NewClient(ctx context.Context, store GenericStore, kube client.Client, namespace string) (SecretsClient, error) {
func (p *PP) NewClient(_ context.Context, _ GenericStore, _ client.Client, _ string) (SecretsClient, error) {
return p, nil
}

// PushSecret writes a single secret into a provider.
func (p *PP) PushSecret(ctx context.Context, value []byte, remoteRef PushRemoteRef) error {
func (p *PP) PushSecret(_ context.Context, _ []byte, _ PushRemoteRef) error {
return nil
}

// DeleteSecret deletes a single secret from a provider.
func (p *PP) DeleteSecret(ctx context.Context, remoteRef PushRemoteRef) error {
func (p *PP) DeleteSecret(_ context.Context, _ PushRemoteRef) error {
return nil
}

// GetSecret returns a single secret from the provider.
func (p *PP) GetSecret(ctx context.Context, ref ExternalSecretDataRemoteRef) ([]byte, error) {
func (p *PP) GetSecret(_ context.Context, _ ExternalSecretDataRemoteRef) ([]byte, error) {
return []byte("NOOP"), nil
}

// GetSecretMap returns multiple k/v pairs from the provider.
func (p *PP) GetSecretMap(ctx context.Context, ref ExternalSecretDataRemoteRef) (map[string][]byte, error) {
func (p *PP) GetSecretMap(_ context.Context, _ ExternalSecretDataRemoteRef) (map[string][]byte, error) {
return map[string][]byte{}, nil
}

// Empty GetAllSecrets.
func (p *PP) GetAllSecrets(ctx context.Context, ref ExternalSecretFind) (map[string][]byte, error) {
func (p *PP) GetAllSecrets(_ context.Context, _ ExternalSecretFind) (map[string][]byte, error) {
// TO be implemented
return map[string][]byte{}, nil
}

func (p *PP) Close(ctx context.Context) error {
func (p *PP) Close(_ context.Context) error {
return nil
}

func (p *PP) Validate() (ValidationResult, error) {
return ValidationResultReady, nil
}

func (p *PP) ValidateStore(store GenericStore) error {
func (p *PP) ValidateStore(_ GenericStore) error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions apis/externalsecrets/v1beta1/secretstore_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
type GenericStoreValidator struct{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *GenericStoreValidator) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (r *GenericStoreValidator) ValidateCreate(_ context.Context, obj runtime.Object) error {
st, ok := obj.(GenericStore)
if !ok {
return fmt.Errorf(errInvalidStore)
Expand All @@ -40,7 +40,7 @@ func (r *GenericStoreValidator) ValidateCreate(ctx context.Context, obj runtime.
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *GenericStoreValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (r *GenericStoreValidator) ValidateUpdate(_ context.Context, _, newObj runtime.Object) error {
st, ok := newObj.(GenericStore)
if !ok {
return fmt.Errorf(errInvalidStore)
Expand All @@ -49,7 +49,7 @@ func (r *GenericStoreValidator) ValidateUpdate(ctx context.Context, oldObj, newO
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *GenericStoreValidator) ValidateDelete(ctx context.Context, obj runtime.Object) error {
func (r *GenericStoreValidator) ValidateDelete(_ context.Context, _ runtime.Object) error {
return nil
}

Expand Down
10 changes: 2 additions & 8 deletions pkg/controllers/crds/crds_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ func (r *Reconciler) updateCRD(ctx context.Context, req ctrl.Request) error {
return err
}
}
if err := r.Update(ctx, &updatedResource); err != nil {
return err
}
return nil
return r.Update(ctx, &updatedResource)
}

func injectService(crd *apiext.CustomResourceDefinition, svc types.NamespacedName) error {
Expand Down Expand Up @@ -344,10 +341,7 @@ func (r *Reconciler) refreshCerts(refreshCA bool, secret *corev1.Secret) error {
if err != nil {
return err
}
if err := r.writeSecret(cert, key, caArtifacts, secret); err != nil {
return err
}
return nil
return r.writeSecret(cert, key, caArtifacts, secret)
}

func buildArtifactsFromSecret(secret *corev1.Secret) (*KeyPairArtifacts, error) {
Expand Down
10 changes: 2 additions & 8 deletions pkg/controllers/externalsecret/externalsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,7 @@ func createOrUpdate(ctx context.Context, c client.Client, obj client.Object, f f
return err
}
// Setting Field Owner even for CreationPolicy==Create
if err := c.Create(ctx, obj, client.FieldOwner(fqdn)); err != nil {
return err
}
return nil
return c.Create(ctx, obj, client.FieldOwner(fqdn))
}

existing := obj.DeepCopyObject()
Expand All @@ -346,10 +343,7 @@ func createOrUpdate(ctx context.Context, c client.Client, obj client.Object, f f
return nil
}

if err := c.Update(ctx, obj, client.FieldOwner(fqdn)); err != nil {
return err
}
return nil
return c.Update(ctx, obj, client.FieldOwner(fqdn))
}

func patchSecret(ctx context.Context, c client.Client, scheme *runtime.Scheme, secret *v1.Secret, mutationFunc func() error, fieldOwner string) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (p *Parser) MergeSecret(ctx context.Context, namespace string, tpl esv1beta
return nil
}

func (p *Parser) MergeLiteral(ctx context.Context, tpl esv1beta1.TemplateFrom) error {
func (p *Parser) MergeLiteral(_ context.Context, tpl esv1beta1.TemplateFrom) error {
if tpl.Literal == nil {
return nil
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/controllers/secretstore/client_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (f *WrapProvider) Capabilities() esv1beta1.SecretStoreCapabilities {
}

// ValidateStore checks if the provided store is valid.
func (f *WrapProvider) ValidateStore(store esv1beta1.GenericStore) error {
func (f *WrapProvider) ValidateStore(_ esv1beta1.GenericStore) error {
return nil
}

Expand All @@ -340,15 +340,15 @@ type MockFakeClient struct {
closeCalled bool
}

func (c *MockFakeClient) PushSecret(ctx context.Context, value []byte, remoteRef esv1beta1.PushRemoteRef) error {
func (c *MockFakeClient) PushSecret(_ context.Context, _ []byte, _ esv1beta1.PushRemoteRef) error {
return nil
}

func (c *MockFakeClient) DeleteSecret(ctx context.Context, remoteRef esv1beta1.PushRemoteRef) error {
func (c *MockFakeClient) DeleteSecret(_ context.Context, _ esv1beta1.PushRemoteRef) error {
return nil
}

func (c *MockFakeClient) GetSecret(ctx context.Context, ref esv1beta1.ExternalSecretDataRemoteRef) ([]byte, error) {
func (c *MockFakeClient) GetSecret(_ context.Context, _ esv1beta1.ExternalSecretDataRemoteRef) ([]byte, error) {
return nil, nil
}

Expand All @@ -357,16 +357,16 @@ func (c *MockFakeClient) Validate() (esv1beta1.ValidationResult, error) {
}

// GetSecretMap returns multiple k/v pairs from the provider.
func (c *MockFakeClient) GetSecretMap(ctx context.Context, ref esv1beta1.ExternalSecretDataRemoteRef) (map[string][]byte, error) {
func (c *MockFakeClient) GetSecretMap(_ context.Context, _ esv1beta1.ExternalSecretDataRemoteRef) (map[string][]byte, error) {
return nil, nil
}

// GetAllSecrets returns multiple k/v pairs from the provider.
func (c *MockFakeClient) GetAllSecrets(ctx context.Context, ref esv1beta1.ExternalSecretFind) (map[string][]byte, error) {
func (c *MockFakeClient) GetAllSecrets(_ context.Context, _ esv1beta1.ExternalSecretFind) (map[string][]byte, error) {
return nil, nil
}

func (c *MockFakeClient) Close(ctx context.Context) error {
func (c *MockFakeClient) Close(_ context.Context) error {
c.closeCalled = true
return nil
}
2 changes: 1 addition & 1 deletion pkg/generator/acr/acr.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (g *Generator) generate(

type accessTokenFetcher func(acrRefreshToken, tenantID, registryURL, scope string) (string, error)

func fetchACRAccessToken(acrRefreshToken, tenantID, registryURL, scope string) (string, error) {
func fetchACRAccessToken(acrRefreshToken, _, registryURL, scope string) (string, error) {
formData := url.Values{
"grant_type": {"refresh_token"},
"service": {registryURL},
Expand Down
2 changes: 1 addition & 1 deletion pkg/generator/acr/acr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ type FakeTokenGetter struct {
err error
}

func (f *FakeTokenGetter) GetToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
func (f *FakeTokenGetter) GetToken(_ context.Context, _ policy.TokenRequestOptions) (azcore.AccessToken, error) {
return f.token, f.err
}
2 changes: 1 addition & 1 deletion pkg/generator/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
errGetToken = "unable to get authorization token: %w"
)

func (g *Generator) Generate(ctx context.Context, jsonSpec *apiextensions.JSON, kube client.Client, namespace string) (map[string][]byte, error) {
func (g *Generator) Generate(_ context.Context, jsonSpec *apiextensions.JSON, _ client.Client, _ string) (map[string][]byte, error) {
if jsonSpec == nil {
return nil, fmt.Errorf(errNoSpec)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/generator/password/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type generateFunc func(
allowRepeat bool,
) (string, error)

func (g *Generator) Generate(ctx context.Context, jsonSpec *apiextensions.JSON, kube client.Client, namespace string) (map[string][]byte, error) {
func (g *Generator) Generate(_ context.Context, jsonSpec *apiextensions.JSON, _ client.Client, _ string) (map[string][]byte, error) {
return g.generate(
jsonSpec,
generateSafePassword,
Expand Down
6 changes: 3 additions & 3 deletions pkg/provider/akeyless/akeyless.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func newClient(_ context.Context, store esv1beta1.GenericStore, kube client.Clie
return &Akeyless{Client: akl, url: akeylessGwAPIURL}, nil
}

func (a *Akeyless) Close(ctx context.Context) error {
func (a *Akeyless) Close(_ context.Context) error {
return nil
}

Expand All @@ -227,11 +227,11 @@ func (a *Akeyless) Validate() (esv1beta1.ValidationResult, error) {
return esv1beta1.ValidationResultReady, nil
}

func (a *Akeyless) PushSecret(ctx context.Context, value []byte, remoteRef esv1beta1.PushRemoteRef) error {
func (a *Akeyless) PushSecret(_ context.Context, _ []byte, _ esv1beta1.PushRemoteRef) error {
return fmt.Errorf("not implemented")
}

func (a *Akeyless) DeleteSecret(ctx context.Context, remoteRef esv1beta1.PushRemoteRef) error {
func (a *Akeyless) DeleteSecret(_ context.Context, _ esv1beta1.PushRemoteRef) error {
return fmt.Errorf("not implemented")
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/provider/akeyless/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ type AkeylessMockClient struct {
getSecret func(secretName, token string, version int32) (string, error)
}

func (mc *AkeylessMockClient) TokenFromSecretRef(ctx context.Context) (string, error) {
func (mc *AkeylessMockClient) TokenFromSecretRef(_ context.Context) (string, error) {
return "newToken", nil
}

func (mc *AkeylessMockClient) GetSecretByType(_ context.Context, secretName, token string, version int32) (string, error) {
return mc.getSecret(secretName, token, version)
}

func (mc *AkeylessMockClient) ListSecrets(ctx context.Context, path, tag, token string) ([]string, error) {
func (mc *AkeylessMockClient) ListSecrets(_ context.Context, _, _, _ string) ([]string, error) {
return nil, nil
}

func (mc *AkeylessMockClient) WithValue(in *Input, out *Output) {
func (mc *AkeylessMockClient) WithValue(_ *Input, out *Output) {
if mc != nil {
mc.getSecret = func(secretName, token string, version int32) (string, error) {
return out.Value, out.Err
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/alibaba/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (mc *AlibabaMockClient) GetSecretValue(context.Context, *kmssdk.GetSecretVa
return mc.getSecretValue(&kmssdk.GetSecretValueRequest{})
}

func (mc *AlibabaMockClient) WithValue(in *kmssdk.GetSecretValueRequest, val *kmssdk.GetSecretValueResponseBody, err error) {
func (mc *AlibabaMockClient) WithValue(_ *kmssdk.GetSecretValueRequest, val *kmssdk.GetSecretValueResponseBody, err error) {
if mc != nil {
mc.getSecretValue = func(paramIn *kmssdk.GetSecretValueRequest) (*kmssdk.GetSecretValueResponseBody, error) {
return val, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/provider/alibaba/kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ type SMInterface interface {
Endpoint() string
}

func (kms *KeyManagementService) PushSecret(ctx context.Context, value []byte, remoteRef esv1beta1.PushRemoteRef) error {
func (kms *KeyManagementService) PushSecret(_ context.Context, _ []byte, _ esv1beta1.PushRemoteRef) error {
return fmt.Errorf("not implemented")
}

func (kms *KeyManagementService) DeleteSecret(ctx context.Context, remoteRef esv1beta1.PushRemoteRef) error {
func (kms *KeyManagementService) DeleteSecret(_ context.Context, _ esv1beta1.PushRemoteRef) error {
return fmt.Errorf("not implemented")
}

// Empty GetAllSecrets.
func (kms *KeyManagementService) GetAllSecrets(ctx context.Context, ref esv1beta1.ExternalSecretFind) (map[string][]byte, error) {
func (kms *KeyManagementService) GetAllSecrets(_ context.Context, _ esv1beta1.ExternalSecretFind) (map[string][]byte, error) {
// TO be implemented
return nil, fmt.Errorf("GetAllSecrets not implemented")
}
Expand Down Expand Up @@ -278,7 +278,7 @@ func newAccessKeyAuth(ctx context.Context, kube kclient.Client, store esv1beta1.
return credential.NewCredential(credentialConfig)
}

func (kms *KeyManagementService) Close(ctx context.Context) error {
func (kms *KeyManagementService) Close(_ context.Context) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/aws/auth/fake/assumeroler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (f *AssumeRoler) AssumeRole(input *sts.AssumeRoleInput) (*sts.AssumeRoleOut
return f.AssumeRoleFunc(input)
}

func (f *AssumeRoler) AssumeRoleWithContext(ctx aws.Context, input *sts.AssumeRoleInput, opts ...request.Option) (*sts.AssumeRoleOutput, error) {
func (f *AssumeRoler) AssumeRoleWithContext(_ aws.Context, input *sts.AssumeRoleInput, _ ...request.Option) (*sts.AssumeRoleOutput, error) {
return f.AssumeRoleFunc(input)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/aws/parameterstore/parameterstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (pm *ParameterStore) GetSecretMap(ctx context.Context, ref esv1beta1.Extern
return secretData, nil
}

func (pm *ParameterStore) Close(ctx context.Context) error {
func (pm *ParameterStore) Close(_ context.Context) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/aws/secretsmanager/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (sm Client) DeleteSecretWithContext(ctx aws.Context, input *awssm.DeleteSec
}

func NewDeleteSecretWithContextFn(output *awssm.DeleteSecretOutput, err error) DeleteSecretWithContextFn {
return func(ctx aws.Context, input *awssm.DeleteSecretInput, opts ...request.Option) (output *awssm.DeleteSecretOutput, err error) {
return func(ctx aws.Context, input *awssm.DeleteSecretInput, opts ...request.Option) (*awssm.DeleteSecretOutput, error) {
return output, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/aws/secretsmanager/secretsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (sm *SecretsManager) GetSecretMap(ctx context.Context, ref esv1beta1.Extern
return secretData, nil
}

func (sm *SecretsManager) Close(ctx context.Context) error {
func (sm *SecretsManager) Close(_ context.Context) error {
return nil
}

Expand Down
Loading

0 comments on commit 1cf7c3a

Please sign in to comment.