adding a default action type
diff --git a/api-gateway-config/scripts/lua/lib/filemgmt.lua b/api-gateway-config/scripts/lua/lib/filemgmt.lua
index 3be5256..9962251 100644
--- a/api-gateway-config/scripts/lua/lib/filemgmt.lua
+++ b/api-gateway-config/scripts/lua/lib/filemgmt.lua
@@ -18,9 +18,9 @@
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
---- @module
---
--- @author Alex Song (songs)
+--- @module filemgmt
+-- Creates the Nginx Conf files
+-- @author Alex Song (songs), David Green (greend)
local utils = require "lib/utils"
local cjson = require "cjson"
diff --git a/api-gateway-config/scripts/lua/lib/utils.lua b/api-gateway-config/scripts/lua/lib/utils.lua
index fe49819..3d2cc10 100644
--- a/api-gateway-config/scripts/lua/lib/utils.lua
+++ b/api-gateway-config/scripts/lua/lib/utils.lua
@@ -18,11 +18,10 @@
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
---- @module
---
--- @author Alex Song (songs), Cody Walker (cmwalker)
+--- @module utils
+-- Holds the common supporting functions in one file to be referenced else where
+-- @author Alex Song (songs), Cody Walker (cmwalker), David Green (greend)
-local cjson = require "cjson"
local _Utils = {}
--- Concatenate a list of strings into a single string. This is more efficient than concatenating
diff --git a/api-gateway-config/scripts/lua/policies/mapping.lua b/api-gateway-config/scripts/lua/policies/mapping.lua
index a970bf4..6748fe3 100644
--- a/api-gateway-config/scripts/lua/policies/mapping.lua
+++ b/api-gateway-config/scripts/lua/policies/mapping.lua
@@ -20,6 +20,7 @@
--- @module mapping
-- Process mapping object, turning implementation details into request transformations
+-- @author Cody Walker (cmwalker), Alex Song (songs), David Green (greend)
local logger = require "lib/logger"
local utils = require "lib/utils"
@@ -43,6 +44,8 @@
removeParam(v)
elseif v.action == "transform" then
transformParam(v)
+ elseif v.action == "default" then
+ checkDefault(v)
else
logger.err(utils.concatStrings({'Map action not recognized. Skipping... ', v.action}))
end
@@ -62,7 +65,6 @@
for k, v in pairs (incomingQuery) do
query[k] = v
end
-
end
--- Insert parameter value to header, body, or query params into request
@@ -116,6 +118,18 @@
end
end
+--- Checks if the header has been set, and sets the header to a value if found to be null.
+-- @param m Header name and value to be set, if header is null.
+function checkDefault(m)
+ if m.to.location == "header" and headers[m.to.name] == nil then
+ insertHeader(m.to.name, m.from.value)
+ elseif m.to.location == "query" and query[m.to.name] == nil then
+ insertQuery(m.to.name, m.from.value)
+ elseif m.to.location == "body" and body[m.to.name] == nil then
+ insertBody(m.to.name, m.from.value)
+ end
+end
+
--- Function to handle wildcarding in the transform process.
-- If the value in the from object is '*', this function will pull all values from the incoming request
-- and move them to the location provided in the to object
@@ -181,6 +195,7 @@
function insertHeader(k, v)
ngx.req.set_header(k, v)
+ headers[k] = v
end
function insertQuery(k, v)
@@ -211,7 +226,7 @@
function parseUrl(url)
local map = {}
- for k,v in url:gmatch('([^&=?]+)=([^&=?]+)' ) do
+ for k,v in url:gmatch('([^&=?]+)=([^&=?]+)') do
map[ k ] = decodeQuery(v)
end
return map
diff --git a/api-gateway-config/scripts/lua/routing.lua b/api-gateway-config/scripts/lua/routing.lua
index aab80f5..2eb6a78 100644
--- a/api-gateway-config/scripts/lua/routing.lua
+++ b/api-gateway-config/scripts/lua/routing.lua
@@ -114,7 +114,7 @@
function getUriPath(backendPath)
local uriPath
local i, j = ngx.var.uri:find(ngx.var.gatewayPath)
- local incomingPath = ngx.var.uri:sub(j + 1)
+ local incomingPath = ((j and ngx.var.uri:sub(j + 1)) or nil)
-- Check for backendUrl path
if backendPath == nil or backendPath== '' or backendPath== '/' then
uriPath = (incomingPath and incomingPath ~= '') and incomingPath or '/'