mirror of
https://gitee.com/iresty/apisix.git
synced 2024-11-29 18:48:31 +08:00
chore(plugin): add scope equals to global attribute for some plugins (#5126)
This commit is contained in:
parent
31fe0ff1d9
commit
0e72b67762
@ -48,6 +48,7 @@ function _M.get(name)
|
||||
metadata_schema = true,
|
||||
consumer_schema = true,
|
||||
type = true,
|
||||
scope = true,
|
||||
})
|
||||
|
||||
if arg["subsystem"] == "stream" then
|
||||
|
@ -37,6 +37,7 @@ function _M.schema()
|
||||
metadata_schema = true,
|
||||
consumer_schema = true,
|
||||
type = true,
|
||||
scope = true,
|
||||
})
|
||||
local schema = {
|
||||
main = {
|
||||
|
@ -120,6 +120,7 @@ local _M = {
|
||||
schema = schema,
|
||||
metadata_schema = metadata_schema,
|
||||
attr_schema = attr_schema,
|
||||
scope = "global",
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,6 +110,7 @@ local _M = {
|
||||
name = plugin_name,
|
||||
schema = schema,
|
||||
metadata_schema = metadata_schema,
|
||||
scope = "global",
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,6 +48,7 @@ local _M = {
|
||||
priority = 100,
|
||||
name = plugin_name,
|
||||
schema = schema,
|
||||
scope = "global",
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,6 +33,7 @@ local _M = {
|
||||
priority = 1000,
|
||||
name = plugin_name,
|
||||
schema = schema,
|
||||
scope = "global",
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,6 +63,7 @@ local _M = {
|
||||
priority = 990,
|
||||
name = plugin_name,
|
||||
schema = schema,
|
||||
scope = "global",
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,8 +35,8 @@ http {
|
||||
listen 1980;
|
||||
|
||||
access_log off;
|
||||
location = /hello {
|
||||
echo_duplicate 400 "1234567890";
|
||||
location / {
|
||||
echo_duplicate 1 "1234567890";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,27 +60,6 @@ plugins: # plugin list
|
||||
|
||||
After starting `APISIX`, you can get status information through the API `/apisix/status`.
|
||||
|
||||
2. Create a route object, and enable plugin `node-status`.
|
||||
|
||||
```sh
|
||||
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
|
||||
{
|
||||
"uri": "/route1",
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
"nodes": {
|
||||
"192.168.1.100:80:": 1
|
||||
}
|
||||
},
|
||||
"plugins": {
|
||||
"node-status":{}
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
You have to configure `node-status` in the configuration file `apisix/conf/config.yaml` before creating a route like this.
|
||||
And this plugin will not make any difference in future requests, so usually we don't set this plugin when creating routes.
|
||||
|
||||
## Test Plugin
|
||||
|
||||
1. Request with uri `/apisix/status`
|
||||
|
@ -58,26 +58,6 @@ plugins: # plugin list
|
||||
|
||||
启动 `APISIX` 之后,即可访问该插件提供的接口,获得基本的状态信息。
|
||||
|
||||
2. 在创建 route 时添加插件 `node-status`
|
||||
|
||||
```sh
|
||||
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
|
||||
{
|
||||
"uri": "/route1",
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
"nodes": {
|
||||
"192.168.1.100:80:": 1
|
||||
}
|
||||
},
|
||||
"plugins": {
|
||||
"node-status":{}
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
发送该请求的前提是 `apisix/conf/config.yaml` 中已经配置 `node-status`,此时 `node-status` 插件对该请求处理无影响,所以一般不会将 `node-status` 插件设置到路由中。
|
||||
|
||||
## 测试插件
|
||||
|
||||
1. 发送请求
|
||||
|
44
t/admin/plugins.t
vendored
44
t/admin/plugins.t
vendored
@ -301,3 +301,47 @@ qr/\{"properties":\{"password":\{"type":"string"\},"username":\{"type":"string"\
|
||||
{"priority":1003,"schema":{"$comment":"this is a mark for our injected plugin schema","properties":{"burst":{"minimum":0,"type":"integer"},"conn":{"exclusiveMinimum":0,"type":"integer"},"default_conn_delay":{"exclusiveMinimum":0,"type":"number"},"disable":{"type":"boolean"},"key":{"enum":["remote_addr","server_addr"],"type":"string"},"only_use_default_delay":{"default":false,"type":"boolean"}},"required":["conn","burst","default_conn_delay","key"],"type":"object"},"version":0.1}
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 12: confirm the scope of plugin
|
||||
--- yaml_config
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
admin_key: null
|
||||
plugins:
|
||||
- batch-requests
|
||||
- error-log-logger
|
||||
- server-info
|
||||
- example-plugin
|
||||
- node-status
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local json = require("toolkit.json")
|
||||
local t = require("lib.test_admin").test
|
||||
|
||||
local code, message, res = t('/apisix/admin/plugins?all=true',
|
||||
ngx.HTTP_GET
|
||||
)
|
||||
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
ngx.say(message)
|
||||
return
|
||||
end
|
||||
|
||||
res = json.decode(res)
|
||||
local global_plugins = {}
|
||||
for k, v in pairs(res) do
|
||||
if v.scope == "global" then
|
||||
global_plugins[k] = v.scope
|
||||
end
|
||||
end
|
||||
ngx.say(json.encode(global_plugins))
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
{"batch-requests":"global","error-log-logger":"global","node-status":"global","server-info":"global"}
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
43
t/control/schema.t
vendored
43
t/control/schema.t
vendored
@ -98,3 +98,46 @@ __DATA__
|
||||
}
|
||||
--- response_body
|
||||
passed
|
||||
|
||||
|
||||
|
||||
=== TEST 2: confirm the scope of plugin
|
||||
--- yaml_config
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
admin_key: null
|
||||
plugins:
|
||||
- batch-requests
|
||||
- error-log-logger
|
||||
- server-info
|
||||
- example-plugin
|
||||
- node-status
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local json = require("toolkit.json")
|
||||
local t = require("lib.test_admin").test
|
||||
|
||||
local code, message, res = t('/v1/schema',
|
||||
ngx.HTTP_GET
|
||||
)
|
||||
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
ngx.say(message)
|
||||
return
|
||||
end
|
||||
|
||||
res = json.decode(res)
|
||||
local global_plugins = {}
|
||||
local plugins = res["plugins"]
|
||||
for k, v in pairs(plugins) do
|
||||
if v.scope == "global" then
|
||||
global_plugins[k] = v.scope
|
||||
end
|
||||
end
|
||||
ngx.say(json.encode(global_plugins))
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
{"batch-requests":"global","error-log-logger":"global","node-status":"global","server-info":"global"}
|
||||
|
Loading…
Reference in New Issue
Block a user