Skip to content

Commit

Permalink
Logs: disable invalid warning when no api_backend
Browse files Browse the repository at this point in the history
Since API as a product, api_backend is no longer a required parameter of
the config. Due to the change, a warning message was in place on each
request due to invalid upstream.

With this change, in case of no api_backend, a nil object is returned
and no error message at all.

Fix THREESCALE-5225

Signed-off-by: Eloy Coto <eloy.coto@acalustra.com>
  • Loading branch information
eloycoto committed Jun 22, 2021
1 parent 6fbb0cc commit 0c1ddd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gateway/src/apicast/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ function _M.get_upstream(service, context)
if not service then
return errors.service_not_found()
end

-- Due to API as a product, the api_backend is no longer needed because this
-- can be handled by routing policy
if not service.api_backend then
return nil, nil
end

local upstream, err = Upstream.new(service.api_backend)
if not upstream then
return nil, err
Expand Down
13 changes: 13 additions & 0 deletions spec/proxy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ describe('Proxy', function()
assert.same(80, get_upstream({ api_backend = 'http://example.com' }):port())
assert.same(8080, get_upstream({ api_backend = 'http://example.com:8080' }):port())
end)

it("on invalid api_backend return error", function()
local upstream, err = get_upstream({ api_backend = 'test.com' })
assert.falsy(upstream)
assert.same(err, "invalid upstream")
end)

it("on no api_backend return nil and no error", function()
local upstream, err = get_upstream({})
assert.falsy(upstream)
assert.falsy(err)
end)

end)

describe('.authorize', function()
Expand Down

0 comments on commit 0c1ddd4

Please sign in to comment.