From 20c1bebf69e6117cea3c246d032d0a24116f78ca Mon Sep 17 00:00:00 2001 From: amitkr-22 Date: Fri, 13 Mar 2026 17:45:22 +0000 Subject: [PATCH 1/3] fixed non fhir operation outcome --- azure/templates/post-deploy.yml | 98 +++++++++---------- .../AssignMessage.GPCAuthError400Response.xml | 2 +- ...AssignMessage.ODSNotFoundErrorResponse.xml | 2 +- .../AssignMessage.TooBigBodyErrorResponse.xml | 23 ----- .../resources/jsc/HandleErrorContent.js | 32 ++++-- proxies/live/apiproxy/targets/target.xml | 6 -- proxies/live/apiproxy/targets/targetdev.xml | 6 -- terraform/api/lambda.tf | 2 +- terraform/mock-provider/container_image.tf | 2 +- tests/test_endpoints.py | 52 +++++----- tests/test_mock_provider.py | 2 +- 11 files changed, 106 insertions(+), 121 deletions(-) delete mode 100644 proxies/live/apiproxy/policies/AssignMessage.TooBigBodyErrorResponse.xml diff --git a/azure/templates/post-deploy.yml b/azure/templates/post-deploy.yml index ce56ed2..099f68d 100644 --- a/azure/templates/post-deploy.yml +++ b/azure/templates/post-deploy.yml @@ -35,55 +35,55 @@ steps: profile: "apim-dev" aws_account: "dev" - #- bash: | - # set -e - # if ! [[ $APIGEE_ENVIRONMENT =~ .*-*sandbox ]]; then - # export AWS_PROFILE=apim-dev - # aws_account_no="$(aws sts get-caller-identity --query Account --output text)" - - # service_name=$(FULLY_QUALIFIED_SERVICE_NAME) - - # introspection_client_id=$(INTROSPECTION_CLIENT_ID) - # introspection_client_secret=$(INTROSPECTION_CLIENT_SECRET) - # if [[ $APIGEE_ENVIRONMENT = int ]]; then - # introspection_client_id=$(INTROSPECTION_CLIENT_ID_INT) - # introspection_client_secret=$(INTROSPECTION_CLIENT_SECRET_INT) - # fi - - # pr_no=$(echo $service_name | { grep -oE '[0-9]+$' || true; }) - # if [ -z $pr_no ]; then - # workspace=$APIGEE_ENVIRONMENT - # else - # workspace=pr-$pr_no - # fi - - # echo Deploy mock provider with following parameters: - # echo service_name: $service_name - # echo workspace: $workspace - # echo Apigee environment: $APIGEE_ENVIRONMENT - # echo pr_no: $pr_no - # echo introspection client id: $introspection_client_id - - # cd terraform - - # make init - # make apply aws_account_no=${aws_account_no} environment=$workspace \ - # client_id=$introspection_client_id \ - # client_secret=$introspection_client_secret \ - # keycloak_environment=$APIGEE_ENVIRONMENT - # cd .. - - # if [ -n "$pr_no" ]; then - # echo add KVM for PR-$pr_no - # source .venv/bin/activate - # domain_name=https://$(make -C terraform -s output name=service_domain_name) - # oauth_endpoint="https://identity.ptl.api.platform.nhs.uk/realms/gpconnect-pfs-mock-$APIGEE_ENVIRONMENT/protocol/openid-connect/token" - # python scripts/apigee_kvm.py --env $APIGEE_ENVIRONMENT --access-token $(secret.AccessToken) populate-interaction-ids gp-connect-user-permissions-endpoints-pr-$pr_no --ods H81109 --provider-endpoint $domain_name --oauth-endpoint $oauth_endpoint - # fi - # fi - # displayName: Deploy mock provider - # workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)" - # retryCountOnTaskFailure: 2 + - bash: | + set -e + if ! [[ $APIGEE_ENVIRONMENT =~ .*-*sandbox || $APIGEE_ENVIRONMENT == "int" ]]; then + export AWS_PROFILE=apim-dev + aws_account_no="$(aws sts get-caller-identity --query Account --output text)" + + service_name=$(FULLY_QUALIFIED_SERVICE_NAME) + + introspection_client_id=$(INTROSPECTION_CLIENT_ID) + introspection_client_secret=$(INTROSPECTION_CLIENT_SECRET) + if [[ $APIGEE_ENVIRONMENT = int ]]; then + introspection_client_id=$(INTROSPECTION_CLIENT_ID_INT) + introspection_client_secret=$(INTROSPECTION_CLIENT_SECRET_INT) + fi + + pr_no=$(echo $service_name | { grep -oE '[0-9]+$' || true; }) + if [ -z $pr_no ]; then + workspace=$APIGEE_ENVIRONMENT + else + workspace=pr-$pr_no + fi + + echo Deploy mock provider with following parameters: + echo service_name: $service_name + echo workspace: $workspace + echo Apigee environment: $APIGEE_ENVIRONMENT + echo pr_no: $pr_no + echo introspection client id: $introspection_client_id + + cd terraform + + make init + make apply aws_account_no=${aws_account_no} environment=$workspace \ + client_id=$introspection_client_id \ + client_secret=$introspection_client_secret \ + keycloak_environment=$APIGEE_ENVIRONMENT + cd .. + + if [ -n "$pr_no" ]; then + echo add KVM for PR-$pr_no + source .venv/bin/activate + domain_name=https://$(make -C terraform -s output name=service_domain_name) + oauth_endpoint="https://identity.ptl.api.platform.nhs.uk/realms/gpconnect-pfs-mock-$APIGEE_ENVIRONMENT/protocol/openid-connect/token" + python scripts/apigee_kvm.py --env $APIGEE_ENVIRONMENT --access-token $(secret.AccessToken) populate-interaction-ids gp-connect-user-permissions-endpoints-pr-$pr_no --ods H81109 --provider-endpoint $domain_name --oauth-endpoint $oauth_endpoint + fi + fi + displayName: Deploy mock provider + workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)" + retryCountOnTaskFailure: 2 - bash: | set -e diff --git a/proxies/live/apiproxy/policies/AssignMessage.GPCAuthError400Response.xml b/proxies/live/apiproxy/policies/AssignMessage.GPCAuthError400Response.xml index 19f509d..5febac0 100644 --- a/proxies/live/apiproxy/policies/AssignMessage.GPCAuthError400Response.xml +++ b/proxies/live/apiproxy/policies/AssignMessage.GPCAuthError400Response.xml @@ -8,7 +8,7 @@ "issue": [ { "severity": "error", - "code": "400", + "code": "exception", "details": { "coding": [{"code": "400", "display": "Bad Request"}] diff --git a/proxies/live/apiproxy/policies/AssignMessage.ODSNotFoundErrorResponse.xml b/proxies/live/apiproxy/policies/AssignMessage.ODSNotFoundErrorResponse.xml index a7b5c35..14ab5cf 100644 --- a/proxies/live/apiproxy/policies/AssignMessage.ODSNotFoundErrorResponse.xml +++ b/proxies/live/apiproxy/policies/AssignMessage.ODSNotFoundErrorResponse.xml @@ -8,7 +8,7 @@ "issue": [ { "severity": "error", - "code": "Bad Request", + "code": "value", "details": { "coding": [{"code": "BAD_REQUEST", "display": "ODS code not found"}] }, diff --git a/proxies/live/apiproxy/policies/AssignMessage.TooBigBodyErrorResponse.xml b/proxies/live/apiproxy/policies/AssignMessage.TooBigBodyErrorResponse.xml deleted file mode 100644 index 41d5b97..0000000 --- a/proxies/live/apiproxy/policies/AssignMessage.TooBigBodyErrorResponse.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - 400 - - { - "resourceType": "OperationOutcome", - "issue": [ - { - "severity": "error", - "code": "Bad Request", - "details": { - "coding": [{"code": "BAD_REQUEST", "display": "Response body exceeded buffer limit"}] - }, - "diagnostics": "Body buffer overflow: response exceeded 10MB limit" - } - ] - } - - - true - - \ No newline at end of file diff --git a/proxies/live/apiproxy/resources/jsc/HandleErrorContent.js b/proxies/live/apiproxy/resources/jsc/HandleErrorContent.js index c04c89e..a53903e 100644 --- a/proxies/live/apiproxy/resources/jsc/HandleErrorContent.js +++ b/proxies/live/apiproxy/resources/jsc/HandleErrorContent.js @@ -21,6 +21,26 @@ if (parsed && parsed.resourceType === "OperationOutcome") { context.setVariable("Error-Handled", "passthrough"); } +// --- For Body buffer overflow --- +else if (parsed && parsed.fault && parsed.fault.faultstring === "Body buffer overflow") { + error.status.code = "400" + responseContent = { + resourceType: "OperationOutcome", + issue: [ + { + severity: "error", + code: "processing", + details: { + coding: [{ system: "https://fhir.nhs.uk/R4/CodeSystem/Spine-ErrorOrWarningCode", code: "BAD_GATEWAY_BUFFER_OVERFLOW", display: "Response body exceeded buffer limit" }] + }, + diagnostics: "Body buffer overflow: response exceeded 10MB limit" + } + ] + }; + context.setVariable("Error-Handled", "transformed-raisefault"); + +} + // --- Apigee RaiseFault / ServiceCallout format --- else if (parsed && parsed.fault && parsed.fault.faultstring) { responseContent = { @@ -28,9 +48,9 @@ else if (parsed && parsed.fault && parsed.fault.faultstring) { issue: [ { severity: "error", - code: statusCode.toString(), + code: "exception", details: { - coding: [{ code: statusCode.toString(), display: reasonPhrase }] + coding: [{ system: "https://fhir.nhs.uk/R4/CodeSystem/Spine-ErrorOrWarningCode", code: statusCode.toString(), display: reasonPhrase }] }, diagnostics: parsed.fault.faultstring } @@ -47,9 +67,9 @@ else if (parsed && parsed.faultstring) { issue: [ { severity: "error", - code: statusCode.toString(), + code: "exception", details: { - coding: [{ code: statusCode.toString(), display: reasonPhrase }] + coding: [{ system: "https://fhir.nhs.uk/R4/CodeSystem/Spine-ErrorOrWarningCode", code: statusCode.toString(), display: reasonPhrase }] }, diagnostics: parsed.faultstring } @@ -65,9 +85,9 @@ else { issue: [ { severity: "error", - code: statusCode.toString(), + code: "exception", details: { - coding: [{ code: statusCode.toString(), display: reasonPhrase }] + coding: [{ system: "https://fhir.nhs.uk/R4/CodeSystem/Spine-ErrorOrWarningCode", code: statusCode.toString(), display: reasonPhrase }] }, diagnostics: errorContent || "" } diff --git a/proxies/live/apiproxy/targets/target.xml b/proxies/live/apiproxy/targets/target.xml index cbe20da..707f3f2 100644 --- a/proxies/live/apiproxy/targets/target.xml +++ b/proxies/live/apiproxy/targets/target.xml @@ -98,12 +98,6 @@ endpoints = null - - - AssignMessage.TooBigErrorResponse - - fault.errorcode = "protocol.http.TooBigBody" - diff --git a/proxies/live/apiproxy/targets/targetdev.xml b/proxies/live/apiproxy/targets/targetdev.xml index abde3b5..8981deb 100644 --- a/proxies/live/apiproxy/targets/targetdev.xml +++ b/proxies/live/apiproxy/targets/targetdev.xml @@ -108,12 +108,6 @@ endpoints = null - - - AssignMessage.TooBigErrorResponse - - fault.errorcode = "protocol.http.TooBigBody" - diff --git a/terraform/api/lambda.tf b/terraform/api/lambda.tf index 4240aef..934f1d6 100644 --- a/terraform/api/lambda.tf +++ b/terraform/api/lambda.tf @@ -26,7 +26,7 @@ resource "null_resource" "push_token_validator_image" { interpreter = ["bash", "-c"] command = < Date: Fri, 13 Mar 2026 17:52:06 +0000 Subject: [PATCH 2/3] fixed lint issues --- tests/test_endpoints.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index a123688..d15853d 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -8,7 +8,7 @@ import pytest import os from os import getenv -# from .example_loader import load_example +from .example_loader import load_example @pytest.fixture() @@ -118,16 +118,16 @@ def test_nhs_login_p9(nhsd_apim_proxy_url, nhsd_apim_auth_headers): } ) def test_prism_returns_external_file(nhsd_apim_proxy_url, nhsd_apim_auth_headers): - headers = { - "accept": "*/*", - "X-Correlation-ID": "11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA", - "X-Request-ID": "60E0B220-8136-4CA5-AE46-1D97EF59D068" - } - headers.update(nhsd_apim_auth_headers) - - resp = requests.get( - f"{nhsd_apim_proxy_url}/Patient/9000000009", - headers=headers - ) - expected_response = load_example("GetResponsePermissionsFull.yaml") - assert resp.json() == expected_response.get("value") + headers = { + "accept": "*/*", + "X-Correlation-ID": "11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA", + "X-Request-ID": "60E0B220-8136-4CA5-AE46-1D97EF59D068" + } + headers.update(nhsd_apim_auth_headers) + + resp = requests.get( + f"{nhsd_apim_proxy_url}/Patient/9000000009", + headers=headers + ) + expected_response = load_example("GetResponsePermissionsFull.yaml") + assert resp.json() == expected_response.get("value") From 1c6b8271f5096848d3839b83a34362c9bc93b0fc Mon Sep 17 00:00:00 2001 From: amitkr-22 Date: Fri, 13 Mar 2026 18:22:16 +0000 Subject: [PATCH 3/3] fixed post deploy yaml --- azure/templates/post-deploy.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azure/templates/post-deploy.yml b/azure/templates/post-deploy.yml index 099f68d..c06ae54 100644 --- a/azure/templates/post-deploy.yml +++ b/azure/templates/post-deploy.yml @@ -81,9 +81,9 @@ steps: python scripts/apigee_kvm.py --env $APIGEE_ENVIRONMENT --access-token $(secret.AccessToken) populate-interaction-ids gp-connect-user-permissions-endpoints-pr-$pr_no --ods H81109 --provider-endpoint $domain_name --oauth-endpoint $oauth_endpoint fi fi - displayName: Deploy mock provider - workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)" - retryCountOnTaskFailure: 2 + displayName: Deploy mock provider + workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)" + retryCountOnTaskFailure: 2 - bash: | set -e