From 7430b27ff895d943d31288a2d87cf4bb8d97ae48 Mon Sep 17 00:00:00 2001 From: itaimarongwe-okta <112408457+itaimarongwe-okta@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:21:04 -0400 Subject: [PATCH] Update rl-wrapper.py --- scripts/rl-wrapper.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/scripts/rl-wrapper.py b/scripts/rl-wrapper.py index 76b95030..72319f07 100644 --- a/scripts/rl-wrapper.py +++ b/scripts/rl-wrapper.py @@ -91,11 +91,7 @@ def detect_malware(report_file): try: report_metadata = report_data['report']['metadata'] malware_violation_rule_ids = MALWARE_VIOLATION_IDS - is_malware_detected = process_violations(report_metadata, malware_violation_rule_ids) - - if not is_malware_detected: - print('[i] No Malware was detected.') except KeyError: handle_key_error() @@ -109,22 +105,15 @@ def load_report(report_file): sys.exit(f'[x] Error reading report data from {report_file}') def process_violations(report_metadata, malware_violation_rule_ids): - print('----------------- Detections -----------------', file=sys.stderr) is_malware_detected = False if violations := report_metadata['violations']: for _, violation in violations.items(): if violation['rule_id'] in malware_violation_rule_ids: # Malware was detected is_malware_detected = True - for component_id in violation['references']['component']: - print(f'[!] {violation["rule_id"]}: {violation["description"]} -> {report_metadata["components"][component_id]["path"]}', file=sys.stderr) - report_malware_detection(violation['rule_id']) return is_malware_detected -def report_malware_detection(rule_id): - print(f'\t* More information on the detections can be found at: https://docs.secure.software/policies/malware/{rule_id}', file=sys.stderr) - def handle_key_error(): _, _, traceback = sys.exc_info() sys.exit(f'[x] Inconsistency in report JSON at {traceback.tb_frame.f_code.co_filename}:{traceback.tb_lineno}') @@ -160,14 +149,14 @@ def upload_to_s3(file_path, s3_bucket_name, s3_key): s3 = boto3.client('s3') try: s3.upload_file(file_path, s3_bucket_name, s3_key) - print(f'[i] S3 - Uploaded {file_path} to s3://{s3_bucket_name}/{s3_key}') + print(f'[i] S3 - Uploaded to s3://...{s3_key}') return except FileNotFoundError: - sys.exit(f'[x] S3 - The file {file_path} was not found.') + sys.exit(f'[x] S3 - The file file was not found.') except NoCredentialsError: sys.exit('[x] S3 - Credentials not available.') except ClientError as e: - sys.exit(f'[x] S3 - Failed to upload {file_path} to S3: {e}.') + sys.exit(f'[x] S3 - Failed to upload files to S3.') def submit_to_s3(workdir, targetdir, s3_bucket_name, tool_name, artifact_name, artifact_version, timestamp): print('---------------------------------------------')