Skip to content

Commit 7246a69

Browse files
committed
resolve comments
1 parent 8b98408 commit 7246a69

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

lambdas/filenameprocessor/src/constants.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
)
1212

1313
SOURCE_BUCKET_NAME = os.getenv("SOURCE_BUCKET_NAME")
14+
15+
# We have used an internal temporary bucket here and an acutal dps bucket will replace this
1416
DPS_DESTINATION_BUCKET_NAME = os.getenv("ACK_BUCKET_NAME")
17+
EXPECTED_BUCKET_OWNER_ACCOUNT = os.getenv("ACCOUNT_ID")
1518
AUDIT_TABLE_NAME = os.getenv("AUDIT_TABLE_NAME")
1619
AUDIT_TABLE_TTL_DAYS = os.getenv("AUDIT_TABLE_TTL_DAYS")
1720
VALID_VERSIONS = ["V5"]
1821

1922
VACCINE_TYPE_TO_DISEASES_HASH_KEY = "vacc_to_diseases"
2023
ODS_CODE_TO_SUPPLIER_SYSTEM_HASH_KEY = "ods_code_to_supplier"
21-
EXTENDED_ATTRIBUTES_PREFIXES = "Vaccination_Extended_Attributes"
24+
EXTENDED_ATTRIBUTES_FILE_PREFIXES = "Vaccination_Extended_Attributes"
25+
DPS_DESTINATION_PREFIX = "dps_destination/"
2226

