Skip to content

Commit

Permalink
fix(outputs): refactor unroll_tags to use str as tags
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrooot committed Aug 21, 2024
1 parent a557d62 commit 37d2f8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion prowler/lib/outputs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/outputs/outputs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ def test_unroll_tags_lowercase(self):
"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"],
Expand Down

0 comments on commit 37d2f8b

Please sign in to comment.