-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NRLF-187] deploy to sandbox env (#18)
Co-authored-by: Joel Klinger <[email protected]>
- Loading branch information
Showing
11 changed files
with
173 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
proxies/sandbox/apiproxy/resources/jsc/ClientRPDetailsHeader.SetRequestHeaders.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* This script is used to set the NHSD-Client-RP-Details header, which is passed | ||
* to the API. | ||
* | ||
* this contains: | ||
* | ||
* developer.app.id - The APIGEE ID associated with the APIGEE App connecting | ||
* developer.app.name - The name of the APIGEE App | ||
* developer.app.nhs-login-minimum-proofing-level - The P0/P5/P9 requirement when using User Based Authentication | ||
* client.ip - The client's IP address | ||
* | ||
*/ | ||
|
||
var clientIP = context.getVariable("client.ip"); | ||
|
||
var clientRpDetailsHeader = { | ||
"developer.app.name": "sandbox-app-not-a-real-app", | ||
"developer.app.id": "sandbox-id-not-a-real-app", | ||
"developer.app.nhs-login-minimum-proofing-level": "not-a-real-proofing-level", | ||
"client.ip": clientIP, | ||
}; | ||
|
||
context.targetRequest.headers["NHSD-Client-RP-Details"] = clientRpDetailsHeader; |
40 changes: 40 additions & 0 deletions
40
proxies/sandbox/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This script reads a mocked (hard-coded, thanks APIGEE...) Custom Attribute which | ||
* in the non-sandbox environments comes from an APIGEE app. These are sent to the API | ||
* as the `NHSD-Connection-Metadata` header. | ||
* | ||
* The Http Header 'NHSD-End-User-Organisation-ODS' is expected. | ||
*/ | ||
|
||
//---- CHANGE AVAILABLE POINTER TYPES FOR EACH ORGANISATION HERE ----// | ||
const nrlPointers = { | ||
RJ11: [ | ||
"https://snomed.info/ict|736253001", | ||
"https://snomed.info/ict|736253002", | ||
], | ||
XYZ: ["https://snomed.info/ict|123", "https://snomed.info/ict|456"], | ||
}; | ||
//-------------------------------------------------------------------// | ||
|
||
(function () { | ||
var odsCode = context.getVariable( | ||
"request.header.NHSD-End-User-Organisation-ODS" | ||
); | ||
if (!odsCode || odsCode.trim().length === 0) { | ||
context.setVariable("badRequest", true); | ||
return; | ||
} | ||
|
||
var nrlPointerTypes = nrlPointers[odsCode]; | ||
if (!nrlPointerTypes) { | ||
context.setVariable("badRequest", true); | ||
return; | ||
} | ||
|
||
var connectionMetadata = { | ||
"nrl.ods-code": odsCode, | ||
"nrl.pointer-types": nrlPointerTypes, | ||
}; | ||
context.targetRequest.headers["NHSD-Connection-Metadata"] = | ||
connectionMetadata; | ||
})(); |
21 changes: 21 additions & 0 deletions
21
proxies/sandbox/apiproxy/resources/jsc/WritePathToVariable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* This JS has been added to rewrite the path | ||
* from /FHIR/R4/xxx | ||
* to /production/xxx | ||
* | ||
* We are required to do this because we are using the AWS Auto Generated | ||
* hostnames for AWS API Gateway and the resulting URL then contains the stage | ||
* name (e.g. "production"), which must be removed. | ||
* | ||
* We do this by calculating a new path and writing it to the `target_path` | ||
* variable. This variable is then used in the TargetEndpoint | ||
* (proxies/live/targets/default.xml) under the HTTPTargetConnection/Path | ||
*/ | ||
|
||
proxyPathsuffix = context.getVariable("proxy.pathsuffix"); // -> /FHIR/R4/DocumentReference | ||
targetPathsuffix = proxyPathsuffix.replace("/FHIR/R4", "/production"); // -> /production/DocumentReference | ||
|
||
// If we don't set this then it will add the "/FHIR/R4/DocumentReference" | ||
context.setVariable("target.copy.pathsuffix", false); | ||
// Write the new path into the variable 'target_path' | ||
context.setVariable("target_path", targetPathsuffix); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import requests | ||
import json | ||
|
||
|
||
def test_ping_endpoint(nhsd_apim_proxy_url): | ||
resp = requests.get(nhsd_apim_proxy_url + "/_ping") | ||
assert resp.status_code == 200 | ||
ping_data = json.loads(resp.text) | ||
assert "version" in ping_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from uuid import uuid4 | ||
|
||
import pytest | ||
import requests | ||
|
||
import urllib.parse | ||
|
||
|
||
@pytest.mark.sandbox | ||
@pytest.mark.parametrize( | ||
["ods_code", "expected"], | ||
[ | ||
[ | ||
"RJ11", | ||
200, | ||
], | ||
[ | ||
"", | ||
400, | ||
], | ||
[ | ||
"VALID_ODS_CODE_BUT_NOT_GRANTED", | ||
403, | ||
], | ||
], | ||
) | ||
def test_smoke(ods_code: str, expected: int, nhsd_apim_proxy_url): | ||
|
||
headers = { | ||
"accept": "application/json; version=1.0", | ||
"x-correlation-id": f"SMOKE:{uuid4()}-odsCode_{ods_code}-expected_{expected}", | ||
"x-request-id": f"{uuid4()}", | ||
"NHSD-End-User-Organisation-ODS": ods_code, | ||
"Authorization": "letmein", | ||
} | ||
|
||
patient_id = urllib.parse.quote("https://fhir.nhs.uk/Id/nhs-number|9278693472") | ||
url = f"{nhsd_apim_proxy_url}/FHIR/R4/DocumentReference?subject={patient_id}" | ||
response = requests.get(url, headers=headers) | ||
assert response.status_code == expected, response.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters