1313
1414from audit_table import upsert_audit_table
1515from common .aws_s3_utils import (
16- copy_file_outside_bucket ,
16+ copy_file_to_external_bucket ,
1717 delete_file ,
1818 is_file_in_bucket ,
1919 move_file ,
2323from common .models .errors import UnhandledAuditTableError
2424from constants import (
2525 DPS_DESTINATION_BUCKET_NAME ,
26+ DPS_DESTINATION_PREFIX ,
2627 ERROR_TYPE_TO_STATUS_CODE_MAP ,
27- EXTENDED_ATTRIBUTES_PREFIXES ,
28+ EXTENDED_ATTRIBUTES_FILE_PREFIX ,
2829 SOURCE_BUCKET_NAME ,
2930 FileNotProcessedReason ,
3031 FileStatus ,
@@ -83,7 +84,7 @@ def handle_record(record) -> dict:
8384 s3_response = get_s3_client ().get_object (Bucket = bucket_name , Key = file_key )
8485 created_at_formatted_string , expiry_timestamp = get_creation_and_expiry_times (s3_response )
8586
86- if file_key .startswith (EXTENDED_ATTRIBUTES_PREFIXES ):
87+ if file_key .startswith (EXTENDED_ATTRIBUTES_FILE_PREFIX ):
8788 return handle_extended_attributes_file (
8889 file_key ,
8990 bucket_name ,
@@ -113,7 +114,7 @@ def handle_unexpected_bucket_name(bucket_name: str, file_key: str) -> dict:
113114 """Handles scenario where Lambda was not invoked by the data-sources bucket. Should not occur due to terraform
114115 config and overarching design"""
115116 try :
116- if file_key .startswith (EXTENDED_ATTRIBUTES_PREFIXES ):
117+ if file_key .startswith (EXTENDED_ATTRIBUTES_FILE_PREFIX ):
117118 extended_attribute_identifier = validate_extended_attributes_file_key (file_key )
118119 logger .error (
119120 "Unable to process file %s due to unexpected bucket name %s" ,
@@ -162,7 +163,9 @@ def handle_unexpected_bucket_name(bucket_name: str, file_key: str) -> dict:
162163 }
163164
164165
165- def handle_batch_file (file_key , bucket_name , message_id , created_at_formatted_string , expiry_timestamp ) -> dict :
166+ def handle_batch_file (
167+ file_key : str , bucket_name : str , message_id : str , created_at_formatted_string : str , expiry_timestamp : str
168+ ) -> dict :
166169 """
167170 Processes a single record for batch file.
168171 Returns a dictionary containing information to be included in the logs.
@@ -244,7 +247,7 @@ def handle_batch_file(file_key, bucket_name, message_id, created_at_formatted_st
244247
245248
246249def handle_extended_attributes_file (
247- file_key , bucket_name , message_id , created_at_formatted_string , expiry_timestamp
250+ file_key : str , bucket_name : str , message_id : str , created_at_formatted_string : str , expiry_timestamp : str
248251) -> dict :
249252 """
250253 Processes a single record for extended attributes file.
@@ -261,19 +264,18 @@ def handle_extended_attributes_file(
261264
262265 try :
263266 extended_attribute_identifier = validate_extended_attributes_file_key (file_key )
264- queue_name = extended_attribute_identifier
265267
266268 upsert_audit_table (
267269 message_id ,
268270 file_key ,
269271 created_at_formatted_string ,
270272 expiry_timestamp ,
271- queue_name ,
273+ extended_attribute_identifier ,
272274 FileStatus .PROCESSING ,
273275 )
274276
275277 dest_file_key = f"dps_destination/{ file_key } "
276- copy_file_outside_bucket (bucket_name , file_key , DPS_DESTINATION_BUCKET_NAME , dest_file_key )
278+ copy_file_to_external_bucket (bucket_name , file_key , DPS_DESTINATION_BUCKET_NAME , dest_file_key )
277279 is_file_in_bucket (DPS_DESTINATION_BUCKET_NAME , dest_file_key )
278280 delete_file (bucket_name , dest_file_key )
279281
@@ -282,7 +284,7 @@ def handle_extended_attributes_file(
282284 file_key ,
283285 created_at_formatted_string ,
284286 expiry_timestamp ,
285- queue_name ,
287+ extended_attribute_identifier ,
286288 FileStatus .PROCESSED ,
287289 )
288290
@@ -291,7 +293,7 @@ def handle_extended_attributes_file(
291293 "message" : "Extended Attributes file successfully processed" ,
292294 "file_key" : file_key ,
293295 "message_id" : message_id ,
294- "queue_name" : queue_name ,
296+ "queue_name" : extended_attribute_identifier ,
295297 }
296298
297299 except ( # pylint: disable=broad-exception-caught
@@ -307,8 +309,8 @@ def handle_extended_attributes_file(
307309 file_status = get_file_status_for_error (error )
308310
309311 # NB if we got InvalidFileKeyError we won't have a valid queue name
310- if not queue_name :
311- queue_name = "unknown"
312+ if not extended_attribute_identifier :
313+ extended_attribute_identifier = "unknown"
312314
313315 # Move file to archive
314316 move_file (bucket_name , file_key , f"archive/{ file_key } " )
@@ -318,7 +320,7 @@ def handle_extended_attributes_file(
318320 file_key ,
319321 created_at_formatted_string ,
320322 expiry_timestamp ,
321- queue_name ,
323+ extended_attribute_identifier ,
322324 file_status ,
323325 error_details = str (error ),
324326 )
0 commit comments