[go: nahoru, domu]

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

refactor(ASFF): create class #4368

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor(asff): pass findings as a dict and fix tests
  • Loading branch information
pedrooot committed Jul 4, 2024
commit 35e4866e122b215c7ee671ca395359eba429af7a
14 changes: 3 additions & 11 deletions prowler/providers/aws/lib/security_hub/security_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ def batch_send_to_security_hub(

success_count = 0
try:
# print(security_hub_findings_per_region['eu-west-1'][0])
# exit()
# Iterate findings by region
for region, findings in security_hub_findings_per_region.items():
# Send findings to Security Hub
Expand All @@ -124,6 +122,8 @@ def batch_send_to_security_hub(
)

security_hub_client = session.client("securityhub", region_name=region)
# Convert findings to dict
findings = [finding.dict() for finding in findings]
success_count += _send_findings_to_security_hub(
findings, region, security_hub_client
)
Expand Down Expand Up @@ -201,15 +201,7 @@ def _send_findings_to_security_hub(
for i in range(0, len(findings), SECURITY_HUB_MAX_BATCH)
]
for findings in list_chunked:
findings_to_send = []
for finding in findings:
if isinstance(finding, dict):
findings_to_send.append(finding)
else:
findings_to_send.append(finding.dict())
batch_import = security_hub_client.batch_import_findings(
Findings=findings_to_send
)
batch_import = security_hub_client.batch_import_findings(Findings=findings)
if batch_import["FailedCount"] > 0:
failed_import = batch_import["FailedFindings"][0]
logger.error(
Expand Down
6 changes: 3 additions & 3 deletions tests/providers/aws/lib/security_hub/security_hub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_verify_security_hub_integration_enabled_per_region_security_hub_disable
(
"root",
WARNING,
f"ClientError -- [68]: An error occurred ({error_code}) when calling the {operation_name} operation: {error_message}",
f"ClientError -- [67]: An error occurred ({error_code}) when calling the {operation_name} operation: {error_message}",
)
]

Expand Down Expand Up @@ -153,7 +153,7 @@ def test_verify_security_hub_integration_enabled_per_region_another_ClientError(
(
"root",
ERROR,
f"ClientError -- [68]: An error occurred ({error_code}) when calling the {operation_name} operation: {error_message}",
f"ClientError -- [67]: An error occurred ({error_code}) when calling the {operation_name} operation: {error_message}",
)
]

Expand All @@ -179,7 +179,7 @@ def test_verify_security_hub_integration_enabled_per_region_another_Exception(
(
"root",
ERROR,
f"Exception -- [68]: {error_message}",
f"Exception -- [67]: {error_message}",
)
]

Expand Down