From ab815123c9bfe0e8fd82d3f5fe885acf4c91fc38 Mon Sep 17 00:00:00 2001 From: Pepe Fagoaga Date: Tue, 19 Mar 2024 11:24:11 +0100 Subject: [PATCH] chore(slack): fix integration with provider (#3565) Co-authored-by: Sergio Garcia <38561120+sergargar@users.noreply.github.com> --- prowler/__main__.py | 30 +++++++++++++++--------------- prowler/lib/outputs/slack.py | 4 ++-- tests/lib/outputs/slack_test.py | 4 +--- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/prowler/__main__.py b/prowler/__main__.py index 4c2bc63fc4..fc139d6580 100644 --- a/prowler/__main__.py +++ b/prowler/__main__.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import sys +from os import environ from colorama import Fore, Style @@ -35,6 +36,7 @@ from prowler.lib.logger import logger, set_logging_config from prowler.lib.outputs.compliance.compliance import display_compliance_table from prowler.lib.outputs.json.json import close_json from prowler.lib.outputs.outputs import extract_findings_statistics +from prowler.lib.outputs.slack import send_slack_message from prowler.lib.outputs.summary_table import display_summary_table from prowler.providers.aws.lib.s3.s3 import send_to_s3_bucket from prowler.providers.aws.lib.security_hub.security_hub import ( @@ -200,21 +202,19 @@ def prowler(): # Extract findings stats stats = extract_findings_statistics(findings) - # TODO: adapt the slack integration for the new AWS provider - # if args.slack: - # if "SLACK_API_TOKEN" in os.environ and "SLACK_CHANNEL_ID" in os.environ: - # _ = send_slack_message( - # os.environ["SLACK_API_TOKEN"], - # os.environ["SLACK_CHANNEL_ID"], - # stats, - # provider, - # provider, - # ) - # else: - # logger.critical( - # "Slack integration needs SLACK_API_TOKEN and SLACK_CHANNEL_ID environment variables (see more in https://docs.prowler.cloud/en/latest/tutorials/integrations/#slack)." - # ) - # sys.exit(1) + if args.slack: + if "SLACK_API_TOKEN" in environ and "SLACK_CHANNEL_ID" in environ: + _ = send_slack_message( + environ["SLACK_API_TOKEN"], + environ["SLACK_CHANNEL_ID"], + stats, + provider, + ) + else: + logger.critical( + "Slack integration needs SLACK_API_TOKEN and SLACK_CHANNEL_ID environment variables (see more in https://docs.prowler.cloud/en/latest/tutorials/integrations/#slack)." + ) + sys.exit(1) if args.output_modes: for mode in args.output_modes: diff --git a/prowler/lib/outputs/slack.py b/prowler/lib/outputs/slack.py index 8fbaff73b1..998ffd12a4 100644 --- a/prowler/lib/outputs/slack.py +++ b/prowler/lib/outputs/slack.py @@ -6,10 +6,10 @@ from prowler.config.config import aws_logo, azure_logo, gcp_logo, square_logo_im from prowler.lib.logger import logger -def send_slack_message(token, channel, stats, provider, audit_info): +def send_slack_message(token, channel, stats, provider): try: client = WebClient(token=token) - identity, logo = create_message_identity(provider, audit_info) + identity, logo = create_message_identity(provider) response = client.chat_postMessage( username="Prowler", icon_url=square_logo_img, diff --git a/tests/lib/outputs/slack_test.py b/tests/lib/outputs/slack_test.py index f8758d6281..668de70528 100644 --- a/tests/lib/outputs/slack_test.py +++ b/tests/lib/outputs/slack_test.py @@ -333,7 +333,5 @@ class TestSlackIntegration: ), mock.patch( "prowler.lib.outputs.slack.WebClient", new=mocked_web_client ): - response = send_slack_message( - "test-token", "test-channel", {}, "provider", {} - ) + response = send_slack_message("test-token", "test-channel", {}, "provider") assert response == mocked_slack_response