-
Notifications
You must be signed in to change notification settings - Fork 2.8k
change: Improve results from admin API while GET all plugins #9580
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
Changes from all commits
cdb9c42
75db0b1
b74771d
2679448
fea340e
186c792
113218d
b2f5834
c9ad2fd
8bec519
8af5454
69790fd
bf1d23d
fccea25
4044a27
1b0105e
0873c32
fa254ee
446ad91
d80cd68
2f1f302
dad573b
edea4a0
a801549
4c405f0
20de18a
e279e3b
abc0435
cbba4c8
4512a1b
043f1e1
2197c1f
b6232d3
babd145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,12 @@ local require = require | |
| local core = require("apisix.core") | ||
| local check_schema = require("apisix.plugin").check_schema | ||
| local ipairs = ipairs | ||
| local pcall = pcall | ||
| local table_sort = table.sort | ||
| local table_insert = table.insert | ||
| local get_uri_args = ngx.req.get_uri_args | ||
| local plugin_get_all = require("apisix.plugin").get_all | ||
| local plugin_get_http = require("apisix.plugin").get | ||
| local plugin_get_stream = require("apisix.plugin").get_stream | ||
| local encrypt_conf = require("apisix.plugin").encrypt_conf | ||
| local pairs = pairs | ||
|
|
||
|
|
@@ -42,7 +43,15 @@ end | |
|
|
||
| function _M.get(name) | ||
| local arg = get_uri_args() | ||
| if arg and arg["all"] == "true" then | ||
monkeyDluffy6017 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -- If subsystem is passed inside args then it should be oneOf: http / stream. | ||
| local subsystem = arg["subsystem"] or "http" | ||
| if subsystem ~= "http" and subsystem ~= "stream" then | ||
| return 400, {error_msg = "unsupported subsystem: "..subsystem} | ||
| end | ||
monkeyDluffy6017 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| -- arg all to be deprecated | ||
| if (arg and arg["all"] == "true") then | ||
| core.log.warn("query parameter \"all\" will be deprecated soon.") | ||
| local http_plugins, stream_plugins = plugin_get_all({ | ||
| version = true, | ||
| priority = true, | ||
|
|
@@ -60,16 +69,18 @@ function _M.get(name) | |
| return 200, http_plugins | ||
| end | ||
|
|
||
| if not name then | ||
| return 400, {error_msg = "not found plugin name"} | ||
| end | ||
| local plugin | ||
|
|
||
| local plugin_name = "apisix.plugins." .. name | ||
| if subsystem == "http" then | ||
| plugin = plugin_get_http(name) | ||
| else | ||
| plugin = plugin_get_stream(name) | ||
| end | ||
|
|
||
| local ok, plugin = pcall(require, plugin_name) | ||
| if not ok then | ||
| core.log.warn("failed to load plugin [", name, "] err: ", plugin) | ||
| return 400, {error_msg = "failed to load plugin " .. name} | ||
| if not plugin then | ||
| local err = "plugin not found in subsystem " .. subsystem | ||
| core.log.warn(err) | ||
| return 404, {error_msg = err} | ||
| end | ||
|
|
||
| local json_schema = plugin.schema | ||
|
|
@@ -85,16 +96,34 @@ function _M.get(name) | |
| end | ||
|
|
||
|
|
||
| function _M.get_plugins_list() | ||
| local plugins = core.config.local_conf().plugins | ||
| function _M.get_plugins_list(subsystem) | ||
| local http_plugins | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean before defining
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @monkeyDluffy6017 The check is already performed here https://github.com/apache/apisix/pull/9580/files#diff-8baac20135bcefd8d1beffe08f44b5271bc1c717c6ab2e720a0e14cb1a02599dR262 before calling this function |
||
| local stream_plugins | ||
| if subsystem == "http" then | ||
| http_plugins = core.config.local_conf().plugins | ||
| else | ||
| stream_plugins = core.config.local_conf().stream_plugins | ||
| end | ||
|
|
||
monkeyDluffy6017 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| local priorities = {} | ||
| local success = {} | ||
| for i, name in ipairs(plugins) do | ||
| local plugin_name = "apisix.plugins." .. name | ||
| local ok, plugin = pcall(require, plugin_name) | ||
| if ok and plugin.priority then | ||
| priorities[name] = plugin.priority | ||
| table_insert(success, name) | ||
| if http_plugins then | ||
| for i, name in ipairs(http_plugins) do | ||
| local plugin = plugin_get_http(name) | ||
| if plugin and plugin.priority then | ||
| priorities[name] = plugin.priority | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can these two function be used here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those functions are to get the entire plugin loaded with plugin.load(). Here we just need the names.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| table_insert(success, name) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| if stream_plugins then | ||
| for i, name in ipairs(stream_plugins) do | ||
| local plugin = plugin_get_stream(name) | ||
| if plugin and plugin.priority then | ||
| priorities[name] = plugin.priority | ||
| table_insert(success, name) | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.