Skip to content

Commit

Permalink
fix(tags): handle AWS dictionary type tags (#4656)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCloudSec authored Aug 7, 2024
1 parent 8aca456 commit 89c6652
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions prowler/lib/outputs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ def unroll_tags(tags: list) -> dict:
>>> tags = []
>>> unroll_tags(tags)
{}
>>> tags = {"name": "John", "age": "30"}
>>> unroll_tags(tags)
{'name': 'John', 'age': '30'}
"""
if tags and tags != [{}] and tags != [None]:
if isinstance(tags, dict):
return tags
if "key" in tags[0]:
return {item["key"]: item["value"] for item in tags}
elif "Key" in tags[0]:
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/outputs/outputs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ def test_unroll_tags(self):
"terraform": "true",
}

def test_unroll_dict_tags(self):
tags_dict = {
"environment": "dev",
"name": "test",
"project": "prowler",
"terraform": "true",
}

assert unroll_tags(tags_dict) == {
"environment": "dev",
"name": "test",
"project": "prowler",
"terraform": "true",
}

def test_unroll_tags_unique(self):
unique_dict_list = [
{
Expand Down

0 comments on commit 89c6652

Please sign in to comment.