From 075f359601753ebbb129df7ab7f62678482c0642 Mon Sep 17 00:00:00 2001 From: Joel Klinger Date: Tue, 8 Aug 2023 14:27:30 +0100 Subject: [PATCH] [feature/NRLF-658-enable-s3-auth-2] add enable auth lookup metadata --- .../ConnectionMetadata.SetRequestHeaders.js | 102 +++++++++--------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/proxies/live/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js b/proxies/live/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js index 7fd1931..96c7030 100644 --- a/proxies/live/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js +++ b/proxies/live/apiproxy/resources/jsc/ConnectionMetadata.SetRequestHeaders.js @@ -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-` 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-` 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; })();