Skip to content
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

Fix bug when downloading configs that contain Liquid (portal endpoint with path) #847

Merged
merged 3 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- OpenTracing support [PR #669](https://github.com/3scale/apicast/pull/669), [THREESCALE-1159](https://issues.jboss.org/browse/THREESCALE-1159)
- Generate new policy scaffold from the CLI [PR #682](https://github.com/3scale/apicast/pull/682)
- 3scale batcher policy [PR #685](https://github.com/3scale/apicast/pull/685), [PR #710](https://github.com/3scale/apicast/pull/710), [PR #757](https://github.com/3scale/apicast/pull/757), [PR #786](https://github.com/3scale/apicast/pull/786), [PR #823](https://github.com/3scale/apicast/pull/823), [THREESCALE-1155](https://issues.jboss.org/browse/THREESCALE-1155)
- Liquid templating support in the headers policy configuration [PR #716](https://github.com/3scale/apicast/pull/716), [PR #845](https://github.com/3scale/apicast/pull/845), [THREESCALE-1140](https://issues.jboss.org/browse/THREESCALE-1140)
- Liquid templating support in the headers policy configuration [PR #716](https://github.com/3scale/apicast/pull/716), [PR #845](https://github.com/3scale/apicast/pull/845), [PR #847](https://github.com/3scale/apicast/pull/847), [THREESCALE-1140](https://issues.jboss.org/browse/THREESCALE-1140)
- Ability to modify query parameters in the URL rewriting policy [PR #724](https://github.com/3scale/apicast/pull/724), [PR #818](https://github.com/3scale/apicast/pull/818), [THREESCALE-1139](https://issues.jboss.org/browse/THREESCALE-1139)
- 3scale referrer policy [PR #728](https://github.com/3scale/apicast/pull/728), [PR #777](https://github.com/3scale/apicast/pull/777), [THREESCALE-329](https://issues.jboss.org/browse/THREESCALE-329)
- Liquid templating support in the rate-limit policy [PR #719](https://github.com/3scale/apicast/pull/719), [PR #845](https://github.com/3scale/apicast/pull/845), [THREESCALE-411](https://issues.jboss.org/browse/THREESCALE-411)
- Liquid templating support in the rate-limit policy [PR #719](https://github.com/3scale/apicast/pull/719), [PR #845](https://github.com/3scale/apicast/pull/845), [PR #847](https://github.com/3scale/apicast/pull/847), [THREESCALE-411](https://issues.jboss.org/browse/THREESCALE-411)
- Default credentials policy [PR #741](https://github.com/3scale/apicast/pull/741), [THREESCALE-586](https://issues.jboss.org/browse/THREESCALE-586)
- Configurable caching for the token introspection policy [PR #656](https://github.com/3scale/apicast/pull/656)
- `APICAST_ACCESS_LOG_FILE` env to make the access log location configurable [PR #743](https://github.com/3scale/apicast/pull/743), [THREESCALE-1148](https://issues.jboss.org/browse/THREESCALE-1148)
Expand Down
8 changes: 7 additions & 1 deletion gateway/src/apicast/configuration_loader/remote_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,19 @@ function _M:index(host)

for i=1, #proxy_configs do
local proxy_config = proxy_configs[i].proxy_config

-- Copy the config because parse_service have side-effects. It adds
-- liquid templates in some policies and those cannot be encoded into a
-- JSON. We should get rid of these side effects.
local original_proxy_config = deepcopy(proxy_config)

local service = configuration.parse_service(proxy_config.content)
local issuer, oidc_config = self:oidc_issuer_configuration(service)

if issuer then
config.oidc[i] = { issuer = issuer, config = oidc_config }
end
config.services[i] = proxy_config.content
config.services[i] = original_proxy_config.content
end

return cjson.encode(config)
Expand Down
61 changes: 61 additions & 0 deletions t/configuration-loading-boot-remote.t
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,64 @@ echo '
--- request
GET /t
--- exit_code: 200

=== TEST 4: retrieve config with liquid values using THREESCALE_PORTAL_ENDPOINT with path
should not fail
--- main_config
env THREESCALE_PORTAL_ENDPOINT=http://127.0.0.1:$TEST_NGINX_SERVER_PORT/config;
env APICAST_CONFIGURATION_LOADER=boot;
env THREESCALE_DEPLOYMENT_ENV=production;
env PATH;
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
--- config
location = /t {
content_by_lua_block {
local loader = require('apicast.configuration_loader.remote_v2')
ngx.say(assert(loader:call()))
}
}

location = /config/production.json {
echo '
{
"proxy_configs": [
{
"proxy_config": {
"id": 42,
"version": 1,
"environment": "production",
"content": {
"proxy": {
"hosts": [
"127.0.0.1"
],
"policy_chain": [
{
"name": "headers",
"version": "builtin",
"configuration": {
"request": [
{
"op": "set",
"header": "New-Header",
"value": "{{ service.id }}",
"value_type": "liquid"
}
]
}
}
],
"proxy_rules": []
}
}
}
}
]
}

';
}
--- request
GET /t
--- exit_code: 200