diff --git a/bin/kong b/bin/kong index 3c216085b71..9e5ee7f3097 100755 --- a/bin/kong +++ b/bin/kong @@ -22,9 +22,9 @@ fi PID=$NGINX_TMP/nginx.pid -###################### -# Utility function # -###################### +##################### +# Utility functions # +##################### function check_file_exists { if [ ! -f $1 ]; then @@ -45,9 +45,12 @@ function real_path_func { fi } -function print_start_error { - printf "Starting Kong" - printf "$(tput setaf 1) [$1]\n$(tput sgr 0)" +function print_error { + printf "$1 $(tput setaf 1)[$2]\n$(tput sgr 0)" +} + +function print_success { + printf "$1 $(tput setaf 2)[$2]\n$(tput sgr 0)" } ############## @@ -56,16 +59,13 @@ function print_start_error { function show_help { printf "Usage: kong [OPTION]... {start|stop|restart}\n -\t-c specify the path to a custom Kong configuration file -\t default is: '$KONG_HOME/kong.yml' -\t-v output version informations and exit +\t-c path to a kong configuration file. Default is: $KONG_CONF +\t-v output version and exit \t-h show this message \nCommands:\n -\tstart start Kong -\tstop stop a running Kong -\trestart restart Kong -\t it is equivalent to executing 'stop' and 'start' in succession -\tversion output version informations and exit +\tstart start kong +\tstop stop a running kong +\trestart restart kong. Equivalent to executing 'stop' and 'start' in succession \n" } @@ -77,17 +77,17 @@ function start { if [ -f $PID ]; then if ps -p $(cat $PID) > /dev/null then - print_start_error "ALREADY RUNNING" + print_error "Starting Kong" "ALREADY RUNNING" exit 1 fi fi - printf "Kong (configuration at "$KONG_CONF" output at "$NGINX_TMP")\n" + printf "configuration: $KONG_CONF\nnginx container: $NGINX_TMP\n\n" mkdir -p $NGINX_TMP/logs &> /dev/null if [ $? -ne 0 ]; then printf "Cannot operate on $NGINX_TMP - Make sure you have the right permissions.\n\n" - print_start_error "ERROR" + print_error "\nStarting Kong:" "ERROR" exit 1 fi @@ -97,26 +97,30 @@ function start { nginx -p $NGINX_TMP -c $NGINX_TMP/nginx.conf if [ $? -eq 0 ]; then - printf "Starting Kong" - printf "$(tput setaf 2) [OK]\n$(tput sgr 0)" + print_success "Starting Kong" "OK" else - printf "\nYou can get more information about this error by checking the error log file.\n\n" - print_start_error "ERROR" + print_error "\nStarting Kong" "ERROR" + error_file=`grep -e '^error_log' $NGINX_TMP/nginx.conf | grep -v syslog:server | grep -v stderr | awk '{print $2}'` + if [ -n "$error_file" ]; then + if [[ "$error_file" = /* ]]; then + printf "Error logs: $error_file\n" + else + printf "Error logs: $NGINX_TMP/$error_file\n" + fi + fi exit 1 fi } function stop { - printf "Stopping Kong" - if [ ! -f $PID ]; then - printf "$(tput setaf 1) [NOT RUNNING]\n$(tput sgr 0)" + print_error "Stopping Kong" "NOT RUNNING" if [ "$1" = false ] ; then # $1 is true when it's part of a restart exit 1 fi else kill $(cat $PID) - printf "$(tput setaf 2) [OK]\n$(tput sgr 0)" + print_success "Stopping Kong" "OK" fi } @@ -135,15 +139,16 @@ cmd="" while getopts "h?vc:n:" opt; do case "$opt" in h|\?) - show_help - exit 0 - ;; - v) show_version - exit 0 - ;; + show_help + exit 0 + ;; + v) + show_version + exit 0 + ;; c) - KONG_CONF=$(real_path_func $OPTARG) - ;; + KONG_CONF=$(real_path_func $OPTARG) + ;; esac done @@ -155,19 +160,16 @@ check_file_exists $KONG_CONF case "$@" in start) - start - ;; + start + ;; stop) - stop - ;; + stop + ;; restart) - restart - ;; - version) - show_version - ;; + restart + ;; *) - show_help + show_help esac diff --git a/kong-0.0.1beta-1.rockspec b/kong-0.0.1beta-1.rockspec index 85cb59933bc..20c7de3f16d 100644 --- a/kong-0.0.1beta-1.rockspec +++ b/kong-0.0.1beta-1.rockspec @@ -35,53 +35,53 @@ dependencies = { build = { type = "builtin", modules = { - ["kong"] = "src/main.lua", + ["kong"] = "src/kong.lua", ["classic"] = "src/classic.lua", - ["kong.constants"] = "src/kong/constants.lua", + ["kong.constants"] = "src/constants.lua", - ["kong.tools.utils"] = "src/kong/tools/utils.lua", - ["kong.tools.timestamp"] = "src/kong/tools/timestamp.lua", - ["kong.tools.cache"] = "src/kong/tools/cache.lua", - ["kong.tools.http_client"] = "src/kong/tools/http_client.lua", - ["kong.tools.faker"] = "src/kong/tools/faker.lua", - ["kong.tools.migrations"] = "src/kong/tools/migrations.lua", + ["kong.tools.utils"] = "src/tools/utils.lua", + ["kong.tools.timestamp"] = "src/tools/timestamp.lua", + ["kong.tools.cache"] = "src/tools/cache.lua", + ["kong.tools.http_client"] = "src/tools/http_client.lua", + ["kong.tools.faker"] = "src/tools/faker.lua", + ["kong.tools.migrations"] = "src/tools/migrations.lua", - ["kong.base_plugin"] = "src/kong/base_plugin.lua", + ["kong.plugins.base_plugin"] = "src/plugins/base_plugin.lua", - ["kong.core.handler"] = "src/kong/core/handler.lua", - ["kong.core.access"] = "src/kong/core/access.lua", - ["kong.core.header_filter"] = "src/kong/core/header_filter.lua", + ["kong.resolver.handler"] = "src/resolver/handler.lua", + ["kong.resolver.access"] = "src/resolver/access.lua", + ["kong.resolver.header_filter"] = "src/resolver/header_filter.lua", - ["kong.dao.schemas"] = "src/kong/dao/schemas.lua", + ["kong.dao.schemas"] = "src/dao/schemas.lua", - ["kong.dao.error"] = "src/kong/dao/error.lua", - ["kong.dao.cassandra.factory"] = "src/kong/dao/cassandra/factory.lua", - ["kong.dao.cassandra.base_dao"] = "src/kong/dao/cassandra/base_dao.lua", - ["kong.dao.cassandra.apis"] = "src/kong/dao/cassandra/apis.lua", - ["kong.dao.cassandra.metrics"] = "src/kong/dao/cassandra/metrics.lua", - ["kong.dao.cassandra.plugins"] = "src/kong/dao/cassandra/plugins.lua", - ["kong.dao.cassandra.accounts"] = "src/kong/dao/cassandra/accounts.lua", - ["kong.dao.cassandra.applications"] = "src/kong/dao/cassandra/applications.lua", + ["kong.dao.error"] = "src/dao/error.lua", + ["kong.dao.cassandra.factory"] = "src/dao/cassandra/factory.lua", + ["kong.dao.cassandra.base_dao"] = "src/dao/cassandra/base_dao.lua", + ["kong.dao.cassandra.apis"] = "src/dao/cassandra/apis.lua", + ["kong.dao.cassandra.metrics"] = "src/dao/cassandra/metrics.lua", + ["kong.dao.cassandra.plugins"] = "src/dao/cassandra/plugins.lua", + ["kong.dao.cassandra.accounts"] = "src/dao/cassandra/accounts.lua", + ["kong.dao.cassandra.applications"] = "src/dao/cassandra/applications.lua", - ["kong.plugins.authentication.handler"] = "src/kong/plugins/authentication/handler.lua", - ["kong.plugins.authentication.access"] = "src/kong/plugins/authentication/access.lua", - ["kong.plugins.authentication.schema"] = "src/kong/plugins/authentication/schema.lua", + ["kong.plugins.authentication.handler"] = "src/plugins/authentication/handler.lua", + ["kong.plugins.authentication.access"] = "src/plugins/authentication/access.lua", + ["kong.plugins.authentication.schema"] = "src/plugins/authentication/schema.lua", - ["kong.plugins.networklog.handler"] = "src/kong/plugins/networklog/handler.lua", - ["kong.plugins.networklog.log"] = "src/kong/plugins/networklog/log.lua", - ["kong.plugins.networklog.schema"] = "src/kong/plugins/networklog/schema.lua", + ["kong.plugins.networklog.handler"] = "src/plugins/networklog/handler.lua", + ["kong.plugins.networklog.log"] = "src/plugins/networklog/log.lua", + ["kong.plugins.networklog.schema"] = "src/plugins/networklog/schema.lua", - ["kong.plugins.ratelimiting.handler"] = "src/kong/plugins/ratelimiting/handler.lua", - ["kong.plugins.ratelimiting.access"] = "src/kong/plugins/ratelimiting/access.lua", - ["kong.plugins.ratelimiting.schema"] = "src/kong/plugins/ratelimiting/schema.lua", + ["kong.plugins.ratelimiting.handler"] = "src/plugins/ratelimiting/handler.lua", + ["kong.plugins.ratelimiting.access"] = "src/plugins/ratelimiting/access.lua", + ["kong.plugins.ratelimiting.schema"] = "src/plugins/ratelimiting/schema.lua", - ["kong.web.app"] = "src/kong/web/app.lua", - ["kong.web.routes.accounts"] = "src/kong/web/routes/accounts.lua", - ["kong.web.routes.apis"] = "src/kong/web/routes/apis.lua", - ["kong.web.routes.applications"] = "src/kong/web/routes/applications.lua", - ["kong.web.routes.plugins"] = "src/kong/web/routes/plugins.lua", - ["kong.web.routes.base_controller"] = "src/kong/web/routes/base_controller.lua" + ["kong.web.app"] = "src/web/app.lua", + ["kong.web.routes.accounts"] = "src/web/routes/accounts.lua", + ["kong.web.routes.apis"] = "src/web/routes/apis.lua", + ["kong.web.routes.applications"] = "src/web/routes/applications.lua", + ["kong.web.routes.plugins"] = "src/web/routes/plugins.lua", + ["kong.web.routes.base_controller"] = "src/web/routes/base_controller.lua" }, - copy_directories = { "src/kong/web/admin", "src/kong/web/static" } + copy_directories = { "src/web/admin", "src/web/static" } } diff --git a/kong.yml b/kong.yml index 8302b963a33..ebc3ce4957c 100644 --- a/kong.yml +++ b/kong.yml @@ -42,7 +42,7 @@ nginx: | } http { - lua_package_path ";;"; + lua_package_path ';;'; lua_code_cache on; access_log logs/access.log; @@ -80,13 +80,20 @@ nginx: | resolver 8.8.8.8; charset UTF-8; - init_by_lua "kong = require 'kong'; kong.init()"; + init_by_lua ' + kong = require "kong" + local status, err = pcall(kong.init) + if not status then + ngx.log(ngx.ERR, "Startup error: "..err) + os.exit(1) + end + '; server { listen 8000; location /robots.txt { - return 200 "User-agent: *\nDisallow: /"; + return 200 'User-agent: *\nDisallow: /'; } location / { @@ -99,7 +106,7 @@ nginx: | set $querystring nil; # Authenticate the user and load the API info - access_by_lua "kong.access()"; + access_by_lua 'kong.exec_plugins_access()'; # Proxy the request proxy_set_header X-Real-IP $remote_addr; @@ -107,13 +114,13 @@ nginx: | proxy_pass $backend_url; # Add additional response headers - header_filter_by_lua "kong.header_filter()"; + header_filter_by_lua 'kong.exec_plugins_header_filter()'; # Change the response body - body_filter_by_lua "kong.body_filter()"; + body_filter_by_lua 'kong.exec_plugins_body_filter()'; # Log the request - log_by_lua "kong.log()"; + log_by_lua 'kong.exec_plugins_log()'; } error_page 500 /500.html; @@ -121,7 +128,8 @@ nginx: | internal; content_by_lua ' local utils = require "kong.tools.utils" - utils.show_error(ngx.status, "Ops, an unexpected error occurred!")'; + utils.show_error(ngx.status, "Oops, an unexpected error occurred!") + '; } } diff --git a/scripts/config.lua b/scripts/config.lua index 65a8fcb8164..f5e8f2b66c4 100755 --- a/scripts/config.lua +++ b/scripts/config.lua @@ -27,7 +27,7 @@ if args.COMMAND == "create" then TEST = { ["send_anonymous_reports: true"] = "send_anonymous_reports: false", ["keyspace: kong"] = "keyspace: kong_tests", - ["lua_package_path \";;\""] = "lua_package_path \""..args.kong.."/src/?.lua;;\"", + ["lua_package_path ';;'"] = "lua_package_path '"..args.kong.."/src/?.lua;;'", ["error_log logs/error.log info"] = "error_log logs/error.log debug", ["listen 8000"] = "listen 8100", ["listen 8001"] = "listen 8101" @@ -35,7 +35,7 @@ if args.COMMAND == "create" then DEVELOPMENT = { ["send_anonymous_reports: true"] = "send_anonymous_reports: false", ["keyspace: kong"] = "keyspace: kong_development", - ["lua_package_path \";;\""] = "lua_package_path \""..args.kong.."/src/?.lua;;\"", + ["lua_package_path ';;'"] = "lua_package_path '"..args.kong.."/src/?.lua;;'", ["error_log logs/error.log info"] = "error_log logs/error.log debug", ["lua_code_cache on"] = "lua_code_cache off", ["daemon on"] = "daemon off" diff --git a/spec/integration/api/api_spec.lua b/spec/integration/api/api_spec.lua index 5110aaf92b5..cb1e77023da 100644 --- a/spec/integration/api/api_spec.lua +++ b/spec/integration/api/api_spec.lua @@ -2,13 +2,14 @@ local spec_helper = require "spec.spec_helpers" local http_client = require "kong.tools.http_client" local cjson = require "cjson" +local env = spec_helper.get_env() local created_ids = {} local kWebURL = spec_helper.API_URL local ENDPOINTS = { { collection = "apis", - total = table.getn(spec_helper.faker.FIXTURES.api) + 1, + total = table.getn(env.faker.FIXTURES.api) + 1, entity = { public_dns = "api.mockbin.com", name = "mockbin", @@ -21,7 +22,7 @@ local ENDPOINTS = { }, { collection = "accounts", - total = table.getn(spec_helper.faker.FIXTURES.account) + 1, + total = table.getn(env.faker.FIXTURES.account) + 1, entity = { provider_id = "123456789" }, @@ -32,7 +33,7 @@ local ENDPOINTS = { }, { collection = "applications", - total = table.getn(spec_helper.faker.FIXTURES.application) + 1, + total = table.getn(env.faker.FIXTURES.application) + 1, entity = { public_key = "PUB_key", secret_key = "SEC_key", @@ -48,7 +49,7 @@ local ENDPOINTS = { }, { collection = "plugins", - total = table.getn(spec_helper.faker.FIXTURES.plugin) + 1, + total = table.getn(env.faker.FIXTURES.plugin) + 1, entity = { name = "ratelimiting", api_id = function() diff --git a/spec/integration/server/server_spec.lua b/spec/integration/server/server_spec.lua index 324ef157b55..71a8ae2238e 100644 --- a/spec/integration/server/server_spec.lua +++ b/spec/integration/server/server_spec.lua @@ -7,20 +7,16 @@ local stringy = require "stringy" local TEST_CONF = "kong_TEST.yml" local SERVER_CONF = "kong_TEST_SERVER.yml" -local function replace_conf_property(name, value) +local function replace_conf_property(key, value) local yaml_value = yaml.load(utils.read_file(TEST_CONF)) if type(value) == "table" and utils.table_size(value) == 0 then value = nil end - yaml_value[name] = value + yaml_value[key] = value utils.write_to_file(SERVER_CONF, yaml.dump(yaml_value)) end -local function result_contains(result, val) - return result:find(val, 1, true) -end - -describe("#server-cli", function() +describe("Server", function() describe("CLI", function() @@ -31,25 +27,46 @@ describe("#server-cli", function() end) - describe("Plugins Check", function() + describe("Startup migration", function() setup(function() - os.execute("cp "..TEST_CONF.." "..SERVER_CONF) - spec_helper.prepare_db() + local databases_available = yaml.load(utils.read_file(TEST_CONF)).databases_available + databases_available.cassandra.properties.keyspace = "kong_tests_server_migrations" + replace_conf_property("databases_available", databases_available) + spec_helper.add_env(SERVER_CONF) end) teardown(function() + spec_helper.stop_kong(SERVER_CONF) + spec_helper.reset_db(SERVER_CONF) os.remove(SERVER_CONF) - spec_helper.reset_db() + spec_helper.remove_env(SERVER_CONF) end) - before_each(function() - spec_helper.stop_kong(SERVER_CONF) - spec_helper.drop_db() + it("should migrate when starting for the first time on a new keyspace", function() + spec_helper.start_kong(SERVER_CONF) + local env = spec_helper.get_env(SERVER_CONF) + local migrations = env.dao_factory:get_migrations() + assert.True(#migrations > 0) + end) + + end) + + describe("Startup plugins check", function() + + setup(function() + os.execute("cp "..TEST_CONF.." "..SERVER_CONF) + spec_helper.prepare_db() + spec_helper.drop_db() -- remove the seed from prepare_db() + end) + + teardown(function() + os.remove(SERVER_CONF) end) after_each(function() spec_helper.stop_kong(SERVER_CONF) + spec_helper.reset_db() end) it("should work when no plugins are enabled and the DB is empty", function() @@ -82,7 +99,7 @@ describe("#server-cli", function() it("should not work when a plugin is being used in the DB but it's not in the configuration", function() replace_conf_property("plugins_available", {"authentication"}) - spec_helper.prepare_db(true) + spec_helper.prepare_db() assert.has_error(function() spec_helper.start_kong(SERVER_CONF, true) end, "You are using a plugin that has not been enabled in the configuration: ratelimiting") @@ -90,7 +107,6 @@ describe("#server-cli", function() it("should work the used plugins are enabled", function() replace_conf_property("plugins_available", {"ratelimiting", "authentication"}) - spec_helper.prepare_db(true) local result, exit_code = spec_helper.start_kong(SERVER_CONF, true) assert.are.same(0, exit_code) end) diff --git a/spec/spec_helpers.lua b/spec/spec_helpers.lua index 76e967aced9..65ed7437178 100644 --- a/spec/spec_helpers.lua +++ b/spec/spec_helpers.lua @@ -1,3 +1,7 @@ +-- This file offers helpers for dao and integration tests (migrate, start kong, stop, faker...) +-- It is built so that it only needs to be required at the beginning of any spec file. +-- It supports other environments by passing a configuration file. + local utils = require "kong.tools.utils" local Faker = require "kong.tools.faker" local Migrations = require "kong.tools.migrations" @@ -5,26 +9,43 @@ local Migrations = require "kong.tools.migrations" -- Constants local KONG_BIN = "bin/kong" local TEST_CONF_FILE = "kong_TEST.yml" -local PROXY_URL = "http://localhost:8100" -local API_URL = "http://localhost:8101" - --- DB objects -local configuration, dao_factory = utils.load_configuration_and_dao(TEST_CONF_FILE) -local migrations = Migrations(dao_factory) -local faker = Faker(dao_factory) +local TEST_PROXY_URL = "http://localhost:8100" +local TEST_API_URL = "http://localhost:8101" local _M = {} _M.KONG_BIN = KONG_BIN -_M.CONF_FILE = TEST_CONF_FILE -_M.PROXY_URL = PROXY_URL -_M.API_URL = API_URL -_M.STUB_GET_URL = PROXY_URL.."/request" -_M.STUB_POST_URL = PROXY_URL.."/request" -_M.configuration = configuration -_M.dao_factory = dao_factory -_M.faker = faker +_M.PROXY_URL = TEST_PROXY_URL +_M.API_URL = TEST_API_URL +_M.STUB_GET_URL = TEST_PROXY_URL.."/request" +_M.STUB_POST_URL = TEST_PROXY_URL.."/request" +_M.envs = {} + +-- When dealing with another configuration file for a few tests, this allows to add +-- a factory/migrations/faker that are environment-specific to this new config. +function _M.add_env(conf_file) + local env_configuration, env_factory = utils.load_configuration_and_dao(conf_file) + _M.envs[conf_file] = { + configuration = env_configuration, + migrations = Migrations(env_factory), + faker = Faker(env_factory), + dao_factory = env_factory + } +end + +-- Retrieve environment-specific tools. If no conf_file passed, +-- default environment is TEST_CONF_FILE +function _M.get_env(conf_file) + return _M.envs[conf_file] and _M.envs[conf_file] or _M.envs[TEST_CONF_FILE] +end +function _M.remove_env(conf_file) + _M.envs[conf_file] = nil +end + +-- +-- OS and bin/kong helpers +-- function _M.os_execute(command) local n = os.tmpname() -- get a temporary file name to store output local exit_code = os.execute(command.." > "..n.." 2>&1") @@ -60,41 +81,52 @@ function _M.stop_kong(conf_file) os.execute("while [ `pgrep nginx | grep -c -v grep` -gt 0 ]; do sleep 1; done") end -function _M.prepare_db() +-- +-- DAO helpers +-- +function _M.prepare_db(conf_file) + local env = _M.get_env(conf_file) + -- 1. Migrate our keyspace - migrations:migrate(function(_, err) + env.migrations:migrate(function(_, err) if err then error(err) end end) -- 2. Prepare statements - local err = dao_factory:prepare() + local err = env.dao_factory:prepare() if err then error(err) end -- 3. Seed DB with our default data. This will throw any necessary error - faker:seed() + env.faker:seed() end function _M.drop_db() - local err = dao_factory:drop() + local env = _M.get_env(conf_file) + local err = env.dao_factory:drop() if err then error(err) end end function _M.seed_db(random_amount) - faker:seed(random_amount) + local env = _M.get_env(conf_file) + env.faker:seed(random_amount) end function _M.reset_db() - migrations:reset(function(_, err) + local env = _M.get_env(conf_file) + env.migrations:reset(function(_, err) if err then error(err) end end) end +-- Add the default env to our spec_helper +_M.add_env(TEST_CONF_FILE) + return _M diff --git a/spec/unit/base_controller_spec.lua b/spec/unit/base_controller_spec.lua index f53de3d36c4..559bfcd5bcf 100644 --- a/spec/unit/base_controller_spec.lua +++ b/spec/unit/base_controller_spec.lua @@ -1,20 +1,22 @@ local base_controller = require "kong.web.routes.base_controller" local spec_helper = require "spec.spec_helpers" +local env = spec_helper.get_env() + describe("Base Controller", function() it("should not parse params with empty values", function() - local result = base_controller.parse_params(spec_helper.dao_factory.accounts._schema, nil) + local result = base_controller.parse_params(env.dao_factory.accounts._schema, nil) assert.are.same({}, result) end) it("should not parse params with empty values", function() - local result = base_controller.parse_params(spec_helper.dao_factory.accounts._schema, {}) + local result = base_controller.parse_params(env.dao_factory.accounts._schema, {}) assert.are.same({}, result) end) it("should not parse params with invalid values", function() - local result = base_controller.parse_params(spec_helper.dao_factory.accounts._schema, {hello = true}) + local result = base_controller.parse_params(env.dao_factory.accounts._schema, {hello = true}) assert.are.same({}, result) end) @@ -29,37 +31,37 @@ describe("Base Controller", function() end) it("should not parse params with empty values", function() - local result = base_controller.parse_params(spec_helper.dao_factory.accounts._schema, {}) + local result = base_controller.parse_params(env.dao_factory.accounts._schema, {}) assert.are.same({}, result) end) it("should not parse params with invalid values", function() - local result = base_controller.parse_params(spec_helper.dao_factory.accounts._schema, {hello = true, wot = 123}) + local result = base_controller.parse_params(env.dao_factory.accounts._schema, {hello = true, wot = 123}) assert.are.same({}, result) end) it("should parse only existing params", function() - local result = base_controller.parse_params(spec_helper.dao_factory.accounts._schema, {hello = true, provider_id = 123}) + local result = base_controller.parse_params(env.dao_factory.accounts._schema, {hello = true, provider_id = 123}) assert.are.same({ provider_id = 123 }, result) end) it("should parse tables without invalid sub-schema values", function() - local result = base_controller.parse_params(spec_helper.dao_factory.plugins._schema, {name = "wot", ["value.authentication_type"] = "query" }) + local result = base_controller.parse_params(env.dao_factory.plugins._schema, {name = "wot", ["value.authentication_type"] = "query" }) assert.are.same({ name = "wot", value = {} }, result) - result = base_controller.parse_params(spec_helper.dao_factory.plugins._schema, {name = "authentication", wot = "query" }) + result = base_controller.parse_params(env.dao_factory.plugins._schema, {name = "authentication", wot = "query" }) assert.are.same({ name = "authentication", value = {} }, result) end) it("should parse tables with valid sub-schema values", function() - local result = base_controller.parse_params(spec_helper.dao_factory.plugins._schema, {name = "authentication", ["value.authentication_type"] = "query" }) + local result = base_controller.parse_params(env.dao_factory.plugins._schema, {name = "authentication", ["value.authentication_type"] = "query" }) assert.are.same({ name = "authentication", value = { @@ -68,13 +70,13 @@ describe("Base Controller", function() }, result) end) it("should not parse tables with invalid subschema prefix", function() - local result = base_controller.parse_params(spec_helper.dao_factory.plugins._schema, {name = "authentication", ["asd.authentication_type"] = "query" }) + local result = base_controller.parse_params(env.dao_factory.plugins._schema, {name = "authentication", ["asd.authentication_type"] = "query" }) assert.are.same({ name = "authentication", value = {} }, result) - result = base_controller.parse_params(spec_helper.dao_factory.plugins._schema, {name = "authentication", ["authentication_type"] = "query" }) + result = base_controller.parse_params(env.dao_factory.plugins._schema, {name = "authentication", ["authentication_type"] = "query" }) assert.are.same({ name = "authentication", value = {} @@ -82,7 +84,7 @@ describe("Base Controller", function() end) it("should parse tables with skippig invalid values", function() - local result = base_controller.parse_params(spec_helper.dao_factory.plugins._schema, {name = "authentication", ["value.authentication_type"] = "query", ["value.wot"] = "ciao" }) + local result = base_controller.parse_params(env.dao_factory.plugins._schema, {name = "authentication", ["value.authentication_type"] = "query", ["value.wot"] = "ciao" }) assert.are.same({ name = "authentication", value = { @@ -92,7 +94,7 @@ describe("Base Controller", function() end) it("should parse reversed-order tables with valid sub-schema values", function() - local result = base_controller.parse_params(spec_helper.dao_factory.plugins._schema, {["value.authentication_type"] = "query", name = "authentication" }) + local result = base_controller.parse_params(env.dao_factory.plugins._schema, {["value.authentication_type"] = "query", name = "authentication" }) assert.are.same({ name = "authentication", value = { @@ -102,7 +104,7 @@ describe("Base Controller", function() end) it("should parse arrays with a correct delimitator", function() - local result = base_controller.parse_params(spec_helper.dao_factory.plugins._schema, {["value.authentication_type"] = "query", name = "authentication", ["value.authentication_key_names"] = "wot,wat" }) + local result = base_controller.parse_params(env.dao_factory.plugins._schema, {["value.authentication_type"] = "query", name = "authentication", ["value.authentication_key_names"] = "wot,wat" }) assert.are.same({ name = "authentication", value = { @@ -113,7 +115,7 @@ describe("Base Controller", function() end) it("should parse arrays with a incorrect delimitator", function() - local result = base_controller.parse_params(spec_helper.dao_factory.plugins._schema, {["value.authentication_type"] = "query", name = "authentication", ["value.authentication_key_names"] = "wot;wat" }) + local result = base_controller.parse_params(env.dao_factory.plugins._schema, {["value.authentication_type"] = "query", name = "authentication", ["value.authentication_key_names"] = "wot;wat" }) assert.are.same({ name = "authentication", value = { @@ -123,4 +125,4 @@ describe("Base Controller", function() }, result) end) -end) \ No newline at end of file +end) diff --git a/spec/unit/dao/cassandra_spec.lua b/spec/unit/dao/cassandra_spec.lua index 05045abe066..b6bc62b2dad 100644 --- a/spec/unit/dao/cassandra_spec.lua +++ b/spec/unit/dao/cassandra_spec.lua @@ -11,9 +11,10 @@ local uuid = require "uuid" -- Raw session for double-check purposes local session -- Load everything we need from the spec_helper -local faker = spec_helper.faker -local dao_factory = spec_helper.dao_factory -local configuration = spec_helper.configuration +local env = spec_helper.get_env() +local faker = env.faker +local dao_factory = env.dao_factory +local configuration = env.configuration configuration.cassandra = configuration.databases_available[configuration.database].properties -- An utility function to apply tests on each collection diff --git a/spec/unit/migrations_spec.lua b/spec/unit/migrations_spec.lua index 4414610fc85..b7cda7e3a73 100644 --- a/spec/unit/migrations_spec.lua +++ b/spec/unit/migrations_spec.lua @@ -5,16 +5,17 @@ local path = require("path").new("/") describe("Migrations #tools", function() + local env = spec_helper.get_env() local migrations before_each(function() - migrations = Migrations(spec_helper.dao_factory) + migrations = Migrations(env.dao_factory) end) describe("#create()", function() it("should create an empty migration interface for each available dao", function() - local n_databases_available = utils.table_size(spec_helper.configuration.databases_available) + local n_databases_available = utils.table_size(env.configuration.databases_available) local s_cb = spy.new(function(interface, f_path, f_name, dao_type) assert.are.same("string", type(interface)) @@ -27,14 +28,14 @@ describe("Migrations #tools", function() assert.are.same(f_name, mig_module.name) end) - migrations.create(spec_helper.configuration, "test_migration", s_cb) + migrations.create(env.configuration, "test_migration", s_cb) assert.spy(s_cb).was.called(n_databases_available) end) end) - for db_type, v in pairs(spec_helper.configuration.databases_available) do + for db_type, v in pairs(env.configuration.databases_available) do local migrations_names = {} -- used to mock dao's get_migrations for already executed migrations local migrations_path = path:join("./database/migrations", db_type) @@ -62,9 +63,9 @@ describe("Migrations #tools", function() end) before_each(function() - stub(spec_helper.dao_factory, "execute_queries") - stub(spec_helper.dao_factory, "delete_migration") - stub(spec_helper.dao_factory, "add_migration") + stub(env.dao_factory, "execute_queries") + stub(env.dao_factory, "delete_migration") + stub(env.dao_factory, "add_migration") end) it("first migration should have an init boolean property", function() @@ -76,7 +77,7 @@ describe("Migrations #tools", function() describe(db_type.." #migrate()", function() it("1st run should execute all created migrations in order for a given dao", function() - spec_helper.dao_factory.get_migrations = spy.new(function() return nil end) + env.dao_factory.get_migrations = spy.new(function() return nil end) local i = 0 migrations:migrate(function(migration, err) @@ -89,15 +90,15 @@ describe("Migrations #tools", function() assert.are.same(#migrations_names, i) -- all migrations should be recorded in db - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was.called(#migrations_names) - assert.spy(spec_helper.dao_factory.add_migration).was.called(#migrations_names) + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was.called(#migrations_names) + assert.spy(env.dao_factory.add_migration).was.called(#migrations_names) end) describe("Partly already migrated", function() it("if running with some migrations pending, it should only execute the non-recorded ones", function() - spec_helper.dao_factory.get_migrations = spy.new(function() return {migrations_names[1]} end) + env.dao_factory.get_migrations = spy.new(function() return {migrations_names[1]} end) local i = 0 migrations:migrate(function(migration, err) @@ -108,9 +109,9 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was.called(1) - assert.spy(spec_helper.dao_factory.add_migration).was.called(1) + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was.called(1) + assert.spy(env.dao_factory.add_migration).was.called(1) end) end) @@ -119,7 +120,7 @@ describe("Migrations #tools", function() describe("Already migrated", function() it("if running again, should detect if migrations are already up to date", function() - spec_helper.dao_factory.get_migrations = spy.new(function() return migrations_names end) + env.dao_factory.get_migrations = spy.new(function() return migrations_names end) local i = 0 migrations:migrate(function(migration, err) @@ -129,14 +130,14 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was_not_called() - assert.spy(spec_helper.dao_factory.add_migration).was_not_called() + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was_not_called() + assert.spy(env.dao_factory.add_migration).was_not_called() end) end) it("should report get_migrations errors", function() - spec_helper.dao_factory.get_migrations = spy.new(function() + env.dao_factory.get_migrations = spy.new(function() return nil, "get err" end) local i = 0 @@ -148,14 +149,14 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was_not_called() - assert.spy(spec_helper.dao_factory.add_migration).was_not_called() + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was_not_called() + assert.spy(env.dao_factory.add_migration).was_not_called() end) it("should report execute_queries errors", function() - spec_helper.dao_factory.get_migrations = spy.new(function() return {} end) - spec_helper.dao_factory.execute_queries = spy.new(function() + env.dao_factory.get_migrations = spy.new(function() return {} end) + env.dao_factory.execute_queries = spy.new(function() return "execute error" end) local i = 0 @@ -167,14 +168,14 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was.called(1) - assert.spy(spec_helper.dao_factory.add_migration).was_not_called() + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was.called(1) + assert.spy(env.dao_factory.add_migration).was_not_called() end) it("should report add_migrations errors", function() - spec_helper.dao_factory.get_migrations = spy.new(function() return {} end) - spec_helper.dao_factory.add_migration = spy.new(function() + env.dao_factory.get_migrations = spy.new(function() return {} end) + env.dao_factory.add_migration = spy.new(function() return nil, "add error" end) local i = 0 @@ -186,9 +187,9 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was.called(1) - assert.spy(spec_helper.dao_factory.add_migration).was.called(1) + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was.called(1) + assert.spy(env.dao_factory.add_migration).was.called(1) end) describe(db_type.." #rollback()", function() @@ -204,7 +205,7 @@ describe("Migrations #tools", function() describe("rollback latest migration", function() it("should only rollback the latest executed migration", function() - spec_helper.dao_factory.get_migrations = spy.new(function() return old_migrations end) + env.dao_factory.get_migrations = spy.new(function() return old_migrations end) local i = 0 migrations:rollback(function(migration, err) @@ -215,15 +216,15 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was.called(1) - assert.spy(spec_helper.dao_factory.delete_migration).was.called(1) + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was.called(1) + assert.spy(env.dao_factory.delete_migration).was.called(1) end) end) it("should not call delete_migration if init migration is rollbacked", function() - spec_helper.dao_factory.get_migrations = spy.new(function() return {old_migrations[1]} end) + env.dao_factory.get_migrations = spy.new(function() return {old_migrations[1]} end) local i = 0 migrations:rollback(function(migration, err) @@ -234,13 +235,13 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was.called(1) - assert.spy(spec_helper.dao_factory.delete_migration).was_not_called() + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was.called(1) + assert.spy(env.dao_factory.delete_migration).was_not_called() end) it("should report get_migrations errors", function() - spec_helper.dao_factory.get_migrations = spy.new(function() + env.dao_factory.get_migrations = spy.new(function() return nil, "get err" end) local i = 0 @@ -252,14 +253,14 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was_not_called() - assert.spy(spec_helper.dao_factory.delete_migration).was_not_called() + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was_not_called() + assert.spy(env.dao_factory.delete_migration).was_not_called() end) it("should report execute_queries errors", function() - spec_helper.dao_factory.get_migrations = spy.new(function() return old_migrations end) - spec_helper.dao_factory.execute_queries = spy.new(function() + env.dao_factory.get_migrations = spy.new(function() return old_migrations end) + env.dao_factory.execute_queries = spy.new(function() return "execute error" end) local i = 0 @@ -271,14 +272,14 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was.called(1) - assert.spy(spec_helper.dao_factory.delete_migration).was_not_called() + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was.called(1) + assert.spy(env.dao_factory.delete_migration).was_not_called() end) it("should report delete_migrations errors", function() - spec_helper.dao_factory.get_migrations = spy.new(function() return old_migrations end) - spec_helper.dao_factory.delete_migration = spy.new(function() + env.dao_factory.get_migrations = spy.new(function() return old_migrations end) + env.dao_factory.delete_migration = spy.new(function() return nil, "delete error" end) local i = 0 @@ -290,9 +291,9 @@ describe("Migrations #tools", function() end) assert.are.same(1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(1) - assert.spy(spec_helper.dao_factory.execute_queries).was.called(1) - assert.spy(spec_helper.dao_factory.delete_migration).was.called(1) + assert.spy(env.dao_factory.get_migrations).was.called(1) + assert.spy(env.dao_factory.execute_queries).was.called(1) + assert.spy(env.dao_factory.delete_migration).was.called(1) end) end) @@ -310,7 +311,7 @@ describe("Migrations #tools", function() it("should rollback all migrations at once", function() local i = 0 local expected_rollbacks = #old_migrations - spec_helper.dao_factory.get_migrations = spy.new(function() + env.dao_factory.get_migrations = spy.new(function() return old_migrations end) migrations:reset(function(migration, err) @@ -327,9 +328,9 @@ describe("Migrations #tools", function() end) assert.are.same(expected_rollbacks + 1, i) - assert.spy(spec_helper.dao_factory.get_migrations).was.called(expected_rollbacks + 1) -- becaue also run one last time to check if any more migrations - assert.spy(spec_helper.dao_factory.execute_queries).was.called(expected_rollbacks) - assert.spy(spec_helper.dao_factory.delete_migration).was.called(expected_rollbacks - 1) -- because doesn't run for ini migration + assert.spy(env.dao_factory.get_migrations).was.called(expected_rollbacks + 1) -- becaue also run one last time to check if any more migrations + assert.spy(env.dao_factory.execute_queries).was.called(expected_rollbacks) + assert.spy(env.dao_factory.delete_migration).was.called(expected_rollbacks - 1) -- because doesn't run for ini migration end) end) diff --git a/src/kong/constants.lua b/src/constants.lua similarity index 100% rename from src/kong/constants.lua rename to src/constants.lua diff --git a/src/kong/dao/cassandra/accounts.lua b/src/dao/cassandra/accounts.lua similarity index 100% rename from src/kong/dao/cassandra/accounts.lua rename to src/dao/cassandra/accounts.lua diff --git a/src/kong/dao/cassandra/apis.lua b/src/dao/cassandra/apis.lua similarity index 100% rename from src/kong/dao/cassandra/apis.lua rename to src/dao/cassandra/apis.lua diff --git a/src/kong/dao/cassandra/applications.lua b/src/dao/cassandra/applications.lua similarity index 100% rename from src/kong/dao/cassandra/applications.lua rename to src/dao/cassandra/applications.lua diff --git a/src/kong/dao/cassandra/base_dao.lua b/src/dao/cassandra/base_dao.lua similarity index 100% rename from src/kong/dao/cassandra/base_dao.lua rename to src/dao/cassandra/base_dao.lua diff --git a/src/kong/dao/cassandra/factory.lua b/src/dao/cassandra/factory.lua similarity index 100% rename from src/kong/dao/cassandra/factory.lua rename to src/dao/cassandra/factory.lua diff --git a/src/kong/dao/cassandra/metrics.lua b/src/dao/cassandra/metrics.lua similarity index 100% rename from src/kong/dao/cassandra/metrics.lua rename to src/dao/cassandra/metrics.lua diff --git a/src/kong/dao/cassandra/plugins.lua b/src/dao/cassandra/plugins.lua similarity index 100% rename from src/kong/dao/cassandra/plugins.lua rename to src/dao/cassandra/plugins.lua diff --git a/src/kong/dao/error.lua b/src/dao/error.lua similarity index 100% rename from src/kong/dao/error.lua rename to src/dao/error.lua diff --git a/src/kong/dao/schemas.lua b/src/dao/schemas.lua similarity index 100% rename from src/kong/dao/schemas.lua rename to src/dao/schemas.lua diff --git a/src/main.lua b/src/kong.lua similarity index 81% rename from src/main.lua rename to src/kong.lua index 1935fb81220..683e55777ed 100644 --- a/src/main.lua +++ b/src/kong.lua @@ -50,7 +50,7 @@ local function load_plugin_conf(api_id, application_id, plugin_name) if #rows > 0 then return table.remove(rows, 1) else - return {null=true} + return { null = true } end end) @@ -71,7 +71,7 @@ local function init_plugins() end -- Checking that the plugins in the DB are also enabled - for _,v in ipairs(db_plugins) do + for _, v in ipairs(db_plugins) do if not utils.array_contains(plugins_available, v) then error("You are using a plugin that has not been enabled in the configuration: "..v) end @@ -101,11 +101,12 @@ local function init_plugins() local result = {} - -- Now construct the final ordered plugin list, core is always the first plugin + -- Now construct the final ordered plugin list + -- resolver is always the first plugin as it is the one retrieving any needed information table.insert(result, { - core = true, - name = "core", - handler = require("kong.core.handler")() + resolver = true, + name = "resolver", + handler = require("kong.resolver.handler")() }) -- Add the plugins in a sorted order @@ -120,6 +121,19 @@ local function init_plugins() return result end +-- To be called by nginx's init_by_lua directive. +-- Execution: +-- - load the configuration +-- - instanciate the DAO +-- - if the keyspace is empty run the migrations +-- - prepare the statements +-- - load the used plugins +-- - load all plugins if used and installed +-- - load the resolver +-- - sort the plugins by priority +-- +-- If any error during the initialization of the DAO or plugins, it will be thrown and needs to be catched in init_by_lua. +-- @return nil function _M.init() -- Loading configuration configuration, dao = utils.load_configuration_and_dao(os.getenv("KONG_CONF")) @@ -142,14 +156,16 @@ function _M.init() -- Initializing DAO local err = dao:prepare() if err then - error("Cannot prepare statements: "..err) + error("cannot prepare statements: "..err) end -- Initializing plugins plugins = init_plugins() end -function _M.access() +-- Calls plugins_access() on every loaded plugin +-- @return nil +function _M.exec_plugins_access() -- Setting a property that will be available for every plugin ngx.ctx.start = ngx.now() ngx.ctx.plugin_conf = {} @@ -168,7 +184,7 @@ function _M.access() end local conf = ngx.ctx.plugin_conf[plugin.name] - if not ngx.ctx.error and (plugin.core or conf) then + if not ngx.ctx.error and (plugin.resolver or conf) then plugin.handler:access(conf and conf.value or nil) end end @@ -176,7 +192,9 @@ function _M.access() ngx.ctx.proxy_start = ngx.now() -- Setting a property that will be available for every plugin end -function _M.header_filter() +-- Calls header_filter() on every loaded plugin +-- @return nil +function _M.exec_plugins_header_filter() ngx.ctx.proxy_end = ngx.now() -- Setting a property that will be available for every plugin if not ngx.ctx.error then @@ -189,7 +207,9 @@ function _M.header_filter() end end -function _M.body_filter() +-- Calls body_filter() on every loaded plugin +-- @return nil +function _M.exec_plugins_body_filter() if not ngx.ctx.error then for _, plugin in ipairs(plugins) do local conf = ngx.ctx.plugin_conf[plugin.name] @@ -200,7 +220,9 @@ function _M.body_filter() end end -function _M.log() +-- Calls log() on every loaded plugin +-- @return nil +function _M.exec_plugins_log() if not ngx.ctx.error then local now = ngx.now() diff --git a/src/kong/plugins/authentication/access.lua b/src/plugins/authentication/access.lua similarity index 100% rename from src/kong/plugins/authentication/access.lua rename to src/plugins/authentication/access.lua diff --git a/src/kong/plugins/authentication/handler.lua b/src/plugins/authentication/handler.lua similarity index 88% rename from src/kong/plugins/authentication/handler.lua rename to src/plugins/authentication/handler.lua index cc7184a12af..12e0a8f5e4d 100644 --- a/src/kong/plugins/authentication/handler.lua +++ b/src/plugins/authentication/handler.lua @@ -1,6 +1,6 @@ -- Copyright (C) Mashape, Inc. -local BasePlugin = require "kong.base_plugin" +local BasePlugin = require "kong.plugins.base_plugin" local access = require "kong.plugins.authentication.access" local AuthenticationHandler = BasePlugin:extend() diff --git a/src/kong/plugins/authentication/schema.lua b/src/plugins/authentication/schema.lua similarity index 100% rename from src/kong/plugins/authentication/schema.lua rename to src/plugins/authentication/schema.lua diff --git a/src/kong/base_plugin.lua b/src/plugins/base_plugin.lua similarity index 100% rename from src/kong/base_plugin.lua rename to src/plugins/base_plugin.lua diff --git a/src/kong/plugins/networklog/handler.lua b/src/plugins/networklog/handler.lua similarity index 86% rename from src/kong/plugins/networklog/handler.lua rename to src/plugins/networklog/handler.lua index 14eb63af4f8..dce96e004a7 100644 --- a/src/kong/plugins/networklog/handler.lua +++ b/src/plugins/networklog/handler.lua @@ -1,6 +1,6 @@ -- Copyright (C) Mashape, Inc. -local BasePlugin = require "kong.base_plugin" +local BasePlugin = require "kong.plugins.base_plugin" local log = require "kong.plugins.networklog.log" local NetworkLogHandler = BasePlugin:extend() diff --git a/src/kong/plugins/networklog/log.lua b/src/plugins/networklog/log.lua similarity index 100% rename from src/kong/plugins/networklog/log.lua rename to src/plugins/networklog/log.lua diff --git a/src/kong/plugins/networklog/schema.lua b/src/plugins/networklog/schema.lua similarity index 100% rename from src/kong/plugins/networklog/schema.lua rename to src/plugins/networklog/schema.lua diff --git a/src/kong/plugins/ratelimiting/access.lua b/src/plugins/ratelimiting/access.lua similarity index 100% rename from src/kong/plugins/ratelimiting/access.lua rename to src/plugins/ratelimiting/access.lua diff --git a/src/kong/plugins/ratelimiting/handler.lua b/src/plugins/ratelimiting/handler.lua similarity index 88% rename from src/kong/plugins/ratelimiting/handler.lua rename to src/plugins/ratelimiting/handler.lua index 3f46b2c0bb7..82b0e24f8c4 100644 --- a/src/kong/plugins/ratelimiting/handler.lua +++ b/src/plugins/ratelimiting/handler.lua @@ -1,6 +1,6 @@ -- Copyright (C) Mashape, Inc. -local BasePlugin = require "kong.base_plugin" +local BasePlugin = require "kong.plugins.base_plugin" local access = require "kong.plugins.ratelimiting.access" local RateLimitingHandler = BasePlugin:extend() diff --git a/src/kong/plugins/ratelimiting/schema.lua b/src/plugins/ratelimiting/schema.lua similarity index 100% rename from src/kong/plugins/ratelimiting/schema.lua rename to src/plugins/ratelimiting/schema.lua diff --git a/src/kong/core/access.lua b/src/resolver/access.lua similarity index 100% rename from src/kong/core/access.lua rename to src/resolver/access.lua diff --git a/src/kong/core/handler.lua b/src/resolver/handler.lua similarity index 58% rename from src/kong/core/handler.lua rename to src/resolver/handler.lua index 526ebe18c9b..36eef73db14 100644 --- a/src/kong/core/handler.lua +++ b/src/resolver/handler.lua @@ -1,13 +1,11 @@ --- Copyright (C) Mashape, Inc. - -local access = require "kong.core.access" -local header_filter = require "kong.core.header_filter" -local BasePlugin = require "kong.base_plugin" +local access = require "kong.resolver.access" +local header_filter = require "kong.resolver.header_filter" +local BasePlugin = require "kong.plugins.base_plugin" local CoreHandler = BasePlugin:extend() function CoreHandler:new() - CoreHandler.super.new(self, "core") + CoreHandler.super.new(self, "resolver") end function CoreHandler:access(conf) diff --git a/src/kong/core/header_filter.lua b/src/resolver/header_filter.lua similarity index 100% rename from src/kong/core/header_filter.lua rename to src/resolver/header_filter.lua diff --git a/src/kong/tools/cache.lua b/src/tools/cache.lua similarity index 100% rename from src/kong/tools/cache.lua rename to src/tools/cache.lua diff --git a/src/kong/tools/faker.lua b/src/tools/faker.lua similarity index 100% rename from src/kong/tools/faker.lua rename to src/tools/faker.lua diff --git a/src/kong/tools/http_client.lua b/src/tools/http_client.lua similarity index 100% rename from src/kong/tools/http_client.lua rename to src/tools/http_client.lua diff --git a/src/kong/tools/migrations.lua b/src/tools/migrations.lua similarity index 100% rename from src/kong/tools/migrations.lua rename to src/tools/migrations.lua diff --git a/src/kong/tools/timestamp.lua b/src/tools/timestamp.lua similarity index 100% rename from src/kong/tools/timestamp.lua rename to src/tools/timestamp.lua diff --git a/src/kong/tools/utils.lua b/src/tools/utils.lua similarity index 100% rename from src/kong/tools/utils.lua rename to src/tools/utils.lua diff --git a/src/kong/web/admin/index.html b/src/web/admin/index.html similarity index 100% rename from src/kong/web/admin/index.html rename to src/web/admin/index.html diff --git a/src/kong/web/app.lua b/src/web/app.lua similarity index 100% rename from src/kong/web/app.lua rename to src/web/app.lua diff --git a/src/kong/web/routes/accounts.lua b/src/web/routes/accounts.lua similarity index 100% rename from src/kong/web/routes/accounts.lua rename to src/web/routes/accounts.lua diff --git a/src/kong/web/routes/apis.lua b/src/web/routes/apis.lua similarity index 100% rename from src/kong/web/routes/apis.lua rename to src/web/routes/apis.lua diff --git a/src/kong/web/routes/applications.lua b/src/web/routes/applications.lua similarity index 100% rename from src/kong/web/routes/applications.lua rename to src/web/routes/applications.lua diff --git a/src/kong/web/routes/base_controller.lua b/src/web/routes/base_controller.lua similarity index 100% rename from src/kong/web/routes/base_controller.lua rename to src/web/routes/base_controller.lua diff --git a/src/kong/web/routes/plugins.lua b/src/web/routes/plugins.lua similarity index 100% rename from src/kong/web/routes/plugins.lua rename to src/web/routes/plugins.lua diff --git a/src/kong/web/static/favicon.ico b/src/web/static/favicon.ico similarity index 100% rename from src/kong/web/static/favicon.ico rename to src/web/static/favicon.ico