diff --git a/azure/templates/post-deploy.yml b/azure/templates/post-deploy.yml index ce56ed2..c06ae54 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 = <