Skip to content

Commit

Permalink
Merge pull request #252 from NHSDigital/em-1514-pass-product-and-devi…
Browse files Browse the repository at this point in the history
…ce-id-to-backend

EM-1514 Pass product and device id to backend
  • Loading branch information
acarriedev authored Jan 9, 2025
2 parents 96a2c4b + be72c91 commit 142dbb9
Show file tree
Hide file tree
Showing 25 changed files with 285 additions and 334 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ PROD_TEST_CMD := $(TEST_CMD) \
--apigee-app-id=$(APIGEE_APP_ID) \
--apigee-organization=nhsd-prod \
--status-endpoint-api-key=$(STATUS_ENDPOINT_API_KEY) \
-k "test_wait_for_status"
-s

#Command to run end-to-end smoketests post-deployment to verify the environment is working
smoketest:
Expand Down
5 changes: 2 additions & 3 deletions azure/azure-pr-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ extends:
- environment: internal-dev
post_deploy:
- template: ./templates/run-tests.yml
parameters:
app_id: "73ee66da-247c-49be-8822-d23aaf4823ec"
full: true
- environment: internal-dev-sandbox
proxy_path: sandbox
post_deploy:
- template: ./templates/run-tests.yml
parameters:
test_command: make smoketest
17 changes: 8 additions & 9 deletions azure/azure-release-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,32 @@ extends:
- environment: internal-dev
post_deploy:
- template: ./templates/run-tests.yml
parameters:
full: true
- environment: internal-dev-sandbox
proxy_path: sandbox
post_deploy:
- template: ./templates/run-tests.yml
- environment: internal-qa
- environment: internal-qa-sandbox
proxy_path: sandbox
parameters:
test_command: make smoketest
- environment: ref
post_deploy:
- template: ./templates/run-tests.yml
- environment: sandbox
proxy_path: sandbox
post_deploy:
- template: ./templates/run-tests.yml
parameters:
test_command: make smoketest
- environment: int
post_deploy:
- template: ./templates/run-tests.yml
parameters:
app_id: "0d334714-4548-4cf7-8b7f-ac194f341bc6"
full: true
test_command: make test-prod
test_command: make smoketest-prod
- environment: prod
depends_on:
- int
post_deploy:
- template: ./templates/run-tests.yml
parameters:
app_id: "0d334714-4548-4cf7-8b7f-ac194f341bc6"
full: true
test_command: make test-prod
test_command: make smoketest-prod
59 changes: 16 additions & 43 deletions azure/templates/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ parameters:
- name: app_id
type: string
default: ""
- name: full
type: boolean
default: false
- name: test_command
type: string
default: 'make test'
- name: smoketest_command
type: string
default: 'make smoketest'
default: make test

