Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhammerl committed Oct 16, 2023
1 parent 891e8a9 commit 435e243
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
30 changes: 20 additions & 10 deletions steps/gather/src/handler/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ def gather_results(event, context):
)

master_report = deepcopy(account_reports[0]["report"])
master_report = list(unique_everseen([
{
k: v
for k, v in elem.items()
if k in ["plugin", "category", "title", "description"]
}
for elem in master_report
]))
master_report = list(
unique_everseen(
[
{
k: v
for k, v in elem.items()
if k in ["plugin", "category", "title", "description"]
}
for elem in master_report
]
)
)
for plugin in master_report:
plugin["reports"] = {
report["account"]: [
Expand All @@ -56,8 +60,14 @@ def gather_results(event, context):
for report in account_reports
}

master_report_by_category = {k:list(v) for k,v in groupby(master_report, key=itemgetter("category"))}
master_report_by_category = {
k: list(v) for k, v in groupby(master_report, key=itemgetter("category"))
}

result = s3.put_object(Bucket=bucket, Key=f"{date}/report.json", Body=json.dumps(master_report_by_category).encode())
result = s3.put_object(
Bucket=bucket,
Key=f"{date}/report.json",
Body=json.dumps(master_report_by_category).encode(),
)

return master_report_by_category
1 change: 1 addition & 0 deletions steps/gather/test/fixture/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path


def read_test_scan_reports():
report_files = ["123123123123.json", "456456456456.json", "789789789789.json"]

Expand Down
12 changes: 8 additions & 4 deletions steps/gather/test/unit/handler/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ def test_should_create_master_report():
assert_that(category, is_(instance_of(str)))
for plugin in plugins:
for key in plugin.keys():
assert_that(key, is_in(["plugin", "category", "title", "description", "reports"]))
assert_that(
key,
is_in(["plugin", "category", "title", "description", "reports"]),
)

for account, findings in plugin["reports"].items():
assert_that(account, is_(instance_of(str)))
for finding in findings:
for finding_property in finding.keys():
assert_that(finding_property, is_in(["resource", "region", "status", "message"]))


assert_that(
finding_property,
is_in(["resource", "region", "status", "message"]),
)

0 comments on commit 435e243

Please sign in to comment.