Skip to content

Commit

Permalink
Update rl-wrapper.py
Browse files Browse the repository at this point in the history
  • Loading branch information
itaimarongwe-okta committed Sep 24, 2024
1 parent 2a183c1 commit 7430b27
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions scripts/rl-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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}')
Expand Down Expand Up @@ -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('---------------------------------------------')
Expand Down

0 comments on commit 7430b27

Please sign in to comment.