Skip to content

Commit

Permalink
SecretsManager - update_secret() now supports the Description-paramet…
Browse files Browse the repository at this point in the history
…er (#6352)
  • Loading branch information
bblommers authored May 31, 2023
1 parent 1a8060c commit 37cb6ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion moto/secretsmanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def update_secret(
secret_binary: Optional[str] = None,
client_request_token: Optional[str] = None,
kms_key_id: Optional[str] = None,
description: Optional[str] = None,
) -> str:

# error if secret does not exist
Expand All @@ -366,7 +367,7 @@ def update_secret(

secret = self.secrets[secret_id]
tags = secret.tags
description = secret.description
description = description or secret.description

secret = self._add_secret(
secret_id,
Expand Down
2 changes: 2 additions & 0 deletions moto/secretsmanager/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def update_secret(self) -> str:
secret_id = self._get_param("SecretId")
secret_string = self._get_param("SecretString")
secret_binary = self._get_param("SecretBinary")
description = self._get_param("Description")
client_request_token = self._get_param("ClientRequestToken")
kms_key_id = self._get_param("KmsKeyId", if_none=None)
return self.backend.update_secret(
Expand All @@ -79,6 +80,7 @@ def update_secret(self) -> str:
secret_binary=secret_binary,
client_request_token=client_request_token,
kms_key_id=kms_key_id,
description=description,
)

def get_random_password(self) -> str:
Expand Down
8 changes: 7 additions & 1 deletion tests/test_secretsmanager/test_secretsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,11 @@ def test_update_secret(pass_arn):
secret = conn.get_secret_value(SecretId=secret_id)
assert secret["SecretString"] == "foosecret"

updated_secret = conn.update_secret(SecretId=secret_id, SecretString="barsecret")
updated_secret = conn.update_secret(
SecretId=secret_id,
SecretString="barsecret",
Description="new desc",
)

assert updated_secret["ARN"]
assert updated_secret["Name"] == "test-secret"
Expand All @@ -1356,6 +1360,8 @@ def test_update_secret(pass_arn):
assert secret["SecretString"] == "barsecret"
assert created_secret["VersionId"] != updated_secret["VersionId"]

assert conn.describe_secret(SecretId=secret_id)["Description"] == "new desc"


@mock_secretsmanager
@pytest.mark.parametrize("pass_arn", [True, False])
Expand Down

0 comments on commit 37cb6ce

Please sign in to comment.