Skip to content

Commit 0129911

Browse files
committed
Merge branch 'master' into VED-365-batch-performance-investigation
# Conflicts: # backend/poetry.lock # e2e_batch/poetry.lock # e2e_batch/pyproject.toml # lambdas/id_sync/poetry.lock # recordprocessor/poetry.lock # recordprocessor/src/batch_processor.py # recordprocessor/src/file_level_validation.py # recordprocessor/src/utils_for_recordprocessor.py
2 parents c09798f + 5d3555a commit 0129911

File tree

97 files changed

+4865
-5201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4865
-5201
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ updates:
5151
- "/"
5252
- "/ack_backend"
5353
- "/backend"
54+
- "/batch_processor_filter"
5455
- "/delta_backend"
5556
- "/e2e"
5657
- "/e2e_batch"

ack_backend/poetry.lock

Lines changed: 146 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ack_backend/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ packages = [
1010

1111
[tool.poetry.dependencies]
1212
python = "~3.11"
13-
boto3 = "~1.38.42"
14-
mypy-boto3-dynamodb = "^1.38.4"
13+
boto3 = "~1.40.28"
14+
mypy-boto3-dynamodb = "^1.40.20"
1515
freezegun = "^1.5.2"
1616
moto = "^4"
17-
coverage = "^7.9.1"
17+
coverage = "^7.10.6"
1818

1919

2020
[build-system]

backend/poetry.lock

Lines changed: 455 additions & 450 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ packages = [{include = "src"}]
99
[tool.poetry.dependencies]
1010
python = "~3.11"
1111
"fhir.resources" = "~7.0.2"
12-
boto3 = "~1.38.42"
13-
boto3-stubs-lite = {extras = ["dynamodb"], version = "~1.38.42"}
12+
boto3 = "~1.40.28"
13+
boto3-stubs-lite = {extras = ["dynamodb"], version = "~1.40.28"}
1414
aws-lambda-typing = "~2.20.0"
1515
redis = "^4.6.0"
16-
moto = "^5.1.6"
17-
requests = "~2.32.4"
16+
moto = "^5.1.12"
17+
requests = "~2.32.5"
1818
responses = "~0.25.7"
1919
pydantic = "~1.10.13"
2020
pyjwt = "~2.10.1"
@@ -25,7 +25,7 @@ simplejson = "^3.19.2"
2525
structlog = "^24.1.0"
2626
python-stdnum = "^2.1"
2727
freezegun = "^1.5.1"
28-
coverage = "^7.9.1"
28+
coverage = "^7.10.6"
2929

3030
[build-system]
3131
requires = ["poetry-core ~= 1.5.0"]

backend/src/authorisation/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from enum import StrEnum
2+
3+
4+
class ApiOperationCode(StrEnum):
5+
CREATE = "c"
6+
READ = "r"
7+
UPDATE = "u"
8+
DELETE = "d"
9+
SEARCH = "s"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Authoriser class"""
2+
import json
3+
4+
from authorisation.api_operation_code import ApiOperationCode
5+
from clients import redis_client, logger
6+
from constants import SUPPLIER_PERMISSIONS_HASH_KEY
7+
8+
9+
class Authoriser:
10+
"""Authoriser class. Used for authorising operations on FHIR vaccinations."""
11+
def __init__(self):
12+
self._cache_client = redis_client
13+
14+
@staticmethod
15+
def _expand_permissions(permissions: list[str]) -> dict[str, list[ApiOperationCode]]:
16+
"""Parses and expands permissions data into a dictionary mapping vaccination types to a list of permitted
17+
API operations. The raw string from Redis will be in the form VAC.PERMS e.g. COVID19.CRUDS"""
18+
expanded_permissions = {}
19+
20+
for permission in permissions:
21+
vaccine_type, operation_codes_str = permission.split(".", maxsplit=1)
22+
vaccine_type = vaccine_type.lower()
23+
operation_codes = [
24+
operation_code
25+
for operation_code in operation_codes_str.lower()
26+
if operation_code in list(ApiOperationCode)
27+
]
28+
expanded_permissions[vaccine_type] = operation_codes
29+
30+
return expanded_permissions
31+
32+
def _get_supplier_permissions(self, supplier_system: str) -> dict[str, list[ApiOperationCode]]:
33+
raw_permissions_data = self._cache_client.hget(SUPPLIER_PERMISSIONS_HASH_KEY, supplier_system)
34+
permissions_data = json.loads(raw_permissions_data) if raw_permissions_data else []
35+
36+
return self._expand_permissions(permissions_data)
37+
38+
def authorise(
39+
self,
40+
supplier_system: str,
41+
requested_operation: ApiOperationCode,
42+
vaccination_types: set[str]
43+
) -> bool:
44+
"""Checks that the supplier system is permitted to carry out the requested operation on the given vaccination
45+
type(s)"""
46+
supplier_permissions = self._get_supplier_permissions(supplier_system)
47+
48+
logger.info(
49+
f"operation: {requested_operation}, supplier_permissions: {supplier_permissions}, "
50+
f"vaccine_types: {vaccination_types}"
51+
)
52+
return all(
53+
requested_operation in supplier_permissions.get(vaccination_type.lower(), [])
54+
for vaccination_type in vaccination_types
55+
)
56+
57+
def filter_permitted_vacc_types(
58+
self,
59+
supplier_system: str,
60+
requested_operation: ApiOperationCode,
61+
vaccination_types: set[str]
62+
) -> set[str]:
63+
"""Returns the set of vaccine types that a given supplier can interact with for a given operation type.
64+
This is a more permissive form of authorisation e.g. used in search as it will filter out any requested vacc
65+
types that they cannot interact with without throwing an error"""
66+
supplier_permissions = self._get_supplier_permissions(supplier_system)
67+
68+
return {
69+
vaccine_type
70+
for vaccine_type in vaccination_types
71+
if requested_operation in supplier_permissions.get(vaccine_type.lower(), [])
72+
}

backend/src/authorization.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

backend/src/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ class Urls:
2323

2424

2525
GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE = "Unable to process request. Issue may be transient."
26+
SUPPLIER_PERMISSIONS_HASH_KEY = "supplier_permissions"

0 commit comments

Comments
 (0)