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

refactor: workflow plugin registration #11832

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
@@ -185,6 +185,10 @@ local function load_plugin(name, plugins_list, plugin_type)
plugin.init()
end

if plugin.workflow_handler then
plugin.workflow_handler()
end

return
end

10 changes: 10 additions & 0 deletions apisix/plugins/limit-count.lua
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
--
local fetch_secrets = require("apisix.secret").fetch_secrets
local limit_count = require("apisix.plugins.limit-count.init")
local workflow = require("apisix.plugins.workflow")

local plugin_name = "limit-count"
local _M = {
@@ -36,5 +37,14 @@ function _M.access(conf, ctx)
return limit_count.rate_limit(conf, ctx, plugin_name, 1)
end

function _M.workflow_handler()
workflow.register(plugin_name,
function (conf, ctx)
return limit_count.rate_limit(conf, ctx, plugin_name, 1)
end,
function (conf)
return limit_count.check_schema(conf)
end)
end

return _M
16 changes: 7 additions & 9 deletions apisix/plugins/workflow.lua
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
-- limitations under the License.
--
local core = require("apisix.core")
local limit_count = require("apisix.plugins.limit-count.init")
local expr = require("resty.expr.v1")
local ipairs = ipairs

@@ -93,23 +92,22 @@ local function exit(conf)
end


local function rate_limit(conf, ctx)
return limit_count.rate_limit(conf, ctx, "limit-count", 1)
end


local support_action = {
["return"] = {
handler = exit,
check_schema = check_return_schema,
},
["limit-count"] = {
handler = rate_limit,
check_schema = limit_count.check_schema,
}
}


function _M.register(plugin_name, handler, check_schema)
support_action[plugin_name] = {
handler = handler,
check_schema = check_schema
}
end

function _M.check_schema(conf)
local ok, err = core.schema.check(schema, conf)
if not ok then