Skip to content

Commit 829e1cd

Browse files
committed
Merge branch 'VED-26-permissions-api' of https://github.com/NHSDigital/immunisation-fhir-api into VED-26-permissions-api
meger remote with the local branch
2 parents 025104f + 8208760 commit 829e1cd

File tree

8 files changed

+67
-19
lines changed

8 files changed

+67
-19
lines changed

backend/src/clients.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
logging.basicConfig(level="INFO")
2121
logger = logging.getLogger()
22-
logger.setLevel("INFO")
2322
logger.info(f"Connecting to Redis at {REDIS_HOST}:{REDIS_PORT}")
2423

25-
redis_client = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, decode_responses=True)
24+
redis_client = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, decode_responses=True)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from clients import redis_client
22
import json
33

4+
45
def get_supplier_permissions(supplier: str) -> list[str]:
6+
print(f"Getting permissions for supplier: {supplier}")
57
permissions_data = redis_client.hget("supplier_permissions", supplier)
8+
print(f"Got permissions: {permissions_data}")
69
if not permissions_data:
710
return []
811
return json.loads(permissions_data)

backend/tests/test_fhir_service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import datetime
44
import unittest
55
from copy import deepcopy
6+
from unittest import skip
67
from unittest.mock import create_autospec
78
from decimal import Decimal
89

@@ -304,7 +305,7 @@ def test_immunization_not_found(self):
304305

305306
# Then
306307
self.imms_repo.get_immunization_by_identifier.assert_called_once_with(imms_id, "COVID19:search")
307-
308+
308309
self.assertEqual(act_imms["entry"], [])
309310

310311

@@ -343,7 +344,7 @@ def test_create_immunization(self):
343344

344345
# Then
345346
self.imms_repo.create_immunization.assert_called_once_with(req_imms, pds_patient, ["COVID19:create"], "Test")
346-
347+
347348
self.validator.validate.assert_called_once_with(req_imms)
348349
self.fhir_service.pds_service.get_patient_details.assert_called_once_with(
349350
nhs_number

backend/tests/utils/test_permissions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import patch
33
from src.models.utils.permissions import get_supplier_permissions
44

5+
56
class TestPermissions(unittest.TestCase):
67

78
@patch("clients.redis_client.hget")
@@ -14,4 +15,4 @@ def test_returns_list_if_permissions_exist(self, mock_hget):
1415
def test_returns_empty_list_if_no_permissions(self, mock_hget):
1516
mock_hget.return_value = None
1617
result = get_supplier_permissions("UNKNOWN")
17-
self.assertEqual(result, [])
18+
self.assertEqual(result, [])

terraform/endpoints.tf

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/// This file creates all lambdas needed for each endpoint plus api-gateway
22

33
locals {
4-
policy_path = "${path.root}/policies"
5-
domain_name_url = "https://${local.service_domain_name}"
4+
policy_path = "${path.root}/policies"
65
}
76

87
data "aws_iam_policy_document" "logs_policy_document" {
@@ -52,20 +51,23 @@ data "aws_iam_policy_document" "imms_policy_document" {
5251
}),
5352
templatefile("${local.policy_path}/secret_manager.json", {
5453
"account_id" : data.aws_caller_identity.current.account_id
55-
})
54+
}),
55+
file("${local.policy_path}/ec2_network_interfaces.json")
5656
]
5757
}
5858

5959
module "imms_event_endpoint_lambdas" {
6060
source = "./lambda"
6161
count = length(local.imms_endpoints)
6262

63-
prefix = local.prefix
64-
short_prefix = local.short_prefix
65-
function_name = local.imms_endpoints[count.index]
66-
image_uri = module.docker_image.image_uri
67-
policy_json = data.aws_iam_policy_document.imms_policy_document.json
68-
environments = local.imms_lambda_env_vars
63+
prefix = local.prefix
64+
short_prefix = local.short_prefix
65+
function_name = local.imms_endpoints[count.index]
66+
image_uri = module.docker_image.image_uri
67+
policy_json = data.aws_iam_policy_document.imms_policy_document.json
68+
environments = local.imms_lambda_env_vars
69+
vpc_subnet_ids = data.aws_subnets.default.ids
70+
vpc_security_group_ids = [data.aws_security_group.existing_securitygroup.id]
6971
}
7072

7173
locals {

terraform/lambda/lambda.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ module "lambda_function_container_image" {
1313
architectures = ["x86_64"]
1414
timeout = 6
1515

16+
vpc_subnet_ids = var.vpc_subnet_ids
17+
vpc_security_group_ids = var.vpc_security_group_ids
18+
1619
# A JWT encode took 7 seconds at default memory size of 128 and 0.8 seconds at 1024.
1720
# 2048 gets it down to around 0.5 but since Lambda is charged at GB * ms then it costs more for minimal benefit.
1821
memory_size = 1024

terraform/lambda/variables.tf

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
1-
variable "prefix" {}
2-
variable "short_prefix" {}
3-
variable "function_name" {}
4-
variable "image_uri" {}
1+
variable "prefix" {
2+
type = string
3+
}
4+
5+
variable "short_prefix" {
6+
type = string
7+
}
8+
9+
variable "function_name" {
10+
type = string
11+
}
12+
13+
variable "image_uri" {
14+
type = string
15+
}
16+
517
variable "environments" {
18+
type = map(string)
619
default = {}
720
}
821

9-
variable "policy_json" {}
22+
variable "policy_json" {
23+
type = string
24+
}
25+
26+
variable "vpc_security_group_ids" {
27+
type = list(string)
28+
default = null
29+
}
30+
31+
variable "vpc_subnet_ids" {
32+
type = list(string)
33+
default = null
34+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Action": [
7+
"ec2:CreateNetworkInterface",
8+
"ec2:DescribeNetworkInterfaces",
9+
"ec2:DeleteNetworkInterface"
10+
],
11+
"Resource": "*"
12+
}
13+
]
14+
}

0 commit comments

Comments
 (0)