change: 'get_plugin_list' API sorts the return list base on priority (#1779)

This commit is contained in:
ko han 2020-07-01 17:05:02 +08:00 committed by GitHub
parent 0bcd397a90
commit aeab71df80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -18,9 +18,13 @@ local core = require("apisix.core")
local local_plugins = require("apisix.plugin").plugins_hash
local stream_local_plugins = require("apisix.plugin").stream_plugins_hash
local pairs = pairs
local ipairs = ipairs
local pcall = pcall
local require = require
local table_remove = table.remove
local table_sort = table.sort
local table_insert = table.insert
local _M = {
version = 0.1,
@ -114,7 +118,23 @@ function _M.get_plugins_list()
table_remove(plugins, 1)
end
return plugins
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)
end
end
local function cmp(x, y)
return priorities[x] > priorities[y]
end
table_sort(success, cmp)
return success
end

View File

@ -30,7 +30,7 @@ __DATA__
--- request
GET /apisix/admin/plugins/list
--- response_body_like eval
qr/\["limit-req","limit-count","limit-conn","key-auth","basic-auth","prometheus","node-status","jwt-auth","zipkin","ip-restriction","grpc-transcode","serverless-pre-function","serverless-post-function","openid-connect","proxy-rewrite","redirect","response-rewrite","fault-injection","udp-logger","wolf-rbac","proxy-cache","tcp-logger","proxy-mirror","kafka-logger","cors","consumer-restriction","syslog","batch-requests","http-logger","skywalking","echo","authz-keycloak","uri-blocker"\]/
qr/\["fault-injection","serverless-pre-function","batch-requests","cors","ip-restriction","uri-blocker","openid-connect","wolf-rbac","basic-auth","jwt-auth","key-auth","consumer-restriction","authz-keycloak","proxy-mirror","proxy-cache","proxy-rewrite","limit-conn","limit-count","limit-req","node-status","redirect","response-rewrite","grpc-transcode","prometheus","echo","http-logger","tcp-logger","kafka-logger","syslog","udp-logger","zipkin","skywalking","serverless-post-function"\]/
--- no_error_log
[error]