Browse Source

Added GetSecretValueWithContext to aws SetSecret

Signed-off-by: Marcus Dantas <marcus.dantas@engineerbetter.com>
Co-authored-by: Lilly Daniell <lilly.daniell@engineerbetter.com>
Co-authored-by: William Young <will.young@engineerbetter.com>
Co-authored-by: Amr Fawzy <amr.fawzy@container-solutions.com>
Marcus Dantas 3 years ago
parent
commit
a00b2b5ca6

+ 15 - 2
pkg/provider/aws/secretsmanager/secretsmanager.go

@@ -47,9 +47,10 @@ type SecretsManager struct {
 // SMInterface is a subset of the smiface api.
 // see: https://docs.aws.amazon.com/sdk-for-go/api/service/secretsmanager/secretsmanageriface/
 type SMInterface interface {
-	GetSecretValue(*awssm.GetSecretValueInput) (*awssm.GetSecretValueOutput, error)
 	ListSecrets(*awssm.ListSecretsInput) (*awssm.ListSecretsOutput, error)
+	GetSecretValue(*awssm.GetSecretValueInput) (*awssm.GetSecretValueOutput, error)
 	CreateSecretWithContext(aws.Context, *awssm.CreateSecretInput, ...request.Option) (*awssm.CreateSecretOutput, error)
+	GetSecretValueWithContext(aws.Context, *awssm.GetSecretValueInput, ...request.Option) (*awssm.GetSecretValueOutput, error)
 }
 
 const (
@@ -113,7 +114,19 @@ func (sm *SecretsManager) SetSecret(ctx context.Context, value []byte, remoteRef
 		SecretBinary: value,
 	}
 
-	_, err := sm.client.CreateSecretWithContext(ctx, &secretRequest)
+	secretValue := awssm.GetSecretValueInput{
+		SecretId: &secretName,
+	}
+
+	output, err := sm.client.GetSecretValueWithContext(ctx, &secretValue)
+
+	if err != nil {
+		return err
+	}
+
+	fmt.Println(output)
+
+	_, err = sm.client.CreateSecretWithContext(ctx, &secretRequest)
 
 	if err != nil {
 		return err

+ 1 - 1
pkg/provider/aws/secretsmanager/secretsmanager_test.go

@@ -392,7 +392,7 @@ func TestSetSecret(t *testing.T) {
 func makeValidSecretStore() *esv1beta1.SecretStore {
 	return &esv1beta1.SecretStore{
 		ObjectMeta: metav1.ObjectMeta{
-			Name:      "vault-store",
+			Name:      "aws-secret-store",
 			Namespace: "default",
 		},
 		Spec: esv1beta1.SecretStoreSpec{