2327
ERROR_TYPE_TO_STATUS_CODE_MAP = {
2428
VaccineTypePermissionsError: 403,

lambdas/filenameprocessor/src/file_name_processor.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
from uuid import uuid4
1111

1212
from audit_table import upsert_audit_table
13-
from common.aws_s3_utils import move_file, move_file_outside_bucket
13+
from common.aws_s3_utils import move_file, move_file_to_external_bucket
1414
from common.clients import STREAM_NAME, get_s3_client, logger
1515
from common.log_decorator import logging_decorator
1616
from common.models.errors import UnhandledAuditTableError
1717
from constants import (
1818
DPS_DESTINATION_BUCKET_NAME,
19+
DPS_DESTINATION_PREFIX,
1920
ERROR_TYPE_TO_STATUS_CODE_MAP,
20-
EXTENDED_ATTRIBUTES_PREFIXES,
21+
EXTENDED_ATTRIBUTES_FILE_PREFIXES,
2122
SOURCE_BUCKET_NAME,
2223
FileNotProcessedReason,
2324
FileStatus,
@@ -76,7 +77,7 @@ def handle_record(record) -> dict:
7677
s3_response = get_s3_client().get_object(Bucket=bucket_name, Key=file_key)
7778
created_at_formatted_string, expiry_timestamp = get_creation_and_expiry_times(s3_response)
7879

79-
if file_key.startswith(EXTENDED_ATTRIBUTES_PREFIXES):
80+
if file_key.startswith(EXTENDED_ATTRIBUTES_FILE_PREFIXES):
8081
return handle_extended_attributes_file(
8182
file_key,
8283
bucket_name,
@@ -106,7 +107,7 @@ def handle_unexpected_bucket_name(bucket_name: str, file_key: str) -> dict:
106107
"""Handles scenario where Lambda was not invoked by the data-sources bucket. Should not occur due to terraform
107108
config and overarching design"""
108109
try:
109-
if file_key.startswith(EXTENDED_ATTRIBUTES_PREFIXES):
110+
if file_key.startswith(EXTENDED_ATTRIBUTES_FILE_PREFIXES):
110111
extended_attribute_identifier = validate_extended_attributes_file_key(file_key)
111112
logger.error(
112113
"Unable to process file %s due to unexpected bucket name %s",
@@ -155,7 +156,9 @@ def handle_unexpected_bucket_name(bucket_name: str, file_key: str) -> dict:
155156
}
156157

157158

158-
def handle_batch_file(file_key, bucket_name, message_id, created_at_formatted_string, expiry_timestamp) -> dict:
159+
def handle_batch_file(
160+
file_key: str, bucket_name: str, message_id: str, created_at_formatted_string: str, expiry_timestamp: str
161+
) -> dict:
159162
"""
160163
Processes a single record for batch file.
161164
Returns a dictionary containing information to be included in the logs.
@@ -236,31 +239,32 @@ def handle_batch_file(file_key, bucket_name, message_id, created_at_formatted_st
236239

237240

238241
def handle_extended_attributes_file(
239-
file_key, bucket_name, message_id, created_at_formatted_string, expiry_timestamp
242+
file_key: str, bucket_name: str, message_id: str, created_at_formatted_string: str, expiry_timestamp: str
240243
) -> dict:
241244
"""
242245
Processes a single record for extended attributes file.
243246
Returns a dictionary containing information to be included in the logs.
244247
"""
245248
try:
246249
extended_attribute_identifier = validate_extended_attributes_file_key(file_key)
247-
move_file_outside_bucket(bucket_name, file_key, DPS_DESTINATION_BUCKET_NAME, f"dps_destination/{file_key}")
248-
queue_name = extended_attribute_identifier
250+
move_file_to_external_bucket(
251+
bucket_name, file_key, DPS_DESTINATION_BUCKET_NAME, f"{DPS_DESTINATION_PREFIX}{file_key}"
252+
)
249253

250254
upsert_audit_table(
251255
message_id,
252256
file_key,
253257
created_at_formatted_string,
254258
expiry_timestamp,
255-
queue_name,
259+
extended_attribute_identifier,
256260
FileStatus.PROCESSING,
257261
)
258262
return {
259263
"statusCode": 200,
260264
"message": "Extended Attributes file successfully processed",
261265
"file_key": file_key,
262266
"message_id": message_id,
263-
"queue_name": queue_name,
267+
"queue_name": extended_attribute_identifier,
264268
}
265269
except ( # pylint: disable=broad-exception-caught
266270
VaccineTypePermissionsError,
@@ -273,7 +277,6 @@ def handle_extended_attributes_file(
273277

274278
file_status = get_file_status_for_error(error)
275279
extended_attribute_identifier = validate_extended_attributes_file_key(file_key)
276-
queue_name = extended_attribute_identifier
277280

278281
upsert_audit_table(
279282
message_id,

lambdas/filenameprocessor/tests/test_lambda_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def test_lambda_handler_extended_attributes_success(self):
269269
return_value=test_cases[0].ods_code + "_COVID",
270270
),
271271
patch(
272-
"file_name_processor.move_file_outside_bucket",
272+
"file_name_processor.move_file_to_external_bucket",
273273
side_effect=lambda src_bucket, key, dst_bucket, dst_key: (
274274
s3_client.put_object(
275275
Bucket=BucketNames.DESTINATION,

lambdas/filenameprocessor/tests/utils_for_tests/values_for_tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ class MockFileDetails:
9595
extended_attributes_file = FileDetails(
9696
vaccine_type="Vaccination_Extended_Attributes", file_number=1, organization_code="RJ123"
9797
)
98-
# extended_attributes_file = "Vaccination_Extended_Attributes_v1_5_RJ123_20000101T00000001.csv"
9998

10099

101100
MOCK_FILE_HEADERS = (

lambdas/shared/src/common/aws_s3_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from common.clients import get_s3_client, logger
66

77
EXPECTED_BUCKET_OWNER_ACCOUNT = os.getenv("ACCOUNT_ID")
8-
DSP_DESTINATION_BUCKET_NAME = os.getenv("ACK_BUCKET_NAME")
98

109

1110
def move_file(bucket_name: str, source_file_key: str, destination_file_key: str) -> None:
@@ -20,7 +19,9 @@ def move_file(bucket_name: str, source_file_key: str, destination_file_key: str)
2019
logger.info("File moved from %s to %s", source_file_key, destination_file_key)
2120

2221

23-
def move_file_outside_bucket(source_bucket: str, source_key: str, destination_bucket: str, destination_key: str) -> None:
22+
def move_file_to_external_bucket(
23+
source_bucket: str, source_key: str, destination_bucket: str, destination_key: str
24+
) -> None:
2425
s3_client = get_s3_client()
2526
s3_client.copy_object(
2627
CopySource={"Bucket": source_bucket, "Key": source_key},

0 commit comments

Comments
 (0)