in assets/lambda/code/scan/lambda.py [0:0]
def scan(input_bucket, input_key, download_path, definitions_path, tmp_path):
"""Scans the object from S3"""
# Max file size support by ClamAV
try:
command = [
"clamscan",
"-v",
"--stdout",
f"--max-filesize={MAX_BYTES}",
f"--max-scansize={MAX_BYTES}",
f"--database={definitions_path}",
"-r",
f"--tempdir={tmp_path}",
f"{download_path}",
]
scan_summary = subprocess.run(
command,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
)
status = ""
if scan_summary.returncode == 0:
status = CLEAN
elif scan_summary.returncode == 1:
status = INFECTED
else:
raise ClamAVException(
f"ClamAV exited with unexpected code: {scan_summary.returncode}."
f"\nOutput: {scan_summary.stdout.decode('utf-8')}"
)
set_status(input_bucket, input_key, status)
return {
"source": "serverless-clamscan",
"input_bucket": input_bucket,
"input_key": input_key,
"status": status,
"message": scan_summary.stdout.decode("utf-8"),
}
except subprocess.CalledProcessError as e:
report_failure(input_bucket, input_key, download_path, str(e.stderr))
except ClamAVException as e:
report_failure(input_bucket, input_key, download_path, e.message)