Skip to content

Commit 44391e0

Browse files
authored
refactor: workflow plugin registeration (#11832)
1 parent de7bd0b commit 44391e0

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

apisix/plugin.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ local function load_plugin(name, plugins_list, plugin_type)
185185
plugin.init()
186186
end
187187

188+
if plugin.workflow_handler then
189+
plugin.workflow_handler()
190+
end
191+
188192
return
189193
end
190194

apisix/plugins/limit-count.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
--
1717
local fetch_secrets = require("apisix.secret").fetch_secrets
1818
local limit_count = require("apisix.plugins.limit-count.init")
19+
local workflow = require("apisix.plugins.workflow")
1920

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

40+
function _M.workflow_handler()
41+
workflow.register(plugin_name,
42+
function (conf, ctx)
43+
return limit_count.rate_limit(conf, ctx, plugin_name, 1)
44+
end,
45+
function (conf)
46+
return limit_count.check_schema(conf)
47+
end)
48+
end
3949

4050
return _M

apisix/plugins/workflow.lua

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
-- limitations under the License.
1616
--
1717
local core = require("apisix.core")
18-
local limit_count = require("apisix.plugins.limit-count.init")
1918
local expr = require("resty.expr.v1")
2019
local ipairs = ipairs
2120

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

9594

96-
local function rate_limit(conf, ctx)
97-
return limit_count.rate_limit(conf, ctx, "limit-count", 1)
98-
end
99-
10095

10196
local support_action = {
10297
["return"] = {
10398
handler = exit,
10499
check_schema = check_return_schema,
105-
},
106-
["limit-count"] = {
107-
handler = rate_limit,
108-
check_schema = limit_count.check_schema,
109100
}
110101
}
111102

112103

104+
function _M.register(plugin_name, handler, check_schema)
105+
support_action[plugin_name] = {
106+
handler = handler,
107+
check_schema = check_schema
108+
}
109+
end
110+
113111
function _M.check_schema(conf)
114112
local ok, err = core.schema.check(schema, conf)
115113
if not ok then

0 commit comments

Comments
 (0)