fix(outputs): refactor unroll_tags to use str as tags (#4819)

Co-authored-by: Pedro Martín <pedromarting3@gmail.com>
This commit is contained in:
github-actions[bot]
2024-08-21 15:19:16 -04:00
committed by GitHub
parent 03064f1f29
commit dae26ad484
2 changed files with 16 additions and 1 deletions
+7 -1
View File
@@ -63,10 +63,16 @@ def unroll_tags(tags: list) -> dict:
>>> tags = {"name": "John", "age": "30"}
>>> unroll_tags(tags)
{'name': 'John', 'age': '30'}
>>> tags = ["name", "age"]
>>> unroll_tags(tags)
{'name': '', 'age': ''}
"""
if tags and tags != [{}] and tags != [None]:
if tags and tags != [{}] and tags != [None] and tags != []:
if isinstance(tags, dict):
return tags
if isinstance(tags[0], str) and len(tags) > 0:
return {tag: "" for tag in tags}
if "key" in tags[0]:
return {item["key"]: item["value"] for item in tags}
elif "Key" in tags[0]:
+9
View File
@@ -150,6 +150,15 @@ class TestOutputs:
"terraform": "true",
}
def test_unroll_tags_only_list(self):
tags_list = ["tag1", "tag2", "tag3"]
assert unroll_tags(tags_list) == {
"tag1": "",
"tag2": "",
"tag3": "",
}
def test_unroll_dict(self):
test_compliance_dict = {
"CISA": ["your-systems-3", "your-data-1", "your-data-2"],