From 1609e4331695437969e3f1d06422b05e495ffc3b Mon Sep 17 00:00:00 2001 From: thefosk Date: Thu, 5 Mar 2015 17:27:26 -0800 Subject: [PATCH] Closes #59 --- .luacheckrc | 2 +- kong.yml | 4 ++-- site/app/_includes/pages/docs.md | 8 +++++--- spec/server/server_spec.lua | 12 ++++++------ src/kong/web/app.lua | 10 +++++++++- src/main.lua | 6 +++--- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 9ac8872c083..78341981ea5 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -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"} diff --git a/kong.yml b/kong.yml index 76bdc0a7709..308959efa9b 100644 --- a/kong.yml +++ b/kong.yml @@ -1,5 +1,5 @@ -# Enabled plugins, in this order -plugins_enabled: +# Available plugins on this node +plugins_available: - authentication - ratelimiting - networklog diff --git a/site/app/_includes/pages/docs.md b/site/app/_includes/pages/docs.md index 63ba56ec8a8..d83aa0ca442 100644 --- a/site/app/_includes/pages/docs.md +++ b/site/app/_includes/pages/docs.md @@ -96,8 +96,8 @@ A typical `kong.yml` file looks like: # Specify the DAO to use database: cassandra -# Enabled plugins -plugins_enabled: +# Plugins available on the server +plugins_available: - authentication - ratelimiting - networklog @@ -112,7 +112,9 @@ databases_available: keepalive: 60000 ``` -The `plugins_enabled` array describes the plugins that the server should support system-wide (the order is irrelevant). Then you can configure which Plugin to install to which API by using the `/plugins/` API endpoint. Plugins that haven't been added to `plugins_enabled` won't be executed. +The `plugins_available` array describes the plugins available that can be used by the server. Then you can configure which Plugin to install to which API by using the `/plugins/` API endpoint. Plugins that haven't been added to `plugins_enabled` won't be executed. + +**Note**: Make sure that every node in the cluster has the same `plugins_available` property value. # Scalability diff --git a/spec/server/server_spec.lua b/spec/server/server_spec.lua index e9546d4f9d8..b411980b138 100644 --- a/spec/server/server_spec.lua +++ b/spec/server/server_spec.lua @@ -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")) @@ -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")) @@ -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 @@ -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) diff --git a/src/kong/web/app.lua b/src/kong/web/app.lua index 9cdaaa5acd1..ed9b5e8f506 100644 --- a/src/kong/web/app.lua +++ b/src/kong/web/app.lua @@ -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) diff --git a/src/main.lua b/src/main.lua index 61a4bc9b9af..4d720f7a9bc 100644 --- a/src/main.lua +++ b/src/main.lua @@ -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() @@ -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)