Skip to content

Commit 7705c6c

Browse files
mfjarvisdlzhry2nhs
authored andcommitted
VED-901: Update extended attribute file destination. (#1141)
* VED-901: Update extended attributes destination prefix. * VED-901: Update tests. * VED-901: Upload EA files directly to the S3 submission upload bucket. * VED-901: Lint tfvars files.
1 parent 054e5ca commit 7705c6c

6 files changed

Lines changed: 23 additions & 26 deletions

File tree

infrastructure/instance/environments/prod/blue/variables.tfvars

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ error_alarm_notifications_enabled = true
99
mesh_no_invocation_period_seconds = 86400
1010
create_mesh_processor = true
1111
has_sub_environment_scope = false
12-
dspp_kms_key_alias = "nhsd-dspp-core-prod-extended-attributes-gdp-key"
12+
dspp_submission_s3_bucket_name = "nhsd-dspp-core-prod-s3-submission-upload"
13+
dspp_submission_kms_key_alias = "nhsd-dspp-core-prod-s3-submission-upload-key"

infrastructure/instance/environments/prod/green/variables.tfvars

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ error_alarm_notifications_enabled = true
99
mesh_no_invocation_period_seconds = 86400
1010
create_mesh_processor = true
1111
has_sub_environment_scope = false
12-
dspp_kms_key_alias = "nhsd-dspp-core-prod-extended-attributes-gdp-key"
12+
dspp_submission_s3_bucket_name = "nhsd-dspp-core-prod-s3-submission-upload"
13+
dspp_submission_kms_key_alias = "nhsd-dspp-core-prod-s3-submission-upload-key"

infrastructure/instance/file_name_processor.tf

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,8 @@ locals {
44
filename_lambda_files = fileset(local.filename_lambda_dir, "**")
55
filename_lambda_dir_sha = sha1(join("", [for f in local.filename_lambda_files : filesha1("${local.filename_lambda_dir}/${f}")]))
66
filename_lambda_name = "${local.short_prefix}-filenameproc-lambda"
7-
8-
dps_bucket_name_for_extended_attribute = (
9-
var.environment == "prod"
10-
? "nhsd-dspp-core-prod-extended-attributes-gdp"
11-
: "nhsd-dspp-core-ref-extended-attributes-gdp"
12-
)
13-
dps_bucket_arn_for_extended_attribute = [
14-
"arn:aws:s3:::${local.dps_bucket_name_for_extended_attribute}/*"
15-
]
167
}
178

18-
19-
209
resource "aws_ecr_repository" "file_name_processor_lambda_repository" {
2110
image_scanning_configuration {
2211
scan_on_push = true
@@ -180,7 +169,7 @@ resource "aws_iam_policy" "filenameprocessor_lambda_exec_policy" {
180169
"Action" : [
181170
"s3:PutObject"
182171
],
183-
"Resource" : local.dps_bucket_arn_for_extended_attribute
172+
"Resource" : ["arn:aws:s3:::${var.dspp_submission_s3_bucket_name}/*"]
184173
}
185174
]
186175
})
@@ -266,14 +255,14 @@ resource "aws_iam_policy" "filenameprocessor_dps_extended_attribute_kms_policy"
266255
{
267256
Effect = "Allow",
268257
Action = [
269-
"kms:Decrypt",
258+
"kms:Encrypt",
270259
"kms:GenerateDataKey",
271-
"kms:DescribeKey"
260+
"kms:DescribeKey",
272261
],
273262
Resource = "arn:aws:kms:${var.aws_region}:${var.dspp_core_account_id}:key/*",
274263
"Condition" = {
275264
"ForAnyValue:StringEquals" = {
276-
"kms:ResourceAliases" = "alias/${var.dspp_kms_key_alias}"
265+
"kms:ResourceAliases" = "alias/${var.dspp_submission_kms_key_alias}"
277266
}
278267
}
279268
}
@@ -331,7 +320,7 @@ resource "aws_lambda_function" "file_processor_lambda" {
331320
DPS_ACCOUNT_ID = var.dspp_core_account_id
332321
SOURCE_BUCKET_NAME = aws_s3_bucket.batch_data_source_bucket.bucket
333322
ACK_BUCKET_NAME = aws_s3_bucket.batch_data_destination_bucket.bucket
334-
DPS_BUCKET_NAME = local.dps_bucket_name_for_extended_attribute
323+
DPS_BUCKET_NAME = var.dspp_submission_s3_bucket_name
335324
QUEUE_URL = aws_sqs_queue.batch_file_created.url
336325
REDIS_HOST = data.aws_elasticache_cluster.existing_redis.cache_nodes[0].address
337326
REDIS_PORT = data.aws_elasticache_cluster.existing_redis.cache_nodes[0].port

infrastructure/instance/variables.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ variable "mns_account_id" {
2727
default = "631615744739"
2828
}
2929

30-
variable "dspp_kms_key_alias" {
31-
description = "Alias name of the DPS KMS key allowed for SSE-KMS encryption"
30+
variable "dspp_submission_s3_bucket_name" {
31+
description = "Name of the DSPP (DPS) S3 bucket where extended attributes files should be submitted"
3232
type = string
33-
default = "nhsd-dspp-core-ref-extended-attributes-gdp-key"
33+
default = "nhsd-dspp-core-ref-s3-submission-upload"
34+
}
35+
36+
variable "dspp_submission_kms_key_alias" {
37+
description = "Alias of the DSPP (DPS) KMS key required to encrypt extended attributes files"
38+
type = string
39+
default = "nhsd-dspp-core-ref-s3-submission-upload-key"
3440
}
3541

3642
variable "create_mesh_processor" {

lambdas/filenameprocessor/src/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Currently only COVID extended attributes files are supported, might be extended in future for other vaccine types
2222
EXTENDED_ATTRIBUTES_VACC_TYPE = "COVID"
2323

24-
DPS_DESTINATION_PREFIX = "dps_destination"
24+
DPS_DESTINATION_PREFIX = "generic/EXTENDED_ATTRIBUTES_DAILY_1"
2525
EXTENDED_ATTRIBUTES_ARCHIVE_PREFIX = "extended-attributes-archive"
2626
VALID_EA_VERSIONS = ["V1_5"]
2727
ERROR_TYPE_TO_STATUS_CODE_MAP = {

lambdas/filenameprocessor/tests/test_lambda_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ def test_lambda_handler_extended_attributes_success(self, mock_get_redis_client)
288288
archived_obj = s3_client.get_object(Bucket=BucketNames.SOURCE, Key=archived_key)
289289
self.assertIsNotNone(archived_obj)
290290

291-
# Also verify file copied to DPS destination bucket under dps_destination/<file_key>
292-
dps_key = f"dps_destination/{test_cases[0].file_key}"
291+
# Also verify file copied to DPS destination bucket under generic/EXTENDED_ATTRIBUTES_DAILY_1/<file_key>
292+
dps_key = f"generic/EXTENDED_ATTRIBUTES_DAILY_1/{test_cases[0].file_key}"
293293
copied_obj = s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=dps_key)
294294
self.assertIsNotNone(copied_obj)
295295

@@ -463,7 +463,7 @@ def test_lambda_handler_extended_attributes_extension_checks(self, mock_get_redi
463463
# Ensure processed path hit by checking archive move in source bucket
464464
s3_client.get_object(Bucket=BucketNames.SOURCE, Key=f"extended-attributes-archive/{csv_key}")
465465
# And verify copy to DPS destination
466-
s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=f"dps_destination/{csv_key}")
466+
s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=f"generic/EXTENDED_ATTRIBUTES_DAILY_1/{csv_key}")
467467

468468
# .DAT accepted
469469
dat_key = MockFileDetails.extended_attributes_file.file_key[:-3] + "dat"
@@ -474,7 +474,7 @@ def test_lambda_handler_extended_attributes_extension_checks(self, mock_get_redi
474474
):
475475
lambda_handler(self.make_event([self.make_record(dat_key)]), None)
476476
s3_client.get_object(Bucket=BucketNames.SOURCE, Key=f"extended-attributes-archive/{dat_key}")
477-
s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=f"dps_destination/{dat_key}")
477+
s3_client.get_object(Bucket=BucketNames.DPS_DESTINATION, Key=f"generic/EXTENDED_ATTRIBUTES_DAILY_1/{dat_key}")
478478

479479
# Invalid extension fails
480480
bad_ext_key = csv_key[:-3] + "txt"

0 commit comments

Comments
 (0)