Skip to content

Commit 9fd2c64

Browse files
committed
VED-470: Resolve Sonar warnings. Remove redundant multipart handling in record processor. Add missing TF changes.
1 parent ee0039c commit 9fd2c64

File tree

4 files changed

+5
-42
lines changed

4 files changed

+5
-42
lines changed

mesh_processor/src/converter.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def read_until_part_start(input_file: BinaryIO, boundary: bytes) -> None:
3636
while line := input_file.readline():
3737
if line == b"--" + boundary + b"\r\n":
3838
return
39-
else:
40-
raise ValueError(f"Unexpected EOF")
39+
raise ValueError("Unexpected EOF")
4140

4241

4342
def read_headers_bytes(input_file: BinaryIO) -> bytes:
@@ -46,8 +45,7 @@ def read_headers_bytes(input_file: BinaryIO) -> bytes:
4645
if line == b"\r\n":
4746
return headers_bytes
4847
headers_bytes += line
49-
else:
50-
raise ValueError("Unexpected EOF")
48+
raise ValueError("Unexpected EOF")
5149

5250

5351
def read_part_headers(input_file: BinaryIO) -> dict[str, str]:

recordprocessor/src/utils_for_recordprocessor.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ def get_environment() -> str:
1919
def get_csv_content_dict_reader(file_key: str) -> (DictReader, str):
2020
"""Returns the requested file contents from the source bucket in the form of a DictReader"""
2121
response = s3_client.get_object(Bucket=os.getenv("SOURCE_BUCKET_NAME"), Key=file_key)
22+
# TODO - this reads everything into memory! Look into streaming instead
2223
csv_data = response["Body"].read().decode("utf-8")
23-
24-
# Verify and process the DAT file content coming from MESH
25-
if ".dat" in file_key:
26-
csv_data = extract_content(csv_data)
2724
return DictReader(StringIO(csv_data), delimiter="|"), csv_data
2825

2926

@@ -46,21 +43,3 @@ def invoke_filename_lambda(file_key: str, message_id: str) -> None:
4643
except Exception as error:
4744
logger.error("Error invoking filename lambda: %s", error)
4845
raise
49-
50-
51-
def extract_content(dat_file_content):
52-
53-
boundary_pattern = re.compile(r"----------------------------\d+")
54-
55-
parts = boundary_pattern.split(dat_file_content)
56-
57-
# Extract the content between the boundaries
58-
filecontent = None
59-
for part in parts:
60-
if "Content-Disposition" in part and "Content-Type" in part:
61-
62-
content_start = part.index("Content-Type") + len("Content-Type: text/csv") + 2
63-
filecontent = part[content_start:].strip()
64-
break
65-
66-
return filecontent

recordprocessor/tests/test_utils_for_recordprocessor.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
get_environment,
2020
get_csv_content_dict_reader,
2121
create_diagnostics_dictionary,
22-
extract_content,
2322
)
2423
from file_level_validation import move_file
2524

@@ -81,19 +80,6 @@ def test_create_diagnostics_dictionary(self):
8180
},
8281
)
8382

84-
def test_extract_content_valid_input(self):
85-
dat_file_content = (
86-
"----------------------------1234567890\n"
87-
'Content-Disposition: form-data; name="file";\n'
88-
'filename="COVID19_Vaccinations_v5_YGM41_20250312T113455981.csv"\n'
89-
"Content-Type: text/csv\n\n"
90-
"NHS_NUMBER|PERSON_FORENAME|PERSON_SURNAME|PERSON_DOB|PERSON_GENDER_CODE|PERSON_POSTCODE\n"
91-
"----------------------------1234567890\n"
92-
)
93-
expected_content = "NHS_NUMBER|PERSON_FORENAME|PERSON_SURNAME|PERSON_DOB|PERSON_GENDER_CODE|PERSON_POSTCODE"
94-
result = extract_content(dat_file_content)
95-
self.assertEqual(result, expected_content)
96-
9783
def test_move_file(self):
9884
"""Tests that move_file correctly moves a file from one location to another within a single S3 bucket"""
9985
source_file_key = "test_file_key"

terraform/mesh_processor.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ resource "aws_lambda_function" "mesh_file_converter_lambda" {
212212
package_type = "Image"
213213
image_uri = module.mesh_processor_docker_image[0].image_uri
214214
architectures = ["x86_64"]
215-
timeout = 360
215+
timeout = 900
216216

217217
environment {
218218
variables = {
219-
Destination_BUCKET_NAME = aws_s3_bucket.batch_data_source_bucket.bucket
219+
DESTINATION_BUCKET_NAME = aws_s3_bucket.batch_data_source_bucket.bucket
220220
}
221221
}
222222
}

0 commit comments

Comments
 (0)