Skip to content

Commit

Permalink
Merge pull request #91 from NHSDigital/feature/NRLF-658-enable-s3-auth-2
Browse files Browse the repository at this point in the history
[NRLF-658] enable-s3-auth
  • Loading branch information
samgardner1-nhs authored Aug 10, 2023
2 parents 85166fe + 075f359 commit 22bec21
Showing 1 changed file with 54 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,64 @@
* }
*/

(function(){
// Read the 'NHSD-End-User-Organisation-ODS' header
var odsCode = context.getVariable('request.header.NHSD-End-User-Organisation-ODS');
if (!odsCode || odsCode.trim().length === 0) {
//This will trigger RaiseFault.400BadRequest.xml - see proxies/deafult.xml in the DefaultFaultRules
return;
}
(function () {
// Read the 'NHSD-End-User-Organisation-ODS' header
var odsCode = context.getVariable(
"request.header.NHSD-End-User-Organisation-ODS"
);
if (!odsCode || odsCode.trim().length === 0) {
//This will trigger RaiseFault.400BadRequest.xml - see proxies/deafult.xml in the DefaultFaultRules
return;
}

// Read the associated `nrl-ods-<ods_code>` custom attribute from the APIGEE app
var nrlPointerTypes = context.getVariable('app.nrl-ods-' + odsCode);
if (!nrlPointerTypes) {
//This will trigger RaiseFault.403NoPointers.xml - see targets/target.xml
return;
}
var enableAuthorizationLookup = context.getVariable(
"app.enable-authorization-lookup"
);

if (enableAuthorizationLookup == "true") {
enableAuthorizationLookup = true;
} else if (enableAuthorizationLookup === null) {
enableAuthorizationLookup = false;
} else {
//This will trigger RaiseFault.403NoPointers.xml - see targets/target.xml
return;
}

var pointerTypes = [];
// Read the associated `nrl-ods-<ods_code>` custom attribute from the APIGEE app
var nrlPointerTypes = context.getVariable("app.nrl-ods-" + odsCode);

if (
(enableAuthorizationLookup === true && nrlPointerTypes) ||
(enableAuthorizationLookup === false && !nrlPointerTypes)
) {
//This will trigger RaiseFault.403NoPointers.xml - see targets/target.xml
return;
}

if (nrlPointerTypes) {
// Convert it into a complex object
var lines = nrlPointerTypes.split(/\s+/);
var pointerTypes = [];
for (var i=0;i<lines.length;i++) {
var line = lines[i];
if (line && line.trim().length !== 0) {
pointerTypes.push(line);
}

for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line && line.trim().length !== 0) {
pointerTypes.push(line);
}
}
}

var odsCodeExtension = context.getVariable(
"request.header.NHSD-End-User-Organisation"
);

var odsCodeExtension = context.getVariable(
"request.header.NHSD-End-User-Organisation"
);

// Build the response
var connectionMetadata = {
"nrl.ods-code": odsCode,
"nrl.ods-code-extension": odsCodeExtension,
"nrl.pointer-types": pointerTypes,
};
context.targetRequest.headers['NHSD-Connection-Metadata'] = connectionMetadata;
// Build the response
var connectionMetadata = {
"nrl.ods-code": odsCode,
"nrl.ods-code-extension": odsCodeExtension,
"nrl.pointer-types": pointerTypes,
"nrl.enable-authorization-lookup": enableAuthorizationLookup,
};
context.targetRequest.headers["NHSD-Connection-Metadata"] =
connectionMetadata;
})();

0 comments on commit 22bec21

Please sign in to comment.