Skip to content

Commit

Permalink
Prevents errors when definition files don't exist in bucket yet (blue…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Webb authored Nov 22, 2017
1 parent b270f1b commit c6a25e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ Create an s3 bucket to store current antivirus definitions. This
provides the fastest download speeds for the scanner. This bucket can
be kept as private.

In this bucket, create a directory named clamav_defs (this is the default name of the directory, can be changed at the environment variables)
copy main.cvd | daily.cvd | bytecode.cvd from [https://www.clamav.net/downloads](https://www.clamav.net/downloads)
this is needed for the first run of the script.

To allow public access, useful for other accounts,
add the following policy to the bucket.

Expand Down
11 changes: 7 additions & 4 deletions clamav.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ def update_defs_from_s3(bucket, prefix):
for filename in AV_DEFINITION_FILENAMES:
s3_path = os.path.join(AV_DEFINITION_S3_PREFIX, filename)
local_path = os.path.join(AV_DEFINITION_PATH, filename)
if os.path.exists(local_path) and md5_from_file(local_path) == md5_from_s3_tags(bucket, s3_path):
s3_md5 = md5_from_s3_tags(bucket, s3_path)
if os.path.exists(local_path) and md5_from_file(local_path) == s3_md5:
print("Not downloading %s because local md5 matches s3." % filename)
continue
print("Downloading definition file %s from s3://%s" % (filename, os.path.join(bucket, prefix)))
s3.Bucket(bucket).download_file(s3_path, local_path)
if s3_md5:
print("Downloading definition file %s from s3://%s" % (filename, os.path.join(bucket, prefix)))
s3.Bucket(bucket).download_file(s3_path, local_path)


def upload_defs_to_s3(bucket, prefix, local_path):
Expand Down Expand Up @@ -93,7 +95,8 @@ def md5_from_s3_tags(bucket, key):
try:
tags = s3_client.get_object_tagging(Bucket=bucket, Key=key)["TagSet"]
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
expected_errors = {'404', 'AccessDenied'}
if e.response['Error']['Code'] in expected_errors:
return ""
else:
raise
Expand Down

0 comments on commit c6a25e9

Please sign in to comment.