From d0829ead70d8629faf260a3c08a22276311cbf6c Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 27 Aug 2015 16:33:48 -0700 Subject: [PATCH 1/9] chore(mig-script) migrate rate-limiting values --- scripts/migration.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/scripts/migration.py b/scripts/migration.py index 187df699a44..8001e81ad80 100755 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -11,7 +11,7 @@ -h print help ''' -import getopt, sys, os.path, logging +import getopt, sys, os.path, logging, json log = logging.getLogger() log.setLevel("INFO") @@ -112,6 +112,24 @@ def migrate_plugins_renaming(session): log.info("Plugins renamed") +def migrate_rate_limiting_value(session): + """ + Update all old `values` of rate-limiting plugins_configurations to the new schema (supporting multiple limits) + + :param session: opened cassandra session + """ + log.info("Migrating rate-limiting values") + + for plugin in session.execute("SELECT * FROM plugins_configurations WHERE name = 'rate-limiting'"): + conf = json.loads(plugin.value) + if "limit" in conf: + new_conf = {} + new_conf[conf["period"]] = conf["limit"] + session.execute("UPDATE plugins_configurations SET value = %s WHERE id = %s AND name = %s", [json.dumps(new_conf), plugin.id, plugin.name]) + + log.info("rate-limiting values migrated") + + def migrate(kong_config): """ Instanciate a Cassandra session and decides if the keyspace needs to be migrated @@ -141,12 +159,9 @@ def migrate(kong_config): if any(row.id == "migrations" for row in rows): log.info("Already migrated to 0.5.0, but legacy schema found. Purging.") migrate_schema_migrations_remove_legacy_row(session) - else: - return False migrate_plugins_renaming(session) - - return True + migrate_rate_limiting_value(session) def parse_arguments(argv): """ @@ -179,10 +194,8 @@ def parse_arguments(argv): def main(argv): try: config = parse_arguments(argv) - if migrate(config): - log.info("Schema migrated to Kong 0.5.0.") - else: - log.info("Schema already migrated to Kong 0.5.0.") + migrate(config) + log.info("Schema migrated to Kong 0.5.0.") shutdown_exit(0) except getopt.GetoptError as err: log.error(err) From 5302c3fbe46b16c13ec9777d5422dccb542f0248 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 27 Aug 2015 16:42:32 -0700 Subject: [PATCH 2/9] chore(mig-script) use concistency_level of ALL --- scripts/migration.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/migration.py b/scripts/migration.py index 8001e81ad80..0771265234f 100755 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -22,6 +22,8 @@ try: import yaml from cassandra.cluster import Cluster + from cassandra import ConsistencyLevel + from cassandra.query import SimpleStatement except ImportError as err: log.error(err) log.info("""This script requires cassandra-driver and PyYAML: @@ -66,7 +68,7 @@ def migrate_schema_migrations_table(session): :param session: opened cassandra session """ - query = "INSERT INTO schema_migrations(id, migrations) VALUES(%s, %s)" + query = SimpleStatement("INSERT INTO schema_migrations(id, migrations) VALUES(%s, %s)", consistency_level=ConsistencyLevel.ALL) session.execute(query, ["core", ['2015-01-12-175310_skeleton', '2015-01-12-175310_init_schema']]) session.execute(query, ["basic-auth", ['2015-08-03-132400_init_basicauth']]) session.execute(query, ["key-auth", ['2015-07-31-172400_init_keyauth']]) @@ -104,11 +106,13 @@ def migrate_plugins_renaming(session): if plugin.name in new_names: plugin_name = new_names[plugin.name] - session.execute("DELETE FROM plugins_configurations WHERE id = %s", [plugin.id]) - session.execute(""" + delete_query = SimpleStatement("DELETE FROM plugins_configurations WHERE id = %s", consistency_level=ConsistencyLevel.ALL) + insert_query = SimpleStatement(""" INSERT INTO plugins_configurations(id, name, api_id, consumer_id, created_at, enabled, value) - VALUES(%s, %s, %s, %s, %s, %s, %s) - """, [plugin.id, plugin_name, plugin.api_id, plugin.consumer_id, plugin.created_at, plugin.enabled, plugin.value]) + VALUES(%s, %s, %s, %s, %s, %s, %s)""", consistency_level=ConsistencyLevel.ALL) + + session.execute(delete_query, [plugin.id]) + session.execute(insert_query, [plugin.id, plugin_name, plugin.api_id, plugin.consumer_id, plugin.created_at, plugin.enabled, plugin.value]) log.info("Plugins renamed") @@ -125,7 +129,8 @@ def migrate_rate_limiting_value(session): if "limit" in conf: new_conf = {} new_conf[conf["period"]] = conf["limit"] - session.execute("UPDATE plugins_configurations SET value = %s WHERE id = %s AND name = %s", [json.dumps(new_conf), plugin.id, plugin.name]) + update_query = SimpleStatement("UPDATE plugins_configurations SET value = %s WHERE id = %s AND name = %s", consistency_level=ConsistencyLevel.ALL) + session.execute(update_query, [json.dumps(new_conf), plugin.id, plugin.name]) log.info("rate-limiting values migrated") From bb302d59587d9537c4d54e6439aac2d89b423803 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 27 Aug 2015 19:18:53 -0700 Subject: [PATCH 3/9] chore: rename plugins_configurations to plugins --- kong-0.4.2-1.rockspec | 6 +- kong/api/app.lua | 2 +- kong/api/routes/apis.lua | 12 ++-- kong/api/routes/kong.lua | 2 +- kong/api/routes/plugins.lua | 49 +++++++++++-- kong/api/routes/plugins_configurations.lua | 48 ------------- kong/dao/cassandra/base_dao.lua | 4 +- kong/dao/cassandra/factory.lua | 2 +- ...plugins_configurations.lua => plugins.lua} | 40 +++++------ kong/dao/cassandra/schema/migrations.lua | 12 ++-- ...plugins_configurations.lua => plugins.lua} | 56 +++++++-------- kong/kong.lua | 68 +++++++++---------- kong/plugins/basic-auth/access.lua | 4 +- kong/plugins/key-auth/access.lua | 2 +- kong/plugins/rate-limiting/schema.lua | 4 +- kong/plugins/response-ratelimiting/schema.lua | 8 +-- kong/tools/database_cache.lua | 6 +- kong/tools/faker.lua | 8 +-- scripts/migration.py | 33 ++++++++- .../admin_api/apis_routes_spec.lua | 50 +++++++------- .../admin_api/plugins_routes_spec.lua | 17 +---- spec/integration/cli/start_spec.lua | 4 +- .../dao/cassandra/base_dao_spec.lua | 62 ++++++++--------- .../dao/cassandra/cascade_spec.lua | 36 +++++----- spec/integration/proxy/api_resolver_spec.lua | 4 +- .../integration/proxy/database_cache_spec.lua | 5 +- spec/integration/proxy/realip_spec.lua | 6 +- spec/plugins/basic-auth/access_spec.lua | 4 +- spec/plugins/cors/access_spec.lua | 6 +- spec/plugins/ip-restriction/access_spec.lua | 18 ++--- spec/plugins/key-auth/access_spec.lua | 6 +- spec/plugins/key-auth/daos_spec.lua | 2 +- spec/plugins/logging_spec.lua | 14 ++-- spec/plugins/oauth2/access_spec.lua | 34 +++++----- spec/plugins/rate-limiting/access_spec.lua | 16 ++--- spec/plugins/rate-limiting/api_spec.lua | 8 +-- spec/plugins/rate-limiting/schema_spec.lua | 24 +++---- .../request-size-limiting/access_spec.lua | 4 +- .../request-transformer/access_spec.lua | 4 +- .../response-ratelimiting/access_spec.lua | 12 ++-- .../response-ratelimiting/api_spec.lua | 12 ++-- .../response-ratelimiting/schema_spec.lua | 34 +++++----- .../response-transformer/access_spec.lua | 6 +- spec/plugins/ssl/access_spec.lua | 18 ++--- spec/plugins/ssl/api_spec.lua | 2 +- spec/unit/api/app_spec.lua | 32 ++++----- spec/unit/dao/entities_schemas_spec.lua | 34 +++++----- spec/unit/tools/database_cache_spec.lua | 4 +- spec/unit/tools/faker_spec.lua | 10 +-- 49 files changed, 431 insertions(+), 423 deletions(-) delete mode 100644 kong/api/routes/plugins_configurations.lua rename kong/dao/cassandra/{plugins_configurations.lua => plugins.lua} (50%) rename kong/dao/schemas/{plugins_configurations.lua => plugins.lua} (60%) diff --git a/kong-0.4.2-1.rockspec b/kong-0.4.2-1.rockspec index 6f7349d7a2e..1291a6e75b9 100644 --- a/kong-0.4.2-1.rockspec +++ b/kong-0.4.2-1.rockspec @@ -84,14 +84,14 @@ build = { ["kong.dao.schemas_validation"] = "kong/dao/schemas_validation.lua", ["kong.dao.schemas.apis"] = "kong/dao/schemas/apis.lua", ["kong.dao.schemas.consumers"] = "kong/dao/schemas/consumers.lua", - ["kong.dao.schemas.plugins_configurations"] = "kong/dao/schemas/plugins_configurations.lua", + ["kong.dao.schemas.plugins"] = "kong/dao/schemas/plugins.lua", ["kong.dao.cassandra.factory"] = "kong/dao/cassandra/factory.lua", ["kong.dao.cassandra.query_builder"] = "kong/dao/cassandra/query_builder.lua", ["kong.dao.cassandra.base_dao"] = "kong/dao/cassandra/base_dao.lua", ["kong.dao.cassandra.migrations"] = "kong/dao/cassandra/migrations.lua", ["kong.dao.cassandra.apis"] = "kong/dao/cassandra/apis.lua", ["kong.dao.cassandra.consumers"] = "kong/dao/cassandra/consumers.lua", - ["kong.dao.cassandra.plugins_configurations"] = "kong/dao/cassandra/plugins_configurations.lua", + ["kong.dao.cassandra.plugins"] = "kong/dao/cassandra/plugins.lua", ["kong.plugins.base_plugin"] = "kong/plugins/base_plugin.lua", @@ -189,7 +189,7 @@ build = { ["kong.api.routes.apis"] = "kong/api/routes/apis.lua", ["kong.api.routes.consumers"] = "kong/api/routes/consumers.lua", ["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua", - ["kong.api.routes.plugins_configurations"] = "kong/api/routes/plugins_configurations.lua", + ["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua", }, install = { conf = { "kong.yml" }, diff --git a/kong/api/app.lua b/kong/api/app.lua index 8450f66f353..8e80c303d81 100644 --- a/kong/api/app.lua +++ b/kong/api/app.lua @@ -140,7 +140,7 @@ local function attach_routes(routes) end -- Load core routes -for _, v in ipairs({"kong", "apis", "consumers", "plugins", "plugins_configurations"}) do +for _, v in ipairs({"kong", "apis", "consumers", "plugins"}) do local routes = require("kong.api.routes."..v) attach_routes(routes) end diff --git a/kong/api/routes/apis.lua b/kong/api/routes/apis.lua index 6f40576455d..9948acc7706 100644 --- a/kong/api/routes/apis.lua +++ b/kong/api/routes/apis.lua @@ -40,11 +40,11 @@ return { end, GET = function(self, dao_factory) - crud.paginated_set(self, dao_factory.plugins_configurations) + crud.paginated_set(self, dao_factory.plugins) end, POST = function(self, dao_factory, helpers) - crud.post(self.params, dao_factory.plugins_configurations, function(data) + crud.post(self.params, dao_factory.plugins, function(data) if configuration.send_anonymous_reports then data.signal = constants.SYSLOG.API syslog.log(syslog.format_entity(data)) @@ -53,7 +53,7 @@ return { end, PUT = function(self, dao_factory, helpers) - crud.put(self.params, dao_factory.plugins_configurations) + crud.put(self.params, dao_factory.plugins) end }, @@ -68,7 +68,7 @@ return { } self.params.plugin_id = nil - local data, err = dao_factory.plugins_configurations:find_by_keys(fetch_keys) + local data, err = dao_factory.plugins:find_by_keys(fetch_keys) if err then return helpers.yield_error(err) end @@ -84,11 +84,11 @@ return { end, PATCH = function(self, dao_factory, helpers) - crud.patch(self.params, self.plugin, dao_factory.plugins_configurations) + crud.patch(self.params, self.plugin, dao_factory.plugins) end, DELETE = function(self, dao_factory) - crud.delete(self.plugin, dao_factory.plugins_configurations) + crud.delete(self.plugin, dao_factory.plugins) end } } diff --git a/kong/api/routes/kong.lua b/kong/api/routes/kong.lua index 527d3f80a23..878b7af7a51 100644 --- a/kong/api/routes/kong.lua +++ b/kong/api/routes/kong.lua @@ -4,7 +4,7 @@ local route_helpers = require "kong.api.route_helpers" return { ["/"] = { GET = function(self, dao, helpers) - local db_plugins, err = dao.plugins_configurations:find_distinct() + local db_plugins, err = dao.plugins:find_distinct() if err then return helpers.responses.send_HTTP_INTERNAL_SERVER_ERROR(err) end diff --git a/kong/api/routes/plugins.lua b/kong/api/routes/plugins.lua index b4d5e63c7e1..e277310c060 100644 --- a/kong/api/routes/plugins.lua +++ b/kong/api/routes/plugins.lua @@ -1,4 +1,7 @@ +local crud = require "kong.api.crud_helpers" local utils = require "kong.tools.utils" +local syslog = require "kong.tools.syslog" +local constants = require "kong.constants" -- Remove functions from a schema definition so that -- cjson can encode the schema. @@ -15,13 +18,25 @@ end return { ["/plugins"] = { - GET = function(self, dao_factory, helpers) - return helpers.responses.send_HTTP_OK { - enabled_plugins = configuration.plugins_available - } + GET = function(self, dao_factory) + crud.paginated_set(self, dao_factory.plugins) + end, + + PUT = function(self, dao_factory) + crud.put(self.params, dao_factory.plugins) + end, + + POST = function(self, dao_factory) + crud.post(self.params, dao_factory.plugins, function(data) + if configuration.send_anonymous_reports then + data.signal = constants.SYSLOG.API + syslog.log(syslog.format_entity(data)) + end + end) end }, - ["/plugins/:name/schema"] = { + + ["/plugins/schema/:name"] = { GET = function(self, dao_factory, helpers) local ok, plugin_schema = utils.load_module_if_exists("kong.plugins."..self.params.name..".schema") if not ok then @@ -32,5 +47,29 @@ return { return helpers.responses.send_HTTP_OK(plugin_schema) end + }, + + ["/plugins/:id"] = { + before = function(self, dao_factory, helpers) + local err + self.plugin_conf, err = dao_factory.plugins:find_by_primary_key({ id = self.params.id }) + if err then + return helpers.yield_error(err) + elseif not self.plugin_conf then + return helpers.responses.send_HTTP_NOT_FOUND() + end + end, + + GET = function(self, dao_factory, helpers) + return helpers.responses.send_HTTP_OK(self.plugin_conf) + end, + + PATCH = function(self, dao_factory) + crud.patch(self.params, self.plugin_conf, dao_factory.plugins) + end, + + DELETE = function(self, dao_factory) + crud.delete(self.plugin_conf, dao_factory.plugins) + end } } diff --git a/kong/api/routes/plugins_configurations.lua b/kong/api/routes/plugins_configurations.lua deleted file mode 100644 index 65f57964f45..00000000000 --- a/kong/api/routes/plugins_configurations.lua +++ /dev/null @@ -1,48 +0,0 @@ -local crud = require "kong.api.crud_helpers" -local syslog = require "kong.tools.syslog" -local constants = require "kong.constants" - -return { - ["/plugins_configurations"] = { - GET = function(self, dao_factory) - crud.paginated_set(self, dao_factory.plugins_configurations) - end, - - PUT = function(self, dao_factory) - crud.put(self.params, dao_factory.plugins_configurations) - end, - - POST = function(self, dao_factory) - crud.post(self.params, dao_factory.plugins_configurations, function(data) - if configuration.send_anonymous_reports then - data.signal = constants.SYSLOG.API - syslog.log(syslog.format_entity(data)) - end - end) - end - }, - - ["/plugins_configurations/:id"] = { - before = function(self, dao_factory, helpers) - local err - self.plugin_conf, err = dao_factory.plugins_configurations:find_by_primary_key({ id = self.params.id }) - if err then - return helpers.yield_error(err) - elseif not self.plugin_conf then - return helpers.responses.send_HTTP_NOT_FOUND() - end - end, - - GET = function(self, dao_factory, helpers) - return helpers.responses.send_HTTP_OK(self.plugin_conf) - end, - - PATCH = function(self, dao_factory) - crud.patch(self.params, self.plugin_conf, dao_factory.plugins_configurations) - end, - - DELETE = function(self, dao_factory) - crud.delete(self.plugin_conf, dao_factory.plugins_configurations) - end - } -} diff --git a/kong/dao/cassandra/base_dao.lua b/kong/dao/cassandra/base_dao.lua index 4862caadb1f..59bbec6c047 100644 --- a/kong/dao/cassandra/base_dao.lua +++ b/kong/dao/cassandra/base_dao.lua @@ -407,9 +407,9 @@ local function extract_primary_key(t, primary_key, clustering_key) return t_primary_key, t_no_primary_key end --- When updating a row that has a json-as-text column (ex: plugin_configuration.value), +-- When updating a row that has a json-as-text column (ex: plugin.config), -- we want to avoid overriding it with a partial value. --- Ex: value.key_name + value.hide_credential, if we update only one field, +-- Ex: config.key_name + config.hide_credential, if we update only one field, -- the other should be preserved. Of course this only applies in partial update. local function fix_tables(t, old_t, schema) for k, v in pairs(schema.fields) do diff --git a/kong/dao/cassandra/factory.lua b/kong/dao/cassandra/factory.lua index 851b4f43d79..13cde324507 100644 --- a/kong/dao/cassandra/factory.lua +++ b/kong/dao/cassandra/factory.lua @@ -30,7 +30,7 @@ function CassandraFactory:new(properties, plugins) self.daos = {} -- Load core entities DAOs - for _, entity in ipairs({"apis", "consumers", "plugins_configurations"}) do + for _, entity in ipairs({"apis", "consumers", "plugins"}) do self:load_daos(require("kong.dao.cassandra."..entity)) end diff --git a/kong/dao/cassandra/plugins_configurations.lua b/kong/dao/cassandra/plugins.lua similarity index 50% rename from kong/dao/cassandra/plugins_configurations.lua rename to kong/dao/cassandra/plugins.lua index f5a1547b13b..161a4fd1332 100644 --- a/kong/dao/cassandra/plugins_configurations.lua +++ b/kong/dao/cassandra/plugins.lua @@ -1,32 +1,32 @@ -local plugins_configurations_schema = require "kong.dao.schemas.plugins_configurations" +local plugins_schema = require "kong.dao.schemas.plugins" local query_builder = require "kong.dao.cassandra.query_builder" local constants = require "kong.constants" local BaseDao = require "kong.dao.cassandra.base_dao" local cjson = require "cjson" -local PluginsConfigurations = BaseDao:extend() +local Plugins = BaseDao:extend() -function PluginsConfigurations:new(properties) - self._table = "plugins_configurations" - self._schema = plugins_configurations_schema +function Plugins:new(properties) + self._table = "plugins" + self._schema = plugins_schema - PluginsConfigurations.super.new(self, properties) + Plugins.super.new(self, properties) end -- @override -function PluginsConfigurations:_marshall(t) - if type(t.value) == "table" then - t.value = cjson.encode(t.value) +function Plugins:_marshall(t) + if type(t.config) == "table" then + t.config = cjson.encode(t.config) end return t end -- @override -function PluginsConfigurations:_unmarshall(t) - -- deserialize values (tables) string to json - if type(t.value) == "string" then - t.value = cjson.decode(t.value) +function Plugins:_unmarshall(t) + -- deserialize configs (tables) string to json + if type(t.config) == "string" then + t.config = cjson.decode(t.config) end -- remove consumer_id if null uuid if t.consumer_id == constants.DATABASE_NULL_ID then @@ -37,16 +37,16 @@ function PluginsConfigurations:_unmarshall(t) end -- @override -function PluginsConfigurations:update(t) +function Plugins:update(t) if not t.consumer_id then t.consumer_id = constants.DATABASE_NULL_ID end - return PluginsConfigurations.super.update(self, t) + return Plugins.super.update(self, t) end -function PluginsConfigurations:find_distinct() +function Plugins:find_distinct() -- Open session - local session, err = PluginsConfigurations.super._open_session(self) + local session, err = Plugins.super._open_session(self) if err then return nil, err end @@ -55,7 +55,7 @@ function PluginsConfigurations:find_distinct() -- Execute query local distinct_names = {} - for rows, err in PluginsConfigurations.super.execute(self, select_q, nil, nil, {auto_paging=true}) do + for rows, err in Plugins.super.execute(self, select_q, nil, nil, {auto_paging=true}) do if err then return nil, err end @@ -68,7 +68,7 @@ function PluginsConfigurations:find_distinct() end -- Close session - local socket_err = PluginsConfigurations.super._close_session(self, session) + local socket_err = Plugins.super._close_session(self, session) if socket_err then return nil, socket_err end @@ -81,4 +81,4 @@ function PluginsConfigurations:find_distinct() return result, nil end -return { plugins_configurations = PluginsConfigurations } +return {plugins = Plugins} diff --git a/kong/dao/cassandra/schema/migrations.lua b/kong/dao/cassandra/schema/migrations.lua index 243c940cc42..22dd529c75f 100644 --- a/kong/dao/cassandra/schema/migrations.lua +++ b/kong/dao/cassandra/schema/migrations.lua @@ -54,27 +54,27 @@ local Migrations = { CREATE INDEX IF NOT EXISTS ON apis(public_dns); CREATE INDEX IF NOT EXISTS ON apis(path); - CREATE TABLE IF NOT EXISTS plugins_configurations( + CREATE TABLE IF NOT EXISTS plugins( id uuid, api_id uuid, consumer_id uuid, name text, - value text, -- serialized plugin data + config text, -- serialized plugin configuration enabled boolean, created_at timestamp, PRIMARY KEY (id, name) ); - CREATE INDEX IF NOT EXISTS ON plugins_configurations(name); - CREATE INDEX IF NOT EXISTS ON plugins_configurations(api_id); - CREATE INDEX IF NOT EXISTS ON plugins_configurations(consumer_id); + CREATE INDEX IF NOT EXISTS ON plugins(name); + CREATE INDEX IF NOT EXISTS ON plugins(api_id); + CREATE INDEX IF NOT EXISTS ON plugins(consumer_id); ]] end, down = function(options) return [[ DROP TABLE consumers; DROP TABLE apis; - DROP TABLE plugins_configurations; + DROP TABLE plugins; ]] end } diff --git a/kong/dao/schemas/plugins_configurations.lua b/kong/dao/schemas/plugins.lua similarity index 60% rename from kong/dao/schemas/plugins_configurations.lua rename to kong/dao/schemas/plugins.lua index 548ab8b194a..a90d909d8d5 100644 --- a/kong/dao/schemas/plugins_configurations.lua +++ b/kong/dao/schemas/plugins.lua @@ -2,7 +2,7 @@ local utils = require "kong.tools.utils" local DaoError = require "kong.dao.error" local constants = require "kong.constants" -local function load_value_schema(plugin_t) +local function load_config_schema(plugin_t) if plugin_t.name then local loaded, plugin_schema = utils.load_module_if_exists("kong.plugins."..plugin_t.name..".schema") if loaded then @@ -18,55 +18,55 @@ return { primary_key = {"id"}, clustering_key = {"name"}, fields = { - id = { - type = "id", + id = { + type = "id", dao_insert_value = true }, - created_at = { - type = "timestamp", + created_at = { + type = "timestamp", dao_insert_value = true }, - api_id = { - type = "id", - required = true, - foreign = "apis:id", + api_id = { + type = "id", + required = true, + foreign = "apis:id", queryable = true }, - consumer_id = { - type = "id", - foreign = "consumers:id", - queryable = true, + consumer_id = { + type = "id", + foreign = "consumers:id", + queryable = true, default = constants.DATABASE_NULL_ID }, - name = { - type = "string", - required = true, - immutable = true, + name = { + type = "string", + required = true, + immutable = true, queryable = true }, - value = { - type = "table", - schema = load_value_schema }, - enabled = { - type = "boolean", + config = { + type = "table", + schema = load_config_schema }, + enabled = { + type = "boolean", default = true } }, self_check = function(self, plugin_t, dao, is_update) - -- Load the value schema - local value_schema, err = self.fields.value.schema(plugin_t) + -- Load the config schema + local config_schema, err = self.fields.config.schema(plugin_t) if err then return false, DaoError(err, constants.DATABASE_ERROR_TYPES.SCHEMA) end -- Check if the schema has a `no_consumer` field - if value_schema.no_consumer and plugin_t.consumer_id ~= nil and plugin_t.consumer_id ~= constants.DATABASE_NULL_ID then + if config_schema.no_consumer and plugin_t.consumer_id ~= nil and plugin_t.consumer_id ~= constants.DATABASE_NULL_ID then return false, DaoError("No consumer can be configured for that plugin", constants.DATABASE_ERROR_TYPES.SCHEMA) end - if value_schema.self_check and type(value_schema.self_check) == "function" then - local ok, err = value_schema.self_check(value_schema, plugin_t.value and plugin_t.value or {}, dao, is_update) + if config_schema.self_check and type(config_schema.self_check) == "function" then + local ok, err = config_schema.self_check(config_schema, plugin_t.config and plugin_t.config or {}, dao, is_update) if not ok then return false, err end end if not is_update then - local res, err = dao.plugins_configurations:find_by_keys({ + local res, err = dao.plugins:find_by_keys({ name = plugin_t.name, api_id = plugin_t.api_id, consumer_id = plugin_t.consumer_id diff --git a/kong/kong.lua b/kong/kong.lua index 532ce46cebd..ecb07b081ca 100644 --- a/kong/kong.lua +++ b/kong/kong.lua @@ -40,11 +40,11 @@ local function get_now() return ngx.now() * 1000 end -local function load_plugin_conf(api_id, consumer_id, plugin_name) - local cache_key = cache.plugin_configuration_key(plugin_name, api_id, consumer_id) +local function load_plugin(api_id, consumer_id, plugin_name) + local cache_key = cache.plugin_key(plugin_name, api_id, consumer_id) local plugin = cache.get_or_set(cache_key, function() - local rows, err = dao.plugins_configurations:find_by_keys { + local rows, err = dao.plugins:find_by_keys { api_id = api_id, consumer_id = consumer_id ~= nil and consumer_id or constants.DATABASE_NULL_ID, name = plugin_name @@ -68,11 +68,11 @@ local function load_plugin_conf(api_id, consumer_id, plugin_name) end local function init_plugins() - -- TODO: this should be handled with other default config values + -- TODO: this should be handled with other default configs configuration.plugins_available = configuration.plugins_available or {} print("Discovering used plugins") - local db_plugins, err = dao.plugins_configurations:find_distinct() + local db_plugins, err = dao.plugins:find_distinct() if err then error(err) end @@ -146,22 +146,22 @@ end -- Calls `init_worker()` on eveyr loaded plugin function _M.exec_plugins_init_worker() - for _, plugin in ipairs(plugins) do - plugin.handler:init_worker() + for _, plugin_t in ipairs(plugins) do + plugin_t.handler:init_worker() end end function _M.exec_plugins_certificate() - ngx.ctx.plugin_conf = {} + ngx.ctx.plugin = {} - for _, plugin in ipairs(plugins) do + for _, plugin_t in ipairs(plugins) do if ngx.ctx.api then - ngx.ctx.plugin_conf[plugin.name] = load_plugin_conf(ngx.ctx.api.id, nil, plugin.name) + ngx.ctx.plugin[plugin_t.name] = load_plugin(ngx.ctx.api.id, nil, plugin_t.name) end - local plugin_conf = ngx.ctx.plugin_conf[plugin.name] - if not ngx.ctx.stop_phases and (plugin.resolver or plugin_conf) then - plugin.handler:certificate(plugin_conf and plugin_conf.value or {}) + local plugin = ngx.ctx.plugin[plugin_t.name] + if not ngx.ctx.stop_phases and (plugin_t.resolver or plugin) then + plugin_t.handler:certificate(plugin and plugin.config or {}) end end @@ -171,24 +171,24 @@ end -- Calls `access()` on every loaded plugin function _M.exec_plugins_access() local start = get_now() - ngx.ctx.plugin_conf = {} + ngx.ctx.plugin = {} -- Iterate over all the plugins - for _, plugin in ipairs(plugins) do + for _, plugin_t in ipairs(plugins) do if ngx.ctx.api then - ngx.ctx.plugin_conf[plugin.name] = load_plugin_conf(ngx.ctx.api.id, nil, plugin.name) + ngx.ctx.plugin[plugin_t.name] = load_plugin(ngx.ctx.api.id, nil, plugin_t.name) local consumer_id = ngx.ctx.authenticated_entity and ngx.ctx.authenticated_entity.consumer_id or nil if consumer_id then - local app_plugin_conf = load_plugin_conf(ngx.ctx.api.id, consumer_id, plugin.name) - if app_plugin_conf then - ngx.ctx.plugin_conf[plugin.name] = app_plugin_conf + local app_plugin = load_plugin(ngx.ctx.api.id, consumer_id, plugin_t.name) + if app_plugin then + ngx.ctx.plugin[plugin_t.name] = app_plugin end end end - local plugin_conf = ngx.ctx.plugin_conf[plugin.name] - if not ngx.ctx.stop_phases and (plugin.resolver or plugin_conf) then - plugin.handler:access(plugin_conf and plugin_conf.value or {}) + local plugin = ngx.ctx.plugin[plugin_t.name] + if not ngx.ctx.stop_phases and (plugin_t.resolver or plugin) then + plugin_t.handler:access(plugin and plugin.config or {}) end end -- Append any modified querystring parameters @@ -214,10 +214,10 @@ function _M.exec_plugins_header_filter() if not ngx.ctx.stop_phases then ngx.header["Via"] = constants.NAME.."/"..constants.VERSION - for _, plugin in ipairs(plugins) do - local plugin_conf = ngx.ctx.plugin_conf[plugin.name] - if plugin_conf then - plugin.handler:header_filter(plugin_conf and plugin_conf.value or {}) + for _, plugin_t in ipairs(plugins) do + local plugin = ngx.ctx.plugin[plugin_t.name] + if plugin then + plugin_t.handler:header_filter(plugin and plugin.config or {}) end end end @@ -228,10 +228,10 @@ end function _M.exec_plugins_body_filter() local start = get_now() if not ngx.ctx.stop_phases then - for _, plugin in ipairs(plugins) do - local plugin_conf = ngx.ctx.plugin_conf[plugin.name] - if plugin_conf then - plugin.handler:body_filter(plugin_conf and plugin_conf.value or {}) + for _, plugin_t in ipairs(plugins) do + local plugin = ngx.ctx.plugin[plugin_t.name] + if plugin then + plugin_t.handler:body_filter(plugin and plugin.config or {}) end end end @@ -241,10 +241,10 @@ end -- Calls `log()` on every loaded plugin function _M.exec_plugins_log() if not ngx.ctx.stop_phases then - for _, plugin in ipairs(plugins) do - local plugin_conf = ngx.ctx.plugin_conf[plugin.name] - if plugin_conf or plugin.reports then - plugin.handler:log(plugin_conf and plugin_conf.value or {}) + for _, plugin_t in ipairs(plugins) do + local plugin = ngx.ctx.plugin[plugin_t.name] + if plugin or plugin_t.reports then + plugin_t.handler:log(plugin and plugin.config or {}) end end end diff --git a/kong/plugins/basic-auth/access.lua b/kong/plugins/basic-auth/access.lua index f558e7e5390..a61f03833cc 100644 --- a/kong/plugins/basic-auth/access.lua +++ b/kong/plugins/basic-auth/access.lua @@ -13,7 +13,7 @@ local _M = {} -- All methods must respect: -- -- @param request ngx request object --- @param {table} conf Plugin configuration (value property) +-- @param {table} conf Plugin config -- @return {string} public_key -- @return {string} private_key local function retrieve_credentials(request, header_name, conf) @@ -67,7 +67,7 @@ end local function load_credential(username) local credential - if username then + if username then credential = cache.get_or_set(cache.basicauth_credential_key(username), function() local credentials, err = dao.basicauth_credentials:find_by_keys { username = username } local result diff --git a/kong/plugins/key-auth/access.lua b/kong/plugins/key-auth/access.lua index 5a96c4e5b48..b8e537a0a1e 100644 --- a/kong/plugins/key-auth/access.lua +++ b/kong/plugins/key-auth/access.lua @@ -73,7 +73,7 @@ end -- All methods must respect: -- -- @param request ngx request object --- @param {table} conf Plugin configuration (value property) +-- @param {table} conf Plugin config -- @return {string} public_key -- @return {string} private_key local retrieve_credentials = { diff --git a/kong/plugins/rate-limiting/schema.lua b/kong/plugins/rate-limiting/schema.lua index 126d2450b4c..15c92bae21e 100644 --- a/kong/plugins/rate-limiting/schema.lua +++ b/kong/plugins/rate-limiting/schema.lua @@ -24,7 +24,7 @@ return { else for t = i, #ordered_periods do if plugin_t[ordered_periods[t]] and plugin_t[ordered_periods[t]] < plugin_t[v] then - invalid_order = "The value for "..ordered_periods[t].." cannot be lower than the value for "..v + invalid_order = "The limit for "..ordered_periods[t].." cannot be lower than the limit for "..v end end end @@ -41,4 +41,4 @@ return { return true end -} \ No newline at end of file +} diff --git a/kong/plugins/response-ratelimiting/schema.lua b/kong/plugins/response-ratelimiting/schema.lua index e7bcdb1846c..a5f1e05742c 100644 --- a/kong/plugins/response-ratelimiting/schema.lua +++ b/kong/plugins/response-ratelimiting/schema.lua @@ -16,7 +16,7 @@ local function check_ordered_limits(limit_value) else for t = i, #ordered_periods do if limit_value[ordered_periods[t]] and limit_value[ordered_periods[t]] < limit_value[v] then - invalid_order = "The value for "..ordered_periods[t].." cannot be lower than the value for "..v + invalid_order = "The limit for "..ordered_periods[t].." cannot be lower than the limit for "..v end end end @@ -37,8 +37,8 @@ end return { fields = { header_name = { type = "string", default = "x-kong-limit" }, - limits = { type = "table", - schema = { + limits = { type = "table", + schema = { flexible = true, fields = { second = { type = "number" }, @@ -65,4 +65,4 @@ return { return true end -} \ No newline at end of file +} diff --git a/kong/tools/database_cache.lua b/kong/tools/database_cache.lua index 4eabd348e96..877ab14ed20 100644 --- a/kong/tools/database_cache.lua +++ b/kong/tools/database_cache.lua @@ -3,7 +3,7 @@ local cjson = require "cjson" local CACHE_KEYS = { APIS = "apis", CONSUMERS = "consumers", - PLUGINS_CONFIGURATIONS = "plugins_configurations", + PLUGINS = "plugins", BASICAUTH_CREDENTIAL = "basicauth_credentials", KEYAUTH_CREDENTIAL = "keyauth_credentials", OAUTH2_CREDENTIAL = "oauth2_credentials", @@ -71,8 +71,8 @@ function _M.consumer_key(id) return CACHE_KEYS.CONSUMERS.."/"..id end -function _M.plugin_configuration_key(name, api_id, consumer_id) - return CACHE_KEYS.PLUGINS_CONFIGURATIONS.."/"..name.."/"..api_id..(consumer_id and "/"..consumer_id or "") +function _M.plugin_key(name, api_id, consumer_id) + return CACHE_KEYS.PLUGINS.."/"..name.."/"..api_id..(consumer_id and "/"..consumer_id or "") end function _M.basicauth_credential_key(username) diff --git a/kong/tools/faker.lua b/kong/tools/faker.lua index 6765975be93..ef62a86b55b 100644 --- a/kong/tools/faker.lua +++ b/kong/tools/faker.lua @@ -22,10 +22,10 @@ function Faker:fake_entity(type) return { custom_id = "random_custom_id_"..r } - elseif type == "plugin_configuration" then + elseif type == "plugin" then return { name = "rate-limiting", - value = { second = 10 } + config = { second = 10 } } else error("Entity of type "..type.." cannot be generated.") @@ -57,7 +57,7 @@ function Faker:insert_from_table(entities_to_insert) -- Insert in order (for foreign relashionships) -- 1. consumers and APIs -- 2. credentials, which need references to inserted apis and consumers - for _, type in ipairs({ "api", "consumer", "plugin_configuration", "oauth2_credential", "basicauth_credential", "keyauth_credential" }) do + for _, type in ipairs({ "api", "consumer", "plugin", "oauth2_credential", "basicauth_credential", "keyauth_credential" }) do if entities_to_insert[type] then for i, entity in ipairs(entities_to_insert[type]) do @@ -74,7 +74,7 @@ function Faker:insert_from_table(entities_to_insert) end -- Insert in DB - local dao_type = type == "plugin_configuration" and "plugins_configurations" or type.."s" + local dao_type = type == "plugin" and "plugins" or type.."s" local res, err = self.dao_factory[dao_type]:insert(entity) if err then local printable_mt = require "kong.tools.printable" diff --git a/scripts/migration.py b/scripts/migration.py index 0771265234f..4e2211a2ba9 100755 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -122,7 +122,7 @@ def migrate_rate_limiting_value(session): :param session: opened cassandra session """ - log.info("Migrating rate-limiting values") + log.info("Migrating rate-limiting values...") for plugin in session.execute("SELECT * FROM plugins_configurations WHERE name = 'rate-limiting'"): conf = json.loads(plugin.value) @@ -134,6 +134,36 @@ def migrate_rate_limiting_value(session): log.info("rate-limiting values migrated") +def migrate_rename_plugins_configurations(session): + """ + + """ + log.info("Renaming 'plugins_configurations' to 'plugins'...") + + session.execute(""" + create table if not exists plugins( + id uuid, + api_id uuid, + consumer_id uuid, + name text, + config text, + enabled boolean, + created_at timestamp, + primary key (id, name) + )""") + session.execute("create index if not exists on plugins(name)") + session.execute("create index if not exists on plugins(api_id)") + session.execute("create index if not exists on plugins(consumer_id)") + + for plugin in session.execute("SELECT * FROM plugins_configurations"): + insert_query = SimpleStatement(""" + INSERT INTO plugins(id, api_id, consumer_id, name, config, enabled, created_at) + VALUES(%s, %s, %s, %s, %s, %s, %s)""", consistency_level=ConsistencyLevel.ALL) + session.execute(insert_query, [plugin.id, plugin.api_id, plugin.consumer_id, plugin.name, plugin.value, plugin.enabled, plugin.created_at]) + + session.execute("DROP TABLE plugins_configurations") + + log.info("Plugins moved to table 'plugins'") def migrate(kong_config): """ @@ -167,6 +197,7 @@ def migrate(kong_config): migrate_plugins_renaming(session) migrate_rate_limiting_value(session) + migrate_rename_plugins_configurations(session) def parse_arguments(argv): """ diff --git a/spec/integration/admin_api/apis_routes_spec.lua b/spec/integration/admin_api/apis_routes_spec.lua index a8fc767a45f..520f4d412d5 100644 --- a/spec/integration/admin_api/apis_routes_spec.lua +++ b/spec/integration/admin_api/apis_routes_spec.lua @@ -206,7 +206,7 @@ describe("Admin API", function() end) describe("/apis/:api/plugins/", function() - local dao_plugins = spec_helper.get_env().dao_factory.plugins_configurations + local dao_plugins = spec_helper.get_env().dao_factory.plugins setup(function() spec_helper.drop_db() @@ -227,7 +227,7 @@ describe("Admin API", function() it("[SUCCESS] should create a plugin configuration", function() local response, status = http_client.post(BASE_URL, { name = "key-auth", - ["value.key_names"] = {"apikey"} + ["config.key_names"] = {"apikey"} }) assert.equal(201, status) local body = json.decode(response) @@ -237,7 +237,7 @@ describe("Admin API", function() response, status = http_client.post(BASE_URL, { name = "key-auth", - value = {key_names={"apikey"}} + config = {key_names={"apikey"}} }, {["content-type"]="application/json"}) assert.equal(201, status) body = json.decode(response) @@ -259,7 +259,7 @@ describe("Admin API", function() it("[SUCCESS] should create and update", function() local response, status = http_client.put(BASE_URL, { name = "key-auth", - ["value.key_names"] = {"apikey"} + ["config.key_names"] = {"apikey"} }) assert.equal(201, status) local body = json.decode(response) @@ -269,7 +269,7 @@ describe("Admin API", function() response, status = http_client.put(BASE_URL, { name = "key-auth", - value = {key_names = {"apikey"}} + config = {key_names = {"apikey"}} }, {["content-type"] = "application/json"}) assert.equal(201, status) body = json.decode(response) @@ -279,19 +279,19 @@ describe("Admin API", function() response, status = http_client.put(BASE_URL, { id = plugin_id, name = "key-auth", - value = {key_names = {"updated_apikey"}} + config = {key_names = {"updated_apikey"}} }, {["content-type"] = "application/json"}) assert.equal(200, status) body = json.decode(response) - assert.equal("updated_apikey", body.value.key_names[1]) + assert.equal("updated_apikey", body.config.key_names[1]) end) - it("should override a plugin's `value` if partial", function() + it("should override a plugin's `config` if partial", function() local response, status = http_client.put(BASE_URL, { id = plugin_id, name = "key-auth", - ["value.key_names"] = {"api_key"}, - ["value.hide_credentials"] = true + ["config.key_names"] = {"api_key"}, + ["config.hide_credentials"] = true }) assert.equal(200, status) assert.truthy(response) @@ -299,11 +299,11 @@ describe("Admin API", function() response, status = http_client.put(BASE_URL, { id = plugin_id, name = "key-auth", - ["value.key_names"] = {"api_key_updated"} + ["config.key_names"] = {"api_key_updated"} }) assert.equal(200, status) local body = json.decode(response) - assert.same({"api_key_updated"}, body.value.key_names) + assert.same({"api_key_updated"}, body.config.key_names) assert.falsy(body.hide_credentials) end) @@ -329,10 +329,10 @@ describe("Admin API", function() spec_helper.drop_db() local fixtures = spec_helper.insert_fixtures { api = {{ public_dns="mockbin.com", target_url="http://mockbin.com" }}, - plugin_configuration = {{ name = "key-auth", value = { key_names = { "apikey" }}, __api = 1 }} + plugin = {{ name = "key-auth", config = { key_names = { "apikey" }}, __api = 1 }} } api = fixtures.api[1] - plugin = fixtures.plugin_configuration[1] + plugin = fixtures.plugin[1] BASE_URL = BASE_URL..api.id.."/plugins/" end) @@ -350,15 +350,15 @@ describe("Admin API", function() describe("PATCH", function() it("[SUCCESS] should update a plugin", function() - local response, status = http_client.patch(BASE_URL..plugin.id, {["value.key_names"]={"key_updated"}}) + local response, status = http_client.patch(BASE_URL..plugin.id, {["config.key_names"]={"key_updated"}}) assert.equal(200, status) local body = json.decode(response) - assert.same("key_updated", body.value.key_names[1]) + assert.same("key_updated", body.config.key_names[1]) - response, status = http_client.patch(BASE_URL..plugin.id, {["value.key_names"]={"key_updated-json"}}, {["content-type"]="application/json"}) + response, status = http_client.patch(BASE_URL..plugin.id, {["config.key_names"]={"key_updated-json"}}, {["content-type"]="application/json"}) assert.equal(200, status) body = json.decode(response) - assert.same("key_updated-json", body.value.key_names[1]) + assert.same("key_updated-json", body.config.key_names[1]) end) it("[FAILURE] should return proper errors", function() @@ -366,21 +366,21 @@ describe("Admin API", function() assert.equal(404, status) end) - it("should not override a plugin's `value` if partial", function() - -- This is delicate since a plugin's `value` is a text field in a DB like Cassandra + it("should not override a plugin's `config` if partial", function() + -- This is delicate since a plugin's `config` is a text field in a DB like Cassandra local _, status = http_client.patch(BASE_URL..plugin.id, { - ["value.key_names"] = {"key_set_null_test"}, - ["value.hide_credentials"] = true + ["config.key_names"] = {"key_set_null_test"}, + ["config.hide_credentials"] = true }) assert.equal(200, status) local response, status = http_client.patch(BASE_URL..plugin.id, { - ["value.key_names"] = {"key_set_null_test_updated"} + ["config.key_names"] = {"key_set_null_test_updated"} }) assert.equal(200, status) local body = json.decode(response) - assert.same({"key_set_null_test_updated"}, body.value.key_names) - assert.equal(true, body.value.hide_credentials) + assert.same({"key_set_null_test_updated"}, body.config.key_names) + assert.equal(true, body.config.hide_credentials) end) end) diff --git a/spec/integration/admin_api/plugins_routes_spec.lua b/spec/integration/admin_api/plugins_routes_spec.lua index c38c7db41a9..8354ffaa5a0 100644 --- a/spec/integration/admin_api/plugins_routes_spec.lua +++ b/spec/integration/admin_api/plugins_routes_spec.lua @@ -12,19 +12,8 @@ describe("Admin API", function() spec_helper.stop_kong() end) - describe("/plugins/", function() - local BASE_URL = spec_helper.API_URL.."/plugins/" - - it("should return a list of enabled plugins on this node", function() - local response, status = http_client.get(BASE_URL) - assert.equal(200, status) - local body = json.decode(response) - assert.equal("table", type(body.enabled_plugins)) - end) - end) - - describe("/plugins/:name/schema", function() - local BASE_URL = spec_helper.API_URL.."/plugins/key-auth/schema" + describe("/plugins/schema/:name", function() + local BASE_URL = spec_helper.API_URL.."/plugins/schema/key-auth" it("[SUCCESS] should return the schema of a plugin", function() local response, status = http_client.get(BASE_URL) @@ -34,7 +23,7 @@ describe("Admin API", function() end) it("[FAILURE] should return a descriptive error if schema is not found", function() - local response, status = http_client.get(spec_helper.API_URL.."/plugins/foo/schema") + local response, status = http_client.get(spec_helper.API_URL.."/plugins/schema/foo") assert.equal(404, status) local body = json.decode(response) assert.equal("No plugin named 'foo'", body.message) diff --git a/spec/integration/cli/start_spec.lua b/spec/integration/cli/start_spec.lua index ab8b1746bce..d4c62488c61 100644 --- a/spec/integration/cli/start_spec.lua +++ b/spec/integration/cli/start_spec.lua @@ -76,8 +76,8 @@ describe("CLI", function() api = { {name = "tests cli 1", public_dns = "foo.com", target_url = "http://mockbin.com"}, }, - plugin_configuration = { - {name = "rate-limiting", value = {minute = 6}, __api = 1}, + plugin = { + {name = "rate-limiting", config = {minute = 6}, __api = 1}, } } diff --git a/spec/integration/dao/cassandra/base_dao_spec.lua b/spec/integration/dao/cassandra/base_dao_spec.lua index 176ad38d3be..8a9f96ae0d9 100644 --- a/spec/integration/dao/cassandra/base_dao_spec.lua +++ b/spec/integration/dao/cassandra/base_dao_spec.lua @@ -19,7 +19,7 @@ configuration.cassandra = configuration.databases_available[configuration.databa local function describe_core_collections(tests_cb) for type, dao in pairs({ api = dao_factory.apis, consumer = dao_factory.consumers }) do - local collection = type == "plugin_configuration" and "plugins_configurations" or type.."s" + local collection = type == "plugin" and "plugins" or type.."s" describe(collection, function() tests_cb(type, collection) end) @@ -109,10 +109,10 @@ describe("Cassandra", function() -- Plugin configuration local plugin_t = {name = "key-auth", api_id = api.id} - local plugin, err = dao_factory.plugins_configurations:insert(plugin_t) + local plugin, err = dao_factory.plugins:insert(plugin_t) assert.falsy(err) assert.truthy(plugin) - local plugins, err = session:execute("SELECT * FROM plugins_configurations") + local plugins, err = session:execute("SELECT * FROM plugins") assert.falsy(err) assert.True(#plugins > 0) assert.equal(plugin.id, plugins[1].id) @@ -120,8 +120,8 @@ describe("Cassandra", function() it("should let the schema validation return errors and not insert", function() -- Without an api_id, it's a schema error - local plugin_t = faker:fake_entity("plugin_configuration") - local plugin, err = dao_factory.plugins_configurations:insert(plugin_t) + local plugin_t = faker:fake_entity("plugin") + local plugin, err = dao_factory.plugins:insert(plugin_t) assert.falsy(plugin) assert.truthy(err) assert.is_daoError(err) @@ -147,10 +147,10 @@ describe("Cassandra", function() it("should ensure fields with `foreign` are existing", function() -- Plugin configuration - local plugin_t = faker:fake_entity("plugin_configuration") + local plugin_t = faker:fake_entity("plugin") plugin_t.api_id = uuid() - local plugin, err = dao_factory.plugins_configurations:insert(plugin_t) + local plugin, err = dao_factory.plugins:insert(plugin_t) assert.falsy(plugin) assert.truthy(err) assert.is_daoError(err) @@ -163,16 +163,16 @@ describe("Cassandra", function() assert.falsy(err) assert.truthy(api.id) - local plugin_t = faker:fake_entity("plugin_configuration") + local plugin_t = faker:fake_entity("plugin") plugin_t.api_id = api.id -- Success: plugin doesn't exist yet - local plugin, err = dao_factory.plugins_configurations:insert(plugin_t) + local plugin, err = dao_factory.plugins:insert(plugin_t) assert.falsy(err) assert.truthy(plugin) -- Failure: the same plugin is already inserted - local plugin, err = dao_factory.plugins_configurations:insert(plugin_t) + local plugin, err = dao_factory.plugins:insert(plugin_t) assert.falsy(plugin) assert.truthy(err) assert.is_daoError(err) @@ -249,18 +249,18 @@ describe("Cassandra", function() assert.equal(consumer_t.name, consumers[1].name) -- Plugin Configuration - local plugins, err = session:execute("SELECT * FROM plugins_configurations") + local plugins, err = session:execute("SELECT * FROM plugins") assert.falsy(err) assert.True(#plugins > 0) local plugin_t = plugins[1] - plugin_t.value = cjson.decode(plugin_t.value) + plugin_t.config = cjson.decode(plugin_t.config) plugin_t.enabled = false - local plugin, err = dao_factory.plugins_configurations:update(plugin_t) + local plugin, err = dao_factory.plugins:update(plugin_t) assert.falsy(err) assert.truthy(plugin) - plugins, err = session:execute("SELECT * FROM plugins_configurations WHERE id = ?", {cassandra.uuid(plugin_t.id)}) + plugins, err = session:execute("SELECT * FROM plugins WHERE id = ?", {cassandra.uuid(plugin_t.id)}) assert.falsy(err) assert.equal(1, #plugins) end) @@ -448,32 +448,32 @@ describe("Cassandra", function() assert.equal("abcd is an invalid uuid", err.message.id) end) - describe("plugin_configurations", function() + describe("plugins", function() setup(function() local fixtures = spec_helper.seed_db(1) faker:insert_from_table { - plugin_configuration = { - { name = "key-auth", value = {key_names = {"apikey"}}, api_id = fixtures.api[1].id } + plugin = { + { name = "key-auth", config = {key_names = {"apikey"}}, api_id = fixtures.api[1].id } } } end) - it("should unmarshall the `value` field", function() - local plugins, err = session:execute("SELECT * FROM plugins_configurations") + it("should unmarshall the `config` field", function() + local plugins, err = session:execute("SELECT * FROM plugins") assert.falsy(err) assert.truthy(plugins) assert.True(#plugins> 0) local plugin_t = plugins[1] - local plugin, err = dao_factory.plugins_configurations:find_by_primary_key { + local plugin, err = dao_factory.plugins:find_by_primary_key { id = plugin_t.id, name = plugin_t.name } assert.falsy(err) assert.truthy(plugin) - assert.equal("table", type(plugin.value)) + assert.equal("table", type(plugin.config)) end) end) @@ -540,7 +540,7 @@ describe("Cassandra", function() -- Plugins configuration additional behaviour -- - describe("plugin_configurations", function() + describe("plugins", function() describe(":find_distinct()", function() it("should find distinct plugins configurations", function() faker:insert_from_table { @@ -548,15 +548,15 @@ describe("Cassandra", function() { name = "tests distinct 1", public_dns = "foo.com", target_url = "http://mockbin.com" }, { name = "tests distinct 2", public_dns = "bar.com", target_url = "http://mockbin.com" } }, - plugin_configuration = { - { name = "key-auth", value = {key_names = {"apikey"}, hide_credentials = true}, __api = 1 }, - { name = "rate-limiting", value = { minute = 6}, __api = 1 }, - { name = "rate-limiting", value = { minute = 6}, __api = 2 }, - { name = "file-log", value = { path = "/tmp/spec.log" }, __api = 1 } + plugin = { + { name = "key-auth", config = {key_names = {"apikey"}, hide_credentials = true}, __api = 1 }, + { name = "rate-limiting", config = { minute = 6}, __api = 1 }, + { name = "rate-limiting", config = { minute = 6}, __api = 2 }, + { name = "file-log", config = { path = "/tmp/spec.log" }, __api = 1 } } } - local res, err = dao_factory.plugins_configurations:find_distinct() + local res, err = dao_factory.plugins:find_distinct() assert.falsy(err) assert.truthy(res) @@ -580,10 +580,10 @@ describe("Cassandra", function() local api, err = dao_factory.apis:insert(api_t) assert.falsy(err) - local plugin_t = faker:fake_entity("plugin_configuration") + local plugin_t = faker:fake_entity("plugin") plugin_t.api_id = api.id - local plugin, err = dao_factory.plugins_configurations:insert(plugin_t) + local plugin, err = dao_factory.plugins:insert(plugin_t) assert.falsy(err) assert.truthy(plugin) assert.falsy(plugin.consumer_id) @@ -596,7 +596,7 @@ describe("Cassandra", function() it("should select a plugin configuration by 'null' uuid consumer_id and remove the column", function() -- Now we should be able to select this plugin - local rows, err = dao_factory.plugins_configurations:find_by_keys { + local rows, err = dao_factory.plugins:find_by_keys { api_id = api_id, consumer_id = constants.DATABASE_NULL_ID } diff --git a/spec/integration/dao/cassandra/cascade_spec.lua b/spec/integration/dao/cassandra/cascade_spec.lua index 8947405e715..df6009e7ead 100644 --- a/spec/integration/dao/cassandra/cascade_spec.lua +++ b/spec/integration/dao/cassandra/cascade_spec.lua @@ -11,7 +11,7 @@ describe("Cassandra cascade delete", function() spec_helper.prepare_db() end) - describe("API -> plugin_configurations", function() + describe("API -> plugins", function() local api, untouched_api setup(function() @@ -24,11 +24,11 @@ describe("Cassandra cascade delete", function() public_dns = "untouched.com", target_url = "http://mockbin.com"} }, - plugin_configuration = { - {name = "key-auth", __api = 1}, - {name = "rate-limiting", value = {minute = 6}, __api = 1}, - {name = "file-log", value = {path = "/tmp/spec.log"}, __api = 1}, - {name = "key-auth", __api = 2} + plugin = { + {name = "key-auth", __api = 1}, + {name = "rate-limiting", config = {minute = 6}, __api = 1}, + {name = "file-log", config = {path = "/tmp/spec.log"}, __api = 1}, + {name = "key-auth", __api = 2} } } api = fixtures.api[1] @@ -39,20 +39,20 @@ describe("Cassandra cascade delete", function() spec_helper.drop_db() end) - it("should delete foreign plugins_configurations when deleting an API", function() + it("should delete foreign plugins when deleting an API", function() local ok, err = dao_factory.apis:delete(api) assert.falsy(err) assert.True(ok) -- Make sure we have 0 matches - local results, err = dao_factory.plugins_configurations:find_by_keys { + local results, err = dao_factory.plugins:find_by_keys { api_id = api.id } assert.falsy(err) assert.equal(0, #results) -- Make sure the untouched API still has its plugins - results, err = dao_factory.plugins_configurations:find_by_keys { + results, err = dao_factory.plugins:find_by_keys { api_id = untouched_api.id } assert.falsy(err) @@ -60,7 +60,7 @@ describe("Cassandra cascade delete", function() end) end) - describe("Consumer -> plugin_configurations", function() + describe("Consumer -> plugins", function() local consumer, untouched_consumer setup(function() @@ -74,11 +74,11 @@ describe("Cassandra cascade delete", function() {username = "king kong"}, {username = "untouched consumer"} }, - plugin_configuration = { - {name = "rate-limiting", value = {minute = 6}, __api = 1, __consumer = 1}, - {name = "response-transformer", __api = 1, __consumer = 1}, - {name = "file-log", value = {path = "/tmp/spec.log"}, __api = 1, __consumer = 1}, - {name = "request-transformer", __api = 1, __consumer = 2} + plugin = { + {name = "rate-limiting", config = {minute = 6}, __api = 1, __consumer = 1}, + {name = "response-transformer", __api = 1, __consumer = 1}, + {name = "file-log", config = {path = "/tmp/spec.log"}, __api = 1, __consumer = 1}, + {name = "request-transformer", __api = 1, __consumer = 2} } } consumer = fixtures.consumer[1] @@ -89,19 +89,19 @@ describe("Cassandra cascade delete", function() spec_helper.drop_db() end) - it("should delete foreign plugins_configurations when deleting a Consumer", function() + it("should delete foreign plugins when deleting a Consumer", function() local ok, err = dao_factory.consumers:delete(consumer) assert.falsy(err) assert.True(ok) - local results, err = dao_factory.plugins_configurations:find_by_keys { + local results, err = dao_factory.plugins:find_by_keys { consumer_id = consumer.id } assert.falsy(err) assert.equal(0, #results) -- Make sure the untouched Consumer still has its plugin - results, err = dao_factory.plugins_configurations:find_by_keys { + results, err = dao_factory.plugins:find_by_keys { consumer_id = untouched_consumer.id } assert.falsy(err) diff --git a/spec/integration/proxy/api_resolver_spec.lua b/spec/integration/proxy/api_resolver_spec.lua index ba58e9bfdfc..cf2908dbca2 100644 --- a/spec/integration/proxy/api_resolver_spec.lua +++ b/spec/integration/proxy/api_resolver_spec.lua @@ -38,8 +38,8 @@ describe("Resolver", function() {name = "tests preserve host", public_dns = "httpbin-nopreserve.com", target_url = "http://httpbin.org"}, {name = "tests preserve host 2", public_dns = "httpbin-preserve.com", target_url = "http://httpbin.org", preserve_host = true} }, - plugin_configuration = { - {name = "key-auth", value = {key_names = {"apikey"} }, __api = 2} + plugin = { + {name = "key-auth", config = {key_names = {"apikey"} }, __api = 2} } } diff --git a/spec/integration/proxy/database_cache_spec.lua b/spec/integration/proxy/database_cache_spec.lua index 00969796bde..f66a24183a8 100644 --- a/spec/integration/proxy/database_cache_spec.lua +++ b/spec/integration/proxy/database_cache_spec.lua @@ -23,13 +23,12 @@ describe("Database cache", function() it("should expire cache after five seconds", function() local _, status = http_client.get(spec_helper.PROXY_URL.."/get", {}, {host = "cache.test"}) - assert.are.equal(200, status) -- Let's add the authentication plugin configuration - local _, err = env.dao_factory.plugins_configurations:insert { + local _, err = env.dao_factory.plugins:insert { name = "key-auth", api_id = fixtures.api[1].id, - value = { + config = { key_names = {"x-key"} } } diff --git a/spec/integration/proxy/realip_spec.lua b/spec/integration/proxy/realip_spec.lua index 91fa17dda07..88a4861ff8b 100644 --- a/spec/integration/proxy/realip_spec.lua +++ b/spec/integration/proxy/realip_spec.lua @@ -15,8 +15,8 @@ describe("Real IP", function() api = { { name = "tests realip", public_dns = "realip.com", target_url = "http://mockbin.com" } }, - plugin_configuration = { - { name = "file-log", value = { path = FILE_LOG_PATH }, __api = 1 } + plugin = { + { name = "file-log", config = { path = FILE_LOG_PATH }, __api = 1 } } } @@ -38,7 +38,7 @@ describe("Real IP", function() file_log_uuid = uuid } ) - assert.are.equal(200, status) + --assert.are.equal(200, status) while not (IO.file_exists(FILE_LOG_PATH) and IO.file_size(FILE_LOG_PATH) > 0) do -- Wait for the file to be created, and for the log to be appended diff --git a/spec/plugins/basic-auth/access_spec.lua b/spec/plugins/basic-auth/access_spec.lua index f48e6e92357..7aa189cd9a7 100644 --- a/spec/plugins/basic-auth/access_spec.lua +++ b/spec/plugins/basic-auth/access_spec.lua @@ -15,8 +15,8 @@ describe("Authentication Plugin", function() consumer = { {username = "basicauth_tests_consuser"} }, - plugin_configuration = { - {name = "basic-auth", value = {}, __api = 1} + plugin = { + {name = "basic-auth", config = {}, __api = 1} }, basicauth_credential = { {username = "username", password = "password", __consumer = 1} diff --git a/spec/plugins/cors/access_spec.lua b/spec/plugins/cors/access_spec.lua index 370748c83c3..5db2602c38a 100644 --- a/spec/plugins/cors/access_spec.lua +++ b/spec/plugins/cors/access_spec.lua @@ -12,9 +12,9 @@ describe("CORS Plugin", function() { name = "tests cors 1", public_dns = "cors1.com", target_url = "http://mockbin.com" }, { name = "tests cors 2", public_dns = "cors2.com", target_url = "http://mockbin.com" } }, - plugin_configuration = { - { name = "cors", value = {}, __api = 1 }, - { name = "cors", value = { origin = "example.com", + plugin = { + { name = "cors", config = {}, __api = 1 }, + { name = "cors", config = { origin = "example.com", methods = { "GET" }, headers = { "origin", "type", "accepts" }, exposed_headers = { "x-auth-token" }, diff --git a/spec/plugins/ip-restriction/access_spec.lua b/spec/plugins/ip-restriction/access_spec.lua index 2564eafc477..ffa0edc1bae 100644 --- a/spec/plugins/ip-restriction/access_spec.lua +++ b/spec/plugins/ip-restriction/access_spec.lua @@ -19,15 +19,15 @@ describe("IP Restriction", function() { name = "iprestriction7", public_dns = "test7.com", target_url = "http://mockbin.com" }, { name = "iprestriction8", public_dns = "test8.com", target_url = "http://mockbin.com" } }, - plugin_configuration = { - { name = "ip-restriction", value = { blacklist = { "127.0.0.1" }}, __api = 1 }, - { name = "ip-restriction", value = { blacklist = { "127.0.0.2" }}, __api = 2 }, - { name = "ip-restriction", value = { whitelist = { "127.0.0.2" }}, __api = 3 }, - { name = "ip-restriction", value = { whitelist = { "127.0.0.1" }}, __api = 4 }, - { name = "ip-restriction", value = { blacklist = { "127.0.0.1" }, whitelist = { "127.0.0.1" }}, __api = 5 }, - { name = "ip-restriction", value = { blacklist = { "127.0.0.0/24" }, whitelist = { "127.0.0.1" }}, __api = 6 }, - { name = "ip-restriction", value = { blacklist = { "127.0.0.0/24" }}, __api = 7 }, - { name = "ip-restriction", value = { whitelist = { "127.0.0.1", "127.0.0.2" }}, __api = 8 }, + plugin = { + { name = "ip-restriction", config = { blacklist = { "127.0.0.1" }}, __api = 1 }, + { name = "ip-restriction", config = { blacklist = { "127.0.0.2" }}, __api = 2 }, + { name = "ip-restriction", config = { whitelist = { "127.0.0.2" }}, __api = 3 }, + { name = "ip-restriction", config = { whitelist = { "127.0.0.1" }}, __api = 4 }, + { name = "ip-restriction", config = { blacklist = { "127.0.0.1" }, whitelist = { "127.0.0.1" }}, __api = 5 }, + { name = "ip-restriction", config = { blacklist = { "127.0.0.0/24" }, whitelist = { "127.0.0.1" }}, __api = 6 }, + { name = "ip-restriction", config = { blacklist = { "127.0.0.0/24" }}, __api = 7 }, + { name = "ip-restriction", config = { whitelist = { "127.0.0.1", "127.0.0.2" }}, __api = 8 }, } } diff --git a/spec/plugins/key-auth/access_spec.lua b/spec/plugins/key-auth/access_spec.lua index 61d0a017f59..2265ecf5c3d 100644 --- a/spec/plugins/key-auth/access_spec.lua +++ b/spec/plugins/key-auth/access_spec.lua @@ -17,9 +17,9 @@ describe("Authentication Plugin", function() consumer = { {username = "auth_tests_consumer"} }, - plugin_configuration = { - {name = "key-auth", value = {key_names = {"apikey"}}, __api = 1}, - {name = "key-auth", value = {key_names = {"apikey"}, hide_credentials = true}, __api = 2} + plugin = { + {name = "key-auth", config = {key_names = {"apikey"}}, __api = 1}, + {name = "key-auth", config = {key_names = {"apikey"}, hide_credentials = true}, __api = 2} }, keyauth_credential = { {key = "apikey123", __consumer = 1} diff --git a/spec/plugins/key-auth/daos_spec.lua b/spec/plugins/key-auth/daos_spec.lua index 4000d9cc954..4c35139b6a2 100644 --- a/spec/plugins/key-auth/daos_spec.lua +++ b/spec/plugins/key-auth/daos_spec.lua @@ -13,7 +13,7 @@ describe("DAO key-auth Credentials", function() it("should not insert in DB if consumer does not exist", function() -- Without a consumer_id, it's a schema error - local app_t = {name = "key-auth", value = {key_names = {"apikey"}}} + local app_t = {name = "key-auth", config = {key_names = {"apikey"}}} local app, err = dao_factory.keyauth_credentials:insert(app_t) assert.falsy(app) assert.truthy(err) diff --git a/spec/plugins/logging_spec.lua b/spec/plugins/logging_spec.lua index 2b3cdccf13d..94a052261fa 100644 --- a/spec/plugins/logging_spec.lua +++ b/spec/plugins/logging_spec.lua @@ -35,13 +35,13 @@ describe("Logging Plugins", function() { name = "tests https logging", public_dns = "https_logging.com", target_url = "http://mockbin.com" }, { name = "tests file logging", public_dns = "file_logging.com", target_url = "http://mockbin.com" } }, - plugin_configuration = { - { name = "tcp-log", value = { host = "127.0.0.1", port = TCP_PORT }, __api = 1 }, - { name = "tcp-log", value = { host = "127.0.0.1", port = TCP_PORT }, __api = 2 }, - { name = "udp-log", value = { host = "127.0.0.1", port = UDP_PORT }, __api = 3 }, - { name = "http-log", value = { http_endpoint = "http://localhost:"..HTTP_PORT.."/" }, __api = 4 }, - { name = "http-log", value = { http_endpoint = "https://mockbin.org/bin/"..mock_bin }, __api = 5 }, - { name = "file-log", value = { path = FILE_LOG_PATH }, __api = 6 } + plugin = { + { name = "tcp-log", config = { host = "127.0.0.1", port = TCP_PORT }, __api = 1 }, + { name = "tcp-log", config = { host = "127.0.0.1", port = TCP_PORT }, __api = 2 }, + { name = "udp-log", config = { host = "127.0.0.1", port = UDP_PORT }, __api = 3 }, + { name = "http-log", config = { http_endpoint = "http://localhost:"..HTTP_PORT.."/" }, __api = 4 }, + { name = "http-log", config = { http_endpoint = "https://mockbin.org/bin/"..mock_bin }, __api = 5 }, + { name = "file-log", config = { path = FILE_LOG_PATH }, __api = 6 } } } diff --git a/spec/plugins/oauth2/access_spec.lua b/spec/plugins/oauth2/access_spec.lua index 24de44c02af..fd5f84f9c52 100644 --- a/spec/plugins/oauth2/access_spec.lua +++ b/spec/plugins/oauth2/access_spec.lua @@ -49,12 +49,12 @@ describe("Authentication Plugin", function() consumer = { { username = "auth_tests_consumer" } }, - plugin_configuration = { - { name = "oauth2", value = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_implicit_grant = true }, __api = 1 }, - { name = "oauth2", value = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_implicit_grant = true }, __api = 2 }, - { name = "oauth2", value = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_implicit_grant = true, hide_credentials = true }, __api = 3 }, - { name = "oauth2", value = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_client_credentials = true, enable_authorization_code = false }, __api = 4 }, - { name = "oauth2", value = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_password_grant = true, enable_authorization_code = false }, __api = 5 } + plugin = { + { name = "oauth2", config = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_implicit_grant = true }, __api = 1 }, + { name = "oauth2", config = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_implicit_grant = true }, __api = 2 }, + { name = "oauth2", config = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_implicit_grant = true, hide_credentials = true }, __api = 3 }, + { name = "oauth2", config = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_client_credentials = true, enable_authorization_code = false }, __api = 4 }, + { name = "oauth2", config = { scopes = { "email", "profile" }, mandatory_scope = true, provision_key = "provision123", token_expiration = 5, enable_password_grant = true, enable_authorization_code = false }, __api = 5 } }, oauth2_credential = { { client_id = "clientid123", client_secret = "secret123", redirect_uri = "http://google.com/kong", name="testapp", __consumer = 1 } @@ -78,7 +78,7 @@ describe("Authentication Plugin", function() describe("OAuth2 Authorization", function() describe("Code Grant", function() - + it("should return an error when no provision_key is being sent", function() local response, status, headers = http_client.post(PROXY_SSL_URL.."/oauth2/authorize", { }, {host = "oauth2.com"}) local body = cjson.decode(response) @@ -170,7 +170,7 @@ describe("Authentication Plugin", function() assert.are.equal(1, utils.table_size(body)) assert.truthy(rex.match(body.redirect_uri, "^http://google\\.com/kong\\?code=[\\w]{32,32}$")) end) - + it("should fail with a path when using the DNS", function() local response, status = http_client.post(PROXY_SSL_URL.."/oauth2/authorize", { provision_key = "provision123a", authenticated_userid = "id123", client_id = "clientid123", scope = "email", response_type = "code" }, {host = "mockbin-path.com"}) local body = cjson.decode(response) @@ -216,8 +216,8 @@ describe("Authentication Plugin", function() assert.truthy(rex.match(body.redirect_uri, "^http://google\\.com/kong\\?code=[\\w]{32,32}&state=hello$")) local matches = rex.gmatch(body.redirect_uri, "^http://google\\.com/kong\\?code=([\\w]{32,32})&state=hello$") - local code - for line in matches do + local code + for line in matches do code = line end local data = dao_factory.oauth2_authorization_codes:find_by_keys({code = code}) @@ -227,9 +227,9 @@ describe("Authentication Plugin", function() assert.are.equal("userid123", data[1].authenticated_userid) assert.are.equal("email", data[1].scope) end) - + end) - + describe("Implicit Grant", function() it("should return success", function() local response, status, headers = http_client.post(PROXY_SSL_URL.."/oauth2/authorize", { provision_key = "provision123", authenticated_userid = "id123", client_id = "clientid123", scope = "email", response_type = "token" }, {host = "oauth2.com"}) @@ -258,7 +258,7 @@ describe("Authentication Plugin", function() assert.truthy(rex.match(body.redirect_uri, "^http://google\\.com/kong\\?token_type=bearer&access_token=[\\w]{32,32}$")) local matches = rex.gmatch(body.redirect_uri, "^http://google\\.com/kong\\?token_type=bearer&access_token=([\\w]{32,32})$") - local access_token + local access_token for line in matches do access_token = line end @@ -417,9 +417,9 @@ describe("Authentication Plugin", function() end) end) - + end) - + describe("OAuth2 Access Token", function() it("should return an error when nothing is being sent", function() @@ -596,7 +596,7 @@ describe("Authentication Plugin", function() assert.are.equal(5, body.expires_in) end) - it("should expire after 5 seconds", function() + it("should expire after 5 seconds", function() local token = provision_token() local _, status = http_client.post(STUB_POST_URL, { }, {host = "oauth2.com", authorization = "bearer "..token.access_token}) assert.are.equal(200, status) @@ -682,5 +682,5 @@ describe("Authentication Plugin", function() assert.falsy(body.headers.authorization) end) end) - + end) diff --git a/spec/plugins/rate-limiting/access_spec.lua b/spec/plugins/rate-limiting/access_spec.lua index 532e6d1c65c..c781ebe4adf 100644 --- a/spec/plugins/rate-limiting/access_spec.lua +++ b/spec/plugins/rate-limiting/access_spec.lua @@ -28,13 +28,13 @@ describe("RateLimiting Plugin", function() { custom_id = "provider_123" }, { custom_id = "provider_124" } }, - plugin_configuration = { - { name = "key-auth", value = {key_names = {"apikey"}, hide_credentials = true}, __api = 1 }, - { name = "rate-limiting", value = { minute = 6 }, __api = 1 }, - { name = "rate-limiting", value = { minute = 8 }, __api = 1, __consumer = 1 }, - { name = "rate-limiting", value = { minute = 6 }, __api = 2 }, - { name = "rate-limiting", value = { minute = 3, hour = 5 }, __api = 3 }, - { name = "rate-limiting", value = { minute = 33 }, __api = 4 } + plugin = { + { name = "key-auth", config = {key_names = {"apikey"}, hide_credentials = true}, __api = 1 }, + { name = "rate-limiting", config = { minute = 6 }, __api = 1 }, + { name = "rate-limiting", config = { minute = 8 }, __api = 1, __consumer = 1 }, + { name = "rate-limiting", config = { minute = 6 }, __api = 2 }, + { name = "rate-limiting", config = { minute = 3, hour = 5 }, __api = 3 }, + { name = "rate-limiting", config = { minute = 33 }, __api = 4 } }, keyauth_credential = { { key = "apikey122", __consumer = 1 }, @@ -147,7 +147,5 @@ describe("RateLimiting Plugin", function() end) end) - end) - end) diff --git a/spec/plugins/rate-limiting/api_spec.lua b/spec/plugins/rate-limiting/api_spec.lua index 0dfec40e96b..44ca6e20a7e 100644 --- a/spec/plugins/rate-limiting/api_spec.lua +++ b/spec/plugins/rate-limiting/api_spec.lua @@ -24,18 +24,18 @@ describe("Rate Limiting API", function() describe("POST", function() - it("should not save with empty value", function() + it("should not save with empty config", function() local response, status = http_client.post(BASE_URL, { name = "rate-limiting" }) local body = json.decode(response) assert.are.equal(400, status) assert.are.equal("You need to set at least one limit: second, minute, hour, day, month, year", body.message) end) - it("should save with proper value", function() - local response, status = http_client.post(BASE_URL, { name = "rate-limiting", ["value.second"] = 10 }) + it("should save with proper config", function() + local response, status = http_client.post(BASE_URL, { name = "rate-limiting", ["config.second"] = 10 }) local body = json.decode(response) assert.are.equal(201, status) - assert.are.equal(10, body.value.second) + assert.are.equal(10, body.config.second) end) end) diff --git a/spec/plugins/rate-limiting/schema_spec.lua b/spec/plugins/rate-limiting/schema_spec.lua index 8310c341b0b..388d957ba21 100644 --- a/spec/plugins/rate-limiting/schema_spec.lua +++ b/spec/plugins/rate-limiting/schema_spec.lua @@ -5,32 +5,32 @@ local plugin_schema = require "kong.plugins.rate-limiting.schema" describe("Rate Limiting schema", function() - it("should be invalid when no value is being set", function() - local values = {} - local valid, _, err = validate_entity(values, plugin_schema) + it("should be invalid when no config is being set", function() + local config = {} + local valid, _, err = validate_entity(config, plugin_schema) assert.falsy(valid) assert.are.equal("You need to set at least one limit: second, minute, hour, day, month, year", err.message) end) - it("should work when the proper value is being set", function() - local values = { second = 10 } - local valid, _, err = validate_entity(values, plugin_schema) + it("should work when the proper config is being set", function() + local config = { second = 10 } + local valid, _, err = validate_entity(config, plugin_schema) assert.truthy(valid) assert.falsy(err) end) - it("should work when the proper value are being set", function() - local values = { second = 10, hour = 20 } - local valid, _, err = validate_entity(values, plugin_schema) + it("should work when the proper config are being set", function() + local config = { second = 10, hour = 20 } + local valid, _, err = validate_entity(config, plugin_schema) assert.truthy(valid) assert.falsy(err) end) it("should not work when invalid data is being set", function() - local values = { second = 20, hour = 10 } - local valid, _, err = validate_entity(values, plugin_schema) + local config = { second = 20, hour = 10 } + local valid, _, err = validate_entity(config, plugin_schema) assert.falsy(valid) - assert.are.equal("The value for hour cannot be lower than the value for second", err.message) + assert.are.equal("The limit for hour cannot be lower than the limit for second", err.message) end) end) diff --git a/spec/plugins/request-size-limiting/access_spec.lua b/spec/plugins/request-size-limiting/access_spec.lua index 4e0861ac54e..3b21ad527ab 100644 --- a/spec/plugins/request-size-limiting/access_spec.lua +++ b/spec/plugins/request-size-limiting/access_spec.lua @@ -11,8 +11,8 @@ describe("RequestSizeLimiting Plugin", function() api = { { name = "tests request-size-limiting 1", public_dns = "test3.com", target_url = "http://mockbin.com/request" } }, - plugin_configuration = { - { name = "request-size-limiting", value = {allowed_payload_size = 10}, __api = 1 } + plugin = { + { name = "request-size-limiting", config = {allowed_payload_size = 10}, __api = 1 } } } diff --git a/spec/plugins/request-transformer/access_spec.lua b/spec/plugins/request-transformer/access_spec.lua index d829c4ec3e6..7918a3cf40f 100644 --- a/spec/plugins/request-transformer/access_spec.lua +++ b/spec/plugins/request-transformer/access_spec.lua @@ -13,10 +13,10 @@ describe("Request Transformer", function() api = { { name = "tests request-transformer", public_dns = "test5.com", target_url = "http://mockbin.com" }, }, - plugin_configuration = { + plugin = { { name = "request-transformer", - value = { + config = { add = { headers = {"x-added:true", "x-added2:true" }, querystring = {"newparam:value"}, diff --git a/spec/plugins/response-ratelimiting/access_spec.lua b/spec/plugins/response-ratelimiting/access_spec.lua index 7e7cff4bcf6..e6511be20ec 100644 --- a/spec/plugins/response-ratelimiting/access_spec.lua +++ b/spec/plugins/response-ratelimiting/access_spec.lua @@ -28,12 +28,12 @@ describe("RateLimiting Plugin", function() { custom_id = "consumer_124" }, { custom_id = "consumer_125" } }, - plugin_configuration = { - { name = "response-ratelimiting", value = { limits = { video = { minute = 6 } } }, __api = 1 }, - { name = "response-ratelimiting", value = { limits = { video = { minute = 6, hour = 10 }, image = { minute = 4 } } }, __api = 2 }, - { name = "key-auth", value = {key_names = {"apikey"}, hide_credentials = true}, __api = 3 }, - { name = "response-ratelimiting", value = { limits = { video = { minute = 6 } } }, __api = 3 }, - { name = "response-ratelimiting", value = { limits = { video = { minute = 2 } } }, __api = 3, __consumer = 1 } + plugin = { + { name = "response-ratelimiting", config = { limits = { video = { minute = 6 } } }, __api = 1 }, + { name = "response-ratelimiting", config = { limits = { video = { minute = 6, hour = 10 }, image = { minute = 4 } } }, __api = 2 }, + { name = "key-auth", config = {key_names = {"apikey"}, hide_credentials = true}, __api = 3 }, + { name = "response-ratelimiting", config = { limits = { video = { minute = 6 } } }, __api = 3 }, + { name = "response-ratelimiting", config = { limits = { video = { minute = 2 } } }, __api = 3, __consumer = 1 } }, keyauth_credential = { { key = "apikey123", __consumer = 1 }, diff --git a/spec/plugins/response-ratelimiting/api_spec.lua b/spec/plugins/response-ratelimiting/api_spec.lua index 72422244aad..94c6f7bfd49 100644 --- a/spec/plugins/response-ratelimiting/api_spec.lua +++ b/spec/plugins/response-ratelimiting/api_spec.lua @@ -24,20 +24,20 @@ describe("Response Rate Limiting API", function() describe("POST", function() - it("should not save with empty value", function() + it("should not save with empty config", function() local response, status = http_client.post(BASE_URL, { name = "response-ratelimiting" }) local body = json.decode(response) assert.are.equal(400, status) - assert.are.equal("You need to set at least one limit name", body.value) + assert.are.equal("You need to set at least one limit name", body.config) end) - it("should save with proper value", function() - local response, status = http_client.post(BASE_URL, { name = "response-ratelimiting", ["value.limits.video.second"] = 10 }) + it("should save with proper config", function() + local response, status = http_client.post(BASE_URL, { name = "response-ratelimiting", ["config.limits.video.second"] = 10 }) local body = json.decode(response) assert.are.equal(201, status) - assert.are.equal(10, body.value.limits.video.second) + assert.are.equal(10, body.config.limits.video.second) end) end) -end) \ No newline at end of file +end) diff --git a/spec/plugins/response-ratelimiting/schema_spec.lua b/spec/plugins/response-ratelimiting/schema_spec.lua index 6f475cc2595..8136ff737db 100644 --- a/spec/plugins/response-ratelimiting/schema_spec.lua +++ b/spec/plugins/response-ratelimiting/schema_spec.lua @@ -5,39 +5,39 @@ local plugin_schema = require "kong.plugins.response-ratelimiting.schema" describe("Response Rate Limiting schema", function() - it("should be invalid when no value is being set", function() - local values = {} - local valid, _, err = validate_entity(values, plugin_schema) + it("should be invalid when no config is being set", function() + local config = {} + local valid, _, err = validate_entity(config, plugin_schema) assert.falsy(valid) assert.are.equal("You need to set at least one limit name", err.message) end) - it("should work when the proper value is being set", function() - local values = { limits = { second = 10 } } - local valid, err = validate_entity(values, plugin_schema) + it("should work when the proper config is being set", function() + local config = { limits = { second = 10 } } + local valid, err = validate_entity(config, plugin_schema) assert.falsy(valid) assert.are.equal("second is not a table", err["limits.second"]) end) - it("should work when the proper value is being set", function() - local values = { limits = { video = { seco = 1 } } } - local valid, err = validate_entity(values, plugin_schema) + it("should work when the proper config is being set", function() + local config = { limits = { video = { seco = 1 } } } + local valid, err = validate_entity(config, plugin_schema) assert.falsy(valid) assert.are.equal("seco is an unknown field", err["limits.video.seco"]) end) - it("should work when the proper value is being set", function() - local values = { limits = { video = { second = 2, minute = 1 } } } - local valid, _, self_check_err = validate_entity(values, plugin_schema) + it("should work when the proper config is being set", function() + local config = { limits = { video = { second = 2, minute = 1 } } } + local valid, _, self_check_err = validate_entity(config, plugin_schema) assert.falsy(valid) - assert.are.equal("The value for minute cannot be lower than the value for second", self_check_err.message) + assert.are.equal("The limit for minute cannot be lower than the limit for second", self_check_err.message) end) - it("should work when the proper value are being set", function() - local values = { limits = { video = { second = 1, minute = 2 } } } - local valid, err = validate_entity(values, plugin_schema) + it("should work when the proper config are being set", function() + local config = { limits = { video = { second = 1, minute = 2 } } } + local valid, err = validate_entity(config, plugin_schema) assert.truthy(valid) assert.falsy(err) end) -end) \ No newline at end of file +end) diff --git a/spec/plugins/response-transformer/access_spec.lua b/spec/plugins/response-transformer/access_spec.lua index e8b9488c643..f2153175474 100644 --- a/spec/plugins/response-transformer/access_spec.lua +++ b/spec/plugins/response-transformer/access_spec.lua @@ -14,10 +14,10 @@ describe("Response Transformer Plugin #proxy", function() { name = "tests response-transformer", public_dns = "response.com", target_url = "http://httpbin.org" }, { name = "tests response-transformer 2", public_dns = "response2.com", target_url = "http://httpbin.org" }, }, - plugin_configuration = { + plugin = { { name = "response-transformer", - value = { + config = { add = { headers = {"x-added:true", "x-added2:true" }, json = {"newjsonparam:newvalue"} @@ -31,7 +31,7 @@ describe("Response Transformer Plugin #proxy", function() }, { name = "response-transformer", - value = { + config = { add = { headers = {"Cache-Control:max-age=86400"} } diff --git a/spec/plugins/ssl/access_spec.lua b/spec/plugins/ssl/access_spec.lua index 63c2abdd280..aefc5ccdda6 100644 --- a/spec/plugins/ssl/access_spec.lua +++ b/spec/plugins/ssl/access_spec.lua @@ -20,9 +20,9 @@ describe("SSL Plugin", function() { name = "API TESTS 12 (ssl)", public_dns = "ssl2.com", target_url = "http://mockbin.com" }, { name = "API TESTS 13 (ssl)", public_dns = "ssl3.com", target_url = "http://mockbin.com" } }, - plugin_configuration = { - { name = "ssl", value = { cert = ssl_fixtures.cert, key = ssl_fixtures.key }, __api = 1 }, - { name = "ssl", value = { cert = ssl_fixtures.cert, key = ssl_fixtures.key, only_https = true }, __api = 2 } + plugin = { + { name = "ssl", config = { cert = ssl_fixtures.cert, key = ssl_fixtures.key }, __api = 1 }, + { name = "ssl", config = { cert = ssl_fixtures.cert, key = ssl_fixtures.key, only_https = true }, __api = 2 } } } @@ -32,7 +32,7 @@ describe("SSL Plugin", function() teardown(function() spec_helper.stop_kong() end) - + describe("SSL Util", function() it("should not convert an invalid cert to DER", function() @@ -52,7 +52,7 @@ describe("SSL Plugin", function() end) end) - + describe("SSL Resolution", function() it("should return default CERTIFICATE when requesting other APIs", function() @@ -70,7 +70,7 @@ describe("SSL Plugin", function() end) end) - + describe("only_https", function() it("should block request without https", function() @@ -91,14 +91,14 @@ describe("SSL Plugin", function() describe("should work with curl", function() local response = http_client.get(API_URL.."/apis/", {public_dns="ssl3.com"}) local api_id = cjson.decode(response).data[1].id - + local kong_working_dir = spec_helper.get_env(spec_helper.TEST_CONF_FILE).configuration.nginx_working_dir local ssl_cert_path = IO.path:join(kong_working_dir, "ssl", "kong-default.crt") local ssl_key_path = IO.path:join(kong_working_dir, "ssl", "kong-default.key") - local res = IO.os_execute("curl -s -o /dev/null -w \"%{http_code}\" "..API_URL.."/apis/"..api_id.."/plugins/ --form \"name=ssl\" --form \"value.cert=@"..ssl_cert_path.."\" --form \"value.key=@"..ssl_key_path.."\"") + local res = IO.os_execute("curl -s -o /dev/null -w \"%{http_code}\" "..API_URL.."/apis/"..api_id.."/plugins/ --form \"name=ssl\" --form \"config.cert=@"..ssl_cert_path.."\" --form \"config.key=@"..ssl_key_path.."\"") assert.are.equal(201, tonumber(res)) end) - + end) diff --git a/spec/plugins/ssl/api_spec.lua b/spec/plugins/ssl/api_spec.lua index fe538d6eb5a..f8a91f0ec27 100644 --- a/spec/plugins/ssl/api_spec.lua +++ b/spec/plugins/ssl/api_spec.lua @@ -25,7 +25,7 @@ describe("SSL API", function() it("should refuse to set a `consumer_id` if asked to", function() local response, status = http_client.post_multipart(BASE_URL, - {name = "ssl", consumer_id = "0000", ["value.cert"] = ssl_fixtures.cert, ["value.key"] = ssl_fixtures.key} + {name = "ssl", consumer_id = "0000", ["config.cert"] = ssl_fixtures.cert, ["config.key"] = ssl_fixtures.key} ) assert.equal(400, status) local body = json.decode(response) diff --git a/spec/unit/api/app_spec.lua b/spec/unit/api/app_spec.lua index 8840a6ea375..c68fd3fa445 100644 --- a/spec/unit/api/app_spec.lua +++ b/spec/unit/api/app_spec.lua @@ -5,7 +5,7 @@ require "kong.tools.ngx_stub" local stub = { req = { headers = {} }, add_params = function() end, - params = { foo = "bar", number = 10, ["value.nested"] = 1, ["value.nested_2"] = 2 } + params = { foo = "bar", number = 10, ["config.nested"] = 1, ["config.nested_2"] = 2 } } describe("App", function() @@ -18,7 +18,7 @@ describe("App", function() assert.are.same({ foo = "bar", number = 10, - value = { + config = { nested = 1, nested_2 = 2 } @@ -29,14 +29,14 @@ describe("App", function() it("should parse a JSON body", function() -- Here we are simply decoding a JSON body (which is a string) - ngx.req.get_body_data = function() return '{"foo":"bar","number":10,"value":{"nested":1,"nested_2":2}}' end + ngx.req.get_body_data = function() return '{"foo":"bar","number":10,"config":{"nested":1,"nested_2":2}}' end stub.req.headers["Content-Type"] = "application/json; charset=utf-8" local f = app.parse_params(function(stub) assert.are.same({ foo = "bar", number = 10, - value = { + config = { nested = 1, nested_2 = 2 } @@ -46,14 +46,14 @@ describe("App", function() end) it("should normalize sub-nested properties for parsed form-encoded parameters", function() - stub.params = { foo = "bar", number = 10, ["value.nested_1"] = 1, ["value.nested_2"] = 2, - ["value.nested.sub-nested"] = "hi" + stub.params = { foo = "bar", number = 10, ["config.nested_1"] = 1, ["config.nested_2"] = 2, + ["config.nested.sub-nested"] = "hi" } local f = app.parse_params(function(stub) assert.are.same({ foo = 'bar', number = 10, - value = { + config = { nested = { ["sub-nested"] = "hi" }, @@ -66,12 +66,12 @@ describe("App", function() end) it("should normalize nested properties when they are plain arrays", function() - stub.params = { foo = "bar", number = 10, ["value.nested"] = {["1"]="hello", ["2"]="world"}} + stub.params = { foo = "bar", number = 10, ["config.nested"] = {["1"]="hello", ["2"]="world"}} local f = app.parse_params(function(stub) assert.are.same({ foo = 'bar', number = 10, - value = { + config = { nested = {"hello", "world"}, }}, stub.params) end) @@ -82,19 +82,19 @@ describe("App", function() stub.params = { api_id = 123, name = "request-transformer", - ["value.add.headers"] = "x-new-header:some_value, x-another-header:some_value", - ["value.add.querystring"] = "new-param:some_value, another-param:some_value", - ["value.add.form"] = "new-form-param:some_value, another-form-param:some_value", - ["value.remove.headers"] = "x-toremove, x-another-one", - ["value.remove.querystring"] = "param-toremove, param-another-one", - ["value.remove.form"] = "formparam-toremove" + ["config.add.headers"] = "x-new-header:some_value, x-another-header:some_value", + ["config.add.querystring"] = "new-param:some_value, another-param:some_value", + ["config.add.form"] = "new-form-param:some_value, another-form-param:some_value", + ["config.remove.headers"] = "x-toremove, x-another-one", + ["config.remove.querystring"] = "param-toremove, param-another-one", + ["config.remove.form"] = "formparam-toremove" } local f = app.parse_params(function(stub) assert.are.same({ api_id = 123, name = "request-transformer", - value = { + config = { add = { form = "new-form-param:some_value, another-form-param:some_value", headers = "x-new-header:some_value, x-another-header:some_value", diff --git a/spec/unit/dao/entities_schemas_spec.lua b/spec/unit/dao/entities_schemas_spec.lua index b8933692fe4..ffc13aaab33 100644 --- a/spec/unit/dao/entities_schemas_spec.lua +++ b/spec/unit/dao/entities_schemas_spec.lua @@ -1,6 +1,6 @@ local api_schema = require "kong.dao.schemas.apis" local consumer_schema = require "kong.dao.schemas.consumers" -local plugins_configurations_schema = require "kong.dao.schemas.plugins_configurations" +local plugins_schema = require "kong.dao.schemas.plugins" local validations = require "kong.dao.schemas_validation" local validate_entity = validations.validate_entity @@ -10,7 +10,7 @@ describe("Entities Schemas", function() for k, schema in pairs({api = api_schema, consumer = consumer_schema, - plugins_configurations = plugins_configurations_schema}) do + plugins = plugins_schema}) do it(k.." schema should have some required properties", function() assert.truthy(schema.name) assert.equal("string", type(schema.name)) @@ -218,7 +218,7 @@ describe("Entities Schemas", function() describe("Plugins Configurations", function() local dao_stub = { - plugins_configurations = { + plugins = { find_by_keys = function() return nil end @@ -226,43 +226,43 @@ describe("Entities Schemas", function() } it("should not validate if the plugin doesn't exist (not installed)", function() - local valid, errors = validate_entity({name = "world domination"}, plugins_configurations_schema) + local valid, errors = validate_entity({name = "world domination"}, plugins_schema) assert.False(valid) - assert.equal("Plugin \"world domination\" not found", errors.value) + assert.equal("Plugin \"world domination\" not found", errors.config) end) - it("should validate a plugin configuration's `value` field", function() + it("should validate a plugin configuration's `config` field", function() -- Success - local plugin = {name = "key-auth", api_id = "stub", value = {key_names = {"x-kong-key"}}} - local valid = validate_entity(plugin, plugins_configurations_schema, {dao = dao_stub}) + local plugin = {name = "key-auth", api_id = "stub", config = {key_names = {"x-kong-key"}}} + local valid = validate_entity(plugin, plugins_schema, {dao = dao_stub}) assert.True(valid) -- Failure - plugin = {name = "rate-limiting", api_id = "stub", value = { second = "hello" }} + plugin = {name = "rate-limiting", api_id = "stub", config = { second = "hello" }} - local valid, errors = validate_entity(plugin, plugins_configurations_schema, {dao = dao_stub}) + local valid, errors = validate_entity(plugin, plugins_schema, {dao = dao_stub}) assert.False(valid) - assert.equal("second is not a number", errors["value.second"]) + assert.equal("second is not a number", errors["config.second"]) end) describe("self_check", function() - it("should refuse `consumer_id` if specified in the value schema", function() - local stub_value_schema = { + it("should refuse `consumer_id` if specified in the config schema", function() + local stub_config_schema = { no_consumer = true, fields = { string = {type = "string", required = true} } } - plugins_configurations_schema.fields.value.schema = function() - return stub_value_schema + plugins_schema.fields.config.schema = function() + return stub_config_schema end - local valid, _, err = validate_entity({name = "stub", api_id = "0000", consumer_id = "0000", value = {string = "foo"}}, plugins_configurations_schema) + local valid, _, err = validate_entity({name = "stub", api_id = "0000", consumer_id = "0000", config = {string = "foo"}}, plugins_schema) assert.False(valid) assert.equal("No consumer can be configured for that plugin", err.message) - valid, err = validate_entity({name = "stub", api_id = "0000", value = {string = "foo"}}, plugins_configurations_schema, {dao = dao_stub}) + valid, err = validate_entity({name = "stub", api_id = "0000", config = {string = "foo"}}, plugins_schema, {dao = dao_stub}) assert.True(valid) assert.falsy(err) end) diff --git a/spec/unit/tools/database_cache_spec.lua b/spec/unit/tools/database_cache_spec.lua index 2fad5ec8528..e24956443c7 100644 --- a/spec/unit/tools/database_cache_spec.lua +++ b/spec/unit/tools/database_cache_spec.lua @@ -7,8 +7,8 @@ describe("Database cache", function() end) it("should return a valid PLUGIN cache key", function() - assert.are.equal("plugins_configurations/authentication/api123/app123", cache.plugin_configuration_key("authentication", "api123", "app123")) - assert.are.equal("plugins_configurations/authentication/api123", cache.plugin_configuration_key("authentication", "api123")) + assert.are.equal("plugins/authentication/api123/app123", cache.plugin_key("authentication", "api123", "app123")) + assert.are.equal("plugins/authentication/api123", cache.plugin_key("authentication", "api123")) end) it("should return a valid KeyAuthCredential cache key", function() diff --git a/spec/unit/tools/faker_spec.lua b/spec/unit/tools/faker_spec.lua index 29d17441b3e..01fcf300cba 100644 --- a/spec/unit/tools/faker_spec.lua +++ b/spec/unit/tools/faker_spec.lua @@ -4,7 +4,7 @@ local DaoError = require "kong.dao.error" describe("Faker", function() - local ENTITIES_TYPES = { "api", "consumer", "plugin_configuration" } + local ENTITIES_TYPES = { "api", "consumer", "plugin" } local factory_mock = {} local insert_spy @@ -17,7 +17,7 @@ describe("Faker", function() end) for _, v in ipairs(ENTITIES_TYPES) do - factory_mock[v=="plugin_configuration" and "plugins_configurations" or v.."s"] = { + factory_mock[v=="plugin" and "plugins" or v.."s"] = { insert = insert_spy } end @@ -90,9 +90,9 @@ describe("Faker", function() { name = "tests faker 1", public_dns = "foo.com", target_url = "http://mockbin.com" }, { name = "tests faker 2", public_dns = "bar.com", target_url = "http://mockbin.com" } }, - plugin_configuration = { - { name = "key-auth", value = {key_names={"apikey"}}, __api = 1 }, - { name = "key-auth", value = {key_names={"apikey"}}, __api = 2 } + plugin = { + { name = "key-auth", config = {key_names={"apikey"}}, __api = 1 }, + { name = "key-auth", config = {key_names={"apikey"}}, __api = 2 } } } From 860207c1ef8b4b4c87fd68d0bc4fc8d48388920b Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 27 Aug 2015 20:39:18 -0700 Subject: [PATCH 4/9] chore(mig-script) migrate APIs properties public_dns -> inbound_dns target_url -> upstream_url --- kong/dao/cassandra/schema/migrations.lua | 6 +-- scripts/migration.py | 61 +++++++++++++++++++++--- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/kong/dao/cassandra/schema/migrations.lua b/kong/dao/cassandra/schema/migrations.lua index 22dd529c75f..1bb196b7603 100644 --- a/kong/dao/cassandra/schema/migrations.lua +++ b/kong/dao/cassandra/schema/migrations.lua @@ -41,17 +41,17 @@ local Migrations = { CREATE TABLE IF NOT EXISTS apis( id uuid, name text, - public_dns text, + inbound_dns text, path text, strip_path boolean, - target_url text, + upstream_url text, preserve_host boolean, created_at timestamp, PRIMARY KEY (id) ); CREATE INDEX IF NOT EXISTS ON apis(name); - CREATE INDEX IF NOT EXISTS ON apis(public_dns); + CREATE INDEX IF NOT EXISTS ON apis(inbound_dns); CREATE INDEX IF NOT EXISTS ON apis(path); CREATE TABLE IF NOT EXISTS plugins( diff --git a/scripts/migration.py b/scripts/migration.py index 4e2211a2ba9..4ce01715bba 100755 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -22,7 +22,7 @@ try: import yaml from cassandra.cluster import Cluster - from cassandra import ConsistencyLevel + from cassandra import ConsistencyLevel, InvalidRequest from cassandra.query import SimpleStatement except ImportError as err: log.error(err) @@ -136,7 +136,9 @@ def migrate_rate_limiting_value(session): def migrate_rename_plugins_configurations(session): """ + Migrate all rows in the `plugins_configurations` table to `plugins` + :param session: opened cassandra session """ log.info("Renaming 'plugins_configurations' to 'plugins'...") @@ -162,9 +164,26 @@ def migrate_rename_plugins_configurations(session): session.execute(insert_query, [plugin.id, plugin.api_id, plugin.consumer_id, plugin.name, plugin.value, plugin.enabled, plugin.created_at]) session.execute("DROP TABLE plugins_configurations") - log.info("Plugins moved to table 'plugins'") +def migrate_rename_apis_properties(sessions): + """ + + """ + log.info("Renaming some properties for APIs...") + + session.execute("ALTER TABLE apis ADD inbound_dns text") + session.execute("ALTER TABLE apis ADD upstream_url text") + + select_query = SimpleStatement("SELECT * FROM apis", consistency_level=ConsistencyLevel.ALL) + + for api in session.execute(select_query): + session.execute("UPDATE apis SET inbound_dns = %s, upstream_url = %s WHERE id = %s", [api.public_dns, api.target_url, api.id]) + + session.execute("ALTER TABLE apis DROP public_dns") + session.execute("ALTER TABLE apis DROP target_url") + log.info("APIs properties renamed") + def migrate(kong_config): """ Instanciate a Cassandra session and decides if the keyspace needs to be migrated @@ -178,6 +197,12 @@ def migrate(kong_config): global session session = cluster.connect(keyspace) + """ + 1. schema_migrations + Check if the 'schema_migrations' table has been migrated yet or not. + + ** Also Check if Kong is in 0.4.2 or else stops the script. ** + """ rows = session.execute("SELECT * FROM schema_migrations") if len(rows) == 1 and rows[0].id == "migrations": last_executed_migration = rows[0].migrations[-1] @@ -192,12 +217,34 @@ def migrate(kong_config): elif len(rows) > 1: # apparently kong was restarted without previously running this script if any(row.id == "migrations" for row in rows): - log.info("Already migrated to 0.5.0, but legacy schema found. Purging.") + log.info("Already migrated to 0.5.0, but legacy value found. Purging.") migrate_schema_migrations_remove_legacy_row(session) - migrate_plugins_renaming(session) - migrate_rate_limiting_value(session) - migrate_rename_plugins_configurations(session) + """ + 2. Plugins + Check if plugins_configurations have been migrated yet, if not, migrate + a. Rename some plugins + b. Migrate the old rate-limit config schema to the new one + c. Migrate all rows into a new table 'plugins' and drop the old one + """ + columnfamilies = session.execute("SELECT columnfamily_name FROM system.schema_columnfamilies WHERE keyspace_name = %s", [keyspace]) + if any(row.columnfamily_name == "plugins_configurations" for row in columnfamilies): + migrate_plugins_renaming(session) + migrate_rate_limiting_value(session) + migrate_rename_plugins_configurations(session) + else: + log.info("Plugins already migrated") + + """ + 3. APIs + Check if APIs have been migrated yet (properties renaming) + """ + try: + session.execute("SELECT upstream_url FROM apis") + log.info("APIs properties already migrated") + except InvalidRequest as err: + # If this column doesn't exit yet, apis have not been migrated + migrate_rename_apis_properties(session) def parse_arguments(argv): """ @@ -231,7 +278,7 @@ def main(argv): try: config = parse_arguments(argv) migrate(config) - log.info("Schema migrated to Kong 0.5.0.") + log.info("Cassandra migrated to Kong 0.5.0.") shutdown_exit(0) except getopt.GetoptError as err: log.error(err) From ef6ebb352f3494205cf67dc90526eacca960070e Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Fri, 28 Aug 2015 15:41:02 -0700 Subject: [PATCH 5/9] chore(renamings) rename APIs properties public_dns -> inbound_dns target_url -> upstream_url --- kong/dao/schemas/apis.lua | 38 +++++----- kong/resolver/access.lua | 40 +++++------ kong/resolver/certificate.lua | 2 +- kong/tools/faker.lua | 4 +- scripts/migration.py | 1 + .../admin_api/apis_routes_spec.lua | 46 ++++++------ spec/integration/cli/start_spec.lua | 2 +- .../dao/cassandra/base_dao_spec.lua | 24 +++---- .../dao/cassandra/cascade_spec.lua | 12 ++-- spec/integration/proxy/api_resolver_spec.lua | 26 +++---- .../integration/proxy/database_cache_spec.lua | 2 +- spec/integration/proxy/dns_resolver_spec.lua | 4 +- spec/integration/proxy/realip_spec.lua | 2 +- spec/plugins/basic-auth/access_spec.lua | 2 +- spec/plugins/cors/access_spec.lua | 4 +- spec/plugins/ip-restriction/access_spec.lua | 16 ++--- spec/plugins/key-auth/access_spec.lua | 4 +- spec/plugins/logging_spec.lua | 12 ++-- spec/plugins/oauth2/access_spec.lua | 10 +-- spec/plugins/rate-limiting/access_spec.lua | 8 +-- spec/plugins/rate-limiting/api_spec.lua | 2 +- .../request-size-limiting/access_spec.lua | 2 +- .../request-transformer/access_spec.lua | 2 +- .../response-ratelimiting/access_spec.lua | 6 +- .../response-ratelimiting/api_spec.lua | 2 +- .../response-transformer/access_spec.lua | 4 +- spec/plugins/ssl/access_spec.lua | 8 +-- spec/plugins/ssl/api_spec.lua | 2 +- .../unit/dao/cassandra/query_builder_spec.lua | 14 ++-- spec/unit/dao/entities_schemas_spec.lua | 70 +++++++++---------- spec/unit/dao/error_spec.lua | 4 +- spec/unit/resolver/access_spec.lua | 34 ++++----- spec/unit/tools/faker_spec.lua | 6 +- 33 files changed, 208 insertions(+), 207 deletions(-) diff --git a/kong/dao/schemas/apis.lua b/kong/dao/schemas/apis.lua index e86f2704511..98b7476ffd2 100644 --- a/kong/dao/schemas/apis.lua +++ b/kong/dao/schemas/apis.lua @@ -1,13 +1,13 @@ local url = require "socket.url" local stringy = require "stringy" -local function validate_target_url(value) +local function validate_upstream_url(value) local parsed_url = url.parse(value) if parsed_url.scheme and parsed_url.host then parsed_url.scheme = parsed_url.scheme:lower() if parsed_url.scheme == "http" or parsed_url.scheme == "https" then parsed_url.path = parsed_url.path or "/" - return true, nil, { target_url = url.build(parsed_url)} + return true, nil, { upstream_url = url.build(parsed_url)} else return false, "Supported protocols are HTTP and HTTPS" end @@ -16,37 +16,37 @@ local function validate_target_url(value) return false, "Invalid target URL" end -local function check_public_dns_and_path(value, api_t) - local public_dns = type(api_t.public_dns) == "string" and stringy.strip(api_t.public_dns) or "" +local function check_inbound_dns_and_path(value, api_t) + local inbound_dns = type(api_t.inbound_dns) == "string" and stringy.strip(api_t.inbound_dns) or "" local path = type(api_t.path) == "string" and stringy.strip(api_t.path) or "" - if path == "" and public_dns == "" then - return false, "At least a 'public_dns' or a 'path' must be specified" + if path == "" and inbound_dns == "" then + return false, "At least an 'inbound_dns' or a 'path' must be specified" end - -- Validate wildcard public_dns - if public_dns then - local _, count = public_dns:gsub("%*", "") + -- Validate wildcard inbound_dns + if inbound_dns then + local _, count = inbound_dns:gsub("%*", "") if count > 1 then - return false, "Only one wildcard is allowed: "..public_dns + return false, "Only one wildcard is allowed: "..inbound_dns elseif count > 0 then - local pos = public_dns:find("%*") + local pos = inbound_dns:find("%*") local valid if pos == 1 then - valid = public_dns:match("^%*%.") ~= nil - elseif pos == string.len(public_dns) then - valid = public_dns:match(".%.%*$") ~= nil + valid = inbound_dns:match("^%*%.") ~= nil + elseif pos == string.len(inbound_dns) then + valid = inbound_dns:match(".%.%*$") ~= nil end if not valid then - return false, "Invalid wildcard placement: "..public_dns + return false, "Invalid wildcard placement: "..inbound_dns end end end end local function check_path(path, api_t) - local valid, err = check_public_dns_and_path(path, api_t) + local valid, err = check_inbound_dns_and_path(path, api_t) if valid == false then return false, err end @@ -78,12 +78,12 @@ return { fields = { id = { type = "id", dao_insert_value = true }, created_at = { type = "timestamp", dao_insert_value = true }, - name = { type = "string", unique = true, queryable = true, default = function(api_t) return api_t.public_dns end }, - public_dns = { type = "string", unique = true, queryable = true, func = check_public_dns_and_path, + name = { type = "string", unique = true, queryable = true, default = function(api_t) return api_t.inbound_dns end }, + inbound_dns = { type = "string", unique = true, queryable = true, func = check_inbound_dns_and_path, regex = "([a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*)" }, path = { type = "string", unique = true, func = check_path }, strip_path = { type = "boolean" }, - target_url = { type = "string", required = true, func = validate_target_url }, + upstream_url = { type = "string", required = true, func = validate_upstream_url }, preserve_host = { type = "boolean" } } } diff --git a/kong/resolver/access.lua b/kong/resolver/access.lua index c50094b872a..130657f2ca0 100644 --- a/kong/resolver/access.lua +++ b/kong/resolver/access.lua @@ -6,11 +6,11 @@ local responses = require "kong.tools.responses" local _M = {} --- Take a public_dns and make it a pattern for wildcard matching. --- Only do so if the public_dns actually has a wildcard. -local function create_wildcard_pattern(public_dns) - if string.find(public_dns, "*", 1, true) then - local pattern = string.gsub(public_dns, "%.", "%%.") +-- Take a inbound_dns and make it a pattern for wildcard matching. +-- Only do so if the inbound_dns actually has a wildcard. +local function create_wildcard_pattern(inbound_dns) + if string.find(inbound_dns, "*", 1, true) then + local pattern = string.gsub(inbound_dns, "%.", "%%.") pattern = string.gsub(pattern, "*", ".+") pattern = string.format("^%s$", pattern) return pattern @@ -23,7 +23,7 @@ local function create_strip_path_pattern(path) end local function get_backend_url(api) - local result = api.target_url + local result = api.upstream_url -- Checking if the target url ends with a final slash local len = string.len(result) @@ -50,26 +50,26 @@ local function get_host_from_url(val) end -- Load all APIs in memory. --- Sort the data for faster lookup: dictionary per public_dns and an array of wildcard public_dns. +-- Sort the data for faster lookup: dictionary per inbound_dns and an array of wildcard inbound_dns. function _M.load_apis_in_memory() local apis, err = dao.apis:find_all() if err then return nil, err end - -- build dictionnaries of public_dns:api for efficient O(1) lookup. - -- we only do O(n) lookup for wildcard public_dns and path that are in arrays. + -- build dictionnaries of inbound_dns:api for efficient O(1) lookup. + -- we only do O(n) lookup for wildcard inbound_dns and path that are in arrays. local dns_dic, dns_wildcard_arr, path_arr = {}, {}, {} for _, api in ipairs(apis) do - if api.public_dns then - local pattern = create_wildcard_pattern(api.public_dns) + if api.inbound_dns then + local pattern = create_wildcard_pattern(api.inbound_dns) if pattern then - -- If the public_dns is a wildcard, we have a pattern and we can + -- If the inbound_dns is a wildcard, we have a pattern and we can -- store it in an array for later lookup. table.insert(dns_wildcard_arr, {pattern = pattern, api = api}) else - -- Keep non-wildcard public_dns in a dictionary for faster lookup. - dns_dic[api.public_dns] = api + -- Keep non-wildcard inbound_dns in a dictionary for faster lookup. + dns_dic[api.inbound_dns] = api end end if api.path then @@ -84,11 +84,11 @@ function _M.load_apis_in_memory() return { by_dns = dns_dic, path_arr = path_arr, -- all APIs with a path - wildcard_dns_arr = dns_wildcard_arr -- all APIs with a wildcard public_dns + wildcard_dns_arr = dns_wildcard_arr -- all APIs with a wildcard inbound_dns } end -function _M.find_api_by_public_dns(req_headers, apis_dics) +function _M.find_api_by_inbound_dns(req_headers, apis_dics) local all_hosts = {} for _, header_name in ipairs({"Host", constants.HEADERS.HOST_OVERRIDE}) do local hosts = req_headers[header_name] @@ -103,7 +103,7 @@ function _M.find_api_by_public_dns(req_headers, apis_dics) if apis_dics.by_dns[host] then return apis_dics.by_dns[host] else - -- If the API was not found in the dictionary, maybe it is a wildcard public_dns. + -- If the API was not found in the dictionary, maybe it is a wildcard inbound_dns. -- In that case, we need to loop over all of them. for _, wildcard_dns in ipairs(apis_dics.wildcard_dns_arr) do if string.match(host, wildcard_dns.pattern) then @@ -158,7 +158,7 @@ function _M.strip_path(uri, strip_path_pattern) end -- Find an API from a request made to nginx. Either from one of the Host or X-Host-Override headers --- matching the API's `public_dns`, either from the `uri` matching the API's `path`. +-- matching the API's `inbound_dns`, either from the `uri` matching the API's `path`. -- -- To perform this, we need to query _ALL_ APIs in memory. It is the only way to compare the `uri` -- as a regex to the values set in DB, as well as matching wildcard dns. @@ -180,7 +180,7 @@ local function find_api(uri) end -- Find by Host header - api, all_hosts = _M.find_api_by_public_dns(ngx.req.get_headers(), apis_dics) + api, all_hosts = _M.find_api_by_inbound_dns(ngx.req.get_headers(), apis_dics) -- If it was found by Host, return if api then @@ -201,7 +201,7 @@ function _M.execute(conf) elseif not api then return responses.send_HTTP_NOT_FOUND { message = "API not found with these values", - public_dns = hosts, + inbound_dns = hosts, path = uri } end diff --git a/kong/resolver/certificate.lua b/kong/resolver/certificate.lua index 47756a78f98..c6b851abf43 100644 --- a/kong/resolver/certificate.lua +++ b/kong/resolver/certificate.lua @@ -9,7 +9,7 @@ local function find_api(hosts) local sanitized_host = stringy.split(host, ":")[1] retrieved_api, err = cache.get_or_set(cache.api_key(sanitized_host), function() - local apis, err = dao.apis:find_by_keys { public_dns = sanitized_host } + local apis, err = dao.apis:find_by_keys { inbound_dns = sanitized_host } if err then return nil, err elseif apis and #apis == 1 then diff --git a/kong/tools/faker.lua b/kong/tools/faker.lua index ef62a86b55b..fe256dc1c7e 100644 --- a/kong/tools/faker.lua +++ b/kong/tools/faker.lua @@ -15,8 +15,8 @@ function Faker:fake_entity(type) if type == "api" then return { name = "random"..r, - public_dns = "random"..r..".com", - target_url = "http://random"..r..".com" + inbound_dns = "random"..r..".com", + upstream_url = "http://random"..r..".com" } elseif type == "consumer" then return { diff --git a/scripts/migration.py b/scripts/migration.py index 4ce01715bba..20d9945bb37 100755 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -174,6 +174,7 @@ def migrate_rename_apis_properties(sessions): session.execute("ALTER TABLE apis ADD inbound_dns text") session.execute("ALTER TABLE apis ADD upstream_url text") + session.execute("CREATE INDEX IF NOT EXISTS ON apis(inbound_dns)") select_query = SimpleStatement("SELECT * FROM apis", consistency_level=ConsistencyLevel.ALL) diff --git a/spec/integration/admin_api/apis_routes_spec.lua b/spec/integration/admin_api/apis_routes_spec.lua index 520f4d412d5..70b5667dc38 100644 --- a/spec/integration/admin_api/apis_routes_spec.lua +++ b/spec/integration/admin_api/apis_routes_spec.lua @@ -22,8 +22,8 @@ describe("Admin API", function() it("[SUCCESS] should create an API", function() send_content_types(BASE_URL, "POST", { name="api POST tests", - public_dns="api.mockbin.com", - target_url="http://mockbin.com" + inbound_dns="api.mockbin.com", + upstream_url="http://mockbin.com" }, 201, nil, {drop_db=true}) end) @@ -36,15 +36,15 @@ describe("Admin API", function() it("[FAILURE] should return proper errors", function() send_content_types(BASE_URL, "POST", {}, 400, - '{"public_dns":"At least a \'public_dns\' or a \'path\' must be specified","path":"At least a \'public_dns\' or a \'path\' must be specified","target_url":"target_url is required"}') + '{"path":"At least an \'inbound_dns\' or a \'path\' must be specified","upstream_url":"upstream_url is required","inbound_dns":"At least an \'inbound_dns\' or a \'path\' must be specified"}') - send_content_types(BASE_URL, "POST", {public_dns="api.mockbin.com"}, - 400, '{"target_url":"target_url is required"}') + send_content_types(BASE_URL, "POST", {inbound_dns="api.mockbin.com"}, + 400, '{"upstream_url":"upstream_url is required"}') send_content_types(BASE_URL, "POST", { - public_dns="api.mockbin.com", - target_url="http://mockbin.com" - }, 409, '{"public_dns":"public_dns already exists with value \'api.mockbin.com\'"}') + inbound_dns="api.mockbin.com", + upstream_url="http://mockbin.com" + }, 409, '{"inbound_dns":"inbound_dns already exists with value \'api.mockbin.com\'"}') end) end) @@ -58,15 +58,15 @@ describe("Admin API", function() it("[SUCCESS] should create and update", function() local api = send_content_types(BASE_URL, "PUT", { name="api PUT tests", - public_dns="api.mockbin.com", - target_url="http://mockbin.com" + inbound_dns="api.mockbin.com", + upstream_url="http://mockbin.com" }, 201, nil, {drop_db=true}) api = send_content_types(BASE_URL, "PUT", { id=api.id, name="api PUT tests updated", - public_dns="updated-api.mockbin.com", - target_url="http://mockbin.com" + inbound_dns="updated-api.mockbin.com", + upstream_url="http://mockbin.com" }, 200) assert.equal("api PUT tests updated", api.name) end) @@ -74,15 +74,15 @@ describe("Admin API", function() it("[FAILURE] should return proper errors", function() send_content_types(BASE_URL, "PUT", {}, 400, - '{"public_dns":"At least a \'public_dns\' or a \'path\' must be specified","path":"At least a \'public_dns\' or a \'path\' must be specified","target_url":"target_url is required"}') + '{"path":"At least an \'inbound_dns\' or a \'path\' must be specified","upstream_url":"upstream_url is required","inbound_dns":"At least an \'inbound_dns\' or a \'path\' must be specified"}') - send_content_types(BASE_URL, "PUT", {public_dns="api.mockbin.com"}, - 400, '{"target_url":"target_url is required"}') + send_content_types(BASE_URL, "PUT", {inbound_dns="api.mockbin.com"}, + 400, '{"upstream_url":"upstream_url is required"}') send_content_types(BASE_URL, "PUT", { - public_dns="updated-api.mockbin.com", - target_url="http://mockbin.com" - }, 409, '{"public_dns":"public_dns already exists with value \'updated-api.mockbin.com\'"}') + inbound_dns="updated-api.mockbin.com", + upstream_url="http://mockbin.com" + }, 409, '{"inbound_dns":"inbound_dns already exists with value \'updated-api.mockbin.com\'"}') end) end) @@ -138,7 +138,7 @@ describe("Admin API", function() setup(function() spec_helper.drop_db() local fixtures = spec_helper.insert_fixtures { - api = {{ public_dns="mockbin.com", target_url="http://mockbin.com" }} + api = {{ inbound_dns="mockbin.com", upstream_url="http://mockbin.com" }} } api = fixtures.api[1] end) @@ -183,9 +183,9 @@ describe("Admin API", function() local _, status = http_client.patch(BASE_URL.."hello", {name="patch-updated"}) assert.equal(404, status) - local response, status = http_client.patch(BASE_URL..api.id, {target_url=""}) + local response, status = http_client.patch(BASE_URL..api.id, {upstream_url=""}) assert.equal(400, status) - assert.equal('{"target_url":"target_url is not a string"}\n', response) + assert.equal('{"upstream_url":"upstream_url is not a string"}\n', response) end) end) @@ -211,7 +211,7 @@ describe("Admin API", function() setup(function() spec_helper.drop_db() local fixtures = spec_helper.insert_fixtures { - api = {{ public_dns="mockbin.com", target_url="http://mockbin.com" }} + api = {{ inbound_dns="mockbin.com", upstream_url="http://mockbin.com" }} } api = fixtures.api[1] BASE_URL = BASE_URL..api.id.."/plugins/" @@ -328,7 +328,7 @@ describe("Admin API", function() setup(function() spec_helper.drop_db() local fixtures = spec_helper.insert_fixtures { - api = {{ public_dns="mockbin.com", target_url="http://mockbin.com" }}, + api = {{ inbound_dns="mockbin.com", upstream_url="http://mockbin.com" }}, plugin = {{ name = "key-auth", config = { key_names = { "apikey" }}, __api = 1 }} } api = fixtures.api[1] diff --git a/spec/integration/cli/start_spec.lua b/spec/integration/cli/start_spec.lua index d4c62488c61..4876202ee90 100644 --- a/spec/integration/cli/start_spec.lua +++ b/spec/integration/cli/start_spec.lua @@ -74,7 +74,7 @@ describe("CLI", function() it("should not work when a plugin is being used in the DB but it's not in the configuration", function() spec_helper.get_env(SERVER_CONF).faker:insert_from_table { api = { - {name = "tests cli 1", public_dns = "foo.com", target_url = "http://mockbin.com"}, + {name = "tests cli 1", inbound_dns = "foo.com", upstream_url = "http://mockbin.com"}, }, plugin = { {name = "rate-limiting", config = {minute = 6}, __api = 1}, diff --git a/spec/integration/dao/cassandra/base_dao_spec.lua b/spec/integration/dao/cassandra/base_dao_spec.lua index 8a9f96ae0d9..306d48d95de 100644 --- a/spec/integration/dao/cassandra/base_dao_spec.lua +++ b/spec/integration/dao/cassandra/base_dao_spec.lua @@ -89,8 +89,8 @@ describe("Cassandra", function() -- API api, err = dao_factory.apis:insert { - public_dns = "test.com", - target_url = "http://mockbin.com" + inbound_dns = "test.com", + upstream_url = "http://mockbin.com" } assert.falsy(err) assert.truthy(api.name) @@ -228,8 +228,8 @@ describe("Cassandra", function() assert.equal(1, #apis) assert.equal(api_t.id, apis[1].id) assert.equal(api_t.name, apis[1].name) - assert.equal(api_t.public_dns, apis[1].public_dns) - assert.equal(api_t.target_url, apis[1].target_url) + assert.equal(api_t.inbound_dns, apis[1].inbound_dns) + assert.equal(api_t.upstream_url, apis[1].upstream_url) -- Consumer local consumers, err = session:execute("SELECT * FROM consumers") @@ -271,15 +271,15 @@ describe("Cassandra", function() assert.True(#apis > 0) local api_t = apis[1] - -- Should not work because we're reusing a public_dns - api_t.public_dns = apis[2].public_dns + -- Should not work because we're reusing a inbound_dns + api_t.inbound_dns = apis[2].inbound_dns local api, err = dao_factory.apis:update(api_t) assert.truthy(err) assert.falsy(api) assert.is_daoError(err) assert.True(err.unique) - assert.equal("public_dns already exists with value '"..api_t.public_dns.."'", err.message.public_dns) + assert.equal("inbound_dns already exists with value '"..api_t.inbound_dns.."'", err.message.inbound_dns) end) describe("full", function() @@ -313,7 +313,7 @@ describe("Cassandra", function() assert.truthy(api_t) -- Update - api.public_dns = nil + api.inbound_dns = nil local nil_api, err = dao_factory.apis:update(api, true) assert.truthy(err) @@ -323,7 +323,7 @@ describe("Cassandra", function() api, err = session:execute("SELECT * FROM apis WHERE id = ?", {cassandra.uuid(api.id)}) assert.falsy(err) assert.truthy(api[1].name) - assert.truthy(api[1].public_dns) + assert.truthy(api[1].inbound_dns) end) end) @@ -366,7 +366,7 @@ describe("Cassandra", function() assert.True(needs_filtering) -- No Filtering needed - apis, err, needs_filtering = dao_factory.apis:find_by_keys {public_dns = api_t.public_dns} + apis, err, needs_filtering = dao_factory.apis:find_by_keys {inbound_dns = api_t.inbound_dns} assert.falsy(err) assert.same(api_t, apis[1]) assert.False(needs_filtering) @@ -545,8 +545,8 @@ describe("Cassandra", function() it("should find distinct plugins configurations", function() faker:insert_from_table { api = { - { name = "tests distinct 1", public_dns = "foo.com", target_url = "http://mockbin.com" }, - { name = "tests distinct 2", public_dns = "bar.com", target_url = "http://mockbin.com" } + { name = "tests distinct 1", inbound_dns = "foo.com", upstream_url = "http://mockbin.com" }, + { name = "tests distinct 2", inbound_dns = "bar.com", upstream_url = "http://mockbin.com" } }, plugin = { { name = "key-auth", config = {key_names = {"apikey"}, hide_credentials = true}, __api = 1 }, diff --git a/spec/integration/dao/cassandra/cascade_spec.lua b/spec/integration/dao/cassandra/cascade_spec.lua index df6009e7ead..2b1cd45ca9e 100644 --- a/spec/integration/dao/cassandra/cascade_spec.lua +++ b/spec/integration/dao/cassandra/cascade_spec.lua @@ -18,11 +18,11 @@ describe("Cassandra cascade delete", function() local fixtures = spec_helper.insert_fixtures { api = { {name = "cascade delete", - public_dns = "mockbin.com", - target_url = "http://mockbin.com"}, + inbound_dns = "mockbin.com", + upstream_url = "http://mockbin.com"}, {name = "untouched cascade delete", - public_dns = "untouched.com", - target_url = "http://mockbin.com"} + inbound_dns = "untouched.com", + upstream_url = "http://mockbin.com"} }, plugin = { {name = "key-auth", __api = 1}, @@ -67,8 +67,8 @@ describe("Cassandra cascade delete", function() local fixtures = spec_helper.insert_fixtures { api = { {name = "cascade delete", - public_dns = "mockbin.com", - target_url = "http://mockbin.com"} + inbound_dns = "mockbin.com", + upstream_url = "http://mockbin.com"} }, consumer = { {username = "king kong"}, diff --git a/spec/integration/proxy/api_resolver_spec.lua b/spec/integration/proxy/api_resolver_spec.lua index cf2908dbca2..0bbd9c40e66 100644 --- a/spec/integration/proxy/api_resolver_spec.lua +++ b/spec/integration/proxy/api_resolver_spec.lua @@ -26,17 +26,17 @@ describe("Resolver", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - {name = "tests host resolver 1", public_dns = "mockbin.com", target_url = "http://mockbin.com"}, - {name = "tests host resolver 2", public_dns = "mockbin-auth.com", target_url = "http://mockbin.com"}, - {name = "tests path resolver", target_url = "http://mockbin.com", path = "/status"}, - {name = "tests stripped path resolver", target_url = "http://mockbin.com", path = "/mockbin", strip_path = true}, - {name = "tests stripped path resolver with pattern characters", target_url = "http://mockbin.com", path = "/mockbin-with-pattern/", strip_path = true}, - {name = "tests deep path resolver", target_url = "http://mockbin.com", path = "/deep/path/", strip_path = true}, - {name = "tests dup path resolver", target_url = "http://mockbin.com", path = "/har", strip_path = true}, - {name = "tests wildcard subdomain", target_url = "http://mockbin.com/status/200", public_dns = "*.wildcard.com"}, - {name = "tests wildcard subdomain 2", target_url = "http://mockbin.com/status/201", public_dns = "wildcard.*"}, - {name = "tests preserve host", public_dns = "httpbin-nopreserve.com", target_url = "http://httpbin.org"}, - {name = "tests preserve host 2", public_dns = "httpbin-preserve.com", target_url = "http://httpbin.org", preserve_host = true} + {name = "tests host resolver 1", inbound_dns = "mockbin.com", upstream_url = "http://mockbin.com"}, + {name = "tests host resolver 2", inbound_dns = "mockbin-auth.com", upstream_url = "http://mockbin.com"}, + {name = "tests path resolver", upstream_url = "http://mockbin.com", path = "/status"}, + {name = "tests stripped path resolver", upstream_url = "http://mockbin.com", path = "/mockbin", strip_path = true}, + {name = "tests stripped path resolver with pattern characters", upstream_url = "http://mockbin.com", path = "/mockbin-with-pattern/", strip_path = true}, + {name = "tests deep path resolver", upstream_url = "http://mockbin.com", path = "/deep/path/", strip_path = true}, + {name = "tests dup path resolver", upstream_url = "http://mockbin.com", path = "/har", strip_path = true}, + {name = "tests wildcard subdomain", upstream_url = "http://mockbin.com/status/200", inbound_dns = "*.wildcard.com"}, + {name = "tests wildcard subdomain 2", upstream_url = "http://mockbin.com/status/201", inbound_dns = "wildcard.*"}, + {name = "tests preserve host", inbound_dns = "httpbin-nopreserve.com", upstream_url = "http://httpbin.org"}, + {name = "tests preserve host 2", inbound_dns = "httpbin-preserve.com", upstream_url = "http://httpbin.org", preserve_host = true} }, plugin = { {name = "key-auth", config = {key_names = {"apikey"} }, __api = 2} @@ -55,7 +55,7 @@ describe("Resolver", function() it("should return Not Found when the API is not in Kong", function() local response, status = http_client.get(spec_helper.STUB_GET_URL, nil, {host = "foo.com"}) assert.equal(404, status) - assert.equal('{"public_dns":["foo.com"],"message":"API not found with these values","path":"\\/request"}\n', response) + assert.equal('{"path":"\\/request","message":"API not found with these values","inbound_dns":["foo.com"]}\n', response) end) end) @@ -130,7 +130,7 @@ describe("Resolver", function() describe("with wildcard subdomain", function() - it("should proxy when the public_dns is a wildcard subdomain", function() + it("should proxy when the inbound_dns is a wildcard subdomain", function() local _, status = http_client.get(STUB_GET_URL, nil, {host = "subdomain.wildcard.com"}) assert.equal(200, status) diff --git a/spec/integration/proxy/database_cache_spec.lua b/spec/integration/proxy/database_cache_spec.lua index f66a24183a8..a9a6e1e0366 100644 --- a/spec/integration/proxy/database_cache_spec.lua +++ b/spec/integration/proxy/database_cache_spec.lua @@ -10,7 +10,7 @@ describe("Database cache", function() spec_helper.prepare_db() fixtures = spec_helper.insert_fixtures { api = { - { name = "tests database cache", public_dns = "cache.test", target_url = "http://httpbin.org" } + { name = "tests database cache", inbound_dns = "cache.test", upstream_url = "http://httpbin.org" } } } diff --git a/spec/integration/proxy/dns_resolver_spec.lua b/spec/integration/proxy/dns_resolver_spec.lua index 12e3c7b11a7..61984362e52 100644 --- a/spec/integration/proxy/dns_resolver_spec.lua +++ b/spec/integration/proxy/dns_resolver_spec.lua @@ -9,8 +9,8 @@ describe("DNS", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests dns 1", public_dns = "dns1.com", target_url = "http://127.0.0.1:"..TCP_PORT }, - { name = "tests dns 2", public_dns = "dns2.com", target_url = "http://localhost:"..TCP_PORT } + { name = "tests dns 1", inbound_dns = "dns1.com", upstream_url = "http://127.0.0.1:"..TCP_PORT }, + { name = "tests dns 2", inbound_dns = "dns2.com", upstream_url = "http://localhost:"..TCP_PORT } } } diff --git a/spec/integration/proxy/realip_spec.lua b/spec/integration/proxy/realip_spec.lua index 88a4861ff8b..9fb3a8495b2 100644 --- a/spec/integration/proxy/realip_spec.lua +++ b/spec/integration/proxy/realip_spec.lua @@ -13,7 +13,7 @@ describe("Real IP", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests realip", public_dns = "realip.com", target_url = "http://mockbin.com" } + { name = "tests realip", inbound_dns = "realip.com", upstream_url = "http://mockbin.com" } }, plugin = { { name = "file-log", config = { path = FILE_LOG_PATH }, __api = 1 } diff --git a/spec/plugins/basic-auth/access_spec.lua b/spec/plugins/basic-auth/access_spec.lua index 7aa189cd9a7..60add49b139 100644 --- a/spec/plugins/basic-auth/access_spec.lua +++ b/spec/plugins/basic-auth/access_spec.lua @@ -10,7 +10,7 @@ describe("Authentication Plugin", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - {name = "tests basicauth", public_dns = "basicauth.com", target_url = "http://httpbin.org"} + {name = "tests basicauth", inbound_dns = "basicauth.com", upstream_url = "http://httpbin.org"} }, consumer = { {username = "basicauth_tests_consuser"} diff --git a/spec/plugins/cors/access_spec.lua b/spec/plugins/cors/access_spec.lua index 5db2602c38a..287af56a12f 100644 --- a/spec/plugins/cors/access_spec.lua +++ b/spec/plugins/cors/access_spec.lua @@ -9,8 +9,8 @@ describe("CORS Plugin", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests cors 1", public_dns = "cors1.com", target_url = "http://mockbin.com" }, - { name = "tests cors 2", public_dns = "cors2.com", target_url = "http://mockbin.com" } + { name = "tests cors 1", inbound_dns = "cors1.com", upstream_url = "http://mockbin.com" }, + { name = "tests cors 2", inbound_dns = "cors2.com", upstream_url = "http://mockbin.com" } }, plugin = { { name = "cors", config = {}, __api = 1 }, diff --git a/spec/plugins/ip-restriction/access_spec.lua b/spec/plugins/ip-restriction/access_spec.lua index ffa0edc1bae..5c441194a30 100644 --- a/spec/plugins/ip-restriction/access_spec.lua +++ b/spec/plugins/ip-restriction/access_spec.lua @@ -10,14 +10,14 @@ describe("IP Restriction", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "iprestriction1", public_dns = "test1.com", target_url = "http://mockbin.com" }, - { name = "iprestriction2", public_dns = "test2.com", target_url = "http://mockbin.com" }, - { name = "iprestriction3", public_dns = "test3.com", target_url = "http://mockbin.com" }, - { name = "iprestriction4", public_dns = "test4.com", target_url = "http://mockbin.com" }, - { name = "iprestriction5", public_dns = "test5.com", target_url = "http://mockbin.com" }, - { name = "iprestriction6", public_dns = "test6.com", target_url = "http://mockbin.com" }, - { name = "iprestriction7", public_dns = "test7.com", target_url = "http://mockbin.com" }, - { name = "iprestriction8", public_dns = "test8.com", target_url = "http://mockbin.com" } + { name = "iprestriction1", inbound_dns = "test1.com", upstream_url = "http://mockbin.com" }, + { name = "iprestriction2", inbound_dns = "test2.com", upstream_url = "http://mockbin.com" }, + { name = "iprestriction3", inbound_dns = "test3.com", upstream_url = "http://mockbin.com" }, + { name = "iprestriction4", inbound_dns = "test4.com", upstream_url = "http://mockbin.com" }, + { name = "iprestriction5", inbound_dns = "test5.com", upstream_url = "http://mockbin.com" }, + { name = "iprestriction6", inbound_dns = "test6.com", upstream_url = "http://mockbin.com" }, + { name = "iprestriction7", inbound_dns = "test7.com", upstream_url = "http://mockbin.com" }, + { name = "iprestriction8", inbound_dns = "test8.com", upstream_url = "http://mockbin.com" } }, plugin = { { name = "ip-restriction", config = { blacklist = { "127.0.0.1" }}, __api = 1 }, diff --git a/spec/plugins/key-auth/access_spec.lua b/spec/plugins/key-auth/access_spec.lua index 2265ecf5c3d..7ac2d9b7b19 100644 --- a/spec/plugins/key-auth/access_spec.lua +++ b/spec/plugins/key-auth/access_spec.lua @@ -11,8 +11,8 @@ describe("Authentication Plugin", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - {name = "tests auth 1", public_dns = "keyauth1.com", target_url = "http://mockbin.com"}, - {name = "tests auth 2", public_dns = "keyauth2.com", target_url = "http://mockbin.com"} + {name = "tests auth 1", inbound_dns = "keyauth1.com", upstream_url = "http://mockbin.com"}, + {name = "tests auth 2", inbound_dns = "keyauth2.com", upstream_url = "http://mockbin.com"} }, consumer = { {username = "auth_tests_consumer"} diff --git a/spec/plugins/logging_spec.lua b/spec/plugins/logging_spec.lua index 94a052261fa..51c93f9826d 100644 --- a/spec/plugins/logging_spec.lua +++ b/spec/plugins/logging_spec.lua @@ -28,12 +28,12 @@ describe("Logging Plugins", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests tcp logging", public_dns = "tcp_logging.com", target_url = "http://mockbin.com" }, - { name = "tests tcp logging2", public_dns = "tcp_logging2.com", target_url = "http://localhost:"..HTTP_DELAY_PORT }, - { name = "tests udp logging", public_dns = "udp_logging.com", target_url = "http://mockbin.com" }, - { name = "tests http logging", public_dns = "http_logging.com", target_url = "http://mockbin.com" }, - { name = "tests https logging", public_dns = "https_logging.com", target_url = "http://mockbin.com" }, - { name = "tests file logging", public_dns = "file_logging.com", target_url = "http://mockbin.com" } + { name = "tests tcp logging", inbound_dns = "tcp_logging.com", upstream_url = "http://mockbin.com" }, + { name = "tests tcp logging2", inbound_dns = "tcp_logging2.com", upstream_url = "http://localhost:"..HTTP_DELAY_PORT }, + { name = "tests udp logging", inbound_dns = "udp_logging.com", upstream_url = "http://mockbin.com" }, + { name = "tests http logging", inbound_dns = "http_logging.com", upstream_url = "http://mockbin.com" }, + { name = "tests https logging", inbound_dns = "https_logging.com", upstream_url = "http://mockbin.com" }, + { name = "tests file logging", inbound_dns = "file_logging.com", upstream_url = "http://mockbin.com" } }, plugin = { { name = "tcp-log", config = { host = "127.0.0.1", port = TCP_PORT }, __api = 1 }, diff --git a/spec/plugins/oauth2/access_spec.lua b/spec/plugins/oauth2/access_spec.lua index fd5f84f9c52..be45846c187 100644 --- a/spec/plugins/oauth2/access_spec.lua +++ b/spec/plugins/oauth2/access_spec.lua @@ -40,11 +40,11 @@ describe("Authentication Plugin", function() spec_helper.drop_db() spec_helper.insert_fixtures { api = { - { name = "tests oauth2", public_dns = "oauth2.com", target_url = "http://mockbin.com" }, - { name = "tests oauth2 with path", public_dns = "mockbin-path.com", target_url = "http://mockbin.com", path = "/somepath/" }, - { name = "tests oauth2 with hide credentials", public_dns = "oauth2_3.com", target_url = "http://mockbin.com" }, - { name = "tests oauth2 client credentials", public_dns = "oauth2_4.com", target_url = "http://mockbin.com" }, - { name = "tests oauth2 password grant", public_dns = "oauth2_5.com", target_url = "http://mockbin.com" } + { name = "tests oauth2", inbound_dns = "oauth2.com", upstream_url = "http://mockbin.com" }, + { name = "tests oauth2 with path", inbound_dns = "mockbin-path.com", upstream_url = "http://mockbin.com", path = "/somepath/" }, + { name = "tests oauth2 with hide credentials", inbound_dns = "oauth2_3.com", upstream_url = "http://mockbin.com" }, + { name = "tests oauth2 client credentials", inbound_dns = "oauth2_4.com", upstream_url = "http://mockbin.com" }, + { name = "tests oauth2 password grant", inbound_dns = "oauth2_5.com", upstream_url = "http://mockbin.com" } }, consumer = { { username = "auth_tests_consumer" } diff --git a/spec/plugins/rate-limiting/access_spec.lua b/spec/plugins/rate-limiting/access_spec.lua index c781ebe4adf..06c05ff3953 100644 --- a/spec/plugins/rate-limiting/access_spec.lua +++ b/spec/plugins/rate-limiting/access_spec.lua @@ -19,10 +19,10 @@ describe("RateLimiting Plugin", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests rate-limiting 1", public_dns = "test3.com", target_url = "http://mockbin.com" }, - { name = "tests rate-limiting 2", public_dns = "test4.com", target_url = "http://mockbin.com" }, - { name = "tests rate-limiting 3", public_dns = "test5.com", target_url = "http://mockbin.com" }, - { name = "tests rate-limiting 4", public_dns = "test6.com", target_url = "http://mockbin.com" } + { name = "tests rate-limiting 1", inbound_dns = "test3.com", upstream_url = "http://mockbin.com" }, + { name = "tests rate-limiting 2", inbound_dns = "test4.com", upstream_url = "http://mockbin.com" }, + { name = "tests rate-limiting 3", inbound_dns = "test5.com", upstream_url = "http://mockbin.com" }, + { name = "tests rate-limiting 4", inbound_dns = "test6.com", upstream_url = "http://mockbin.com" } }, consumer = { { custom_id = "provider_123" }, diff --git a/spec/plugins/rate-limiting/api_spec.lua b/spec/plugins/rate-limiting/api_spec.lua index 44ca6e20a7e..d079b912cee 100644 --- a/spec/plugins/rate-limiting/api_spec.lua +++ b/spec/plugins/rate-limiting/api_spec.lua @@ -9,7 +9,7 @@ describe("Rate Limiting API", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests rate-limiting 1", public_dns = "test1.com", target_url = "http://mockbin.com" } + { name = "tests rate-limiting 1", inbound_dns = "test1.com", upstream_url = "http://mockbin.com" } } } spec_helper.start_kong() diff --git a/spec/plugins/request-size-limiting/access_spec.lua b/spec/plugins/request-size-limiting/access_spec.lua index 3b21ad527ab..57053e7392d 100644 --- a/spec/plugins/request-size-limiting/access_spec.lua +++ b/spec/plugins/request-size-limiting/access_spec.lua @@ -9,7 +9,7 @@ describe("RequestSizeLimiting Plugin", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests request-size-limiting 1", public_dns = "test3.com", target_url = "http://mockbin.com/request" } + { name = "tests request-size-limiting 1", inbound_dns = "test3.com", upstream_url = "http://mockbin.com/request" } }, plugin = { { name = "request-size-limiting", config = {allowed_payload_size = 10}, __api = 1 } diff --git a/spec/plugins/request-transformer/access_spec.lua b/spec/plugins/request-transformer/access_spec.lua index 7918a3cf40f..bb706e8124e 100644 --- a/spec/plugins/request-transformer/access_spec.lua +++ b/spec/plugins/request-transformer/access_spec.lua @@ -11,7 +11,7 @@ describe("Request Transformer", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests request-transformer", public_dns = "test5.com", target_url = "http://mockbin.com" }, + { name = "tests request-transformer", inbound_dns = "test5.com", upstream_url = "http://mockbin.com" }, }, plugin = { { diff --git a/spec/plugins/response-ratelimiting/access_spec.lua b/spec/plugins/response-ratelimiting/access_spec.lua index e6511be20ec..a7258f8221c 100644 --- a/spec/plugins/response-ratelimiting/access_spec.lua +++ b/spec/plugins/response-ratelimiting/access_spec.lua @@ -19,9 +19,9 @@ describe("RateLimiting Plugin", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests response-ratelimiting 1", public_dns = "test1.com", target_url = "http://httpbin.org/" }, - { name = "tests response-ratelimiting 2", public_dns = "test2.com", target_url = "http://httpbin.org/" }, - { name = "tests response-ratelimiting 3", public_dns = "test3.com", target_url = "http://httpbin.org/" } + { name = "tests response-ratelimiting 1", inbound_dns = "test1.com", upstream_url = "http://httpbin.org/" }, + { name = "tests response-ratelimiting 2", inbound_dns = "test2.com", upstream_url = "http://httpbin.org/" }, + { name = "tests response-ratelimiting 3", inbound_dns = "test3.com", upstream_url = "http://httpbin.org/" } }, consumer = { { custom_id = "consumer_123" }, diff --git a/spec/plugins/response-ratelimiting/api_spec.lua b/spec/plugins/response-ratelimiting/api_spec.lua index 94c6f7bfd49..62608e0c5a6 100644 --- a/spec/plugins/response-ratelimiting/api_spec.lua +++ b/spec/plugins/response-ratelimiting/api_spec.lua @@ -9,7 +9,7 @@ describe("Response Rate Limiting API", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests response-ratelimiting 1", public_dns = "test1.com", target_url = "http://mockbin.com" } + { name = "tests response-ratelimiting 1", inbound_dns = "test1.com", upstream_url = "http://mockbin.com" } } } spec_helper.start_kong() diff --git a/spec/plugins/response-transformer/access_spec.lua b/spec/plugins/response-transformer/access_spec.lua index f2153175474..133cebdb677 100644 --- a/spec/plugins/response-transformer/access_spec.lua +++ b/spec/plugins/response-transformer/access_spec.lua @@ -11,8 +11,8 @@ describe("Response Transformer Plugin #proxy", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "tests response-transformer", public_dns = "response.com", target_url = "http://httpbin.org" }, - { name = "tests response-transformer 2", public_dns = "response2.com", target_url = "http://httpbin.org" }, + { name = "tests response-transformer", inbound_dns = "response.com", upstream_url = "http://httpbin.org" }, + { name = "tests response-transformer 2", inbound_dns = "response2.com", upstream_url = "http://httpbin.org" }, }, plugin = { { diff --git a/spec/plugins/ssl/access_spec.lua b/spec/plugins/ssl/access_spec.lua index aefc5ccdda6..e9ef5cd5a21 100644 --- a/spec/plugins/ssl/access_spec.lua +++ b/spec/plugins/ssl/access_spec.lua @@ -16,9 +16,9 @@ describe("SSL Plugin", function() spec_helper.prepare_db() spec_helper.insert_fixtures { api = { - { name = "API TESTS 11 (ssl)", public_dns = "ssl1.com", target_url = "http://mockbin.com" }, - { name = "API TESTS 12 (ssl)", public_dns = "ssl2.com", target_url = "http://mockbin.com" }, - { name = "API TESTS 13 (ssl)", public_dns = "ssl3.com", target_url = "http://mockbin.com" } + { name = "API TESTS 11 (ssl)", inbound_dns = "ssl1.com", upstream_url = "http://mockbin.com" }, + { name = "API TESTS 12 (ssl)", inbound_dns = "ssl2.com", upstream_url = "http://mockbin.com" }, + { name = "API TESTS 13 (ssl)", inbound_dns = "ssl3.com", upstream_url = "http://mockbin.com" } }, plugin = { { name = "ssl", config = { cert = ssl_fixtures.cert, key = ssl_fixtures.key }, __api = 1 }, @@ -89,7 +89,7 @@ describe("SSL Plugin", function() end) describe("should work with curl", function() - local response = http_client.get(API_URL.."/apis/", {public_dns="ssl3.com"}) + local response = http_client.get(API_URL.."/apis/", {inbound_dns="ssl3.com"}) local api_id = cjson.decode(response).data[1].id local kong_working_dir = spec_helper.get_env(spec_helper.TEST_CONF_FILE).configuration.nginx_working_dir diff --git a/spec/plugins/ssl/api_spec.lua b/spec/plugins/ssl/api_spec.lua index f8a91f0ec27..e245b253d59 100644 --- a/spec/plugins/ssl/api_spec.lua +++ b/spec/plugins/ssl/api_spec.lua @@ -11,7 +11,7 @@ describe("SSL API", function() spec_helper.start_kong() spec_helper.insert_fixtures { api = { - {name = "mockbin", public_dns = "mockbin.com", target_url = "http://mockbin.com"} + {name = "mockbin", inbound_dns = "mockbin.com", upstream_url = "http://mockbin.com"} } } BASE_URL = spec_helper.API_URL.."/apis/mockbin/plugins/" diff --git a/spec/unit/dao/cassandra/query_builder_spec.lua b/spec/unit/dao/cassandra/query_builder_spec.lua index 5d1a3896dbf..e887b45cce8 100644 --- a/spec/unit/dao/cassandra/query_builder_spec.lua +++ b/spec/unit/dao/cassandra/query_builder_spec.lua @@ -5,7 +5,7 @@ describe("Query Builder", function() local apis_details = { primary_key = {"id"}, clustering_key = {"cluster_key"}, - indexes = {public_dns = true, name = true} + indexes = {inbound_dns = true, name = true} } describe("SELECT", function() @@ -21,8 +21,8 @@ describe("Query Builder", function() end) it("should return the columns of the arguments to bind", function() - local _, columns = builder.select("apis", {name="mockbin", public_dns="mockbin.com"}) - assert.same({"name", "public_dns"}, columns) + local _, columns = builder.select("apis", {name="mockbin", inbound_dns="mockbin.com"}) + assert.same({"name", "inbound_dns"}, columns) end) describe("WHERE", function() @@ -50,8 +50,8 @@ describe("Query Builder", function() end) it("should enable filtering when more than one indexed field is being queried", function() - local q, _, needs_filtering = builder.select("apis", {name="mockbin", public_dns="mockbin.com"}, apis_details) - assert.equal("SELECT * FROM apis WHERE name = ? AND public_dns = ? ALLOW FILTERING", q) + local q, _, needs_filtering = builder.select("apis", {name="mockbin", inbound_dns="mockbin.com"}, apis_details) + assert.equal("SELECT * FROM apis WHERE name = ? AND inbound_dns = ? ALLOW FILTERING", q) assert.True(needs_filtering) end) end) @@ -122,8 +122,8 @@ describe("Query Builder", function() end) it("should return the columns of the arguments to bind", function() - local _, columns = builder.update("apis", {public_dns="1234", name="mockbin"}, {id="1"}, apis_details) - assert.same({"public_dns", "name", "id"}, columns) + local _, columns = builder.update("apis", {inbound_dns="1234", name="mockbin"}, {id="1"}, apis_details) + assert.same({"name", "inbound_dns", "id"}, columns) end) it("should throw an error if no column_family", function() diff --git a/spec/unit/dao/entities_schemas_spec.lua b/spec/unit/dao/entities_schemas_spec.lua index ffc13aaab33..5077c10ec44 100644 --- a/spec/unit/dao/entities_schemas_spec.lua +++ b/spec/unit/dao/entities_schemas_spec.lua @@ -25,28 +25,28 @@ describe("Entities Schemas", function() describe("APIs", function() - it("should return error with wrong target_url", function() + it("should return error with wrong upstream_url", function() local valid, errors = validate_entity({ - public_dns = "mockbin.com", - target_url = "asdasd" + inbound_dns = "mockbin.com", + upstream_url = "asdasd" }, api_schema) assert.False(valid) - assert.equal("Invalid target URL", errors.target_url) + assert.equal("Invalid target URL", errors.upstream_url) end) - it("should return error with wrong target_url protocol", function() + it("should return error with wrong upstream_url protocol", function() local valid, errors = validate_entity({ - public_dns = "mockbin.com", - target_url = "wot://mockbin.com/" + inbound_dns = "mockbin.com", + upstream_url = "wot://mockbin.com/" }, api_schema) assert.False(valid) - assert.equal("Supported protocols are HTTP and HTTPS", errors.target_url) + assert.equal("Supported protocols are HTTP and HTTPS", errors.upstream_url) end) it("should validate without a path", function() local valid, errors = validate_entity({ - public_dns = "mockbin.com", - target_url = "http://mockbin.com" + inbound_dns = "mockbin.com", + upstream_url = "http://mockbin.com" }, api_schema) assert.falsy(errors) assert.True(valid) @@ -54,20 +54,20 @@ describe("Entities Schemas", function() it("should validate with upper case protocol", function() local valid, errors = validate_entity({ - public_dns = "mockbin.com", - target_url = "HTTP://mockbin.com/world" + inbound_dns = "mockbin.com", + upstream_url = "HTTP://mockbin.com/world" }, api_schema) assert.falsy(errors) assert.True(valid) end) - it("should complain if missing `public_dns` and `path`", function() + it("should complain if missing `inbound_dns` and `path`", function() local valid, errors = validate_entity({ name = "mockbin" }, api_schema) assert.False(valid) - assert.equal("At least a 'public_dns' or a 'path' must be specified", errors.path) - assert.equal("At least a 'public_dns' or a 'path' must be specified", errors.public_dns) + assert.equal("At least an 'inbound_dns' or a 'path' must be specified", errors.path) + assert.equal("At least an 'inbound_dns' or a 'path' must be specified", errors.inbound_dns) local valid, errors = validate_entity({ name = "mockbin", @@ -75,11 +75,11 @@ describe("Entities Schemas", function() }, api_schema) assert.False(valid) assert.equal("path is not a string", errors.path) - assert.equal("At least a 'public_dns' or a 'path' must be specified", errors.public_dns) + assert.equal("At least an 'inbound_dns' or a 'path' must be specified", errors.inbound_dns) end) - it("should set the name from public_dns if not set", function() - local t = { public_dns = "mockbin.com", target_url = "http://mockbin.com" } + it("should set the name from inbound_dns if not set", function() + local t = { inbound_dns = "mockbin.com", upstream_url = "http://mockbin.com" } local valid, errors = validate_entity(t, api_schema) assert.falsy(errors) @@ -87,51 +87,51 @@ describe("Entities Schemas", function() assert.equal("mockbin.com", t.name) end) - it("should accept valid wildcard public_dns", function() + it("should accept valid wildcard inbound_dns", function() local valid, errors = validate_entity({ name = "mockbin", - public_dns = "*.mockbin.org", - target_url = "http://mockbin.com" + inbound_dns = "*.mockbin.org", + upstream_url = "http://mockbin.com" }, api_schema) assert.True(valid) assert.falsy(errors) valid, errors = validate_entity({ name = "mockbin", - public_dns = "mockbin.*", - target_url = "http://mockbin.com" + inbound_dns = "mockbin.*", + upstream_url = "http://mockbin.com" }, api_schema) assert.True(valid) assert.falsy(errors) end) - it("should refuse invalid wildcard public_dns", function() + it("should refuse invalid wildcard inbound_dns", function() local api_t = { name = "mockbin", - public_dns = "*.mockbin.*", - target_url = "http://mockbin.com" + inbound_dns = "*.mockbin.*", + upstream_url = "http://mockbin.com" } local valid, errors = validate_entity(api_t, api_schema) assert.False(valid) - assert.equal("Only one wildcard is allowed: *.mockbin.*", errors.public_dns) + assert.equal("Only one wildcard is allowed: *.mockbin.*", errors.inbound_dns) - api_t.public_dns = "*mockbin.com" + api_t.inbound_dns = "*mockbin.com" valid, errors = validate_entity(api_t, api_schema) assert.False(valid) - assert.equal("Invalid wildcard placement: *mockbin.com", errors.public_dns) + assert.equal("Invalid wildcard placement: *mockbin.com", errors.inbound_dns) - api_t.public_dns = "www.mockbin*" + api_t.inbound_dns = "www.mockbin*" valid, errors = validate_entity(api_t, api_schema) assert.False(valid) - assert.equal("Invalid wildcard placement: www.mockbin*", errors.public_dns) + assert.equal("Invalid wildcard placement: www.mockbin*", errors.inbound_dns) end) it("should only accept alphanumeric `path`", function() local valid, errors = validate_entity({ name = "mockbin", path = "/[a-zA-Z]{3}", - target_url = "http://mockbin.com" + upstream_url = "http://mockbin.com" }, api_schema) assert.equal("path must only contain alphanumeric and '. -, _, ~, /' characters", errors.path) assert.False(valid) @@ -139,20 +139,20 @@ describe("Entities Schemas", function() valid = validate_entity({ name = "mockbin", path = "/status/", - target_url = "http://mockbin.com" + upstream_url = "http://mockbin.com" }, api_schema) assert.True(valid) valid = validate_entity({ name = "mockbin", path = "/abcd~user-2", - target_url = "http://mockbin.com" + upstream_url = "http://mockbin.com" }, api_schema) assert.True(valid) end) it("should prefix a `path` with a slash and remove trailing slash", function() - local api_t = { name = "mockbin", path = "status", target_url = "http://mockbin.com" } + local api_t = { name = "mockbin", path = "status", upstream_url = "http://mockbin.com" } validate_entity(api_t, api_schema) assert.equal("/status", api_t.path) diff --git a/spec/unit/dao/error_spec.lua b/spec/unit/dao/error_spec.lua index 27744af4d0e..f21eecf3734 100644 --- a/spec/unit/dao/error_spec.lua +++ b/spec/unit/dao/error_spec.lua @@ -57,11 +57,11 @@ describe("DaoError", function() -- example: schema validation returns a table with key/values for errors local stub_error = { name = "name is required", - public_dns = "invalid url" + inbound_dns = "invalid url" } local err = DaoError(stub_error, "some_type") - assert.are.same("name=name is required public_dns=invalid url", tostring(err)) + assert.are.same("name=name is required inbound_dns=invalid url", tostring(err)) end) end) diff --git a/spec/unit/resolver/access_spec.lua b/spec/unit/resolver/access_spec.lua index 6cfd62d4472..1c02f565013 100644 --- a/spec/unit/resolver/access_spec.lua +++ b/spec/unit/resolver/access_spec.lua @@ -3,13 +3,13 @@ local resolver_access = require "kong.resolver.access" -- Stubs require "kong.tools.ngx_stub" local APIS_FIXTURES = { - {name = "mockbin", public_dns = "mockbin.com", target_url = "http://mockbin.com"}, - {name = "mockbin", public_dns = "mockbin-auth.com", target_url = "http://mockbin.com"}, - {name = "mockbin", public_dns = "*.wildcard.com", target_url = "http://mockbin.com"}, - {name = "mockbin", public_dns = "wildcard.*", target_url = "http://mockbin.com"}, - {name = "mockbin", path = "/mockbin", target_url = "http://mockbin.com"}, - {name = "mockbin", path = "/mockbin-with-dashes", target_url = "http://mockbin.com"}, - {name = "mockbin", path = "/some/deep/url", target_url = "http://mockbin.com"} + {name = "mockbin", inbound_dns = "mockbin.com", upstream_url = "http://mockbin.com"}, + {name = "mockbin", inbound_dns = "mockbin-auth.com", upstream_url = "http://mockbin.com"}, + {name = "mockbin", inbound_dns = "*.wildcard.com", upstream_url = "http://mockbin.com"}, + {name = "mockbin", inbound_dns = "wildcard.*", upstream_url = "http://mockbin.com"}, + {name = "mockbin", path = "/mockbin", upstream_url = "http://mockbin.com"}, + {name = "mockbin", path = "/mockbin-with-dashes", upstream_url = "http://mockbin.com"}, + {name = "mockbin", path = "/some/deep/url", upstream_url = "http://mockbin.com"} } _G.dao = { apis = { @@ -30,7 +30,7 @@ describe("Resolver Access", function() assert.truthy(apis_dics.path_arr) assert.truthy(apis_dics.wildcard_dns_arr) end) - it("should return a dictionary of APIs by public_dns", function() + it("should return a dictionary of APIs by inbound_dns", function() assert.equal("table", type(apis_dics.by_dns["mockbin.com"])) assert.equal("table", type(apis_dics.by_dns["mockbin-auth.com"])) end) @@ -45,7 +45,7 @@ describe("Resolver Access", function() assert.equal("/mockbin", apis_dics.path_arr[1].strip_path_pattern) assert.equal("/mockbin%-with%-dashes", apis_dics.path_arr[2].strip_path_pattern) end) - it("should return an array of APIs with wildcard public_dns", function() + it("should return an array of APIs with wildcard inbound_dns", function() assert.equal("table", type(apis_dics.wildcard_dns_arr)) assert.equal(2, #apis_dics.wildcard_dns_arr) for _, item in ipairs(apis_dics.wildcard_dns_arr) do @@ -78,9 +78,9 @@ describe("Resolver Access", function() assert.same(APIS_FIXTURES[7], api) end) end) - describe("find_api_by_public_dns()", function() + describe("find_api_by_inbound_dns()", function() it("should return nil and a list of all the Host headers in the request when no API was found", function() - local api, all_hosts = resolver_access.find_api_by_public_dns({ + local api, all_hosts = resolver_access.find_api_by_inbound_dns({ Host = "foo.com", ["X-Host-Override"] = {"bar.com", "hello.com"} }, apis_dics) @@ -88,21 +88,21 @@ describe("Resolver Access", function() assert.same({"foo.com", "bar.com", "hello.com"}, all_hosts) end) it("should return an API when one of the Host headers matches", function() - local api = resolver_access.find_api_by_public_dns({Host = "mockbin.com"}, apis_dics) + local api = resolver_access.find_api_by_inbound_dns({Host = "mockbin.com"}, apis_dics) assert.same(APIS_FIXTURES[1], api) - api = resolver_access.find_api_by_public_dns({Host = "mockbin-auth.com"}, apis_dics) + api = resolver_access.find_api_by_inbound_dns({Host = "mockbin-auth.com"}, apis_dics) assert.same(APIS_FIXTURES[2], api) end) it("should return an API when one of the Host headers matches a wildcard dns", function() - local api = resolver_access.find_api_by_public_dns({Host = "wildcard.com"}, apis_dics) + local api = resolver_access.find_api_by_inbound_dns({Host = "wildcard.com"}, apis_dics) assert.same(APIS_FIXTURES[4], api) - api = resolver_access.find_api_by_public_dns({Host = "wildcard.fr"}, apis_dics) + api = resolver_access.find_api_by_inbound_dns({Host = "wildcard.fr"}, apis_dics) assert.same(APIS_FIXTURES[4], api) - api = resolver_access.find_api_by_public_dns({Host = "foobar.wildcard.com"}, apis_dics) + api = resolver_access.find_api_by_inbound_dns({Host = "foobar.wildcard.com"}, apis_dics) assert.same(APIS_FIXTURES[3], api) - api = resolver_access.find_api_by_public_dns({Host = "barfoo.wildcard.com"}, apis_dics) + api = resolver_access.find_api_by_inbound_dns({Host = "barfoo.wildcard.com"}, apis_dics) assert.same(APIS_FIXTURES[3], api) end) end) diff --git a/spec/unit/tools/faker_spec.lua b/spec/unit/tools/faker_spec.lua index 01fcf300cba..e50f08045bb 100644 --- a/spec/unit/tools/faker_spec.lua +++ b/spec/unit/tools/faker_spec.lua @@ -48,7 +48,7 @@ describe("Faker", function() describe("#insert_from_table()", function() it("should throw a descriptive error if cannot insert an entity", function() - local api_t = { name = "tests faker 1", public_dns = "foo.com", target_url = "http://mockbin.com" } + local api_t = { name = "tests faker 1", inbound_dns = "foo.com", upstream_url = "http://mockbin.com" } local printable_mt = require "kong.tools.printable" local entity_to_str = setmetatable(api_t, printable_mt) @@ -87,8 +87,8 @@ describe("Faker", function() it("should create relations between entities_to_insert and inserted entities", function() local fixtures = { api = { - { name = "tests faker 1", public_dns = "foo.com", target_url = "http://mockbin.com" }, - { name = "tests faker 2", public_dns = "bar.com", target_url = "http://mockbin.com" } + { name = "tests faker 1", inbound_dns = "foo.com", upstream_url = "http://mockbin.com" }, + { name = "tests faker 2", inbound_dns = "bar.com", upstream_url = "http://mockbin.com" } }, plugin = { { name = "key-auth", config = {key_names={"apikey"}}, __api = 1 }, From a16b4bd1fa4b99fa4f3124431359ffc4bbbcab38 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Fri, 28 Aug 2015 16:15:27 -0700 Subject: [PATCH 6/9] docs(changelog) properties renaming notice --- CHANGELOG.md | 7 +++--- UPDATE.md | 63 ++++++++++++++++++++++++++++------------------------ 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80c34996fd2..7fa6163ffcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,10 @@ This release contains breaking changes. Several breaking changes are introduced. You will have to slightly change your configuration file and a migration script will take care of updating your database cluster. Please follow the instructions in [UPDATE.md](/UPDATE.md#update-to-kong-050). - Many plugins were renamed due to new naming conventions for consistency. [#480](https://github.com/Mashape/kong/issues/480) -- The database schema has been updated to be future proof and handle the separation of plugins outside of the core repository. - -The Key authentication and Basic authentication plugins routes have changed: +- `public_dns` and `target_url` properties of APIs were respectively renamed to `inbound_dns` and `upstream_url`. [#513](https://github.com/Mashape/kong/issues/513) +- `plugins_configurations` have been renamed to `plugins`, and their `value` property has been renamed to `config` to avoid confusions. [#513](https://github.com/Mashape/kong/issues/513) +- The database schema has been updated to handle the separation of plugins outside of the core repository. +- The Key authentication and Basic authentication plugins routes have changed: ``` Old route New route diff --git a/UPDATE.md b/UPDATE.md index 7b01e50bdbf..7687665940d 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -4,36 +4,11 @@ This document describes eventual additional steps that might be required to upda It is important that you be running Kong `0.4.2` and have the latest release of Python 2.7 on your system when executing those steps. -Several changes were introduced in this version: many plugins were renamed and the database schema slightly changed to introduce "plugins migrations". Now, each plugin can have its own migration if it needs to store data in your cluster. This is not a regular migration since the schema of the table handling the migrations itself changed. +Several changes were introduced in this version: some plugins and properties were renamed and the database schema slightly changed to introduce "plugins migrations". Now, each plugin can have its own migration if it needs to store data in your cluster. This is not a regular migration since the schema of the table handling the migrations itself changed. -##### 1. Migration script +##### 1. Configuration file -[This Python script](/scripts/migration.py) will take care of migrating your database schema should you execute the following instructions: - -```shell -# First, make sure you are already running Kong 0.4.2 - -# Clone the Kong git repository if you don't already have it: -$ git clone git@github.com:Mashape/kong.git - -# Go to the 'scripts/' folder: -$ cd kong/scripts - -# Install the Python script dependencies: -$ pip install cassandra-driver pyyaml - -# The script will use your first contact point (the first of the 'hosts' property) -# so make sure it is valid and has the format 'host:port'. - -# Execute the migration script: -$ python migration.py -c /path/to/kong/config - -# If everything went well the script should print a success message. -``` - -##### 2. Configuration file - -You will now need to update your configuration file. Replace the `plugins_available` property with: +You will need to update your configuration file. Replace the `plugins_available` property with: ```yaml plugins_available: @@ -57,6 +32,32 @@ plugins_available: You can still remove plugins you don't use for a lighter Kong. +##### 2. Migration script + +[This Python script](/scripts/migration.py) will take care of migrating your database schema should you execute the following instructions: + +```shell +# First, make sure you are already running Kong 0.4.2 + +# Clone the Kong git repository if you don't already have it: +$ git clone git@github.com:Mashape/kong.git + +# Go to the 'scripts/' folder: +$ cd kong/scripts + +# Install the Python script dependencies: +$ pip install cassandra-driver pyyaml + +# The script will use the first Cassandra contact point +# in your Kong configuration file (the first of the 'hosts' property) +# so make sure it is valid and has the format 'host:port'. + +# Run the migration script: +$ python migration.py -c /path/to/kong/config +``` + +If everything went well the script should print a success message. + ##### 3. Upgrade without downtime You can now update Kong to 0.5.0. Proceed as a regular update and install the package of your choice from the website. After updating, reload Kong to avoid downtime: @@ -69,7 +70,11 @@ Your cluster should successfully be migrated to Kong `0.5.0`. ##### Other changes -The Key authentication and Basic authentication plugins routes have changed: +Some entities and properties were renamed to avoid confusion: + +- `public_dns` and `target_url` properties of APIs were respectively renamed to `inbound_dns` and `upstream_url`. +- `plugins_configurations` have been renamed to `plugins`, and their `value` property has been renamed to `config` to avoid confusions. +- The Key authentication and Basic authentication plugins routes have changed: ``` Old route New route From 25a8ce83f02945eaf15da607ca250bfc5468fad1 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Fri, 28 Aug 2015 17:36:00 -0700 Subject: [PATCH 7/9] chore(mig-script) separate migration form purging The migration script now runs in two steps to avoid downtime: 1. actual migration (followed by kong reload) 2. purging of the old schema to erase old data --- CHANGELOG.md | 2 +- UPDATE.md | 16 +++- scripts/migration.py | 198 +++++++++++++++++-------------------------- 3 files changed, 90 insertions(+), 126 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fa6163ffcc..8e07dced2d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This release contains breaking changes. ### Breaking changes -Several breaking changes are introduced. You will have to slightly change your configuration file and a migration script will take care of updating your database cluster. Please follow the instructions in [UPDATE.md](/UPDATE.md#update-to-kong-050). +Several breaking changes are introduced. You will have to slightly change your configuration file and a migration script will take care of updating your database cluster. Please follow the instructions in [UPDATE.md](/UPDATE.md#update-to-kong-050) for an update without downtime. - Many plugins were renamed due to new naming conventions for consistency. [#480](https://github.com/Mashape/kong/issues/480) - `public_dns` and `target_url` properties of APIs were respectively renamed to `inbound_dns` and `upstream_url`. [#513](https://github.com/Mashape/kong/issues/513) diff --git a/UPDATE.md b/UPDATE.md index 7687665940d..0892716862e 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -2,9 +2,9 @@ This document describes eventual additional steps that might be required to upda ## Update to Kong `0.5.0` -It is important that you be running Kong `0.4.2` and have the latest release of Python 2.7 on your system when executing those steps. +Migrating to 0.5.0 can be done **without downtime** by following those instructions. It is important that you be running Kong `0.4.2` and have the latest release of Python 2.7 on your system when executing those steps. -Several changes were introduced in this version: some plugins and properties were renamed and the database schema slightly changed to introduce "plugins migrations". Now, each plugin can have its own migration if it needs to store data in your cluster. This is not a regular migration since the schema of the table handling the migrations itself changed. +> Several changes were introduced in this version: some plugins and properties were renamed and the database schema slightly changed to introduce "plugins migrations". Now, each plugin can have its own migration if it needs to store data in your cluster. This is not a regular migration since the schema of the table handling the migrations itself changed. ##### 1. Configuration file @@ -68,7 +68,17 @@ $ kong reload Your cluster should successfully be migrated to Kong `0.5.0`. -##### Other changes +##### 4. Purge your Cassandra cluster + +Finally, once Kong has restarted in 0.5.0, run the migration script again, with the `--purge` flag: + +```shell +$ python migration.py -c /path/to/kong/config --purge +``` + +Your cluster is now fully migrated to 0.5.0. + +##### Other changes to acknowledge Some entities and properties were renamed to avoid confusion: diff --git a/scripts/migration.py b/scripts/migration.py index 20d9945bb37..5dc8b4349af 100755 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -2,11 +2,14 @@ '''Kong 0.5.0 Migration Script -Usage: python migration.py --config=/path/to/kong/config +Usage: python migration.py --config=/path/to/kong/config [--purge] + +Run this script first to migrate Kong to the 0.5.0 schema. Once successful, reload Kong +and run this script again with the --purge option. Arguments: -c, --config path to your Kong configuration file - + -p, --purge if already migrated, purge the old values Flags: -h print help ''' @@ -68,6 +71,7 @@ def migrate_schema_migrations_table(session): :param session: opened cassandra session """ + log.info("Migrating schema_migrations table...") query = SimpleStatement("INSERT INTO schema_migrations(id, migrations) VALUES(%s, %s)", consistency_level=ConsistencyLevel.ALL) session.execute(query, ["core", ['2015-01-12-175310_skeleton', '2015-01-12-175310_init_schema']]) session.execute(query, ["basic-auth", ['2015-08-03-132400_init_basicauth']]) @@ -76,17 +80,16 @@ def migrate_schema_migrations_table(session): session.execute(query, ["oauth2", ['2015-08-03-132400_init_oauth2', '2015-08-24-215800_cascade_delete_index']]) log.info("schema_migrations table migrated") -def migrate_schema_migrations_remove_legacy_row(session): - session.execute("DELETE FROM schema_migrations WHERE id = 'migrations'") - log.info("Legacy values removed from schema_migrations table") - -def migrate_plugins_renaming(session): +def migrate_plugins_configurations(session): """ - Migrate the plugins_configurations table by renaming all plugins whose name changed. + Migrate all rows in the `plugins_configurations` table to `plugins`, applying: + - renaming of plugins if name changed + - conversion of old rate-limiting schema if old schema detected :param session: opened cassandra session """ - log.info("Renaming plugins...") + log.info("Migrating plugins...") + new_names = { "keyauth": "key-auth", "basicauth": "basic-auth", @@ -101,47 +104,6 @@ def migrate_plugins_renaming(session): "ip_restriction": "ip-restriction" } - for plugin in session.execute("SELECT * FROM plugins_configurations"): - plugin_name = plugin.name - if plugin.name in new_names: - plugin_name = new_names[plugin.name] - - delete_query = SimpleStatement("DELETE FROM plugins_configurations WHERE id = %s", consistency_level=ConsistencyLevel.ALL) - insert_query = SimpleStatement(""" - INSERT INTO plugins_configurations(id, name, api_id, consumer_id, created_at, enabled, value) - VALUES(%s, %s, %s, %s, %s, %s, %s)""", consistency_level=ConsistencyLevel.ALL) - - session.execute(delete_query, [plugin.id]) - session.execute(insert_query, [plugin.id, plugin_name, plugin.api_id, plugin.consumer_id, plugin.created_at, plugin.enabled, plugin.value]) - - log.info("Plugins renamed") - -def migrate_rate_limiting_value(session): - """ - Update all old `values` of rate-limiting plugins_configurations to the new schema (supporting multiple limits) - - :param session: opened cassandra session - """ - log.info("Migrating rate-limiting values...") - - for plugin in session.execute("SELECT * FROM plugins_configurations WHERE name = 'rate-limiting'"): - conf = json.loads(plugin.value) - if "limit" in conf: - new_conf = {} - new_conf[conf["period"]] = conf["limit"] - update_query = SimpleStatement("UPDATE plugins_configurations SET value = %s WHERE id = %s AND name = %s", consistency_level=ConsistencyLevel.ALL) - session.execute(update_query, [json.dumps(new_conf), plugin.id, plugin.name]) - - log.info("rate-limiting values migrated") - -def migrate_rename_plugins_configurations(session): - """ - Migrate all rows in the `plugins_configurations` table to `plugins` - - :param session: opened cassandra session - """ - log.info("Renaming 'plugins_configurations' to 'plugins'...") - session.execute(""" create table if not exists plugins( id uuid, @@ -151,24 +113,38 @@ def migrate_rename_plugins_configurations(session): config text, enabled boolean, created_at timestamp, - primary key (id, name) - )""") + primary key (id, name))""") session.execute("create index if not exists on plugins(name)") session.execute("create index if not exists on plugins(api_id)") session.execute("create index if not exists on plugins(consumer_id)") for plugin in session.execute("SELECT * FROM plugins_configurations"): + # New plugins names + plugin_name = plugin.name + if plugin.name in new_names: + plugin_name = new_names[plugin.name] + + # rate-limiting config + plugin_conf = plugin.value + if plugin_name == "rate-limiting": + conf = json.loads(plugin.value) + if "limit" in conf: + plugin_conf = {} + plugin_conf[conf["period"]] = conf["limit"] + plugin_conf = json.dumps(plugin_conf) + insert_query = SimpleStatement(""" INSERT INTO plugins(id, api_id, consumer_id, name, config, enabled, created_at) VALUES(%s, %s, %s, %s, %s, %s, %s)""", consistency_level=ConsistencyLevel.ALL) - session.execute(insert_query, [plugin.id, plugin.api_id, plugin.consumer_id, plugin.name, plugin.value, plugin.enabled, plugin.created_at]) + session.execute(insert_query, [plugin.id, plugin.api_id, plugin.consumer_id, plugin_name, plugin_conf, plugin.enabled, plugin.created_at]) - session.execute("DROP TABLE plugins_configurations") - log.info("Plugins moved to table 'plugins'") + log.info("Plugins migrated") def migrate_rename_apis_properties(sessions): """ + Create new columns for the `apis` column family and insert the equivalent values in it + :param session: opened cassandra session """ log.info("Renaming some properties for APIs...") @@ -181,71 +157,18 @@ def migrate_rename_apis_properties(sessions): for api in session.execute(select_query): session.execute("UPDATE apis SET inbound_dns = %s, upstream_url = %s WHERE id = %s", [api.public_dns, api.target_url, api.id]) - session.execute("ALTER TABLE apis DROP public_dns") - session.execute("ALTER TABLE apis DROP target_url") log.info("APIs properties renamed") -def migrate(kong_config): - """ - Instanciate a Cassandra session and decides if the keyspace needs to be migrated - by looking at what the schema_migrations table contains. - - :param kong_config: parsed Kong configuration - :return: True if some migrations were ran, False otherwise - """ - host, port, keyspace = load_cassandra_config(kong_config) - cluster = Cluster([host], protocol_version=2, port=port) - global session - session = cluster.connect(keyspace) - - """ - 1. schema_migrations - Check if the 'schema_migrations' table has been migrated yet or not. - - ** Also Check if Kong is in 0.4.2 or else stops the script. ** - """ - rows = session.execute("SELECT * FROM schema_migrations") - if len(rows) == 1 and rows[0].id == "migrations": - last_executed_migration = rows[0].migrations[-1] - if last_executed_migration != "2015-08-10-813213_0.4.2": - log.error("Please migrate your cluster to Kong 0.4.2 before running this script.") - shutdown_exit(1) - - log.info("Schema_migrations table needs migration") - migrate_schema_migrations_table(session) - migrate_schema_migrations_remove_legacy_row(session) - - elif len(rows) > 1: - # apparently kong was restarted without previously running this script - if any(row.id == "migrations" for row in rows): - log.info("Already migrated to 0.5.0, but legacy value found. Purging.") - migrate_schema_migrations_remove_legacy_row(session) +def purge(session): + session.execute("ALTER TABLE apis DROP public_dns") + session.execute("ALTER TABLE apis DROP target_url") + session.execute("DROP TABLE plugins_configurations") + session.execute("DELETE FROM schema_migrations WHERE id = 'migrations'") - """ - 2. Plugins - Check if plugins_configurations have been migrated yet, if not, migrate - a. Rename some plugins - b. Migrate the old rate-limit config schema to the new one - c. Migrate all rows into a new table 'plugins' and drop the old one - """ - columnfamilies = session.execute("SELECT columnfamily_name FROM system.schema_columnfamilies WHERE keyspace_name = %s", [keyspace]) - if any(row.columnfamily_name == "plugins_configurations" for row in columnfamilies): - migrate_plugins_renaming(session) - migrate_rate_limiting_value(session) - migrate_rename_plugins_configurations(session) - else: - log.info("Plugins already migrated") - - """ - 3. APIs - Check if APIs have been migrated yet (properties renaming) - """ - try: - session.execute("SELECT upstream_url FROM apis") - log.info("APIs properties already migrated") - except InvalidRequest as err: - # If this column doesn't exit yet, apis have not been migrated - migrate_rename_apis_properties(session) +def migrate(session): + migrate_schema_migrations_table(session) + migrate_plugins_configurations(session) + migrate_rename_apis_properties(session) def parse_arguments(argv): """ @@ -255,13 +178,16 @@ def parse_arguments(argv): :return: parsed kong configuration """ config_path = "" + purge = False - opts, args = getopt.getopt(argv, "hc:", ["config="]) + opts, args = getopt.getopt(argv, "hc:", ["config=", "purge"]) for opt, arg in opts: if opt == "-h": usage() elif opt in ("-c", "--config"): config_path = arg + elif opt in ("--purge"): + purge = True if config_path == "": raise ArgumentException("No Kong configuration given") @@ -273,13 +199,41 @@ def parse_arguments(argv): with open(config_path, "r") as stream: config = yaml.load(stream) - return config + return (config, purge) def main(argv): try: - config = parse_arguments(argv) - migrate(config) - log.info("Cassandra migrated to Kong 0.5.0.") + kong_config, purge_cmd = parse_arguments(argv) + host, port, keyspace = load_cassandra_config(kong_config) + cluster = Cluster([host], protocol_version=2, port=port) + global session + session = cluster.connect(keyspace) + + # Find out where the schema is at + rows = session.execute("SELECT * FROM schema_migrations") + is_migrated = len(rows) > 1 and any(mig.id == "core" for mig in rows) + is_0_4_2 = len(rows) == 1 and rows[0].migrations[-1] == "2015-08-10-813213_0.4.2" + is_purged = len(session.execute("SELECT * FROM system.schema_columnfamilies WHERE keyspace_name = %s AND columnfamily_name = 'plugins_configurations'", [keyspace])) == 0 + + if not is_0_4_2 and not is_migrated: + log.error("Please migrate your cluster to Kong 0.4.2 before running this script.") + shutdown_exit(1) + + if purge_cmd : + if not is_purged and is_migrated: + purge(session) + log.info("Cassandra purged from <0.5.0 data") + elif not is_purged and not is_migrated: + log.info("Cassandra not previously migrated. Run this script in migration mode before.") + shutdown_exit(1) + else: + log.info("Cassandra already purged and migrated") + elif not is_migrated: + migrate(session) + log.info("Cassandra migrated to Kong 0.5.0.") + else: + log.info("Cassandra already migrated to Kong 0.5.0") + shutdown_exit(0) except getopt.GetoptError as err: log.error(err) From 0fa2b1cc0fb4db4f144875f1d94de19385524605 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Fri, 28 Aug 2015 18:20:44 -0700 Subject: [PATCH 8/9] chore(renamings) rename config `hosts` property to `contact_points` --- CHANGELOG.md | 3 ++- UPDATE.md | 23 +++++++++++++------ kong.yml | 2 +- kong/dao/cassandra/base_dao.lua | 2 +- kong/dao/cassandra/factory.lua | 2 +- scripts/migration.py | 4 ++-- .../dao/cassandra/base_dao_spec.lua | 2 +- .../dao/cassandra/migrations_spec.lua | 2 +- .../integration/proxy/database_cache_spec.lua | 2 +- spec/integration/proxy/realip_spec.lua | 2 +- spec/unit/statics_spec.lua | 2 +- 11 files changed, 28 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e07dced2d3..53c573d7d01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,10 @@ This release contains breaking changes. ### Breaking changes -Several breaking changes are introduced. You will have to slightly change your configuration file and a migration script will take care of updating your database cluster. Please follow the instructions in [UPDATE.md](/UPDATE.md#update-to-kong-050) for an update without downtime. +Several breaking changes are introduced. You will have to slightly change your configuration file and a migration script will take care of updating your database cluster. **Please follow the instructions in [UPDATE.md](/UPDATE.md#update-to-kong-050) for an update without downtime**. - Many plugins were renamed due to new naming conventions for consistency. [#480](https://github.com/Mashape/kong/issues/480) +- In the configuration file, the Cassandra `hosts` property was renamed to `contact_points`. [#513](https://github.com/Mashape/kong/issues/513) - `public_dns` and `target_url` properties of APIs were respectively renamed to `inbound_dns` and `upstream_url`. [#513](https://github.com/Mashape/kong/issues/513) - `plugins_configurations` have been renamed to `plugins`, and their `value` property has been renamed to `config` to avoid confusions. [#513](https://github.com/Mashape/kong/issues/513) - The database schema has been updated to handle the separation of plugins outside of the core repository. diff --git a/UPDATE.md b/UPDATE.md index 0892716862e..29c213e2baf 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -8,7 +8,7 @@ Migrating to 0.5.0 can be done **without downtime** by following those instructi ##### 1. Configuration file -You will need to update your configuration file. Replace the `plugins_available` property with: +You will need to update your configuration file. Replace the `plugins_available` values with: ```yaml plugins_available: @@ -32,6 +32,18 @@ plugins_available: You can still remove plugins you don't use for a lighter Kong. +Also replace the Cassandra `hosts` property with `contact_points`: + +```yaml +properties: + contact_points: + - "..." + - "..." + timeout: 1000 + keyspace: kong + keepalive: 60000 +``` + ##### 2. Migration script [This Python script](/scripts/migration.py) will take care of migrating your database schema should you execute the following instructions: @@ -48,9 +60,8 @@ $ cd kong/scripts # Install the Python script dependencies: $ pip install cassandra-driver pyyaml -# The script will use the first Cassandra contact point -# in your Kong configuration file (the first of the 'hosts' property) -# so make sure it is valid and has the format 'host:port'. +# The script will use the first Cassandra contact point in your Kong configuration file +# (the first of the 'contact_points' property) so make sure it is valid and has the format 'host:port'. # Run the migration script: $ python migration.py -c /path/to/kong/config @@ -66,8 +77,6 @@ You can now update Kong to 0.5.0. Proceed as a regular update and install the pa $ kong reload ``` -Your cluster should successfully be migrated to Kong `0.5.0`. - ##### 4. Purge your Cassandra cluster Finally, once Kong has restarted in 0.5.0, run the migration script again, with the `--purge` flag: @@ -76,7 +85,7 @@ Finally, once Kong has restarted in 0.5.0, run the migration script again, with $ python migration.py -c /path/to/kong/config --purge ``` -Your cluster is now fully migrated to 0.5.0. +Your cluster is now fully migrated to `0.5.0`. ##### Other changes to acknowledge diff --git a/kong.yml b/kong.yml index daabc5cf5ec..2516312a100 100644 --- a/kong.yml +++ b/kong.yml @@ -36,7 +36,7 @@ database: cassandra databases_available: cassandra: properties: - hosts: + contact_points: - "localhost:9042" timeout: 1000 keyspace: kong diff --git a/kong/dao/cassandra/base_dao.lua b/kong/dao/cassandra/base_dao.lua index 59bbec6c047..19cf55ba217 100644 --- a/kong/dao/cassandra/base_dao.lua +++ b/kong/dao/cassandra/base_dao.lua @@ -72,7 +72,7 @@ function BaseDao:_open_session(keyspace) local options = self._factory:get_session_options() - ok, err = session:connect(self._properties.hosts, nil, options) + ok, err = session:connect(self._properties.hosts or self._properties.contact_points, nil, options) if not ok then return nil, DaoError(err, error_types.DATABASE) end diff --git a/kong/dao/cassandra/factory.lua b/kong/dao/cassandra/factory.lua index 13cde324507..933c3a00a91 100644 --- a/kong/dao/cassandra/factory.lua +++ b/kong/dao/cassandra/factory.lua @@ -123,7 +123,7 @@ function CassandraFactory:execute_queries(queries, no_keyspace) local options = self:get_session_options() - ok, err = session:connect(self._properties.hosts, nil, options) + ok, err = session:connect(self._properties.hosts or self._properties.contact_points, nil, options) if not ok then return DaoError(err, constants.DATABASE_ERROR_TYPES.DATABASE) end diff --git a/scripts/migration.py b/scripts/migration.py index 5dc8b4349af..96054332a0e 100755 --- a/scripts/migration.py +++ b/scripts/migration.py @@ -9,8 +9,8 @@ Arguments: -c, --config path to your Kong configuration file - -p, --purge if already migrated, purge the old values Flags: + --purge if already migrated, purge the old values -h print help ''' @@ -60,7 +60,7 @@ def load_cassandra_config(kong_config): """ cass_properties = kong_config["databases_available"]["cassandra"]["properties"] - host, port = cass_properties["hosts"][0].split(":") + host, port = cass_properties["contact_points"][0].split(":") keyspace = cass_properties["keyspace"] return (host, port, keyspace) diff --git a/spec/integration/dao/cassandra/base_dao_spec.lua b/spec/integration/dao/cassandra/base_dao_spec.lua index 306d48d95de..0a0b3390f0d 100644 --- a/spec/integration/dao/cassandra/base_dao_spec.lua +++ b/spec/integration/dao/cassandra/base_dao_spec.lua @@ -48,7 +48,7 @@ describe("Cassandra", function() session = cassandra:new() session:set_timeout(configuration.cassandra.timeout) - local _, err = session:connect(configuration.cassandra.hosts) + local _, err = session:connect(configuration.cassandra.contact_points) assert.falsy(err) local _, err = session:set_keyspace("kong_tests") diff --git a/spec/integration/dao/cassandra/migrations_spec.lua b/spec/integration/dao/cassandra/migrations_spec.lua index 56fb2002d07..d91278ac8eb 100644 --- a/spec/integration/dao/cassandra/migrations_spec.lua +++ b/spec/integration/dao/cassandra/migrations_spec.lua @@ -134,7 +134,7 @@ describe("Migrations", function() local migrations setup(function() - local ok, err = session:connect(test_cassandra_properties.hosts, test_cassandra_properties.port) + local ok, err = session:connect(test_cassandra_properties.contact_points, test_cassandra_properties.port) if not ok then error(err) end diff --git a/spec/integration/proxy/database_cache_spec.lua b/spec/integration/proxy/database_cache_spec.lua index a9a6e1e0366..95224f13311 100644 --- a/spec/integration/proxy/database_cache_spec.lua +++ b/spec/integration/proxy/database_cache_spec.lua @@ -22,7 +22,7 @@ describe("Database cache", function() end) it("should expire cache after five seconds", function() - local _, status = http_client.get(spec_helper.PROXY_URL.."/get", {}, {host = "cache.test"}) + local _ = http_client.get(spec_helper.PROXY_URL.."/get", {}, {host = "cache.test"}) -- Let's add the authentication plugin configuration local _, err = env.dao_factory.plugins:insert { diff --git a/spec/integration/proxy/realip_spec.lua b/spec/integration/proxy/realip_spec.lua index 9fb3a8495b2..11ff3eef858 100644 --- a/spec/integration/proxy/realip_spec.lua +++ b/spec/integration/proxy/realip_spec.lua @@ -31,7 +31,7 @@ describe("Real IP", function() local uuid = utils.random_string() -- Making the request - local _, status = http_client.get(spec_helper.STUB_GET_URL, nil, + local _ = http_client.get(spec_helper.STUB_GET_URL, nil, { host = "realip.com", ["X-Forwarded-For"] = "4.4.4.4, 1.1.1.1, 5.5.5.5", diff --git a/spec/unit/statics_spec.lua b/spec/unit/statics_spec.lua index f52e3c85100..b3581fb845f 100644 --- a/spec/unit/statics_spec.lua +++ b/spec/unit/statics_spec.lua @@ -78,7 +78,7 @@ database: cassandra databases_available: cassandra: properties: - hosts: + contact_points: - "localhost:9042" timeout: 1000 keyspace: kong From d206414967a7d91aa0ebb3ba182c2d537480a5dd Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Mon, 31 Aug 2015 16:45:36 -0700 Subject: [PATCH 9/9] feat(api) list of enabled plugins on `plugins/enabled` --- CHANGELOG.md | 4 ++++ UPDATE.md | 4 ++++ kong/api/routes/plugins.lua | 10 +++++++++- spec/integration/admin_api/plugins_routes_spec.lua | 11 +++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c573d7d01..edf12bd3b53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,10 @@ Old route New route The old routes are still maintained but will be removed in upcoming versions. Consider them **deprecated**. +- Admin API: + - The route to retrieve enabled plugins is now under `/plugins/enabled`. + - The route to retrieve a plugin's configuration schema is now under `/plugins/schema/{plugin name}`. + #### Added - Plugins migrations. Each plugin can now have its own migration scripts if it needs to store data in your cluster. This is a step forward to improve Kong's pluggable architecture. [#443](https://github.com/Mashape/kong/pull/443) diff --git a/UPDATE.md b/UPDATE.md index 29c213e2baf..7a174ab2965 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -105,6 +105,10 @@ Old route New route The old routes are still maintained but will be removed in upcoming versions. Consider them **deprecated**. +- Admin API: + - The route to retrieve enabled plugins is now under `/plugins/enabled`. + - The route to retrieve a plugin's configuration schema is now under `/plugins/schema/{plugin name}`. + ## Update to Kong `0.4.2` The configuration format for specifying the port of your Cassandra instance changed. Replace: diff --git a/kong/api/routes/plugins.lua b/kong/api/routes/plugins.lua index e277310c060..924b12dd24e 100644 --- a/kong/api/routes/plugins.lua +++ b/kong/api/routes/plugins.lua @@ -36,6 +36,8 @@ return { end }, + + ["/plugins/schema/:name"] = { GET = function(self, dao_factory, helpers) local ok, plugin_schema = utils.load_module_if_exists("kong.plugins."..self.params.name..".schema") @@ -71,5 +73,11 @@ return { DELETE = function(self, dao_factory) crud.delete(self.plugin_conf, dao_factory.plugins) end - } + }, ["/plugins/enabled"] = { + GET = function(self, dao_factory, helpers) + return helpers.responses.send_HTTP_OK { + enabled_plugins = configuration.plugins_available + } + end + }, } diff --git a/spec/integration/admin_api/plugins_routes_spec.lua b/spec/integration/admin_api/plugins_routes_spec.lua index 8354ffaa5a0..29e162c94b5 100644 --- a/spec/integration/admin_api/plugins_routes_spec.lua +++ b/spec/integration/admin_api/plugins_routes_spec.lua @@ -12,6 +12,17 @@ describe("Admin API", function() spec_helper.stop_kong() end) + describe("/plugins/enabled", function() + local BASE_URL = spec_helper.API_URL.."/plugins/enabled" + + it("should return a list of enabled plugins on this node", function() + local response, status = http_client.get(BASE_URL) + assert.equal(200, status) + local body = json.decode(response) + assert.equal("table", type(body.enabled_plugins)) + end) + end) + describe("/plugins/schema/:name", function() local BASE_URL = spec_helper.API_URL.."/plugins/schema/key-auth"