Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws): handle AWS key-only tags #4854

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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