Skip to content

Commit

Permalink
Updated python script
Browse files Browse the repository at this point in the history
  • Loading branch information
developerkunal committed Sep 9, 2024
1 parent 53c1529 commit dc3f480
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions scripts/rl-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ def generate_report(rlsecure_path, workdir, targetdir, artifact_name, artifact_v
except subprocess.CalledProcessError as e:
sys.exit(f'[x] Failed to generate report: {e}')

def detect_malware(report_file, artifact_name, artifact_version, repository, commit, build_env):
def detect_malware(report_file,workdir, artifact_name, artifact_version, repository, commit, build_env):
report_data = load_report(report_file)
try:
report_metadata = report_data['report']['metadata']
malware_violation_rule_ids = MALWARE_VIOLATION_IDS

is_malware_detected = process_and_export_violations(report_metadata, malware_violation_rule_ids, artifact_name, artifact_version, repository, commit, build_env)
is_malware_detected = process_and_export_violations(report_metadata, workdir, malware_violation_rule_ids, artifact_name, artifact_version, repository, commit, build_env)

if not is_malware_detected:
print('[i] No Malware was detected.')
Expand All @@ -110,7 +110,7 @@ def load_report(report_file):

import sys

def process_and_export_violations(report_metadata, malware_violation_rule_ids, artifact_name, artifact_version, repository, commit, build_env):
def process_and_export_violations(report_metadata, workdir, malware_violation_rule_ids, artifact_name, artifact_version, repository, commit, build_env):
print('----------------- Detections -----------------', file=sys.stderr)

is_malware_detected = False
Expand All @@ -127,11 +127,8 @@ def process_and_export_violations(report_metadata, malware_violation_rule_ids, a

report_malware_detection(violation['rule_id'])

base_dir = os.getcwd()

file_name = 'violations.txt'
file_path = os.path.join(base_dir, file_name)
print(f'Saving violations to {file_path}', file=sys.stderr)
file_path = os.path.join(workdir, file_name)
print('------------------RL Wrapper Scanner Save Violations------------------', file=sys.stderr)
with open(file_path, 'w') as file:
file.write('## 🚨 RL Wrapper Scanner Results: Malware Detected\n\n')
Expand Down Expand Up @@ -273,7 +270,7 @@ def main():
scan_artifact(rlsecure_path, args.artifact, workdir, args.name, args.version)
generate_report(rlsecure_path, workdir, targetdir, args.name, args.version)

is_non_compliant_violations = detect_malware(f'{workdir}/{targetdir}/report.rl.json', args.name, args.version, args.repository, args.commit, args.build_env)
is_non_compliant_violations = detect_malware(f'{workdir}/{targetdir}/report.rl.json', workdir, args.name, args.version, args.repository, args.commit, args.build_env)

s3_results_path = submit_to_s3(workdir, targetdir, s3_bucket_name, tool_name, args.name, args.version, timestamp)

Expand Down

0 comments on commit dc3f480

Please sign in to comment.