This is an automated email from the ASF dual-hosted git repository. mhamann pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-apigateway.git
The following commit(s) were added to refs/heads/master by this push: new cd556b2 Implement request.path for path parameter mapping cd556b2 is described below commit cd556b2267436440bb3eda2ce3da3f2427bfe344 Author: Alex Song <so...@us.ibm.com> AuthorDate: Wed Nov 8 14:08:49 2017 -0500 Implement request.path for path parameter mapping --- doc/v2/management_interface_v2.md | 2 ++ scripts/lua/policies/backendRouting.lua | 12 +++++++++--- scripts/lua/routing.lua | 3 ++- tools/travis/build.sh | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/v2/management_interface_v2.md b/doc/v2/management_interface_v2.md index 8518ac6..e8dc851 100644 --- a/doc/v2/management_interface_v2.md +++ b/doc/v2/management_interface_v2.md @@ -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`. diff --git a/scripts/lua/policies/backendRouting.lua b/scripts/lua/policies/backendRouting.lua index bbe21eb..b89f7d9 100644 --- a/scripts/lua/policies/backendRouting.lua +++ b/scripts/lua/policies/backendRouting.lua @@ -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 diff --git a/scripts/lua/routing.lua b/scripts/lua/routing.lua index 4eec452..3fea15b 100644 --- a/scripts/lua/routing.lua +++ b/scripts/lua/routing.lua @@ -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" @@ -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) diff --git a/tools/travis/build.sh b/tools/travis/build.sh index 731a74f..114516c 100755 --- a/tools/travis/build.sh +++ b/tools/travis/build.sh @@ -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} -- To stop receiving notification emails like this one, please contact ['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].