Skip to content

Commit

Permalink
Allow force deletion of already marked-for-delete secret
Browse files Browse the repository at this point in the history
  • Loading branch information
dfangl committed Oct 11, 2024
1 parent d184a3f commit 7b04a77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion moto/secretsmanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ def delete_secret(
msg = f"You can't delete secret {secret_id} that still has replica regions [{replica_regions}]"
raise InvalidParameterException(msg)

if secret.is_deleted():
if secret.is_deleted() and not force_delete_without_recovery:
raise InvalidRequestException(
"An error occurred (InvalidRequestException) when calling the DeleteSecret operation: You tried to \
perform the operation on a secret that's currently marked deleted."
Expand Down
11 changes: 11 additions & 0 deletions tests/test_secretsmanager/test_secretsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,17 @@ def test_delete_secret_that_is_marked_deleted():
conn.delete_secret(SecretId="test-secret")


@mock_aws
def test_force_delete_secret_that_is_marked_deleted():
conn = boto3.client("secretsmanager", region_name="us-west-2")

conn.create_secret(Name="test-secret", SecretString="foosecret")

conn.delete_secret(SecretId="test-secret")

conn.delete_secret(SecretId="test-secret", ForceDeleteWithoutRecovery=True)


@mock_aws
def test_get_random_password_default_length():
conn = boto3.client("secretsmanager", region_name="us-west-2")
Expand Down

0 comments on commit 7b04a77

Please sign in to comment.