Skip to content

Commit

Permalink
feat(api) deactivate some /server_names endpoints, add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed Apr 12, 2018
1 parent 25c7205 commit db91399
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 144 deletions.
1 change: 1 addition & 0 deletions kong-0.13.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ build = {
["kong.api.routes.cache"] = "kong/api/routes/cache.lua",
["kong.api.routes.upstreams"] = "kong/api/routes/upstreams.lua",
["kong.api.routes.certificates"] = "kong/api/routes/certificates.lua",
["kong.api.routes.server_names"] = "kong/api/routes/server_names.lua",

["kong.tools.ip"] = "kong/tools/ip.lua",
["kong.tools.ciphers"] = "kong/tools/ciphers.lua",
Expand Down
2 changes: 1 addition & 1 deletion kong/api/routes/certificates.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local endpoints = require "kong.api.endpoints"
local utils = require "kong.tools.utils"


local function get_cert_by_server_name_or_id(self, db, helpers)
local id = self.params.certificates

if not utils.is_valid_uuid(id) then
local cert, _, err_t = db.certificates:select_by_server_name(id)
if err_t then
Expand Down
16 changes: 16 additions & 0 deletions kong/api/routes/server_names.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local function not_found(self, db, helpers)
return helpers.responses.send_HTTP_NOT_FOUND()
end

return {
-- GET / PATCH / DELETE /server_names/server_name are the only methods allowed

["/server_names"] = {
before = not_found,
},

["/server_names/:server_names/certificate"] = {
before = not_found,
},

}
23 changes: 13 additions & 10 deletions kong/dao/migrations/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -718,23 +718,26 @@ return {
{
name = "2018-03-27-125400_fill_in_server_names_ids",
up = function(_, _, dao)
local fmt = string.format

local rows, err = dao.db:query([[
SELECT * FROM server_names;
]])
if err then
return err
end
local sql_buffer = { "BEGIN;" }
local len = #rows
for i = 1, len do
sql_buffer[i + 1] = fmt("UPDATE server_names SET id = '%s' WHERE name = '%s';",
utils.uuid(),
rows[i].name)
end
sql_buffer[len + 2] = "COMMIT;"

local fmt = string.format

for _, row in ipairs(rows) do
local sql = fmt("UPDATE server_names SET id = '%s' WHERE name = '%s';",
utils.uuid(),
row.name)
local _, err = dao.db:query(sql)
if err then
return err
end
local _, err = dao.db:query(table.concat(sql_buffer))
if err then
return err
end
end,
down = nil
Expand Down
2 changes: 2 additions & 0 deletions kong/db/dao/certificates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ local function parse_name_list(input, errors)
local name_list
if type(input) == "string" then
name_list = utils.split(input, ",")

elseif type(input) == "table" then
name_list = utils.shallow_copy(input)

elseif input == ngx.null then
name_list = {}
end
Expand Down
2 changes: 1 addition & 1 deletion kong/db/dao/server_names.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function _ServerNames:check_list_is_new_or_in_cert(cert_pk, name_list)
return nil, err, err_t
end
if row and row.certificate.id ~= cert_pk.id then
local msg = "Server Name '" .. row.name ..
local msg = "Server name '" .. row.name ..
"' already associated with existing " ..
"certificate (" .. row.certificate.id .. ")"
local err_t = self.errors:conflicting_input(msg)
Expand Down
11 changes: 5 additions & 6 deletions kong/db/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local Entity = require "kong.db.schema.entity"
local Errors = require "kong.db.errors"
local Strategies = require "kong.db.strategies"
local MetaSchema = require "kong.db.schema.metaschema"
local pl_pretty = require "pl.pretty"


local fmt = string.format
Expand Down Expand Up @@ -41,6 +40,10 @@ function DB.new(kong_config, strategy)
error("strategy must be a string", 2)
end

-- load errors

local errors = Errors.new(strategy)

local schemas = {}

do
Expand All @@ -55,17 +58,13 @@ function DB.new(kong_config, strategy)
local ok, err_t = MetaSchema:validate(entity_schema)
if not ok then
return nil, fmt("schema of entity '%s' is invalid: %s", entity_name,
pl_pretty.write(err_t))
tostring(errors:schema_violation(err_t)))
end

schemas[entity_name] = Entity.new(entity_schema)
end
end

-- load errors

local errors = Errors.new(strategy)

-- load strategy

local connector, strategies, err = Strategies.new(kong_config, strategy,
Expand Down
Loading

0 comments on commit db91399

Please sign in to comment.