Skip to content

Commit

Permalink
[feature/NRLF-658-enable-s3-auth-2] add enable auth lookup metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jaklinger authored and Chris Kemp committed Aug 10, 2023
1 parent 923ca78 commit 075f359
Showing 1 changed file with 54 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +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;
}

var enableAuthorizationLookup = context.getVariable(
"app.enable-authorization-lookup"
);

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;
}

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+/);

for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line && line.trim().length !== 0) {
pointerTypes.push(line);
}
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+/);

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 075f359

Please sign in to comment.