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

[remote_v2] ignore empty APICAST_SERVICES #401

Merged
merged 1 commit into from
Aug 22, 2017
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Ability to configure how to cache backend authorizations [PR #396](https://github.com/3scale/apicast/pull/396)

### Fixed

- [THREESCALE-281](https://issues.jboss.org/browse/THREESCALE-281) Not loading services when APICAST\_SERVICES is empty [PR #401](https://github.com/3scale/apicast/pull/401)

## [3.1.0-beta1] - 2017-07-21

### Fixed
Expand Down
7 changes: 3 additions & 4 deletions apicast/src/configuration_loader/remote_v2.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local setmetatable = setmetatable
local format = string.format
local len = string.len
local ipairs = ipairs
local insert = table.insert
local rawset = rawset
Expand Down Expand Up @@ -183,15 +184,13 @@ end
local services_subset = function()
local services = resty_env.get('APICAST_SERVICES')

if services then
if services and len(services) > 0 then
local ids = re.split(services, ',', 'oj')
for i=1, #ids do
ids[i] = { service = { id = tonumber(ids[i]) } }
end
services = ids
return ids
end

return services
end

function _M:services()
Expand Down
13 changes: 13 additions & 0 deletions spec/configuration_loader/remote_v2_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ describe('Configuration Remote Loader V2', function()
assert.equal(2, #services)
assert.same({ { service = { id = 11 } }, { service = { id = 42 } } }, services)
end)

it('ignores APICAST_SERVICES when empty', function()
env.set('APICAST_SERVICES', '')

test_backend.expect{ url = "http://example.com/admin/api/services.json" }.
respond_with{ status = 200, body = cjson.encode({ services = { { service = { id = 1 }} }}) }

local services = loader:services()

assert.truthy(services)
assert.equal(1, #services)
assert.same({ { service = { id = 1 } } }, services)
end)
end)

describe(':config', function()
Expand Down