Fix: SecretsManager Added VersionIdsToStages key in describe_secret function (#3029)
* Fix: SecretsManager Added VersionIdsToStages key in describe_secret function * Added more assertions * Linting Co-authored-by: usmankb <usman@krazybee.com> Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
parent
8fa625c3de
commit
2433d64fe2
@ -274,6 +274,7 @@ class SecretsManagerBackend(BaseBackend):
|
||||
raise SecretNotFoundException()
|
||||
|
||||
secret = self.secrets[secret_id]
|
||||
version_id_to_stages = self.form_version_ids_to_stages(secret["versions"])
|
||||
|
||||
response = json.dumps(
|
||||
{
|
||||
@ -291,6 +292,7 @@ class SecretsManagerBackend(BaseBackend):
|
||||
"LastAccessedDate": None,
|
||||
"DeletedDate": secret.get("deleted_date", None),
|
||||
"Tags": secret["tags"],
|
||||
"VersionIdsToStages": version_id_to_stages,
|
||||
}
|
||||
)
|
||||
|
||||
@ -552,6 +554,14 @@ class SecretsManagerBackend(BaseBackend):
|
||||
}
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def form_version_ids_to_stages(secret):
|
||||
version_id_to_stages = {}
|
||||
for key, value in secret.items():
|
||||
version_id_to_stages[key] = value["version_stages"]
|
||||
|
||||
return version_id_to_stages
|
||||
|
||||
|
||||
secretsmanager_backends = {}
|
||||
for region in Session().get_available_regions("secretsmanager"):
|
||||
|
@ -733,25 +733,33 @@ def test_put_secret_value_versions_differ_if_same_secret_put_twice():
|
||||
def test_put_secret_value_maintains_description_and_tags():
|
||||
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
||||
|
||||
conn.create_secret(
|
||||
previous_response = conn.create_secret(
|
||||
Name=DEFAULT_SECRET_NAME,
|
||||
SecretString="foosecret",
|
||||
Description="desc",
|
||||
Tags=[{"Key": "Foo", "Value": "Bar"}, {"Key": "Mykey", "Value": "Myvalue"}],
|
||||
)
|
||||
previous_version_id = previous_response["VersionId"]
|
||||
|
||||
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
||||
conn.put_secret_value(
|
||||
current_response = conn.put_secret_value(
|
||||
SecretId=DEFAULT_SECRET_NAME,
|
||||
SecretString="dupe_secret",
|
||||
VersionStages=["AWSCURRENT"],
|
||||
)
|
||||
current_version_id = current_response["VersionId"]
|
||||
|
||||
secret_details = conn.describe_secret(SecretId=DEFAULT_SECRET_NAME)
|
||||
assert secret_details["Tags"] == [
|
||||
{"Key": "Foo", "Value": "Bar"},
|
||||
{"Key": "Mykey", "Value": "Myvalue"},
|
||||
]
|
||||
assert secret_details["Description"] == "desc"
|
||||
assert secret_details["VersionIdsToStages"] is not None
|
||||
assert previous_version_id in secret_details["VersionIdsToStages"]
|
||||
assert current_version_id in secret_details["VersionIdsToStages"]
|
||||
assert secret_details["VersionIdsToStages"][previous_version_id] == ["AWSPREVIOUS"]
|
||||
assert secret_details["VersionIdsToStages"][current_version_id] == ["AWSCURRENT"]
|
||||
|
||||
|
||||
@mock_secretsmanager
|
||||
|
Loading…
Reference in New Issue
Block a user