You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/07/01 09:05:08 UTC
[incubator-apisix] branch master updated: change: 'get_plugin_list'
API sorts the return list base on priority (#1779)
This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new aeab71d change: 'get_plugin_list' API sorts the return list base on priority (#1779)
aeab71d is described below
commit aeab71df8070f1f6daa2b06e55f0ffaca5eb053f
Author: ko han <ha...@outlook.com>
AuthorDate: Wed Jul 1 17:05:02 2020 +0800
change: 'get_plugin_list' API sorts the return list base on priority (#1779)
---
apisix/admin/plugins.lua | 22 +++++++++++++++++++++-
t/admin/plugins.t | 2 +-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/apisix/admin/plugins.lua b/apisix/admin/plugins.lua
index 7d6262c..7b835e1 100644
--- a/apisix/admin/plugins.lua
+++ b/apisix/admin/plugins.lua
@@ -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
diff --git a/t/admin/plugins.t b/t/admin/plugins.t
index b134b97..784b5d2 100644
--- a/t/admin/plugins.t
+++ b/t/admin/plugins.t
@@ -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]