steps:
- bash: |
Expand All @@ -19,39 +13,18 @@ steps:
displayName: Setup pytests
condition: always()
- ${{ if parameters.full }}:
# In order to run tests in prod you must supply the unique ID of an Apigee app
# that has authorized access to your service proxy.
- bash: |
export PROXY_NAME="$(FULLY_QUALIFIED_SERVICE_NAME)"
export APIGEE_ACCESS_TOKEN="$(secret.AccessToken)"
export APIGEE_APP_ID=${{ parameters.app_id }}
export STATUS_ENDPOINT_API_KEY="$(STATUS_ENDPOINT_API_KEY)"
export SOURCE_COMMIT_ID="$(Build.SourceVersion)"
${{ parameters.test_command }}
workingDirectory: $(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)
displayName: Run full test suite
- task: PublishTestResults@2
displayName: 'Publish test results'
condition: always()
inputs:
testResultsFiles: '$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/test-report.xml'
failTaskOnFailedTests: true
- ${{ if not(parameters.full) }}:
# In order to run tests in prod you must supply the unique ID of an Apigee app
# that has authorized access to your service proxy.
- bash: |
export PROXY_NAME="$(FULLY_QUALIFIED_SERVICE_NAME)"
export APIGEE_ACCESS_TOKEN="$(secret.AccessToken)"
export APIGEE_APP_ID=${{ parameters.app_id }}
export STATUS_ENDPOINT_API_KEY="$(STATUS_ENDPOINT_API_KEY)"
export SOURCE_COMMIT_ID="$(Build.SourceVersion)"
${{ parameters.smoketest_command }}
workingDirectory: $(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)
displayName: Run smoketests
- task: PublishTestResults@2
displayName: 'Publish smoketest results'
condition: always()
inputs:
testResultsFiles: '$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/smoketest-report.xml'
failTaskOnFailedTests: true
- bash: |
export PROXY_NAME="$(FULLY_QUALIFIED_SERVICE_NAME)"
export APIGEE_ACCESS_TOKEN="$(secret.AccessToken)"
export APIGEE_APP_ID=${{ parameters.app_id }}
export STATUS_ENDPOINT_API_KEY="$(STATUS_ENDPOINT_API_KEY)"
export SOURCE_COMMIT_ID="$(Build.SourceVersion)"
${{ parameters.test_command }}
workingDirectory: $(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)
displayName: Run full test suite
- task: PublishTestResults@2
displayName: 'Publish test results'
condition: always()
inputs:
testResultsFiles: '$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/test-report.xml'
failTaskOnFailedTests: true
9 changes: 2 additions & 7 deletions manifest_template.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
SERVICE_NAME: multicast-notification-service
PRODUCT_DISPLAY_NAME: multicast-notification-service
DESCRIPTION: The multicast notification service
PRODUCT_DISPLAY_NAME: Multicast Notification Service API
DESCRIPTION: Publish and receive patient-related state changes from a single centralised system
APIGEE_ENVIRONMENTS:
- name: internal-dev
display_name: Internal Development
has_mock_auth: true
- name: internal-dev-sandbox
display_name: Internal Development Sandbox
- name: internal-qa
display_name: Internal QA
has_mock_auth: true
- name: ref
display_name: Reference
has_mock_auth: true
- name: internal-qa-sandbox
display_name: Internal QA Sandbox
- name: sandbox
display_name: Sandbox
has_mock_auth: true
Expand Down
4 changes: 2 additions & 2 deletions proxies/live/apiproxy/policies/AssignMessage.AddCors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<Set>
<Headers>
<Header name="Access-Control-Allow-Origin">{request.header.origin}</Header>
<Header name="Access-Control-Allow-Headers">origin, x-requested-with, accept, accept-encoding, content-type, content-length, host, nhsd-correlation-id, nhsd-request-id, user-agent, x-correlation-id, x-forwarded-for, x-forwarded-port, x-forwarded-proto, authorization, x-application-id, x-application-name, x-application-mesh-mailboxes, x-mns-application-permissions, x-mns-application-product-id</Header>
<Header name="Access-Control-Expose-Headers">origin, x-requested-with, accept, accept-encoding, content-type, content-length, host, nhsd-correlation-id, nhsd-request-id, user-agent, x-correlation-id, x-forwarded-for, x-forwarded-port, x-forwarded-proto, authorization, x-application-id, x-application-name, x-application-mesh-mailboxes, x-mns-application-permissions, x-mns-application-product-id</Header>
<Header name="Access-Control-Allow-Headers">origin, x-requested-with, accept, accept-encoding, content-type, content-length, host, nhsd-correlation-id, nhsd-request-id, user-agent, x-correlation-id, x-forwarded-for, x-forwarded-port, x-forwarded-proto, authorization, x-application-id, x-application-name, x-application-mesh-mailboxes, x-mns-application-permissions, nhse-product-id, nhse-product-device-id</Header>
<Header name="Access-Control-Expose-Headers">origin, x-requested-with, accept, accept-encoding, content-type, content-length, host, nhsd-correlation-id, nhsd-request-id, user-agent, x-correlation-id, x-forwarded-for, x-forwarded-port, x-forwarded-proto, authorization, x-application-id, x-application-name, x-application-mesh-mailboxes, x-mns-application-permissions, nhse-product-id, nhse-product-device-id</Header>
<Header name="Access-Control-Max-Age">3628800</Header>
<Header name="Access-Control-Allow-Methods">GET, PUT, POST, DELETE</Header>
</Headers>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="Javascript.SetStatusResponse">
<DisplayName>Javascript.SetStatusResponse</DisplayName>
<Properties/>
<ResourceURL>jsc://setStatusResponse.js</ResourceURL>
</Javascript>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="Javascript.SetTargetAttributes">
<ResourceURL>jsc://setTargetAttributes.js</ResourceURL>
</Javascript>

This file was deleted.

