Skip to content

Commit

Permalink
Closes Kong#59
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Mar 6, 2015
1 parent 432efe9 commit a07b0f8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
redefined = false
unused_args = false
globals = {"ngx", "dao", "utils", "app", "configuration", "installed_plugins"}
globals = {"ngx", "dao", "utils", "app", "configuration", "plugins_available"}
4 changes: 2 additions & 2 deletions kong.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Enabled plugins, in this order
plugins_enabled:
# Available plugins on this node
plugins_available:
- authentication
- ratelimiting
- networklog
Expand Down
12 changes: 6 additions & 6 deletions spec/server/server_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ describe("#server-cli", function()
end)

it("should work when no plugins are enabled and the DB is empty", function()
replace_conf_property("plugins_enabled", {})
replace_conf_property("plugins_available", {})
local result, exit_code = spec_helper.start_kong(SERVER_CONF, true)
assert.are.same(0, exit_code)
end)

it("should not work when an unexisting plugin is being enabled", function()
replace_conf_property("plugins_enabled", {"wot-wat"})
replace_conf_property("plugins_available", {"wot-wat"})
local result, exit_code = spec_helper.start_kong(SERVER_CONF, true)
if exit_code == 1 then
assert.truthy(result_contains(result, "The following plugin has been enabled in the configuration but is not installed on the system: wot-wat"))
Expand All @@ -59,13 +59,13 @@ describe("#server-cli", function()
end)

it("should not fail when an existing plugin is being enabled", function()
replace_conf_property("plugins_enabled", {"authentication"})
replace_conf_property("plugins_available", {"authentication"})
local result, exit_code = spec_helper.start_kong(SERVER_CONF, true)
assert.are.same(0, exit_code)
end)

it("should not work when an unexisting plugin is being enabled along with an existing one", function()
replace_conf_property("plugins_enabled", {"authentication", "wot-wat"})
replace_conf_property("plugins_available", {"authentication", "wot-wat"})
local result, exit_code = spec_helper.start_kong(SERVER_CONF, true)
if exit_code == 1 then
assert.truthy(result_contains(result, "The following plugin has been enabled in the configuration but is not installed on the system: wot-wat"))
Expand All @@ -76,7 +76,7 @@ describe("#server-cli", function()
end)

it("should not work when a plugin is being used in the DB but it's not in the configuration", function()
replace_conf_property("plugins_enabled", {"authentication"})
replace_conf_property("plugins_available", {"authentication"})
spec_helper.prepare_db(true)
local result, exit_code = spec_helper.start_kong(SERVER_CONF, true)
if exit_code == 1 then
Expand All @@ -88,7 +88,7 @@ describe("#server-cli", function()
end)

it("should work the used plugins are enabled", function()
replace_conf_property("plugins_enabled", {"ratelimiting", "authentication"})
replace_conf_property("plugins_available", {"ratelimiting", "authentication"})
spec_helper.prepare_db(true)
local result, exit_code = spec_helper.start_kong(SERVER_CONF, true)
assert.are.same(0, exit_code)
Expand Down
10 changes: 9 additions & 1 deletion src/kong/web/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ local Applications = require "kong.web.routes.applications"
app = lapis.Application()

app:get("/", function(self)

local db_plugins, err = dao.plugins:find_distinct()
if err then
ngx.log(ngx.ERR, err)
return utils.show_error(500, err)
end

return utils.success({
tagline = "Welcome to Kong",
version = constants.VERSION,
plugins = installed_plugins
plugins_available = plugins_available,
plugins_used = db_plugins
})
end)

Expand Down
6 changes: 3 additions & 3 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ end
local function init_plugins()
-- Initializing plugins

installed_plugins = configuration.plugins_enabled and configuration.plugins_enabled or {}
plugins_available = configuration.plugins_available and configuration.plugins_available or {}

print("Discovering used plugins. Please wait..")
local db_plugins, err = dao.plugins:find_distinct()
Expand All @@ -73,14 +73,14 @@ local function init_plugins()

-- Checking that the plugins in the DB are also enabled
for _,v in ipairs(db_plugins) do
if not utils.array_contains(installed_plugins, v) then
if not utils.array_contains(plugins_available, v) then
error("You are using a plugin that has not been enabled in the configuration: "..v)
end
end

local unsorted_plugins = {} -- It's a multivalue table: k1 = {v1, v2, v3}, k2 = {...}

for _, v in ipairs(installed_plugins) do
for _, v in ipairs(plugins_available) do
local status, res = pcall(require, "kong.plugins."..v..".handler")
if not status then
error("The following plugin has been enabled in the configuration but is not installed on the system: "..v)
Expand Down

0 comments on commit a07b0f8

Please sign in to comment.