Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Headers Policy: don't render template string when delete header [PR #1586](https://github.com/3scale/APIcast/pull/1586)
- 3scale Batcher Policy: replace regex with string operations [PR #1583](https://github.com/3scale/APIcast/pull/1583)
- Proxy/Upstream Connection: setup configuration in init phase - [PR #1602](https://github.com/3scale/APIcast/pull/1602)
- Reduce memory when reloading with large configurations [PR #1608](https://github.com/3scale/APIcast/pull/1608)

### Fixed
- Correct FAPI header to `x-fapi-interaction-id` [PR #1557](https://github.com/3scale/APIcast/pull/1557) [THREESCALE-11957](https://issues.redhat.com/browse/THREESCALE-11957)
Expand Down
3 changes: 3 additions & 0 deletions gateway/libexec/boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ require('apicast.loader')
local configuration = require 'apicast.configuration_loader'
local config = configuration.boot()

if type(config) == 'table' then
config = require('cjson').encode(config)
end
ngx.say(config)
6 changes: 5 additions & 1 deletion gateway/src/apicast/configuration_loader/oidc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ function _M.call(...)

config.oidc = oidc

return cjson.encode(config), select(2, ...)
-- Return the decoded table instead of re-encoding to JSON.
-- configuration_parser.decode() passes tables through untouched, so
-- downstream configuration_parser.parse() won't need to re-decode it
-- either.
return config, select(2, ...)
else
return ...
end
Expand Down
4 changes: 2 additions & 2 deletions gateway/src/apicast/configuration_loader/remote_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ local function parse_proxy_configs(self, proxy_configs)

config.oidc[i] = oidc_copy
end
return cjson.encode(config)
return config
end

local function parse_resp_body(self, resp_body)
Expand Down Expand Up @@ -207,7 +207,7 @@ function _M:index_per_service()
configs[i] = nil
end

return cjson.encode(configs)
return configs
end

function _M:index_custom_path(host)
Expand Down
38 changes: 18 additions & 20 deletions gateway/src/apicast/mapping_rule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ local _M = {
}

local mt = { __index = _M }
local empty_table = {}

local function hash_to_array(hash)
local array = {}
if not hash or next(hash) == nil then
return empty_table
end

local array = {}
for k,v in pairs(hash or {}) do
insert(array, { k, v })
end
Expand Down Expand Up @@ -86,32 +90,26 @@ local function matches_querystring_params(params, args)
end

local function matches_uri(rule_pattern, uri)
return re_match(uri, format("^%s", rule_pattern), 'oj')
return re_match(uri, rule_pattern, 'oj')
end

local function new(http_method, pattern, params, querystring_params, metric, delta, last, owner_id, owner_type)
local self = setmetatable({}, mt)

local querystring_parameters = hash_to_array(querystring_params)

self.method = http_method
self.pattern = pattern
self.regexpified_pattern = regexpify(pattern)
self.parameters = params
self.system_name = metric or error('missing metric name of rule')
self.delta = delta
self.last = last or false
local self = {
querystring_parameters = hash_to_array(querystring_params),
method = http_method,
pattern = pattern,
regexpified_pattern = format("^%s", regexpify(pattern)),
parameters = params,
system_name = metric or error('missing metric name of rule'),
delta = delta,
last = last or false
}

if owner_type == BackendAPIconst then
self.owner_id = owner_id
end


self.querystring_params = function(args)
return matches_querystring_params(querystring_parameters, args)
end

return self
return setmetatable(self, mt)
end

--- Initializes a mapping rule from a proxy rule of the service configuration.
Expand Down Expand Up @@ -153,7 +151,7 @@ end
function _M:matches(method, uri, args)
local match = (self.method == self.any_method or self.method == method) and
matches_uri(self.regexpified_pattern, uri) and
self.querystring_params(args)
matches_querystring_params(self.querystring_parameters, args)

-- match can be nil. Convert to boolean.
return match == true
Expand Down
12 changes: 7 additions & 5 deletions spec/configuration_loader/oidc_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ describe('OIDC Configuration loader', function()
end)

it('forwards all parameters', function()
assert.same({'{"oidc":[]}', 'one', 'two'}, { loader.call('{}', 'one', 'two')})
local result = { loader.call('{}', 'one', 'two') }
assert.same({ oidc = {} }, result[1])
assert.same({ 'one', 'two' }, { result[2], result[3] })
end)

it('gets openid configuration', function()
Expand Down Expand Up @@ -96,7 +98,7 @@ describe('OIDC Configuration loader', function()
]
}
]])
assert.same(expected_oidc, cjson.decode(oidc))
assert.same(expected_oidc, oidc)
end)

-- This is a regression test. cjson crashed when parsing a config where
Expand Down Expand Up @@ -161,7 +163,7 @@ describe('OIDC Configuration loader', function()
]
}
]])
assert.same(expected_oidc, cjson.decode(oidc))
assert.same(expected_oidc, oidc)
end)

it('handles OIDC discovery failure gracefully without crashing', function()
Expand Down Expand Up @@ -201,7 +203,7 @@ describe('OIDC Configuration loader', function()
local result = loader.call(cjson.encode(config))
assert.is_not_nil(result)

local decoded = cjson.decode(result)
local decoded = result
assert.equals(2, #decoded.oidc)

-- First service should have error
Expand Down Expand Up @@ -265,7 +267,7 @@ describe('OIDC Configuration loader', function()
local result = loader.call(cjson.encode(config))
assert.is_not_nil(result)

local decoded = cjson.decode(result)
local decoded = result
assert.equals(1, #decoded.oidc)
assert.equals(99, decoded.oidc[1].service_id)
-- assert.is_not_nil(decoded.oidc[1].error)
Expand Down
Loading
Loading