Skip to content

Commit

Permalink
Implement request.path for path parameter mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsong93 authored and mhamann committed Nov 9, 2017
1 parent 055b262 commit cd556b2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doc/v2/management_interface_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ See below for a list of policies that are supported in the gateway and how they
}
```
* `target-url`: the backend url
* _optional:_ to pass the path of your managed url down to the `target-url`, append `/${request.path}` to the end of `target-url`.
Eg. `"target-url": "https://openwhisk.ng.bluemix.net/api/some/action/path.http/${request.path}"`
* `verb`: the method to use when invoking the target-url (use "keep" to use the keep the same verb as the API)

To set a different `target-url` for different paths, use the `operation-switch` policy inside `x-gateway-configuration`.
Expand Down
12 changes: 9 additions & 3 deletions scripts/lua/policies/backendRouting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@ local logger = require "lib/logger"
local _M = {}

--- Set upstream based on the backendUrl
function _M.setRoute(backendUrl)
function _M.setRoute(backendUrl, gatewayPath)
local u = url.parse(backendUrl)
if u.scheme == nil then
u = url.parse(utils.concatStrings({'http://', backendUrl}))
end
-- pass down gateway path to upstream path if $(request.path) is specified at the end of backendUrl
if u.path:sub(-15) == '$(request.path)' then
u.path = utils.concatStrings({u.path:sub(1, -16), u.path:sub(-16, -16) == '/' and '' or '/', gatewayPath})
ngx.req.set_uri(u.path)
else
ngx.req.set_uri(getUriPath(u.path))
end
ngx.var.backendUrl = backendUrl
ngx.req.set_uri(getUriPath(u.path))
setUpstream(u)
end

--- Set dynamic route based on the based on the header that is passed in
--- Set dynamic route based on the header that is passed in
function _M.setDynamicRoute(obj)
local whitelist = obj.whitelist
for k in pairs(whitelist) do
Expand Down
3 changes: 2 additions & 1 deletion scripts/lua/routing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local cjson = require "cjson"
local url = require "url"
local utils = require "lib/utils"
local request = require "lib/request"
local logger = require "lib/logger"
-- load policies
local security = require "policies/security"
local mapping = require "policies/mapping"
Expand Down Expand Up @@ -85,7 +86,7 @@ function _M.processCall(dataStore)
setVerb(opFields.backendMethod)
end
-- Set backend upstream and uri
backendRouting.setRoute(opFields.backendUrl)
backendRouting.setRoute(opFields.backendUrl, gatewayPath)
-- Parse policies
if opFields.policies ~= nil then
parsePolicies(dataStore, opFields.policies, key)
Expand Down
2 changes: 1 addition & 1 deletion tools/travis/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export OPENWHISK_HOME=$WHISKDIR
# Tests
cd $WHISKDIR
cat whisk.properties
WSK_TESTS_DEPS_EXCLUDE="-x :core:swift3Action:distDocker -x :core:pythonAction:distDocker -x :core:javaAction:distDocker -x :core:nodejsAction:distDocker -x :core:actionProxy:distDocker -x :sdk:docker:distDocker -x :core:python2Action:copyFiles -x :core:python2Action:distDocker -x :tests:dat:blackbox:badaction:distDocker -x :tests:dat:blackbox:badproxy:distDocker"
WSK_TESTS_DEPS_EXCLUDE="-x :core:swift3Action:distDocker -x :core:pythonAction:distDocker -x :core:javaAction:distDocker -x :core:nodejsAction:distDocker -x :core:actionProxy:distDocker -x :sdk:docker:distDocker -x :core:python2Action:distDocker -x :tests:dat:blackbox:badaction:distDocker -x :tests:dat:blackbox:badproxy:distDocker"
TERM=dumb ./gradlew tests:test --tests apigw.healthtests.* ${WSK_TESTS_DEPS_EXCLUDE}
sleep 60
TERM=dumb ./gradlew tests:test --tests whisk.core.apigw.* ${WSK_TESTS_DEPS_EXCLUDE}
Expand Down

0 comments on commit cd556b2

Please sign in to comment.