Skip to content

Commit

Permalink
feat(configuration): display a warning message when Kong Manager is e…
Browse files Browse the repository at this point in the history
…nabled but the Admin API is not enabled (#12071)

Feedback from issue #11995 highlighted potential user confusion
due to the internal connection between Kong Manager and the Admin API.

To address this, a warning message will now be displayed to notify users
that the current configuration combination will not function as expected.

This resolves KAG-3158
  • Loading branch information
nekolab authored Nov 27, 2023
1 parent c014727 commit f920f1f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: display a warning message when Kong Manager is enabled but the Admin API is not enabled
type: feature
scope: Configuration
6 changes: 6 additions & 0 deletions kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,12 @@ local function check_and_parse(conf, opts)
end
end

if #conf.admin_listen < 1 or strip(conf.admin_listen[1]) == "off" then
if #conf.admin_gui_listen > 0 and strip(conf.admin_gui_listen[1]) ~= "off" then
log.warn("Kong Manager won't be functional because the Admin API is not listened on any interface")
end
end

return #errors == 0, errors[1], errors
end

Expand Down
49 changes: 49 additions & 0 deletions spec/01-unit/03-conf_loader_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local conf_loader = require "kong.conf_loader"
local utils = require "kong.tools.utils"
local log = require "kong.cmd.utils.log"
local helpers = require "spec.helpers"
local tablex = require "pl.tablex"
local pl_path = require "pl.path"
Expand Down Expand Up @@ -1630,6 +1631,54 @@ describe("Configuration loader", function()
local conf = assert(conf_loader(helpers.test_conf_path))
assert.equal(DATABASE, conf.database)
end)
it("should warns user if kong manager is enabled but admin API is not enabled", function ()
local spy_log = spy.on(log, "warn")

finally(function()
log.warn:revert()
assert:unregister("matcher", "str_match")
end)

assert:register("matcher", "str_match", function (_state, arguments)
local expected = arguments[1]
return function(value)
return string.match(value, expected) ~= nil
end
end)

local conf, err = conf_loader(nil, {
admin_listen = "off",
admin_gui_listen = "off",
})
assert.is_nil(err)
assert.is_table(conf)
assert.spy(spy_log).was_called(0)

conf, err = conf_loader(nil, {
admin_listen = "localhost:8001",
admin_gui_listen = "off",
})
assert.is_nil(err)
assert.is_table(conf)
assert.spy(spy_log).was_called(0)

conf, err = conf_loader(nil, {
admin_listen = "localhost:8001",
admin_gui_listen = "localhost:8002",
})
assert.is_nil(err)
assert.is_table(conf)
assert.spy(spy_log).was_called(0)

conf, err = conf_loader(nil, {
admin_listen = "off",
admin_gui_listen = "localhost:8002",
})
assert.is_nil(err)
assert.is_table(conf)
assert.spy(spy_log).was_called(1)
assert.spy(spy_log).was_called_with("Kong Manager won't be functional because the Admin API is not listened on any interface")
end)
end)

describe("pg_semaphore options", function()
Expand Down

0 comments on commit f920f1f

Please sign in to comment.