Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router) new API router with multiple hosts/paths and HTTP methods support #1970

Merged
merged 39 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ded0eb8
feat(router) new routing module
thibaultcha Nov 3, 2016
5307730
feat(schemas) update APIs schema to support hosts/uris/methods
thibaultcha Nov 18, 2016
0c3878d
tests(router) convert Admin API tests to new APIs schemas
thibaultcha Nov 21, 2016
9b9ed4c
feat(router) add postgres migrations for new router
thibaultcha Nov 21, 2016
2ad86c2
chore(router) add new router to rockspec
thibaultcha Nov 21, 2016
1acdd4b
fix(router) correctly set grab_headers + don't caetgorize if array is
thibaultcha Nov 22, 2016
5d03eac
tests(router) add a test for 'exec()' return values
thibaultcha Nov 22, 2016
5ccf4f3
feat(router) integrate new router into Kong runtime
thibaultcha Nov 22, 2016
d82f08a
fix(migrations) add safeguards to router migrations
thibaultcha Nov 22, 2016
8a1141c
feat(router) debug_kong req header + more tests for catch-all root URI
thibaultcha Nov 22, 2016
e1f85ab
feat(router) rename strip_request_path, update DAO/Admin API tests
thibaultcha Nov 28, 2016
33e5df1
fix(router) sort uris-routed APIs by URI length
thibaultcha Nov 28, 2016
1f58f6a
feat(router) check APIs required properties in self_check
thibaultcha Nov 28, 2016
cee77ea
tests(integration) initial router tests + remove old "resolver" tests
thibaultcha Nov 29, 2016
ef1c280
fix(tests) provide a name for a router test (CI busted is crashing on
thibaultcha Nov 29, 2016
99bb0d2
tests(dao) fix DAO schema test due to new router
thibaultcha Dec 1, 2016
5d9b4f7
fix(router) strip URI when plain match occur
thibaultcha Dec 1, 2016
8281775
tests(router) invalidation and upstream_url parsing tests
thibaultcha Dec 1, 2016
383f5d1
refactor(router) re-work router to be easier to maintain
thibaultcha Dec 2, 2016
9b673ba
feat(router) implement an LRU cache
thibaultcha Dec 2, 2016
8b829fd
optimize(router) scoping, tweaks and comments
thibaultcha Dec 2, 2016
b8042fa
tests(router) fixes and tweaks
thibaultcha Dec 3, 2016
9b84644
tests(plugins) convert plugins test to the new router
thibaultcha Dec 3, 2016
9a14c12
fix(tests) run migrations from spec helpers
thibaultcha Dec 5, 2016
ea084ad
feat(ssl) move SSL certificates and SNIs in core
thibaultcha Dec 20, 2016
a79865b
feat(ssl) implement https_only and accept_if_terminated properties on
thibaultcha Dec 21, 2016
80452bd
chore: remove old SSL plugin, lrucache and add missing modules to roc…
thibaultcha Dec 21, 2016
9e7a9f2
feat(ssl) use a key from database_cahce (sigh)
thibaultcha Dec 21, 2016
7042292
chore: remove old resolver code and tests
thibaultcha Dec 21, 2016
5351d5c
fix: remove ssl plugin from plugins list
thibaultcha Dec 21, 2016
ecd7621
tests(hooks) fixing hooks tests
subnetmarco Dec 23, 2016
a349fdf
feat(proxy) support for websockets
subnetmarco Nov 17, 2016
8e961d6
fix(oauth2) ownership check
subnetmarco Dec 28, 2016
2f87c3c
feat(core) upstreams (#1735)
Tieske Dec 28, 2016
b9fcd44
more fixes
subnetmarco Jan 3, 2017
3365b90
fixes #1944
Tieske Jan 6, 2017
9e1c27c
tests(proxy) fix entities being inserted withotu trigerring cache
thibaultcha Jan 11, 2017
73bfaf1
feat(router) create router in init phase for early error detection
thibaultcha Jan 11, 2017
b2db9e8
tests(router) some fixes due to bad merging/rebasing
thibaultcha Jan 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions .ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ set -e
export BUSTED_ARGS="-o gtest -v --exclude-tags=ci"
export TEST_CMD="KONG_SERF_PATH=$SERF_PATH bin/busted $BUSTED_ARGS"

createuser --createdb kong
createdb -U kong kong_tests

if [ "$TEST_SUITE" == "lint" ]; then
make lint
make lint
elif [ "$TEST_SUITE" == "unit" ]; then
make test
else
createuser --createdb kong
createdb -U kong kong_tests

if [ "$TEST_SUITE" == "integration" ]; then
make test
elif [ "$TEST_SUITE" == "integration" ]; then
make test-integration
elif [ "$TEST_SUITE" == "plugins" ]; then
elif [ "$TEST_SUITE" == "plugins" ]; then
make test-plugins
fi
fi
10 changes: 5 additions & 5 deletions kong-0.9.7-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ build = {
["kong.api.routes.cache"] = "kong/api/routes/cache.lua",
["kong.api.routes.cluster"] = "kong/api/routes/cluster.lua",
["kong.api.routes.upstreams"] = "kong/api/routes/upstreams.lua",
["kong.api.routes.certificates"] = "kong/api/routes/certificates.lua",
["kong.api.routes.snis"] = "kong/api/routes/snis.lua",

["kong.tools.dns"] = "kong/tools/dns.lua",
["kong.tools.utils"] = "kong/tools/utils.lua",
Expand All @@ -86,7 +88,7 @@ build = {

["kong.core.handler"] = "kong/core/handler.lua",
["kong.core.certificate"] = "kong/core/certificate.lua",
["kong.core.resolver"] = "kong/core/resolver.lua",
["kong.core.router"] = "kong/core/router.lua",
["kong.core.plugins_iterator"] = "kong/core/plugins_iterator.lua",
["kong.core.hooks"] = "kong/core/hooks.lua",
["kong.core.reports"] = "kong/core/reports.lua",
Expand All @@ -104,6 +106,8 @@ build = {
["kong.dao.schemas.plugins"] = "kong/dao/schemas/plugins.lua",
["kong.dao.schemas.upstreams"] = "kong/dao/schemas/upstreams.lua",
["kong.dao.schemas.targets"] = "kong/dao/schemas/targets.lua",
["kong.dao.schemas.ssl_certificates"] = "kong/dao/schemas/ssl_certificates.lua",
["kong.dao.schemas.ssl_servers_names"] = "kong/dao/schemas/ssl_servers_names.lua",
["kong.dao.db"] = "kong/dao/db/init.lua",
["kong.dao.db.cassandra"] = "kong/dao/db/cassandra.lua",
["kong.dao.db.postgres"] = "kong/dao/db/postgres.lua",
Expand Down Expand Up @@ -204,10 +208,6 @@ build = {
["kong.plugins.cors.handler"] = "kong/plugins/cors/handler.lua",
["kong.plugins.cors.schema"] = "kong/plugins/cors/schema.lua",

["kong.plugins.ssl.handler"] = "kong/plugins/ssl/handler.lua",
["kong.plugins.ssl.hooks"] = "kong/plugins/ssl/hooks.lua",
["kong.plugins.ssl.schema"] = "kong/plugins/ssl/schema.lua",

["kong.plugins.ip-restriction.handler"] = "kong/plugins/ip-restriction/handler.lua",
["kong.plugins.ip-restriction.schema"] = "kong/plugins/ip-restriction/schema.lua",
["kong.plugins.ip-restriction.migrations.cassandra"] = "kong/plugins/ip-restriction/migrations/cassandra.lua",
Expand Down
5 changes: 3 additions & 2 deletions kong/api/crud_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ function _M.paginated_set(self, dao_collection)
end

return responses.send_HTTP_OK {
-- can't use empty_array_mt here since apparently metatables are removed
-- before JSON encoding.
-- FIXME: remove and stick to previous `empty_array_mt` metatable
-- assignment once https://github.com/openresty/lua-cjson/pull/16
-- is included in the OpenResty release we use.
data = #rows > 0 and rows or cjson.empty_array,
total = total_count,
offset = offset,
Expand Down
2 changes: 1 addition & 1 deletion kong/api/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ end
ngx.log(ngx.DEBUG, "Loading Admin API endpoints")

-- Load core routes
for _, v in ipairs({"kong", "apis", "consumers", "plugins", "cache", "cluster", "upstreams" }) do
for _, v in ipairs({"kong", "apis", "consumers", "plugins", "cache", "cluster", "certificates", "snis", "upstreams"}) do
local routes = require("kong.api.routes."..v)
attach_routes(insert_405(routes))
end
Expand Down
2 changes: 1 addition & 1 deletion kong/api/routes/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ return {
GET = function(self, dao_factory)
if self.params.key then
local cached_item = caches[self.params.cache]("get", self.params.key)
if cached_item then
if cached_item ~= nil then
return responses.send_HTTP_OK(cached_item)
end
end
Expand Down
159 changes: 159 additions & 0 deletions kong/api/routes/certificates.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
local crud = require "kong.api.crud_helpers"
local utils = require "kong.tools.utils"
local cjson = require "cjson"


return {
["/certificates/"] = {
POST = function(self, dao_factory, helpers)
local snis
if type(self.params.snis) == "string" then
snis = utils.split(self.params.snis, ",")
self.params.snis = nil
end

local ssl_cert, err = dao_factory.ssl_certificates:insert(self.params)
if err then
return helpers.yield_error(err)
end

-- insert SNIs if given

if type(snis) == "table" then
ssl_cert.snis = {}

for i = 1, #snis do
local ssl_server_name = {
name = snis[i],
ssl_certificate_id = ssl_cert.id,
}

local row, err = dao_factory.ssl_servers_names:insert(ssl_server_name)
if err then
return helpers.yield_error(err)
end

table.insert(ssl_cert.snis, row.name)
end
end

return helpers.responses.send_HTTP_CREATED(ssl_cert)
end,


GET = function(self, dao_factory, helpers)
local ssl_certificates, err = dao_factory.ssl_certificates:find_all()
if err then
return helpers.yield_error(err)
end

for i = 1, #ssl_certificates do
local rows, err = dao_factory.ssl_servers_names:find_all {
ssl_certificate_id = ssl_certificates[i].id
}
if err then
return helpers.yield_error(err)
end

ssl_certificates[i].snis = setmetatable({}, cjson.empty_array_mt)

for j = 1, #rows do
table.insert(ssl_certificates[i].snis, rows[j].name)
end

-- FIXME: remove and stick to previous `empty_array_mt` metatable
-- assignment once https://github.com/openresty/lua-cjson/pull/16
-- is included in the OpenResty release we use.
if #ssl_certificates[i].snis == 0 then
ssl_certificates[i].snis = cjson.empty_array
end
end

return helpers.responses.send_HTTP_OK(ssl_certificates)
end,


PUT = function(self, dao_factory, helpers)
return crud.put(self.params, dao_factory.ssl_certificates)
end,
},


["/certificates/:sni_or_uuid"] = {
before = function(self, dao_factory, helpers)
if utils.is_valid_uuid(self.params.sni_or_uuid) then
self.ssl_certificate_id = self.params.sni_or_uuid

else
-- get requested SNI

local row, err = dao_factory.ssl_servers_names:find {
name = self.params.sni_or_uuid
}
if err then
return helpers.yield_error(err)
end

if not row then
return helpers.responses.send_HTTP_NOT_FOUND()
end

-- cache certificate row id

self.ssl_certificate_id = row.ssl_certificate_id
end

self.params.sni_or_uuid = nil
end,


GET = function(self, dao_factory, helpers)
local row, err = dao_factory.ssl_certificates:find {
id = self.ssl_certificate_id
}
if err then
return helpers.yield_error(err)
end

assert(row, "no SSL certificate for given SNI")

-- add list of other SNIs for this certificate

row.snis = setmetatable({}, cjson.empty_array_mt)

local rows, err = dao_factory.ssl_servers_names:find_all {
ssl_certificate_id = self.ssl_certificate_id
}
if err then
return helpers.yield_error(err)
end

for i = 1, #rows do
table.insert(row.snis, rows[i].name)
end

-- FIXME: remove and stick to previous `empty_array_mt` metatable
-- assignment once https://github.com/openresty/lua-cjson/pull/16
-- is included in the OpenResty release we use.
if #row.snis == 0 then
row.snis = cjson.empty_array
end

return helpers.responses.send_HTTP_OK(row)
end,


PATCH = function(self, dao_factory, helpers)
return crud.patch(self.params, dao_factory.ssl_certificates, {
id = self.ssl_certificate_id
})
end,


DELETE = function(self, dao_factory, helpers)
return crud.delete({
id = self.ssl_certificate_id
}, dao_factory.ssl_certificates)
end,
}
}
53 changes: 53 additions & 0 deletions kong/api/routes/snis.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
local crud = require "kong.api.crud_helpers"


return {
["/snis/"] = {
GET = function(self, dao_factory)
crud.paginated_set(self, dao_factory.ssl_servers_names)
end,


PUT = function(self, dao_factory)
crud.put(self.params, dao_factory.ssl_servers_names)
end,


POST = function(self, dao_factory)
crud.post(self.params, dao_factory.ssl_servers_names)
end,
},


["/snis/:name"] = {
before = function(self, dao_factory, helpers)
local row, err = dao_factory.ssl_servers_names:find {
name = self.params.name
}
if err then
return helpers.yield_error(err)
end

if not row then
return helpers.responses.send_HTTP_NOT_FOUND()
end

self.sni = row
end,


GET = function(self, dao_factory, helpers)
return helpers.responses.send_HTTP_OK(self.sni)
end,


PATCH = function(self, dao_factory)
crud.patch(self.params, dao_factory.ssl_servers_names, self.sni)
end,


DELETE = function(self, dao_factory)
crud.delete(self.sni, dao_factory.ssl_servers_names)
end,
}
}
4 changes: 2 additions & 2 deletions kong/constants.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local plugins = {
"ssl", "jwt", "acl", "correlation-id", "cors", "oauth2", "tcp-log", "udp-log",
"jwt", "acl", "correlation-id", "cors", "oauth2", "tcp-log", "udp-log",
"file-log", "http-log", "key-auth", "hmac-auth", "basic-auth", "ip-restriction",
"galileo", "request-transformer", "response-transformer",
"request-size-limiting", "rate-limiting", "response-ratelimiting", "syslog",
Expand Down Expand Up @@ -47,4 +47,4 @@ return {
CACHE = {
CLUSTER = "cluster"
}
}
}
Loading