2 changes: 1 addition & 1 deletion proxies/live/apiproxy/proxies/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</Request>
<Response>
<Step>
<Name>javascript.SetStatusResponse</Name>
<Name>Javascript.SetStatusResponse</Name>
</Step>
</Response>
<Condition>(proxy.pathsuffix MatchesPath "/_status") and ((request.verb = "GET") or (request.verb = "HEAD"))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const apiproxy_revision = context.getVariable('apiproxy.revision');
const apiproxy_revision = context.getVariable("apiproxy.revision");

const healthcheck_status_code = context.getVariable('healthcheckResponse.status.code');
const healthcheck_request_url = context.getVariable('healthcheckRequest.url');
const healthcheck_status_code = context.getVariable("healthcheckResponse.status.code");
const healthcheck_request_url = context.getVariable("healthcheckRequest.url");
const healthcheck_failed = context.getVariable("servicecallout.ServiceCallout.CallHealthcheckEndpoint.failed");

function json_tryparse(raw) {
Expand All @@ -13,15 +13,15 @@ function json_tryparse(raw) {
}
}

const healthcheck_content = json_tryparse(context.getVariable('healthcheckResponse.content'));
const healthcheck_content = json_tryparse(context.getVariable("healthcheckResponse.content"));
const healthcheck_status = (healthcheck_status_code/100 === 2) ? "pass" : "fail";
const timeout = (healthcheck_status_code === null && healthcheck_failed) ? "true" : "false";

const final_status = (healthcheck_status !== "pass") ? "fail" : "pass";

const resp = {
"status" : final_status,
"version" : "{{ DEPLOYED_VERSION }}" ,
"version" : "{{ DEPLOYED_VERSION }}",
"revision" : apiproxy_revision,
"releaseId" : "{{ RELEASE_RELEASEID }}",
"commitId": "{{ SOURCE_COMMIT_ID }}",
Expand Down
19 changes: 19 additions & 0 deletions proxies/live/apiproxy/resources/jsc/setTargetAttributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// NO MORE CUSTOM ATTRIBUTES SHOULD BE ADDED IN THIS WAY
// There is a limit on custom attributes per app and if apps have many api connections
// this limit could be easily hit. The exception would be potential global custom attributes
// e.g. product-id, product-device-id

// If we need to add more then use extended attributes. See:
// https://nhsd-confluence.digital.nhs.uk/display/APM/ExtendedAttributes+shared+flow

const appPermissions = context.getVariable("app.permissions");
context.targetRequest.headers["X-MNS-Application-Permissions"] = appPermissions;

const appMeshMailboxes = context.getVariable("app.mesh-mailboxes");
context.targetRequest.headers["X-MNS-Application-Mesh-Mailboxes"] = appMeshMailboxes;

const productId = context.getVariable("app.product-id");
context.targetRequest.headers["NHSE-Product-ID"] = productId;

const productDeviceId = context.getVariable("app.product-device-id");
context.targetRequest.headers["NHSE-Product-Device-ID"] = productDeviceId;
2 changes: 1 addition & 1 deletion proxies/live/apiproxy/targets/target.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Name>FlowCallout.ApplyRateLimiting</Name>
</Step>
<Step>
<Name>Javascript.AddAuthorizationHeader</Name>
<Name>Javascript.SetTargetAttributes</Name>
</Step>
<Step>
<Name>AssignMessage.AddApplicationHeaders</Name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="Javascript.SetStatusResponse">
<DisplayName>Javascript.SetStatusResponse</DisplayName>
<Properties/>
<ResourceURL>jsc://setStatusResponse.js</ResourceURL>
</Javascript>

This file was deleted.

2 changes: 1 addition & 1 deletion proxies/sandbox/apiproxy/proxies/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</Request>
<Response>
<Step>
<Name>javascript.SetStatusResponse</Name>
<Name>Javascript.SetStatusResponse</Name>
</Step>
</Response>
<Condition>(proxy.pathsuffix MatchesPath "/_status") and ((request.verb = "GET") or (request.verb = "HEAD"))
Expand Down
29 changes: 0 additions & 29 deletions tests/data/immunisation-vaccination-event-mds.json

This file was deleted.

29 changes: 0 additions & 29 deletions tests/data/nhs-number-change-event-mds.json

This file was deleted.

29 changes: 0 additions & 29 deletions tests/data/pds-change-of-gp-event-mds.json

This file was deleted.

Loading

0 comments on commit 142dbb9

Please sign in to comment.