Skip to content

Commit

Permalink
Merge pull request Kong#1454 from Mashape/chore/deps-removal
Browse files Browse the repository at this point in the history
chore(deps) remove now obsolete dependencies + locking remaining ones
  • Loading branch information
thibaultcha authored Aug 1, 2016
2 parents 4873f74 + c64ca30 commit 417659d
Show file tree
Hide file tree
Showing 36 changed files with 187 additions and 185 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ addons:
apt:
packages:
- dnsmasq
- uuid-dev
- net-tools
- libpcre3-dev
- build-essential
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ The main focus of this release is Kong's new CLI. With a simpler configuration f
- correlation-id: new "tracker" generator, identifying requests per worker and connection. [#1288](https://github.com/Mashape/kong/pull/1288)
- request/response-transformer: ability to add strings including colon characters. [#1353](https://github.com/Mashape/kong/pull/1353)

### Removed

- We now use [lua-resty-jit-uuid](https://github.com/thibaultCha/lua-resty-jit-uuid) for UUID generation, which is a pure Lua implementation of [RFC 4122](https://www.ietf.org/rfc/rfc4122.txt). As a result, libuuid is not a dependency of Kong anymore.

### Fixed

- Sensitive configuration settings are not printed to stdout anymore. [#1256](https://github.com/Mashape/kong/issues/1256)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DEV_ROCKS = busted luacheck
DEV_ROCKS = busted luacheck lua-llthreads2
BUSTED_ARGS ?= -v
TEST_CMD = bin/busted $(BUSTED_ARGS)

Expand Down
37 changes: 16 additions & 21 deletions kong-0.9.0rc1-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,23 @@ description = {
license = "MIT"
}
dependencies = {
"luasec ~> 0.5-2",
"luasocket ~> 2.0.2-6",
"penlight ~> 1.3.2",
"lua-resty-http ~> 0.07-0",
"lua_uuid ~> 0.2.0-2",
"lua_system_constants ~> 0.1.1-0",
"luatz ~> 0.3-1",
"lapis ~> 1.3.1-1",
"stringy ~> 0.4-1",
"lua-cassandra ~> 0.5.2",
"pgmoon ~> 1.5.0",
"multipart ~> 0.3-2",
"lua-cjson ~> 2.1.0-1",
"lbase64 ~> 20120820-1",
"lua-resty-iputils ~> 0.2.0-1",
"mediator_lua ~> 1.1.2-0",
"luasec == 0.6",
"luasocket == 2.0.2",
"penlight == 1.3.2",
"mediator_lua == 1.1.2",
"lua-resty-http == 0.08",
"lua-resty-jit-uuid == 0.0.4",
"multipart == 0.3",
"version == 0.2",
"luacrypto >= 0.3.2-1",
"luasyslog >= 1.0.0-2",
"lua_pack ~> 1.0.4-0",

"lua-llthreads2 ~> 0.1.3-1"
"lapis == 1.5.1",
"lua-cassandra == 0.5.2",
"pgmoon == 1.6.0",
"luatz == 0.3",
"lua_system_constants == 0.1.1",
"lua-resty-iputils == 0.2.1",
"luacrypto == 0.3.2",
"luasyslog == 1.0.0",
"lua_pack == 1.0.4"
}
build = {
type = "builtin",
Expand Down
8 changes: 3 additions & 5 deletions kong/api/crud_helpers.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
local utils = require "kong.tools.utils"
local responses = require "kong.tools.responses"
local validations = require "kong.dao.schemas_validation"
local app_helpers = require "lapis.application"
local utils = require "kong.tools.utils"
local is_uuid = validations.is_valid_uuid

local _M = {}

function _M.find_api_by_name_or_id(self, dao_factory, helpers)
local filter_keys = {
[is_uuid(self.params.name_or_id) and "id" or "name"] = self.params.name_or_id
[utils.is_valid_uuid(self.params.name_or_id) and "id" or "name"] = self.params.name_or_id
}
self.params.name_or_id = nil

Expand All @@ -26,7 +24,7 @@ end

function _M.find_consumer_by_username_or_id(self, dao_factory, helpers)
local filter_keys = {
[is_uuid(self.params.username_or_id) and "id" or "username"] = self.params.username_or_id
[utils.is_valid_uuid(self.params.username_or_id) and "id" or "username"] = self.params.username_or_id
}
self.params.username_or_id = nil

Expand Down
8 changes: 2 additions & 6 deletions kong/api/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local lapis = require "lapis"
local utils = require "kong.tools.utils"
local stringy = require "stringy"
local responses = require "kong.tools.responses"
local singletons = require "kong.singletons"
local app_helpers = require "lapis.application"
Expand Down Expand Up @@ -66,11 +65,8 @@ app.handle_error = function(self, err, trace)
end

app:before_filter(function(self)
if needs_body[ngx.req.get_method()] then
local content_type = self.req.headers["content-type"]
if not content_type or stringy.strip(content_type) == "" then
return responses.send_HTTP_UNSUPPORTED_MEDIA_TYPE()
end
if needs_body[ngx.req.get_method()] and not self.req.headers["content-type"] then
return responses.send_HTTP_UNSUPPORTED_MEDIA_TYPE()
end
end)

Expand Down
6 changes: 3 additions & 3 deletions kong/core/certificate.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
local singletons = require "kong.singletons"
local utils = require "kong.tools.utils"
local cache = require "kong.tools.database_cache"
local stringy = require "stringy"
local singletons = require "kong.singletons"

local _M = {}

local function find_api(hosts)
local retrieved_api, err
for _, host in ipairs(hosts) do
local sanitized_host = stringy.split(host, ":")[1]
local sanitized_host = utils.split(host, ":")[1]

retrieved_api, err = cache.get_or_set(cache.api_key(sanitized_host), function()
local apis, err = singletons.dao.apis:find_all {request_host = sanitized_host}
Expand Down
6 changes: 3 additions & 3 deletions kong/core/hooks.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local singletons = require "kong.singletons"
local events = require "kong.core.events"
local cache = require "kong.tools.database_cache"
local utils = require "kong.tools.utils"
local singletons = require "kong.singletons"
local pl_stringx = require "pl.stringx"
local stringy = require "stringy"

local function invalidate_plugin(entity)
cache.delete(cache.plugin_key(entity.name, entity.api_id, entity.consumer_id))
Expand Down Expand Up @@ -45,7 +45,7 @@ local function retrieve_member_address(name)
end

local function parse_member(member_str)
if member_str and stringy.strip(member_str) ~= "" then
if member_str and utils.strip(member_str) ~= "" then
local result = {}
local index = 1
for v in member_str:gmatch("%S+") do
Expand Down
2 changes: 1 addition & 1 deletion kong/dao/cassandra_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local timestamp = require "kong.tools.timestamp"
local Errors = require "kong.dao.errors"
local BaseDB = require "kong.dao.base_db"
local utils = require "kong.tools.utils"
local uuid = require "lua_uuid"
local uuid = require "resty.jit-uuid"

local ngx_stub = _G.ngx
_G.ngx = nil
Expand Down
3 changes: 1 addition & 2 deletions kong/dao/factory.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local DAO = require "kong.dao.dao"
local utils = require "kong.tools.utils"
local Object = require "kong.vendor.classic"
local stringy = require "stringy"
local ModelFactory = require "kong.dao.model_factory"

local CORE_MODELS = {"apis", "consumers", "plugins", "nodes"}
Expand All @@ -24,7 +23,7 @@ local function build_constraints(schemas)
local constraints = {foreign = {}, unique = {}}
for col, field in pairs(schema.fields) do
if type(field.foreign) == "string" then
local f_entity, f_field = unpack(stringy.split(field.foreign, ":"))
local f_entity, f_field = unpack(utils.split(field.foreign, ":"))
if f_entity ~= nil and f_field ~= nil then
local f_schema = schemas[f_entity]
constraints.foreign[col] = {
Expand Down
4 changes: 2 additions & 2 deletions kong/dao/model_factory.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local utils = require "kong.tools.utils"
local Errors = require "kong.dao.errors"
local schemas_validation = require "kong.dao.schemas_validation"
local validate = schemas_validation.validate_entity
local valid_uuid = schemas_validation.is_valid_uuid

return setmetatable({}, {
__call = function(_, schema)
Expand Down Expand Up @@ -40,7 +40,7 @@ return setmetatable({}, {
local primary_keys, values, nils = {}, {}, {}
for _, key in pairs(schema.primary_key) do
-- check for uuid here. not all dbs might have ids of type uuid however
if schema.fields[key].type == "id" and not valid_uuid(self[key]) then
if schema.fields[key].type == "id" and not utils.is_valid_uuid(self[key]) then
return nil, nil, nil, self[key].." is not a valid uuid"
end
primary_keys[key] = self[key]
Expand Down
2 changes: 1 addition & 1 deletion kong/dao/postgres_db.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local BaseDB = require "kong.dao.base_db"
local Errors = require "kong.dao.errors"
local uuid = require "lua_uuid"
local uuid = require "resty.jit-uuid"
local utils = require "kong.tools.utils"

local TTL_CLEANUP_INTERVAL = 60 -- 1 minute
Expand Down
8 changes: 4 additions & 4 deletions kong/dao/schemas/apis.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local url = require "socket.url"
local stringy = require "stringy"
local utils = require "kong.tools.utils"

local fmt = string.format
local sub = string.sub
Expand All @@ -18,8 +18,8 @@ local function validate_upstream_url_protocol(value)
end

local function check_request_host_and_path(api_t)
local request_host = type(api_t.request_host) == "string" and stringy.strip(api_t.request_host) or ""
local request_path = type(api_t.request_path) == "string" and stringy.strip(api_t.request_path) or ""
local request_host = type(api_t.request_host) == "string" and utils.strip(api_t.request_host) or ""
local request_path = type(api_t.request_path) == "string" and utils.strip(api_t.request_path) or ""

if request_path == "" and request_host == "" then
return false, "At least a 'request_host' or a 'request_path' must be specified"
Expand Down Expand Up @@ -47,7 +47,7 @@ local function check_request_host(request_host, api_t)

-- Reject prefix/trailing dashes and dots in each segment
-- note: punycode allowes prefixed dash, if the characters before the dash are escaped
for _, segment in ipairs(stringy.split(request_host, ".")) do
for _, segment in ipairs(utils.split(request_host, ".")) do
if segment == "" or segment:match("-$") or segment:match("^%.") or segment:match("%.$") then
return false, "Invalid value: "..request_host
end
Expand Down
6 changes: 3 additions & 3 deletions kong/dao/schemas/consumers.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local stringy = require "stringy"
local utils = require "kong.tools.utils"

local function check_custom_id_and_username(value, consumer_t)
local username = type(consumer_t.username) == "string" and stringy.strip(consumer_t.username) or ""
local custom_id = type(consumer_t.custom_id) == "string" and stringy.strip(consumer_t.custom_id) or ""
local username = type(consumer_t.username) == "string" and utils.strip(consumer_t.username) or ""
local custom_id = type(consumer_t.custom_id) == "string" and utils.strip(consumer_t.custom_id) or ""

if custom_id == "" and username == "" then
return false, "At least a 'custom_id' or a 'username' must be specified"
Expand Down
21 changes: 7 additions & 14 deletions kong/dao/schemas_validation.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local utils = require "kong.tools.utils"
local stringy = require "stringy"

local POSSIBLE_TYPES = {
table = true,
Expand Down Expand Up @@ -65,7 +64,7 @@ function _M.validate_entity(tbl, schema, options)
for tk, t in pairs(key_values) do
if t ~= nil then
local error_prefix = ""
if stringy.strip(tk) ~= "" then
if utils.strip(tk) ~= "" then
error_prefix = tk.."."
end

Expand Down Expand Up @@ -94,15 +93,15 @@ function _M.validate_entity(tbl, schema, options)
local is_valid_type
-- ALIASES: number, timestamp, boolean and array can be passed as strings and will be converted
if type(t[column]) == "string" then
t[column] = stringy.strip(t[column])
t[column] = utils.strip(t[column])
if v.type == "boolean" then
local bool = t[column]:lower()
is_valid_type = bool == "true" or bool == "false"
t[column] = bool == "true"
elseif v.type == "array" then
t[column] = stringy.strip(t[column]) == "" and {} or stringy.split(t[column], ",") -- Handling empty arrays
t[column] = utils.strip(t[column]) == "" and {} or utils.split(t[column], ",") -- Handling empty arrays
for arr_k, arr_v in ipairs(t[column]) do
t[column][arr_k] = stringy.strip(arr_v)
t[column][arr_k] = utils.strip(arr_v)
end
is_valid_type = validate_type(v.type, t[column])
elseif v.type == "number" or v.type == "timestamp" then
Expand All @@ -116,7 +115,7 @@ function _M.validate_entity(tbl, schema, options)
end

if not is_valid_type and POSSIBLE_TYPES[v.type] then
errors = utils.add_error(errors, error_prefix..column,
errors = utils.add_error(errors, error_prefix..column,
string.format("%s is not %s %s", column, v.type == "array" and "an" or "a", v.type))
end
end
Expand Down Expand Up @@ -225,7 +224,7 @@ function _M.validate_entity(tbl, schema, options)
for k in pairs(t) do
if schema.fields[k] == nil then
if schema.flexible then
if stringy.strip(tk) ~= "" and k ~= tk then
if utils.strip(tk) ~= "" and k ~= tk then
errors = utils.add_error(errors, error_prefix..k, k.." is an unknown field")
end
else
Expand All @@ -246,20 +245,14 @@ function _M.validate_entity(tbl, schema, options)
return errors == nil, errors
end

local digit = "[0-9a-f]"
local uuid_pattern = "^"..table.concat({ digit:rep(8), digit:rep(4), digit:rep(4), digit:rep(4), digit:rep(12) }, '%-').."$"
function _M.is_valid_uuid(uuid)
return uuid and uuid:match(uuid_pattern) ~= nil
end

function _M.is_schema_subset(tbl, schema)
local errors

for k, v in pairs(tbl) do
if schema.fields[k] == nil then
errors = utils.add_error(errors, k, "unknown field")
elseif schema.fields[k].type == "id" and v ~= nil then
if not _M.is_valid_uuid(v) then
if not utils.is_valid_uuid(v) then
errors = utils.add_error(errors, k, v.."is not a valid uuid")
end
end
Expand Down
8 changes: 8 additions & 0 deletions kong/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ _G._KONG = {

local core = require "kong.core.handler"
local Serf = require "kong.serf"
local uuid = require 'resty.jit-uuid'
local utils = require "kong.tools.utils"
local Events = require "kong.core.events"
local singletons = require "kong.singletons"
Expand Down Expand Up @@ -139,6 +140,13 @@ function Kong.init()
end

function Kong.init_worker()
-- it is very important to seed this module in the init_worker phase
-- to avoid duplicated UUID sequences accross workers since jit-uuid
-- uses LuaJIT's math.random().
-- jit-uuid handles unique seeds for multiple workers thanks to
-- ngx.worker.pid().
uuid.seed()

core.init_worker.before()

singletons.dao:init() -- Executes any initialization by the DB
Expand Down
4 changes: 2 additions & 2 deletions kong/plugins/basic-auth/access.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local utils = require "kong.tools.utils"
local cache = require "kong.tools.database_cache"
local crypto = require "kong.plugins.basic-auth.crypto"
local stringy = require "stringy"
local singletons = require "kong.singletons"
local constants = require "kong.constants"
local responses = require "kong.tools.responses"
Expand Down Expand Up @@ -37,7 +37,7 @@ local function retrieve_credentials(request, header_name, conf)
if m and table.getn(m) > 0 then
local decoded_basic = ngx.decode_base64(m[1])
if decoded_basic then
local basic_parts = stringy.split(decoded_basic, ":")
local basic_parts = utils.split(decoded_basic, ":")
username = basic_parts[1]
password = basic_parts[2]
end
Expand Down
7 changes: 4 additions & 3 deletions kong/plugins/correlation-id/handler.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
-- Copyright (C) Mashape, Inc.

local BasePlugin = require "kong.plugins.base_plugin"
local uuid = require "lua_uuid"
local uuid = require "resty.jit-uuid"
local req_set_header = ngx.req.set_header
local req_get_headers = ngx.req.get_headers
local uuid_v4 = uuid.generate_v4

local CorrelationIdHandler = BasePlugin:extend()

Expand All @@ -16,7 +17,7 @@ local worker_pid = ngx.worker.pid()

local generators = setmetatable({
["uuid"] = function()
return uuid()
return uuid_v4()
end,
["uuid#counter"] = function()
worker_counter = worker_counter + 1
Expand Down Expand Up @@ -44,7 +45,7 @@ end

function CorrelationIdHandler:init_worker()
CorrelationIdHandler.super.init_worker(self)
worker_uuid = uuid()
worker_uuid = uuid_v4()
worker_counter = 0
end

Expand Down
Loading

0 comments on commit 417659d

Please sign in to comment.