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

chore: display a warning message when Kong Manager is enabled but the Admin API is not enabled #12071

Merged
merged 1 commit into from
Nov 27, 2023
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
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
Loading