diff --git a/.github/workflows/persistent-environment.yml b/.github/workflows/persistent-environment.yml index 8c9b751bc..b352e5a63 100644 --- a/.github/workflows/persistent-environment.yml +++ b/.github/workflows/persistent-environment.yml @@ -54,9 +54,8 @@ jobs: env: ENVIRONMENT: ${{ inputs.environment }} run: | - account=$(echo "$ENVIRONMENT" | cut -d '-' -f1) inactive_stack=$(poetry run python ./scripts/get_env_config.py inactive-stack $ENVIRONMENT) - make get-s3-perms ENV=${account} TF_WORKSPACE_NAME=${inactive_stack} + make get-s3-perms ENV=$ENVIRONMENT TF_WORKSPACE_NAME=${inactive_stack} USE_SHARED_RESOURCES=true - name: Save Build Artifacts uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 diff --git a/scripts/get_s3_permissions.py b/scripts/get_s3_permissions.py index 02030a8a7..32c2ded05 100644 --- a/scripts/get_s3_permissions.py +++ b/scripts/get_s3_permissions.py @@ -276,6 +276,53 @@ def add_smoke_test_files(secretsmanager, local_path, env_name): ] +def add_sandbox_files(local_path): + """Add the permissions required for the sandbox environments. + Only call this function if your want to add sandbox permissions. + These permissions are taken from the existing permissions in the API proxy repos. + """ + sandbox_app_id = "NRL-SANDBOX-APP" + nrl_sandbox_perms = { + "RJ11": [ + PointerTypes.MENTAL_HEALTH_PLAN.value, # http://snomed.info/sct|736253002 + ], + # These ones are needed for the Seed data + "Y05868": [ + PointerTypes.MENTAL_HEALTH_PLAN.value, # http://snomed.info/sct|736253002 + PointerTypes.EMERGENCY_HEALTHCARE_PLAN.value, # http://snomed.info/sct|887701000000100 + PointerTypes.NEWS2_CHART.value, # http://snomed.info/sct|1363501000000100 + PointerTypes.EOL_COORDINATION_SUMMARY.value, # http://snomed.info/sct|861421000000109 + ], + "8J008": [ + PointerTypes.NEWS2_CHART.value + ], # http://snomed.info/sct|1363501000000100 + "RY26A": [ + PointerTypes.EOL_COORDINATION_SUMMARY.value + ], # http://snomed.info/sct|861421000000109 + # This one is needed for Smoke Tests + "RM559": [ + PointerTypes.MENTAL_HEALTH_PLAN.value + ], # http://snomed.info/sct|736253002 + } + + for ods_code, snomed_codes in nrl_sandbox_perms.items(): + _write_permission_file( + Path.joinpath(local_path, "producer", sandbox_app_id), + ods_code, + snomed_codes, + ) + _write_permission_file( + Path.joinpath(local_path, "consumer", sandbox_app_id), + ods_code, + snomed_codes, + ) + _write_v1_permission_file( + Path.joinpath(local_path, sandbox_app_id), + ods_code, + snomed_codes, + ) + + def download_files( s3_client, bucket_name, local_path, file_names, folders, secretsmanager, env_name ): @@ -297,6 +344,10 @@ def download_files( add_feature_test_files(local_path) add_smoke_test_files(secretsmanager, local_path, env_name) + if env_name in ["dev-sandbox", "qa-sandbox", "int-sandbox"]: + print(f"Adding sandbox permissions for {env_name} to temporary directory...") + add_sandbox_files(local_path) + def main(use_shared_resources: str, env: str, workspace: str, path_to_store: str): stack_name = env if use_shared_resources else workspace diff --git a/terraform/infrastructure/etc/dev.tfvars b/terraform/infrastructure/etc/dev.tfvars index 9467886a1..545fb4742 100644 --- a/terraform/infrastructure/etc/dev.tfvars +++ b/terraform/infrastructure/etc/dev.tfvars @@ -9,4 +9,4 @@ public_domain = "internal-dev.api.service.nhs.uk" public_sandbox_domain = "internal-dev-sandbox.api.service.nhs.uk" log_retention_period = 90 -enable_reporting = false +enable_reporting = true diff --git a/tests/smoke/conftest.py b/tests/smoke/conftest.py index 4916affc8..56bed11ac 100644 --- a/tests/smoke/conftest.py +++ b/tests/smoke/conftest.py @@ -55,11 +55,18 @@ def producer_client_v1( environment_config: EnvironmentConfig, smoke_test_parameters: SmokeTestParameters ) -> ProducerTestClient: config = environment_config.to_client_config(smoke_test_parameters) + + if ( + environment_config.env_name in ["dev-sandbox", "qa-sandbox", "int-sandbox"] + and smoke_test_parameters.ods_code + ): + client_ods_code = smoke_test_parameters.ods_code + else: + client_ods_code = smoke_test_parameters.v1_ods_code + if environment_config.connect_mode == ConnectMode.INTERNAL: - config.connection_metadata.ods_code = smoke_test_parameters.v1_ods_code - config.custom_headers["NHSD-End-User-Organisation-ODS"] = ( - smoke_test_parameters.v1_ods_code - ) + config.connection_metadata.ods_code = client_ods_code + config.custom_headers["NHSD-End-User-Organisation-ODS"] = client_ods_code return ProducerTestClient(config=config) @@ -68,11 +75,18 @@ def consumer_client_v1( environment_config: EnvironmentConfig, smoke_test_parameters: SmokeTestParameters ) -> ConsumerTestClient: config = environment_config.to_client_config(smoke_test_parameters) + + if ( + environment_config.env_name in ["dev-sandbox", "qa-sandbox", "int-sandbox"] + and smoke_test_parameters.ods_code + ): + client_ods_code = smoke_test_parameters.ods_code + else: + client_ods_code = smoke_test_parameters.v1_ods_code + if environment_config.connect_mode == ConnectMode.INTERNAL: - config.connection_metadata.ods_code = smoke_test_parameters.v1_ods_code - config.custom_headers["NHSD-End-User-Organisation-ODS"] = ( - smoke_test_parameters.v1_ods_code - ) + config.connection_metadata.ods_code = client_ods_code + config.custom_headers["NHSD-End-User-Organisation-ODS"] = client_ods_code return ConsumerTestClient(config=config) diff --git a/tests/smoke/scenarios/1dsync_upsert_delete.py b/tests/smoke/scenarios/1dsync_upsert_delete.py index 6fbc682c5..58a0c1da9 100644 --- a/tests/smoke/scenarios/1dsync_upsert_delete.py +++ b/tests/smoke/scenarios/1dsync_upsert_delete.py @@ -15,7 +15,8 @@ def producer_client_1dsync( if environment_config.connect_mode == ConnectMode.INTERNAL.value: custom_smoke_test_parameters.nrlf_app_id = "SMOKETEST1DSYNC" - custom_smoke_test_parameters.ods_code = "SMOKETEST1DSYNC" + if environment_config.env_name not in ["dev-sandbox", "qa-sandbox", "int-sandbox"]: + custom_smoke_test_parameters.ods_code = "SMOKETEST1DSYNC" client_config = environment_config.to_client_config(custom_smoke_test_parameters) @@ -25,12 +26,17 @@ def producer_client_1dsync( def test_smoke_1dsync_upsert_delete( producer_client_1dsync: ProducerTestClient, smoke_test_parameters: SmokeTestParameters, + environment_config: EnvironmentConfig, test_nhs_numbers: list[str], ): """ Smoke test scenario for 1dsync upsert and delete behaviour """ - test_ods_code = "SMOKETEST1DSYNC" + if environment_config.env_name in ["dev-sandbox", "qa-sandbox", "int-sandbox"]: + test_ods_code = smoke_test_parameters.ods_code + else: + test_ods_code = "SMOKETEST1DSYNC" + test_docref = build_document_reference( nhs_number=test_nhs_numbers[0], custodian=test_ods_code ) diff --git a/tests/smoke/scenarios/consumer_search_read_v1.py b/tests/smoke/scenarios/consumer_search_read_v1.py index cfb26eb9c..9fb9c253d 100644 --- a/tests/smoke/scenarios/consumer_search_read_v1.py +++ b/tests/smoke/scenarios/consumer_search_read_v1.py @@ -2,7 +2,7 @@ import pytest -from tests.smoke.environment import SmokeTestParameters +from tests.smoke.environment import EnvironmentConfig, SmokeTestParameters from tests.smoke.setup import build_document_reference, upsert_test_pointer from tests.utilities.api_clients import ConsumerTestClient, ProducerTestClient @@ -12,8 +12,16 @@ def test_data_v1( test_nhs_numbers: list[str], producer_client_v1: ProducerTestClient, smoke_test_parameters: SmokeTestParameters, -) -> Generator[str, Any, None]: - test_ods_code = smoke_test_parameters.v1_ods_code + environment_config: EnvironmentConfig, +) -> Generator[dict[str, Any], Any, None]: + if ( + environment_config.env_name in ["dev-sandbox", "qa-sandbox", "int-sandbox"] + and smoke_test_parameters.ods_code + ): + test_ods_code = smoke_test_parameters.ods_code + else: + test_ods_code = smoke_test_parameters.v1_ods_code + test_pointers = [ upsert_test_pointer( f"{test_ods_code}-smoketest_consumer_search_read_pointer_{n}", diff --git a/tests/smoke/scenarios/producer_crud_v1.py b/tests/smoke/scenarios/producer_crud_v1.py index 4db76cb20..50012fa6c 100644 --- a/tests/smoke/scenarios/producer_crud_v1.py +++ b/tests/smoke/scenarios/producer_crud_v1.py @@ -1,4 +1,4 @@ -from tests.smoke.environment import SmokeTestParameters +from tests.smoke.environment import EnvironmentConfig, SmokeTestParameters from tests.smoke.setup import build_document_reference from tests.utilities.api_clients import ProducerTestClient @@ -7,11 +7,19 @@ def test_smoke_producer_crud_v1( producer_client_v1: ProducerTestClient, test_nhs_numbers: list[str], smoke_test_parameters: SmokeTestParameters, + environment_config: EnvironmentConfig, ): """ Smoke test scenario for producer CRUD behaviour """ - test_ods_code = smoke_test_parameters.v1_ods_code + if ( + environment_config.env_name in ["dev-sandbox", "qa-sandbox", "int-sandbox"] + and smoke_test_parameters.ods_code + ): + test_ods_code = smoke_test_parameters.ods_code + else: + test_ods_code = smoke_test_parameters.v1_ods_code + test_docref = build_document_reference( nhs_number=test_nhs_numbers[0], custodian=test_ods_code ) diff --git a/tests/smoke/scenarios/producer_search_read_v1.py b/tests/smoke/scenarios/producer_search_read_v1.py index 83f92009e..f7f93ce2e 100644 --- a/tests/smoke/scenarios/producer_search_read_v1.py +++ b/tests/smoke/scenarios/producer_search_read_v1.py @@ -2,7 +2,7 @@ import pytest -from tests.smoke.environment import SmokeTestParameters +from tests.smoke.environment import EnvironmentConfig, SmokeTestParameters from tests.smoke.setup import build_document_reference, upsert_test_pointer from tests.utilities.api_clients import ProducerTestClient @@ -12,8 +12,17 @@ def test_data( test_nhs_numbers: list[str], producer_client_v1: ProducerTestClient, smoke_test_parameters: SmokeTestParameters, -) -> Generator[str, Any, None]: - test_ods_code = smoke_test_parameters.v1_ods_code + environment_config: EnvironmentConfig, +) -> Generator[dict[str, Any], Any, None]: + + if ( + environment_config.env_name in ["dev-sandbox", "qa-sandbox", "int-sandbox"] + and smoke_test_parameters.ods_code + ): + test_ods_code = smoke_test_parameters.ods_code + else: + test_ods_code = smoke_test_parameters.v1_ods_code + test_pointers = [ upsert_test_pointer( f"{test_ods_code}-smoketest_producer_count_search_read_pointer_{n}",