File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed
Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 1- """Initialise s3, kinesis and lambda clients"""
1+ """Initialise s3, kinesis, lambda and redis clients"""
22
33from boto3 import client as boto3_client
4+ import os
5+ import logging
6+ import redis
47
5- REGION_NAME = " eu-west-2"
8+ REGION_NAME = os . getenv ( "AWS_REGION" , " eu-west-2")
69
710s3_client = boto3_client ("s3" , region_name = REGION_NAME )
811kinesis_client = boto3_client ("kinesis" , region_name = REGION_NAME )
912lambda_client = boto3_client ("lambda" , region_name = REGION_NAME )
1013firehose_client = boto3_client ("firehose" , region_name = REGION_NAME )
1114sqs_client = boto3_client ("sqs" , region_name = REGION_NAME )
15+
16+ REDIS_HOST = os .getenv ("REDIS_HOST" , "" )
17+ REDIS_PORT = int (os .getenv ("REDIS_PORT" , 6379 ))
18+
19+
20+ logging .basicConfig (level = "INFO" )
21+ logger = logging .getLogger ()
22+ logger .setLevel ("INFO" )
23+ logger .info (f"Connecting to Redis at { REDIS_HOST } :{ REDIS_PORT } " )
24+
25+ redis_client = redis .StrictRedis (host = REDIS_HOST , port = REDIS_PORT , decode_responses = True )
Original file line number Diff line number Diff line change @@ -265,3 +265,27 @@ class RecordProcessorError(Exception):
265265
266266 def __init__ (self , diagnostics_dictionary : dict ):
267267 self .diagnostics_dictionary = diagnostics_dictionary
268+
269+ class VaccineTypePermissionsError (Exception ):
270+ """
271+ Raised when a supplier tries to access a vaccine type they don't have permission for.
272+ """
273+
274+ def __init__ (self , message : str ):
275+ super ().__init__ (message )
276+ self .message = message
277+
278+ def to_operation_outcome (self ) -> dict :
279+ """
280+ Converts the error to a FHIR-compliant OperationOutcome resource.
281+ """
282+ return {
283+ "resourceType" : "OperationOutcome" ,
284+ "issue" : [
285+ {
286+ "severity" : "error" ,
287+ "code" : "forbidden" ,
288+ "diagnostics" : self .message ,
289+ }
290+ ]
291+ }
Original file line number Diff line number Diff line change 1+ from clients import redis_client
2+ from errors import VaccineTypePermissionsError
3+ import json
4+
5+ def get_supplier_permissions (supplier : str ) -> list [str ]:
6+ permissions_data = redis_client .hget ("supplier_permissions" , supplier )
7+ if not permissions_data :
8+ return []
9+ return json .loads (permissions_data )
10+
11+ def validate_vaccine_type_permissions (vaccine_type : str , supplier : str ):
12+ permissions = get_supplier_permissions (supplier )
13+ if not any (vaccine_type in perm for perm in permissions ):
14+ raise VaccineTypePermissionsError (f"{ supplier } is not allowed to access { vaccine_type } " )
You can’t perform that action at this time.
0 commit comments