generated from NASA-PDS/template-repo-java
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cloud front function updates for version 1.2.0, makes swagger-ui work on AWS #333
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5935a05
refinement for v1.2.0, add provenance docker README
c2c8d44
adapt aws resource to 1.2.0 upgrade
055f49d
revert outdated/deprecated CICD workflow instructions
f6c1311
fix CICD workflow
531ded4
update aws cloud front script, kept here for tracking/archive purpose
38c7be0
reflect code change in description comments
3a70c10
Merge branch 'main' of https://github.com/NASA-PDS/registry-api into …
0dceb53
Merge branch 'main' into fix_aws_1.2.0
tloubrieu-jpl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
/* | ||
Cloudfront Function which performs URL rewrite to direct requests of the form: | ||
/api/<service>{-node}/<version>/<request> | ||
/api/<service>{-node}/<version>/<request> or /api/<service>{-node}/<version>[/] | ||
to: | ||
/<request> | ||
+ the http header json : { "x-request-node" : { "value" : "<service>{-node}/<version>" } | ||
+ the http header json : { "x-request-node" : { "value" : "<service>{-node}/<version>" }, { "x-forwarded-prefix" : { "value" : "/api/<service>{-node}/<version>" } | ||
|
||
This version also fufills the transition from major.minor to major (only) | ||
|
||
x-forwarded-prefix header is used by swagger-ui | ||
|
||
version specs in the API request. | ||
*/ | ||
|
||
|
@@ -14,74 +17,55 @@ var VER_IDX = 3 | |
var CMD_IDX = 4 | ||
|
||
var TARGET_URI_PREFIX = "/api/search" | ||
var DEBUG_PARAM = "cf_debug" | ||
|
||
// The function is in response to the 'viewer request' event | ||
function handler(event) { | ||
var request = event.request; | ||
var incomingUri = request.uri; | ||
|
||
// See if detailed logging is enabled | ||
var debug = false | ||
if (DEBUG_PARAM in request.querystring) { | ||
debug = true | ||
delete request.querystring[DEBUG_PARAM] | ||
} | ||
|
||
// Strip out any leading multiple slashies - registry-api#208 | ||
while (incomingUri.indexOf("//") >= 0) { | ||
incomingUri = incomingUri.replace("//","/"); | ||
} | ||
|
||
// Put the URI back into the request now in case the rewrite doesn't happen | ||
request.uri = incomingUri | ||
|
||
if (debug) console.log("incoming URI [" + incomingUri + "]") | ||
|
||
|
||
// continue with the rewrite only if "/api/search*" is first in the URI | ||
if (incomingUri.startsWith(TARGET_URI_PREFIX)) { | ||
|
||
if (debug) console.log("incoming URI matches prefix [" + TARGET_URI_PREFIX + "]") | ||
|
||
// split the uri - note that w/ a initial '/' the first element in the resulting | ||
// array will be empty, so be sure to consider this when computing indexes of | ||
// each token | ||
// split the uri | ||
var uriParts = incomingUri.split("/"); | ||
|
||
// at a minimum service, version and command are required (i.e. there are non-empty components in the URI after | ||
// "/api/search/<version>") in order consider a rewrite of the URI, otherwise fall through w/o changes | ||
if (uriParts.length > CMD_IDX && uriParts[CMD_IDX].trim() != "") { | ||
if (debug) console.log("incoming URI includes a command") | ||
|
||
// at a minimum service, version and command are required, otherwise fall through w/o changes | ||
//if (uriParts.length > CMD_IDX && uriParts[CMD_IDX].trim() != "") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove if not required |
||
if (uriParts.length > VER_IDX && uriParts[VER_IDX].trim() != "") { | ||
// ensure that the API version is major version only | ||
var reqVer = uriParts[VER_IDX]; | ||
var majorVer = reqVer.split(".")[0]; | ||
if (debug) console.log("revised request version [" + reqVer + "] to [" + majorVer + "]") | ||
|
||
// extract service and version which are placed in the HTTP header | ||
var resultHeader = uriParts[SVC_IDX] + "/" + majorVer; | ||
if (debug) console.log("x-request-node header value [" + resultHeader + "]") | ||
|
||
// copy the rest of the request path to the new URI | ||
var newUri = ""; | ||
for(var i = CMD_IDX; i < uriParts.length; i++) { | ||
newUri += "/" + uriParts[i]; | ||
if (debug) console.log("appending to URI path [" + uriParts[i] + "]") | ||
} | ||
|
||
// set updated URI into request and set request node header | ||
request.uri = newUri; | ||
request.headers['x-request-node'] = { "value" : resultHeader }; | ||
if (debug) { | ||
console.log("incoming URI [" + incomingUri + "] rewritten to [" + newUri | ||
+ "] & x-request-node [" + resultHeader + "]") | ||
} | ||
request.headers["x-forwarded-prefix"] = {"value": "/api/" + resultHeader}; | ||
|
||
console.log("incoming URI [" + incomingUri + "] rewritten to [" + newUri | ||
+ "] & x-request-node [" + resultHeader + "]") | ||
} else { | ||
if (debug) console.log("incoming URI [" + incomingUri + "] : no rewrite (no command)") | ||
console.log("incoming URI [" + incomingUri + "] : no rewrite (no command)") | ||
} | ||
} else { | ||
if (debug) console.log("incoming URI [" + incomingUri + "] : no rewrite (no prefix match)") | ||
console.log("incoming URI [" + incomingUri + "] : no rewrite (no prefix match)") | ||
} | ||
|
||
return request; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubber-stamping these changes