|
31 | 31 | from common import AV_SCAN_START_SNS_ARN |
32 | 32 | from common import AV_SIGNATURE_METADATA |
33 | 33 | from common import AV_STATUS_CLEAN |
| 34 | +from common import AV_STATUS_DO_NOT_SCAN |
34 | 35 | from common import AV_STATUS_INFECTED |
35 | 36 | from common import AV_STATUS_METADATA |
36 | 37 | from common import AV_STATUS_SNS_ARN |
@@ -213,6 +214,14 @@ def lambda_handler(event, context): |
213 | 214 | print("Script starting at %s\n" % (start_time)) |
214 | 215 | s3_object = event_object(event, event_source=EVENT_SOURCE) |
215 | 216 |
|
| 217 | + if not object_have_to_be_scanned(s3_client, s3_object): |
| 218 | + set_av_tags(s3_client, s3_object, AV_STATUS_DO_NOT_SCAN, 'NC', get_timestamp()) |
| 219 | + print( |
| 220 | + "Skipp of s3://%s file is tagged DO_NOT_SCAN \n" |
| 221 | + % (os.path.join(s3_object.bucket_name, s3_object.key)) |
| 222 | + ) |
| 223 | + return |
| 224 | + |
216 | 225 | if str_to_bool(AV_PROCESS_ORIGINAL_VERSION_ONLY): |
217 | 226 | verify_s3_object_version(s3, s3_object) |
218 | 227 |
|
@@ -274,3 +283,15 @@ def lambda_handler(event, context): |
274 | 283 |
|
275 | 284 | def str_to_bool(s): |
276 | 285 | return bool(strtobool(str(s))) |
| 286 | + |
| 287 | + |
| 288 | +# Determine if an object have to be scanned (tagged DO_NOT_CLEAN) |
| 289 | +def object_have_to_be_scanned(s3_client, s3_object): |
| 290 | + s3_object_tags = s3_client.get_object_tagging(Bucket=s3_object.bucket_name, Key=s3_object.key) |
| 291 | + if "TagSet" not in s3_object_tags: |
| 292 | + return True |
| 293 | + for tag in s3_object_tags["TagSet"]: |
| 294 | + if tag["Key"] in [AV_STATUS_METADATA] and tag["Value"] in [AV_STATUS_DO_NOT_SCAN]: |
| 295 | + return False |
| 296 | + return True |
| 297 | + |
0 commit comments