Skip to content

Commit

Permalink
fix(aws): handle AWS key-only tags (#4845)
Browse files Browse the repository at this point in the history
(cherry picked from commit fb449ce)
  • Loading branch information
MrCloudSec committed Aug 23, 2024
1 parent 15fe1e1 commit fc203a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions prowler/lib/outputs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def unroll_tags(tags: list) -> dict:
>>> unroll_tags(tags)
{'name': 'John', 'age': '30'}
>>> tags = [{"key": "name"}]
>>> unroll_tags(tags)
{'name': ''}
>>> tags = [{"Key": "name"}]
>>> unroll_tags(tags)
{'name': ''}
>>> tags = [{"name": "John", "age": "30"}]
>>> unroll_tags(tags)
{'name': 'John', 'age': '30'}
Expand All @@ -74,9 +82,9 @@ def unroll_tags(tags: list) -> dict:
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}
return {item["key"]: item.get("value", "") for item in tags}
elif "Key" in tags[0]:
return {item["Key"]: item["Value"] for item in tags}
return {item["Key"]: item.get("Value", "") for item in tags}
else:
return {key: value for d in tags for key, value in d.items()}
return {}
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/outputs/outputs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ def test_unroll_tags_only_list(self):
"tag3": "",
}

def test_unroll_tags_with_key_only(self):
tags = [{"key": "name"}]

assert unroll_tags(tags) == {"name": ""}

def test_unroll_dict(self):
test_compliance_dict = {
"CISA": ["your-systems-3", "your-data-1", "your-data-2"],
Expand Down

0 comments on commit fc203a6

Please sign in to comment.