Explorar o código

Add logic to check for existing secrets

Signed-off-by: William Young <will.young@engineerbetter.com>
Co-authored-by: Dominic Meddick <dom.meddick@engineerbetter.com>
Co-authored-by: Lilly Daniell <lilly.daniell@engineerbetter.com>
Co-authored-by: Amr Fawzy <amr.fawzy@container-solutions.com>
Co-authored-by: Adrienne Galloway <adrienne.galloway@engineerbetter.com>
Co-authored-by: Gustavo Fernandes de Carvalho <gusfcarvalho@gmail.com>
William Young %!s(int64=3) %!d(string=hai) anos
pai
achega
5ee6fcb166
Modificáronse 1 ficheiros con 14 adicións e 5 borrados
  1. 14 5
      pkg/provider/vault/vault.go

+ 14 - 5
pkg/provider/vault/vault.go

@@ -368,13 +368,22 @@ func (v *client) SetSecret(ctx context.Context, value []byte, remoteRef esv1beta
 	}
 
 	path := v.buildPath(remoteRef.GetRemoteKey())
-	_, err := v.logical.WriteWithContext(ctx, path, secretData)
 
-	if err != nil {
-		return err
+	_, err := v.GetSecret(ctx, esv1beta1.ExternalSecretDataRemoteRef{Key: path})
+
+	var vaultErr *vault.ResponseError
+
+	if errors.As(err, &vaultErr) {
+		if err != nil && vaultErr.StatusCode == 404 {
+			_, err = v.logical.WriteWithContext(ctx, path, secretData)
+			if err != nil {
+				return err
+			}
+		}
+		if err != nil {
+			return err
+		}
 	}
-	// This is the address of our vault on our local cluster
-	// cfg.Address = "vault.vault-ns.svc.cluster.local.8200"
 
 	return nil
 }