fix for duplicate tag keys in secretsmanager (#4900)

This commit is contained in:
stromp 2022-03-01 23:50:42 +01:00 committed by GitHub
parent 206590acf5
commit 7e88a901d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -735,6 +735,16 @@ class SecretsManagerBackend(BaseBackend):
old_tags = secret.tags
for tag in tags:
existing_key_name = next(
(
old_key
for old_key in old_tags
if old_key.get("Key") == tag.get("Key")
),
None,
)
if existing_key_name:
old_tags.remove(existing_key_name)
old_tags.append(tag)
return secret_id

View File

@ -1282,14 +1282,16 @@ def test_tag_resource(pass_arn):
conn.tag_resource(
SecretId=secret_id, Tags=[{"Key": "FirstTag", "Value": "SomeValue"},],
)
conn.tag_resource(
SecretId="test-secret", Tags=[{"Key": "FirstTag", "Value": "SomeOtherValue"},],
)
conn.tag_resource(
SecretId=secret_id, Tags=[{"Key": "SecondTag", "Value": "AnotherValue"},],
)
secrets = conn.list_secrets()
assert secrets["SecretList"][0].get("Tags") == [
{"Key": "FirstTag", "Value": "SomeValue"},
{"Key": "FirstTag", "Value": "SomeOtherValue"},
{"Key": "SecondTag", "Value": "AnotherValue"},
]