You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sh...@apache.org on 2021/06/11 02:32:55 UTC
[apisix] branch master updated: refactor: use plugin_attr to fetch
plugin attribute (#4377)
This is an automated email from the ASF dual-hosted git repository.
shuyangw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 6c38fdf refactor: use plugin_attr to fetch plugin attribute (#4377)
6c38fdf is described below
commit 6c38fdff9c76fd99d23fdb657a9656ee19680605
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Fri Jun 11 10:32:46 2021 +0800
refactor: use plugin_attr to fetch plugin attribute (#4377)
---
apisix/plugins/hmac-auth.lua | 6 +++---
apisix/plugins/log-rotate.lua | 5 ++---
apisix/plugins/prometheus.lua | 5 ++---
apisix/plugins/server-info.lua | 5 ++---
apisix/plugins/skywalking.lua | 12 +++++-------
5 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/apisix/plugins/hmac-auth.lua b/apisix/plugins/hmac-auth.lua
index 15e19a3..eca78a2 100644
--- a/apisix/plugins/hmac-auth.lua
+++ b/apisix/plugins/hmac-auth.lua
@@ -27,6 +27,7 @@ local escape_uri = ngx.escape_uri
local core = require("apisix.core")
local hmac = require("resty.hmac")
local consumer = require("apisix.consumer")
+local plugin = require("apisix.plugin")
local ngx_decode_base64 = ngx.decode_base64
local SIGNATURE_KEY = "X-HMAC-SIGNATURE"
@@ -334,15 +335,14 @@ end
local function get_params(ctx)
local params = {}
- local local_conf = core.config.local_conf()
local access_key = ACCESS_KEY
local signature_key = SIGNATURE_KEY
local algorithm_key = ALGORITHM_KEY
local date_key = DATE_KEY
local signed_headers_key = SIGNED_HEADERS_KEY
- local attr = core.table.try_read_attr(local_conf, "plugin_attr",
- "hmac-auth")
+
+ local attr = plugin.plugin_attr(plugin_name)
if attr then
access_key = attr.access_key or access_key
signature_key = attr.signature_key or signature_key
diff --git a/apisix/plugins/log-rotate.lua b/apisix/plugins/log-rotate.lua
index 4a03a80..e61c586 100644
--- a/apisix/plugins/log-rotate.lua
+++ b/apisix/plugins/log-rotate.lua
@@ -17,6 +17,7 @@
local core = require("apisix.core")
local timers = require("apisix.timers")
+local plugin = require("apisix.plugin")
local process = require("ngx.process")
local signal = require("resty.signal")
local ngx = ngx
@@ -152,11 +153,9 @@ end
local function rotate()
- local local_conf = core.config.local_conf()
local interval = INTERVAL
local max_kept = MAX_KEPT
- local attr = core.table.try_read_attr(local_conf, "plugin_attr",
- "log-rotate")
+ local attr = plugin.plugin_attr(plugin_name)
if attr then
interval = attr.interval or interval
max_kept = attr.max_kept or max_kept
diff --git a/apisix/plugins/prometheus.lua b/apisix/plugins/prometheus.lua
index 3aebf4e..1b9f6ef 100644
--- a/apisix/plugins/prometheus.lua
+++ b/apisix/plugins/prometheus.lua
@@ -16,6 +16,7 @@
--
local ngx = ngx
local core = require("apisix.core")
+local plugin = require("apisix.plugin")
local exporter = require("apisix.plugins.prometheus.exporter")
@@ -54,9 +55,7 @@ end
local function get_api(called_by_api_router)
local export_uri = default_export_uri
- local local_conf = core.config.local_conf()
- local attr = core.table.try_read_attr(local_conf, "plugin_attr",
- plugin_name)
+ local attr = plugin.plugin_attr(plugin_name)
if attr and attr.export_uri then
export_uri = attr.export_uri
end
diff --git a/apisix/plugins/server-info.lua b/apisix/plugins/server-info.lua
index 43f2768..e775c6d 100644
--- a/apisix/plugins/server-info.lua
+++ b/apisix/plugins/server-info.lua
@@ -17,6 +17,7 @@
local require = require
local core = require("apisix.core")
local timers = require("apisix.timers")
+local plugin = require("apisix.plugin")
local ngx_time = ngx.time
local ngx_timer_at = ngx.timer.at
@@ -209,9 +210,7 @@ function _M.init()
return
end
- local local_conf = core.config.local_conf()
- local attr = core.table.try_read_attr(local_conf, "plugin_attr",
- plugin_name)
+ local attr = plugin.plugin_attr(plugin_name)
local ok, err = core.schema.check(attr_schema, attr)
if not ok then
core.log.error("failed to check plugin_attr: ", err)
diff --git a/apisix/plugins/skywalking.lua b/apisix/plugins/skywalking.lua
index ec5b190..41fe814 100644
--- a/apisix/plugins/skywalking.lua
+++ b/apisix/plugins/skywalking.lua
@@ -14,13 +14,14 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-local sw_tracer = require("skywalking.tracer")
+local require = require
local core = require("apisix.core")
+local plugin = require("apisix.plugin")
local process = require("ngx.process")
+local sw_tracer = require("skywalking.tracer")
local Span = require("skywalking.span")
local ngx = ngx
local math = math
-local require = require
local plugin_name = "skywalking"
local attr_schema = {
@@ -112,11 +113,8 @@ function _M.init()
return
end
- local local_conf = core.config.local_conf()
- local local_plugin_info = core.table.try_read_attr(local_conf,
- "plugin_attr",
- plugin_name) or {}
- local_plugin_info = core.table.clone(local_plugin_info)
+ local local_plugin_info = plugin.plugin_attr(plugin_name)
+ local_plugin_info = local_plugin_info and core.table.clone(local_plugin_info) or {}
local ok, err = core.schema.check(attr_schema, local_plugin_info)
if not ok then
core.log.error("failed to check the plugin_attr[", plugin_name, "]",