Просмотр исходного кода

Debugging for aws secretManager versioning

Signed-off-by: Marcus Dantas <marcus.dantas@engineerbetter.com>
Co-authored-by: William Young <will.young@engineerbetter.com>
Marcus Dantas 3 лет назад
Родитель
Сommit
102488b738
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      pkg/provider/aws/secretsmanager/secretsmanager.go

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

@@ -52,6 +52,7 @@ type SMInterface interface {
 	GetSecretValue(*awssm.GetSecretValueInput) (*awssm.GetSecretValueOutput, error)
 	GetSecretValue(*awssm.GetSecretValueInput) (*awssm.GetSecretValueOutput, error)
 	CreateSecretWithContext(aws.Context, *awssm.CreateSecretInput, ...request.Option) (*awssm.CreateSecretOutput, error)
 	CreateSecretWithContext(aws.Context, *awssm.CreateSecretInput, ...request.Option) (*awssm.CreateSecretOutput, error)
 	GetSecretValueWithContext(aws.Context, *awssm.GetSecretValueInput, ...request.Option) (*awssm.GetSecretValueOutput, error)
 	GetSecretValueWithContext(aws.Context, *awssm.GetSecretValueInput, ...request.Option) (*awssm.GetSecretValueOutput, error)
+	UpdateSecretVersionStageWithContext(aws.Context, *awssm.UpdateSecretVersionStageInput, ...request.Option) (*awssm.UpdateSecretVersionStageOutput, error)
 }
 }
 
 
 const (
 const (
@@ -116,14 +117,18 @@ type RequestFailure interface {
 func (sm *SecretsManager) SetSecret(ctx context.Context, value []byte, remoteRef esv1beta1.PushRemoteRef) error {
 func (sm *SecretsManager) SetSecret(ctx context.Context, value []byte, remoteRef esv1beta1.PushRemoteRef) error {
 	secretName := remoteRef.GetRemoteKey()
 	secretName := remoteRef.GetRemoteKey()
 	awsCurrent := "AWSCURRENT"
 	awsCurrent := "AWSCURRENT"
+
+	updateSecretVersion := awssm.UpdateSecretVersionStageInput{
+		SecretId:     &secretName,
+		VersionStage: &awsCurrent,
+	}
 	secretRequest := awssm.CreateSecretInput{
 	secretRequest := awssm.CreateSecretInput{
 		Name:         &secretName,
 		Name:         &secretName,
 		SecretBinary: value,
 		SecretBinary: value,
 	}
 	}
 
 
 	secretValue := awssm.GetSecretValueInput{
 	secretValue := awssm.GetSecretValueInput{
-		SecretId:     &secretName,
-		VersionStage: &awsCurrent,
+		SecretId: &secretName,
 	}
 	}
 
 
 	awsSecret, err := sm.client.GetSecretValueWithContext(ctx, &secretValue)
 	awsSecret, err := sm.client.GetSecretValueWithContext(ctx, &secretValue)
@@ -131,6 +136,8 @@ func (sm *SecretsManager) SetSecret(ctx context.Context, value []byte, remoteRef
 
 
 	if awsSecret != nil && reflect.DeepEqual(awsSecret.SecretBinary, secretRequest.SecretBinary) {
 	if awsSecret != nil && reflect.DeepEqual(awsSecret.SecretBinary, secretRequest.SecretBinary) {
 		return nil
 		return nil
+	} else {
+		sm.client.UpdateSecretVersionStageWithContext(ctx, &updateSecretVersion)
 	}
 	}
 
 
 	if reqerr, ok := err.(RequestFailure); ok {
 	if reqerr, ok := err.(RequestFailure); ok {