Skip to content

Commit

Permalink
refactor: workflow plugin registeration (#11832)
Browse files Browse the repository at this point in the history
  • Loading branch information
Revolyssup authored Dec 17, 2024
1 parent de7bd0b commit 44391e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions apisix/plugins/limit-count.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 44391e0

Please sign in to comment.