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(*) port plugins entities and Admin endpoints to the new DAO #3766

Merged
merged 13 commits into from Sep 14, 2018
Merged
Diff settings

Always

Just for now

feat(db) allow new-db entities to be loaded from plugins/*/daos.lua

  • Loading branch information...
kikito authored and thibaultcha committed Aug 22, 2018
commit 034d3bc69dcc23a59602f54ef8adf8d79ee2d029
@@ -283,7 +283,9 @@ function _M.new(kong_config, new_db)
end
else
for k, v in pairs(plugin_schemas) do
schemas[k] = v
if not v.name then
schemas[k] = v
end
end
end
end
@@ -385,7 +387,9 @@ end

function _M:truncate_tables()
for _, dao in pairs(self.daos) do
self.db:truncate_table(dao.table)
if dao.table then
self.db:truncate_table(dao.table)
end
end

if self.db.additional_tables then
@@ -1,6 +1,9 @@
local constants = require "kong.constants"
local typedefs = require "kong.db.schema.typedefs"
local utils = require "kong.tools.utils"
local Entity = require "kong.db.schema.entity"
local DAO = require "kong.db.dao"
local MetaSchema = require "kong.db.schema.metaschema"


local Plugins = {}
@@ -201,6 +204,7 @@ end
-- @return an array of tables, or nil and an error message.
function Plugins:load_plugin_schemas(plugin_set)
local plugin_list = {}
local db = self.db

-- load installed plugins
for plugin in pairs(plugin_set) do
@@ -257,6 +261,38 @@ function Plugins:load_plugin_schemas(plugin_set)
name = plugin,
handler = handler(),
}

local has_daos, daos_schemas = utils.load_module_if_exists("kong.plugins." .. plugin .. ".daos")
if has_daos then
local Strategy = require(string.format("kong.db.strategies.%s", db.strategy))
for name, schema_def in pairs(daos_schemas) do
if name ~= "tables" and schema_def.name then
ngx_log(ngx_DEBUG, string.format("Loading custom plugin entity: '%s.%s'", plugin, name))
local ok, err_t = MetaSchema:validate(schema_def)
if not ok then
return nil, string.format("schema of custom plugin entity '%s.%s' is invalid: %s", plugin, name,
-- tostring(db.errors:schema_violation(err_t)))
require("inspect")({ err_t = err_t, schema_def = schema_def }))
end
local schema, err = Entity.new(schema_def)
if not schema then
return nil, string.format("schema of custom plugin entity '%s.%s' is invalid: %s", plugin, name,
err)
end
local strategy, err = Strategy.new(db.connector, schema, db.errors)
if not strategy then
return nil, err
end
db.strategies[schema.name] = strategy

local dao, err = DAO.new(db, schema, strategy, db.errors)
if not dao then
return nil, err
end
db.daos[schema.name] = dao
end
end
end
end

return plugin_list
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.