فهرست منبع

fixed the formatting and go mod tidy

Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
Gergely Brautigam 4 ماه پیش
والد
کامیت
6cee66aa49

+ 1 - 1
providers/v1/ovh/client_delete_secret.go

@@ -24,7 +24,7 @@ import (
 	esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
 )
 
-// If deletionPolicy is set to Delete, the Secret Manager Secret
+// DeleteSecret if deletionPolicy is set to Delete, the Secret Manager Secret
 // created from the Push Secret will be automatically removed
 // when the associated Push Secret is deleted.
 func (cl *ovhClient) DeleteSecret(ctx context.Context, remoteRef esv1.PushSecretRemoteRef) error {

+ 7 - 13
providers/v1/ovh/client_get_all_secrets.go

@@ -21,6 +21,7 @@ import (
 	"errors"
 	"fmt"
 	"regexp"
+	"strings"
 
 	"github.com/google/uuid"
 	"github.com/ovh/okms-sdk-go/types"
@@ -83,25 +84,18 @@ func (cl *ovhClient) GetAllSecrets(ctx context.Context, ref esv1.ExternalSecretF
 // Retrieve secrets located under the specified path.
 // If the path is omitted, all secrets from the Secret Manager are returned.
 func getSecretsList(ctx context.Context, okmsClient OkmsClient, okmsID uuid.UUID, path *string) ([]string, error) {
-	var formatPath string
-
-	// if path ends with '/' (and is not "/"), returns an empty list.
-	// Secrets are not supposed to begin with '/'.
-	if path == nil || *path == "" {
-		formatPath = ""
-	} else if len(*path) > 1 &&
-		(*path)[len(*path)-1] == '/' &&
-		(*path)[len(*path)-2] == '/' {
+	if path != nil && strings.HasSuffix(*path, "//") {
 		return []string{}, nil
-	} else {
+	}
+
+	formatPath := ""
+	if path != nil && *path != "" {
 		formatPath = *path
 	}
 
 	// Ensure `formatPath` does not end with '/', otherwise, GetSecretsMetadata
 	// will not be able to retrieve secrets as it should.
-	if formatPath != "" && formatPath[len(formatPath)-1] == '/' {
-		formatPath = formatPath[:len(formatPath)-1]
-	}
+	formatPath = strings.TrimSuffix(formatPath, "/")
 
 	return recursivelyGetSecretsList(ctx, okmsClient, okmsID, formatPath)
 }

+ 15 - 15
providers/v1/ovh/client_push_secret.go

@@ -182,30 +182,30 @@ func extractSecretKeyValue(data map[string][]byte, secretKey string) (map[string
 
 // This pushes the created/updated secret.
 func pushNewSecret(ctx context.Context, okmsClient OkmsClient, okmsID uuid.UUID, secretToPush map[string]any, path string, cas *uint32, secretExists bool) error {
-	var err error
-	var operation string
-
 	if !secretExists {
-		// Create a secret.
-		operation = "create"
-		_, err = okmsClient.PostSecretV2(ctx, okmsID, types.PostSecretV2Request{
+		_, err := okmsClient.PostSecretV2(ctx, okmsID, types.PostSecretV2Request{
 			Path: path,
 			Version: types.SecretV2VersionShort{
 				Data: &secretToPush,
 			},
 		})
-	} else {
-		// Update a secret.
-		operation = "update"
-		_, err = okmsClient.PutSecretV2(ctx, okmsID, path, cas, types.PutSecretV2Request{
-			Version: &types.SecretV2VersionShort{
-				Data: &secretToPush,
-			},
-		})
+
+		if err != nil {
+			return fmt.Errorf("could not create remote secret %q: %w", path, err)
+		}
+
+		return nil
 	}
 
+	_, err := okmsClient.PutSecretV2(ctx, okmsID, path, cas, types.PutSecretV2Request{
+		Version: &types.SecretV2VersionShort{
+			Data: &secretToPush,
+		},
+	})
+
 	if err != nil {
-		return fmt.Errorf("could not %s remote secret %q: %w", operation, path, err)
+		return fmt.Errorf("could not update remote secret %q: %w", path, err)
 	}
+
 	return nil
 }

+ 9 - 6
providers/v1/ovh/client_push_secret_test.go

@@ -28,6 +28,15 @@ import (
 	testingfake "github.com/external-secrets/external-secrets/runtime/testing/fake"
 )
 
+const (
+	mySecretRemoteKey          = "mysecret"
+	mySecret2RemoteKey         = "mysecret2"
+	nonExistentSecretRemoteKey = "non-existent-secret"
+	emptyRemoteKey             = ""
+	emptySecretRemoteKey       = "empty-secret"
+	nilSecretRemoteKey         = "nil-secret"
+)
+
 func TestPushSecret(t *testing.T) {
 	secretData := &v1.Secret{
 		Data: map[string][]byte{
@@ -35,12 +44,6 @@ func TestPushSecret(t *testing.T) {
 			"key2": []byte("value2"),
 		},
 	}
-	mySecretRemoteKey := "mysecret"
-	mySecret2RemoteKey := "mysecret2"
-	nonExistentSecretRemoteKey := "non-existent-secret"
-	emptyRemoteKey := ""
-	emptySecretRemoteKey := "empty-secret"
-	nilSecretRemoteKey := "nil-secret"
 
 	testCases := map[string]struct {
 		errshould  string

+ 2 - 1
providers/v1/ovh/fake/fake_okms_client.go

@@ -22,10 +22,11 @@ import (
 	"maps"
 	"strings"
 
-	esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
 	"github.com/google/uuid"
 	"github.com/ovh/okms-sdk-go"
 	"github.com/ovh/okms-sdk-go/types"
+
+	esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
 )
 
 type GetSecretV2Fn func() (*types.GetSecretV2Response, error)

+ 2 - 1
providers/v1/ovh/fake/fake_resolver.go

@@ -24,8 +24,9 @@ import (
 	"encoding/pem"
 	"sync"
 
-	esmeta "github.com/external-secrets/external-secrets/apis/meta/v1"
 	kclient "sigs.k8s.io/controller-runtime/pkg/client"
+
+	esmeta "github.com/external-secrets/external-secrets/apis/meta/v1"
 )
 
 type FakeResolver struct {

+ 1 - 1
providers/v1/ovh/go.mod

@@ -1,6 +1,6 @@
 module github.com/external-secrets/external-secrets/providers/v1/ovh
 
-go 1.25.5
+go 1.25.7
 
 require (
 	github.com/external-secrets/external-secrets/apis v0.0.0

+ 1 - 1
providers/v1/ovh/provider.go

@@ -84,7 +84,7 @@ type ovhClient struct {
 var _ esv1.SecretsClient = &ovhClient{}
 
 // Resolve returns the value of the referenced key from a Kubernetes Secret.
-func (r DefaultSecretKeyResolver) Resolve(ctx context.Context, kube kclient.Client, ovhStoreKind string, ovhStoreNameSpace string, secretRef *v1.SecretKeySelector) (string, error) {
+func (r DefaultSecretKeyResolver) Resolve(ctx context.Context, kube kclient.Client, ovhStoreKind, ovhStoreNameSpace string, secretRef *v1.SecretKeySelector) (string, error) {
 	return resolvers.SecretKeyRef(ctx, kube, ovhStoreKind, ovhStoreNameSpace, secretRef)
 }