@@ -169,7 +169,6 @@ def add_feature_test_files(local_path):
169169 "v2-z00z-y11y-x22x" ,
170170 "V1ONLY0D5" ,
171171 [PointerTypes .LLOYD_GEORGE_FOLDER .value ],
172- [],
173172 ), # http://snomed.info/sct|16521000000101
174173 ]
175174 [
@@ -178,11 +177,108 @@ def add_feature_test_files(local_path):
178177 ods_code ,
179178 pointer_types ,
180179 )
181- for app_id , ods_code , pointer_types , access_controls in v1_permissions
180+ for app_id , ods_code , pointer_types in v1_permissions
181+ ]
182+
183+
184+ def add_smoke_test_files (secretsmanager , local_path , env_name ):
185+ """Bake in v2 permissions for the smoke test application so that the
186+ v2 permissions model can be proven via smoke tests without
187+ requiring a dynamic layer rebuild between test setup and test execution.
188+ """
189+
190+ parameters_name = f"nhsd-nrlf--{ env_name } --smoke-test-parameters"
191+
192+ secret_value = secretsmanager .get_secret_value (SecretId = parameters_name )
193+ parameters = json .loads (secret_value ["SecretString" ])
194+ smoke_test_app_id = parameters .get ("nrlf_app_id" )
195+
196+ print ("Adding smoke test v2 permissions to temporary directory..." )
197+ org_permissions = {
198+ "consumer" : [
199+ (
200+ smoke_test_app_id ,
201+ "SMOKETEST" ,
202+ [
203+ PointerTypes .MENTAL_HEALTH_PLAN .value
204+ ], # http://snomed.info/sct|736253002
205+ [],
206+ ),
207+ ],
208+ "producer" : [
209+ (
210+ smoke_test_app_id ,
211+ "SMOKETEST" ,
212+ [
213+ PointerTypes .MENTAL_HEALTH_PLAN .value
214+ ], # http://snomed.info/sct|736253002
215+ [],
216+ ),
217+ (
218+ # For public tests - don't have a separate apigee app for 1DSync
219+ smoke_test_app_id ,
220+ "SMOKETEST1DSYNC" ,
221+ [],
222+ [AccessControls .ALLOW_ALL_TYPES .value ],
223+ ),
224+ ],
225+ }
226+ [
227+ _write_permission_file (
228+ Path .joinpath (local_path , actor_type , app_id ),
229+ ods_code ,
230+ pointer_types ,
231+ access_controls ,
232+ )
233+ for actor_type , entries in org_permissions .items ()
234+ for app_id , ods_code , pointer_types , access_controls in entries
235+ ]
236+ app_permissions = {
237+ "producer" : [
238+ (
239+ "SMOKETEST1DSYNC" ,
240+ [],
241+ [AccessControls .ALLOW_ALL_TYPES .value ],
242+ ),
243+ ],
244+ }
245+ [
246+ _write_permission_file (
247+ Path .joinpath (local_path , actor_type ),
248+ app_id ,
249+ pointer_types ,
250+ access_controls ,
251+ )
252+ for actor_type , entries in app_permissions .items ()
253+ for app_id , pointer_types , access_controls in entries
254+ ]
255+
256+ print ("Adding smoke test v1 permissions to temporary directory..." )
257+ v1_permissions = [
258+ ( # not needed, won't hit this file
259+ "SMOKETEST1DSYNCV1" ,
260+ "SMOKETEST" ,
261+ [],
262+ ),
263+ (
264+ smoke_test_app_id ,
265+ "SMOKETESTV1" ,
266+ [PointerTypes .MENTAL_HEALTH_PLAN .value ], # http://snomed.info/sct|736253002
267+ ),
268+ ]
269+ [
270+ _write_v1_permission_file (
271+ Path .joinpath (local_path , app_id ),
272+ ods_code ,
273+ pointer_types ,
274+ )
275+ for app_id , ods_code , pointer_types in v1_permissions
182276 ]
183277
184278
185- def download_files (s3_client , bucket_name , local_path , file_names , folders ):
279+ def download_files (
280+ s3_client , bucket_name , local_path , file_names , folders , secretsmanager , env_name
281+ ):
186282 print (f"Downloading { len (file_names )} S3 files to temporary directory..." )
187283 local_path = Path (local_path )
188284
@@ -199,6 +295,7 @@ def download_files(s3_client, bucket_name, local_path, file_names, folders):
199295
200296 add_test_files ("K6PerformanceTest" , "Y05868.json" , local_path )
201297 add_feature_test_files (local_path )
298+ add_smoke_test_files (secretsmanager , local_path , env_name )
202299
203300
204301def main (use_shared_resources : str , env : str , workspace : str , path_to_store : str ):
@@ -210,12 +307,15 @@ def main(use_shared_resources: str, env: str, workspace: str, path_to_store: str
210307 s3 = boto_session .client ("s3" )
211308 files , folders = get_file_folders (s3 , bucket )
212309
310+ secretsmanager = boto_session .client ("secretsmanager" , region_name = "eu-west-2" )
213311 download_files (
214312 s3 ,
215313 bucket ,
216314 path .abspath (path .join (path_to_store + "/nrlf_permissions" )),
217315 files ,
218316 folders ,
317+ secretsmanager ,
318+ env_name = env ,
219319 )
220320 print ("Downloaded S3 permissions..." )
221321
0 commit comments