Skip to content

Commit e5beecf

Browse files
committed
CCM-8572: set template status on failure
1 parent 7186c7d commit e5beecf

File tree

16 files changed

+300
-180
lines changed

16 files changed

+300
-180
lines changed

frontend/jest.setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import 'whatwg-fetch';
1212

1313
Object.assign(global, { TextDecoder, TextEncoder });
1414

15+
Object.assign(global, {
16+
// eslint-disable-next-line unicorn/prefer-structured-clone
17+
structuredClone: (val: unknown) => JSON.parse(JSON.stringify(val)),
18+
});
19+
1520
createMocks();
1621

1722
// set feature flag

infrastructure/terraform/modules/backend-api/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ No requirements.
2828
|------|--------|---------|
2929
| <a name="module_authorizer_build"></a> [authorizer\_build](#module\_authorizer\_build) | ../typescript-build-zip | n/a |
3030
| <a name="module_authorizer_lambda"></a> [authorizer\_lambda](#module\_authorizer\_lambda) | ../lambda-function | n/a |
31-
| <a name="module_build_get_s3_object_tags_lambda"></a> [build\_get\_s3\_object\_tags\_lambda](#module\_build\_get\_s3\_object\_tags\_lambda) | ../typescript-build-zip | n/a |
3231
| <a name="module_build_template_client"></a> [build\_template\_client](#module\_build\_template\_client) | ../typescript-build-zip | n/a |
3332
| <a name="module_build_template_lambda"></a> [build\_template\_lambda](#module\_build\_template\_lambda) | ../typescript-build-zip | n/a |
33+
| <a name="module_build_virus_scan_lambdas"></a> [build\_virus\_scan\_lambdas](#module\_build\_virus\_scan\_lambdas) | ../typescript-build-zip | n/a |
3434
| <a name="module_create_letter_template_lambda"></a> [create\_letter\_template\_lambda](#module\_create\_letter\_template\_lambda) | ../lambda-function | n/a |
3535
| <a name="module_create_template_lambda"></a> [create\_template\_lambda](#module\_create\_template\_lambda) | ../lambda-function | n/a |
3636
| <a name="module_get_template_lambda"></a> [get\_template\_lambda](#module\_get\_template\_lambda) | ../lambda-function | n/a |
37+
| <a name="module_lambda_copy_scanned_object_to_internal"></a> [lambda\_copy\_scanned\_object\_to\_internal](#module\_lambda\_copy\_scanned\_object\_to\_internal) | ../lambda-function | n/a |
38+
| <a name="module_lambda_delete_failed_scanned_object"></a> [lambda\_delete\_failed\_scanned\_object](#module\_lambda\_delete\_failed\_scanned\_object) | ../lambda-function | n/a |
3739
| <a name="module_lambda_get_s3_object_tags"></a> [lambda\_get\_s3\_object\_tags](#module\_lambda\_get\_s3\_object\_tags) | ../lambda-function | n/a |
40+
| <a name="module_lambda_set_file_virus_scan_status"></a> [lambda\_set\_file\_virus\_scan\_status](#module\_lambda\_set\_file\_virus\_scan\_status) | ../lambda-function | n/a |
3841
| <a name="module_list_template_lambda"></a> [list\_template\_lambda](#module\_list\_template\_lambda) | ../lambda-function | n/a |
3942
| <a name="module_s3bucket_internal"></a> [s3bucket\_internal](#module\_s3bucket\_internal) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
4043
| <a name="module_s3bucket_quarantine"></a> [s3bucket\_quarantine](#module\_s3bucket\_quarantine) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
4144
| <a name="module_sqs_quarantine_tags_added"></a> [sqs\_quarantine\_tags\_added](#module\_sqs\_quarantine\_tags\_added) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v1.0.8 |
42-
| <a name="module_sqs_virus_scan_complete"></a> [sqs\_virus\_scan\_complete](#module\_sqs\_virus\_scan\_complete) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v1.0.8 |
4345
| <a name="module_sqs_virus_scan_failed"></a> [sqs\_virus\_scan\_failed](#module\_sqs\_virus\_scan\_failed) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v1.0.8 |
4446
| <a name="module_sqs_virus_scan_passed"></a> [sqs\_virus\_scan\_passed](#module\_sqs\_virus\_scan\_passed) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v1.0.8 |
4547
| <a name="module_update_template_lambda"></a> [update\_template\_lambda](#module\_update\_template\_lambda) | ../lambda-function | n/a |

infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_virus_scan_failed.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ resource "aws_cloudwatch_event_target" "scan_failed_delete_object" {
2626

2727
resource "aws_cloudwatch_event_target" "scan_failed_set_file_status" {
2828
rule = aws_cloudwatch_event_rule.virus_scan_failed.name
29-
arn = module.lambda_set_letter_file_virus_scan_status.function_arn
29+
arn = module.lambda_set_file_virus_scan_status.function_arn
3030
role_arn = aws_iam_role.handle_scan_failed.arn
3131
}
3232

@@ -50,7 +50,7 @@ data "aws_iam_policy_document" "handle_scan_failed" {
5050
actions = ["lambda:InvokeFunction"]
5151
resources = [
5252
module.lambda_delete_failed_scanned_object.function_arn,
53-
module.lambda_set_letter_file_virus_scan_status.function_arn,
53+
module.lambda_set_file_virus_scan_status.function_arn,
5454
]
5555
}
5656
}

infrastructure/terraform/modules/backend-api/cloudwatch_event_rule_virus_scan_passed.tf

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,39 @@ resource "aws_cloudwatch_event_rule" "virus_scan_passed" {
1818
})
1919
}
2020

21-
resource "aws_cloudwatch_event_target" "virus_scan_passed" {
21+
resource "aws_cloudwatch_event_target" "scan_passed_copy_object" {
2222
rule = aws_cloudwatch_event_rule.virus_scan_passed.name
23-
arn = module.sqs_virus_scan_passed.sqs_queue_arn
24-
role_arn = aws_iam_role.virus_scan_passed_to_sqs.arn
23+
arn = module.lambda_copy_scanned_object_to_internal.function_arn
24+
role_arn = aws_iam_role.handle_scan_passed.arn
2525
}
2626

27-
resource "aws_iam_role" "virus_scan_passed_to_sqs" {
28-
name = "${local.csi}-virus-scan-passed-to-sqs"
27+
resource "aws_cloudwatch_event_target" "scan_passed_set_file_status" {
28+
rule = aws_cloudwatch_event_rule.virus_scan_passed.name
29+
arn = module.lambda_set_file_virus_scan_status.function_arn
30+
role_arn = aws_iam_role.handle_scan_passed.arn
31+
}
32+
33+
resource "aws_iam_role" "handle_scan_passed" {
34+
name = "${local.csi}-virus-scan-passed"
2935
assume_role_policy = data.aws_iam_policy_document.events_assume_role.json
3036
}
3137

32-
resource "aws_iam_role_policy" "virus_scan_passed_to_sqs" {
33-
name = "${local.csi}-virus-scan-passed-to-sqs"
34-
role = aws_iam_role.virus_scan_passed_to_sqs.id
35-
policy = data.aws_iam_policy_document.virus_scan_passed_to_sqs.json
38+
resource "aws_iam_role_policy" "handle_scan_passed" {
39+
name = "${local.csi}-virus-scan-passed"
40+
role = aws_iam_role.handle_scan_passed.id
41+
policy = data.aws_iam_policy_document.handle_scan_passed.json
3642
}
3743

38-
data "aws_iam_policy_document" "virus_scan_passed_to_sqs" {
44+
data "aws_iam_policy_document" "handle_scan_passed" {
3945
version = "2012-10-17"
4046

4147
statement {
42-
sid = "AllowSQSSendMessage"
43-
effect = "Allow"
44-
actions = ["sqs:SendMessage"]
45-
resources = [module.sqs_virus_scan_passed.sqs_queue_arn]
46-
}
47-
48-
statement {
49-
sid = "AllowKMS"
50-
effect = "Allow"
51-
actions = [
52-
"kms:Decrypt",
53-
"kms:GenerateDataKey"
48+
sid = "AllowLambdaInvoke"
49+
effect = "Allow"
50+
actions = ["lambda:InvokeFunction"]
51+
resources = [
52+
module.lambda_copy_scanned_object_to_internal.function_arn,
53+
module.lambda_set_file_virus_scan_status.function_arn,
5454
]
55-
resources = [var.kms_key_arn]
5655
}
5756
}

infrastructure/terraform/modules/backend-api/locals.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ locals {
1515
})
1616

1717
backend_lambda_entrypoints = {
18-
create_template = "src/templates/create.ts"
19-
create_letter_template = "src/templates/create-letter.ts"
20-
get_template = "src/templates/get.ts"
21-
update_template = "src/templates/update.ts"
22-
list_template = "src/templates/list.ts"
23-
template_client = "src/index.ts"
24-
set_letter_file_virus_scan_status = "src/set-letter-file-virus-scan-status.ts"
18+
create_template = "src/templates/create.ts"
19+
create_letter_template = "src/templates/create-letter.ts"
20+
get_template = "src/templates/get.ts"
21+
update_template = "src/templates/update.ts"
22+
list_template = "src/templates/list.ts"
23+
set_file_virus_scan_status = "src/templates/set-letter-file-virus-scan-status.ts"
24+
template_client = "src/index.ts"
2525
}
2626

2727
dynamodb_kms_key_arn = var.dynamodb_kms_key_arn == "" ? aws_kms_key.dynamo[0].arn : var.dynamodb_kms_key_arn

infrastructure/terraform/modules/backend-api/module_build_template_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module "build_template_lambda" {
88
local.backend_lambda_entrypoints.get_template,
99
local.backend_lambda_entrypoints.update_template,
1010
local.backend_lambda_entrypoints.list_template,
11-
local.backend_lambda_entrypoints.set_letter_file_virus_scan_status,
11+
local.backend_lambda_entrypoints.set_file_virus_scan_status,
1212
]
1313
}
1414

infrastructure/terraform/modules/backend-api/module_lambda_copy_scanned_object_to_internal.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,18 @@ data "aws_iam_policy_document" "copy_scanned_object_to_internal" {
5656

5757
resources = ["${module.s3bucket_internal.arn}/*"]
5858
}
59+
60+
statement {
61+
sid = "AllowKMSAccess"
62+
effect = "Allow"
63+
64+
actions = [
65+
"kms:Decrypt",
66+
"kms:GenerateDataKey",
67+
]
68+
69+
resources = [
70+
var.kms_key_arn
71+
]
72+
}
5973
}

infrastructure/terraform/modules/backend-api/module_lambda_delete_failed_scanned_object.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ data "aws_iam_policy_document" "delete_failed_scanned_object" {
1818
effect = "Allow"
1919

2020
actions = [
21-
"s3:DeleteObject"
21+
"s3:DeleteObject",
22+
"s3:DeleteObjectVersion"
2223
]
2324

2425
resources = ["${module.s3bucket_quarantine.arn}/*"]

infrastructure/terraform/modules/backend-api/module_lambda_set_letter_file_virus_scan_status.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
module "lambda_set_letter_file_virus_scan_status" {
1+
module "lambda_set_file_virus_scan_status" {
22
source = "../lambda-function"
33
description = "Sets virus scan status on letter files"
44

5-
function_name = "${local.csi}-set-letter-file-virus-scan-status"
6-
filename = module.build_template_lambda.zips[local.backend_lambda_entrypoints.set_letter_file_virus_scan_status].path
7-
source_code_hash = module.build_template_lambda.zips[local.backend_lambda_entrypoints.set_letter_file_virus_scan_status].base64sha256
5+
function_name = "${local.csi}-set-file-virus-scan-status"
6+
filename = module.build_template_lambda.zips[local.backend_lambda_entrypoints.set_file_virus_scan_status].path
7+
source_code_hash = module.build_template_lambda.zips[local.backend_lambda_entrypoints.set_file_virus_scan_status].base64sha256
88
handler = "set-letter-file-virus-scan-status.handler"
99

1010
environment_variables = {
@@ -14,10 +14,10 @@ module "lambda_set_letter_file_virus_scan_status" {
1414

1515
log_retention_in_days = var.log_retention_in_days
1616

17-
execution_role_policy_document = data.aws_iam_policy_document.set_letter_file_virus_scan_status.json
17+
execution_role_policy_document = data.aws_iam_policy_document.set_file_virus_scan_status.json
1818
}
1919

20-
data "aws_iam_policy_document" "set_letter_file_virus_scan_status" {
20+
data "aws_iam_policy_document" "set_file_virus_scan_status" {
2121
statement {
2222
sid = "AllowDynamoAccess"
2323
effect = "Allow"

infrastructure/terraform/modules/backend-api/spec.tmpl.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@
377377
"SUBMITTED",
378378
"DELETED",
379379
"PENDING_UPLOAD",
380-
"PENDING_VALIDATION"
380+
"PENDING_VALIDATION",
381+
"VIRUS_SCAN_FAILED"
381382
]
382383
},
383384
"Language": {

0 commit comments

Comments
 (0)