Skip to content

Commit

Permalink
Merge branch 'release/0.9.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Sep 2, 2016
2 parents 3235e0a + c2a927a commit 86b7fa9
Show file tree
Hide file tree
Showing 42 changed files with 700 additions and 200 deletions.
38 changes: 37 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
## [Unreleased][unreleased]

## [0.9.1] - 2016/09/02

### Added

- Plugins:
- ACL: allow to retrieve/update/delete an ACL by group name.
[#1544](https://github.com/Mashape/kong/pull/1544)

### Fixed

- Correctly parse configuration file settings contaning comments.
[#1569](https://github.com/Mashape/kong/pull/1569)
- Prevent third-party Lua modules (and plugins) to override the seed for random
number generation. This prevents the creation of conflicitng UUIDs.
[#1558](https://github.com/Mashape/kong/pull/1558)
- Use [pgmoon-mashape](https://github.com/Mashape/pgmoon) `2.0.0` which
properly namespaces our fork, avoiding conflicts with other versions of
pgmoon, such as the one installed by Lapis.
[#1582](https://github.com/Mashape/kong/pull/1582)
- Avoid exposing OpenResty's information on HTTP `4xx` errors.
[#1567](https://github.com/Mashape/kong/pull/1567)
- CLI:
- Stop third-party services (dnsmasq/Serf) when Kong could not start.
[#1588](https://github.com/Mashape/kong/pull/1588)
- Prefix database migration errors (such as Postgres' `connection refused`)
with the database name (`postgres`/`cassandra`) to avoid confusions.
[#1583](https://github.com/Mashape/kong/pull/1583)
- Plugins:
- galileo: Use `Content-Length` header to get request/response body size when
`log_bodies` is disabled.
[#1584](https://github.com/Mashape/kong/pull/1584)
- Admin API:
- Revert the `/plugins/enabled` endpoint's response to be a JSON array, and
not an Object. [#1529](https://github.com/Mashape/kong/pull/1529)

## [0.9.0] - 2016/08/18

The main focus of this release is Kong's new CLI. With a simpler configuration file, new settings, environment variables support, new commands as well as a new interpreter, the new CLI gives more power and flexibility to Kong users and allow for an easier integration in your deployment workflow, as well as better testing for developers and plugins authors. Additionally, some new plugins and performance improvements are included as well as the regular bug fixes.
Expand Down Expand Up @@ -662,7 +697,8 @@ First version running with Cassandra.
- CLI `bin/kong` script.
- Database migrations (using `db.lua`).

[unreleased]: https://github.com/mashape/kong/compare/0.9.0...next
[unreleased]: https://github.com/mashape/kong/compare/0.9.1...next
[0.9.1]: https://github.com/mashape/kong/compare/0.9.0...0.9.1
[0.9.0]: https://github.com/mashape/kong/compare/0.8.3...0.9.0
[0.8.3]: https://github.com/mashape/kong/compare/0.8.2...0.8.3
[0.8.2]: https://github.com/mashape/kong/compare/0.8.1...0.8.2
Expand Down
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
DEV_ROCKS = busted luacheck lua-llthreads2
BUSTED_ARGS ?= -v
TEST_CMD ?= bin/busted $(BUSTED_ARGS)
OPENSSL_DIR ?= /usr/local/opt/openssl

.PHONY: install dev lint test test-integration test-plugins test-all

install:
@if [ `uname` = "Darwin" ]; then \
luarocks make kong-*.rockspec; \
else \
luarocks make kong-*.rockspec \
PCRE_LIBDIR=`find / -type f -name "libpcre.so*" -print -quit | xargs dirname` \
OPENSSL_LIBDIR=`find / -type f -name "libssl.so*" -print -quit | xargs dirname`; \
fi
@luarocks make OPENSSL_DIR=$(OPENSSL_DIR)

dev: install
@for rock in $(DEV_ROCKS) ; do \
if ! command -v $$rock > /dev/null ; then \
if ! luarocks list | grep $$rock > /dev/null ; then \
echo $$rock not found, installing via luarocks... ; \
luarocks install $$rock ; \
else \
Expand Down
2 changes: 1 addition & 1 deletion bin/busted
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- force LuaSocket usage to resolve `/etc/hosts` until
-- supported by resty-cli.
-- See https://github.com/Mashape/kong/issues/1523
for _, namespace in ipairs({"cassandra", "pgmoon"}) do
for _, namespace in ipairs({"cassandra", "pgmoon-mashape"}) do
local socket = require(namespace .. ".socket")
socket.force_luasocket(ngx.get_phase(), true)
end
Expand Down
2 changes: 1 addition & 1 deletion bin/kong
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- force LuaSocket usage to resolve `/etc/hosts` until
-- supported by resty-cli.
-- See https://github.com/Mashape/kong/issues/1523
for _, namespace in ipairs({"cassandra", "pgmoon"}) do
for _, namespace in ipairs({"cassandra", "pgmoon-mashape"}) do
local socket = require(namespace .. ".socket")
socket.force_luasocket(ngx.get_phase(), true)
end
Expand Down
9 changes: 5 additions & 4 deletions kong-0.9.0-0.rockspec → kong-0.9.1-0.rockspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package = "kong"
version = "0.9.0-0"
version = "0.9.1-0"
supported_platforms = {"linux", "macosx"}
source = {
url = "git://github.com/Mashape/kong",
tag = "0.9.0"
tag = "0.9.1"
}
description = {
summary = "Kong is a scalable and customizable API Management Layer built on top of Nginx.",
Expand All @@ -16,12 +16,12 @@ dependencies = {
"penlight == 1.3.2",
"mediator_lua == 1.1.2",
"lua-resty-http == 0.08",
"lua-resty-jit-uuid == 0.0.4",
"lua-resty-jit-uuid == 0.0.5",
"multipart == 0.3",
"version == 0.2",
"lapis == 1.5.1",
"lua-cassandra == 0.5.3",
"pgmoon-mashape == 1.7.0",
"pgmoon-mashape == 2.0.0",
"luatz == 0.3",
"lua_system_constants == 0.1.1",
"lua-resty-iputils == 0.2.1",
Expand Down Expand Up @@ -90,6 +90,7 @@ build = {
["kong.core.cluster"] = "kong/core/cluster.lua",
["kong.core.events"] = "kong/core/events.lua",
["kong.core.error_handlers"] = "kong/core/error_handlers.lua",
["kong.core.globalpatches"] = "kong/core/globalpatches.lua",

["kong.dao.errors"] = "kong/dao/errors.lua",
["kong.dao.schemas_validation"] = "kong/dao/schemas_validation.lua",
Expand Down
7 changes: 6 additions & 1 deletion kong/api/routes/plugins.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local crud = require "kong.api.crud_helpers"
local cjson = require "cjson"
local utils = require "kong.tools.utils"
local reports = require "kong.core.reports"
local singletons = require "kong.singletons"
Expand Down Expand Up @@ -74,8 +75,12 @@ return {

["/plugins/enabled"] = {
GET = function(self, dao_factory, helpers)
local enabled_plugins = setmetatable({}, cjson.empty_array_mt)
for k in pairs(singletons.configuration.plugins) do
enabled_plugins[#enabled_plugins+1] = k
end
return helpers.responses.send_HTTP_OK {
enabled_plugins = singletons.configuration.plugins
enabled_plugins = enabled_plugins
}
end
}
Expand Down
30 changes: 23 additions & 7 deletions kong/cmd/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,30 @@ local function execute(args)
}))

local dao = DAOFactory(conf)
assert(dao:run_migrations())
assert(prefix_handler.prepare_prefix(conf, args.nginx_conf))
if conf.dnsmasq then
assert(dnsmasq_signals.start(conf))
local err
xpcall(function()
assert(dao:run_migrations())
assert(prefix_handler.prepare_prefix(conf, args.nginx_conf))
if conf.dnsmasq then
assert(dnsmasq_signals.start(conf))
end
assert(serf_signals.start(conf, dao))
assert(nginx_signals.start(conf))
log("Kong started")
end, function(e)
log.verbose("could not start Kong, stopping services")
nginx_signals.stop(conf)
serf_signals.stop(conf, dao)
if conf.dnsmasq then
dnsmasq_signals.stop(conf)
end
err = e -- cannot throw from this function
log.verbose("stopped services")
end)

if err then
error(err) -- report to main error handler
end
assert(serf_signals.start(conf, dao))
assert(nginx_signals.start(conf))
log("Kong started")
end

local lapp = [[
Expand Down
7 changes: 6 additions & 1 deletion kong/cmd/utils/prefix_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ end
local function get_ulimit()
local ok, _, stdout, stderr = pl_utils.executeex "ulimit -n"
if not ok then return nil, stderr end
return tonumber(pl_stringx.strip(stdout))
local sanitized_limit = pl_stringx.strip(stdout)
if sanitized_limit:lower():match("unlimited") then
return 65536
else
return tonumber(sanitized_limit)
end
end

local function gather_system_infos(compile_env)
Expand Down
24 changes: 15 additions & 9 deletions kong/conf_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ local function check_and_infer(conf)
local v_schema = CONF_INFERENCES[k] or {}
local typ = v_schema.typ

if type(value) == "string" then
value = string.gsub(value, "#.-$", "") -- remove trailing comment if any
value = pl_stringx.strip(value)
end

-- transform {boolean} values ("on"/"off" aliasing to true/false)
-- transform {ngx_boolean} values ("on"/"off" aliasing to on/off)
-- transform {explicit string} values (number values converted to strings)
Expand All @@ -135,13 +140,9 @@ local function check_and_infer(conf)
value = setmetatable(pl_stringx.split(value, ","), nil) -- remove List mt
end

if type(value) == "string" then
-- default type is string, and an empty if unset
value = value ~= "" and tostring(value) or nil
if value then
value = string.gsub(value, "#.-$", "")
value = pl_stringx.strip(value)
end
if value == "" then
-- unset values are removed
value = nil
end

typ = typ or "string"
Expand Down Expand Up @@ -271,13 +272,18 @@ local function load(path, custom_conf)
end
end

if path then -- we have a file? then load it
if not path then
log.verbose("no config file, skipping loading")
else
local f, err = pl_file.read(path)
if not f then return nil, err end

log.verbose("reading config file at %s", path)
local s = pl_stringio.open(f)
from_file_conf, err = pl_config.read(s)
from_file_conf, err = pl_config.read(s, {
smart = false,
list_delim = "_blank_" -- mandatory but we want to ignore it
})
s:close()
if not from_file_conf then return nil, err end
end
Expand Down
9 changes: 8 additions & 1 deletion kong/core/error_handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ local xml_template = '<?xml version="1.0" encoding="UTF-8"?>\n<error><message>%s
local html_template = '<html><head><title>Kong Error</title></head><body><h1>Kong Error</h1><p>%s.</p></body></html>'

local BODIES = {
s404 = "Not found",
s408 = "Request timeout",
s411 = "Length required",
s412 = "Precondition failed",
s413 = "Payload too large",
s414 = "URI too long",
s417 = "Expectation failed",
s500 = "An unexpected error occurred",
s502 = "An invalid response was received from the upstream server",
s503 = "The upstream server is currently unavailable",
Expand Down Expand Up @@ -48,4 +55,4 @@ return function(ngx)
ngx.header["Server"] = SERVER_HEADER
ngx.header["Content-Type"] = content_type
ngx.say(format(template, message))
end
end
34 changes: 34 additions & 0 deletions kong/core/globalpatches.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local meta = require "kong.meta"
local randomseed = math.randomseed

_G._KONG = {
_NAME = meta._NAME,
_VERSION = meta._VERSION
}

local seed

--- Seeds the random generator, use with care.
-- The uuid.seed() method will create a unique seed per worker
-- process, using a combination of both time and the worker's pid.
-- We only allow it to be called once to prevent third-party modules
-- from overriding our correct seed (many modules make a wrong usage
-- of `math.randomseed()` by calling it multiple times or do not use
-- unique seed for Nginx workers).
-- luacheck: globals math
_G.math.randomseed = function()
if ngx.get_phase() ~= "init_worker" then
ngx.log(ngx.ERR, "math.randomseed() must be called in init_worker")
elseif not seed then
seed = ngx.time() + ngx.worker.pid()
ngx.log(ngx.DEBUG, "random seed: ", seed, " for worker n", ngx.worker.id(),
" (pid: ", ngx.worker.pid(), ")")
randomseed(seed)
else
ngx.log(ngx.DEBUG, "attempt to seed random number generator, but ",
"already seeded")
end

return seed
end

Loading

0 comments on commit 86b7fa9

Please sign in to comment.