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 9c19379
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Bump Openresty version to 1.19.3 [PR #1272](https://github.com/3scale/APIcast/pull/1272) [THREESCALE-6963](https://issues.redhat.com/browse/THREESCALE-6963)
- Change how ngx.encode_args is made on usage [PR #1277](https://github.com/3scale/APIcast/pull/1277) [THREESCALE-7122](https://issues.redhat.com/browse/THREESCALE-7122)
- Upstream pool key when is using HTTPs connection [PR #1274](https://github.com/3scale/APIcast/pull/1274) [THREESCALE-6849](https://issues.redhat.com/browse/THREESCALE-6849)
- Fix a warning message on invalid upstream [PR #1285](https://github.com/3scale/APIcast/pull/1285) [THREESCALE-5225](https://issues.redhat.com/browse/THREESCALE-5225)
- Upstream MTLS server verify [PR #1280](https://github.com/3scale/APIcast/pull/1280) [THREESCALE-7099](https://issues.redhat.com/browse/THREESCALE-7099)


Expand Down
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 9c19379

Please sign in to comment.