mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-02 03:58:02 +08:00
feature: changed plugin_config to plugins. (#84)
This commit is contained in:
parent
10a0fb03f7
commit
c6e69cbcc9
@ -86,7 +86,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-count": {
|
||||
"count": 2,
|
||||
"time_window": 60,
|
||||
|
@ -85,7 +85,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-count": {
|
||||
"count": 2,
|
||||
"time_window": 60,
|
||||
|
@ -59,7 +59,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/100 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": "100",
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
@ -77,7 +77,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/100 -X PUT -d value='
|
||||
|uri |required |除了静态常量匹配,还支持正则 `/foo/{:\w+}/{:\w+}`,更多见 [lua-resty-libr3](https://github.com/iresty/lua-resty-libr3)|
|
||||
|id |required |必须与路径中的 `key` 保持一致|
|
||||
|methods |optional |如果为空或没有该选项,代表没有任何 `method` 限制,也可以是一个或多个组合:GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS。|
|
||||
|plugin_config|required |启用的插件配置,详见 [Plugin](#plugin) |
|
||||
|plugins|required |启用的插件配置,详见 [Plugin](#plugin) |
|
||||
|upstream|required |启用的上游配置,详见 [Upstream](#upstream)|
|
||||
|service_id|optional |绑定的 Service 配置,详见 [Service](#service)|
|
||||
|
||||
@ -98,7 +98,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/100 -X PUT -d value='
|
||||
curl http://127.0.0.1:2379/v2/keys/apisix/services/200 -X PUT -d value='
|
||||
{
|
||||
"id": "200",
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-count": {
|
||||
"count": 2,
|
||||
"time_window": 60,
|
||||
@ -140,7 +140,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/102 -X PUT -d value='
|
||||
"uri": "/bar/index.html",
|
||||
"id": "102",
|
||||
"service_id": "200",
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-count": {
|
||||
"count": 2000,
|
||||
"time_window": 60,
|
||||
@ -178,13 +178,13 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/102 -X PUT -d value='
|
||||
一个插件在一次请求中只会执行一次,即使被同时绑定到多个不同对象中(比如 route 或 service)。
|
||||
插件运行先后顺序是根据插件自身的优先级来决定的,例如:[example-plugin](../lua/apisix/plugins/example-plugin.lua#L16)。
|
||||
|
||||
插件配置作为 route 或 service 的一部分提交的,放到 `plugin_config` 下。它内部是使用插件
|
||||
插件配置作为 route 或 service 的一部分提交的,放到 `plugins` 下。它内部是使用插件
|
||||
名字作为哈希的 key 来保存不同插件的配置项。
|
||||
|
||||
```json
|
||||
{
|
||||
...
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-count": {
|
||||
"count": 2,
|
||||
"time_window": 60,
|
||||
@ -258,7 +258,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"id": "2"
|
||||
@ -274,7 +274,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-count": {
|
||||
"count": 2,
|
||||
"time_window": 60,
|
||||
|
@ -30,7 +30,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/hello",
|
||||
"id": 1,
|
||||
"plugin_config": {},
|
||||
"plugins": {},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
"nodes": {
|
||||
@ -73,7 +73,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/hello",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-count": {
|
||||
"count": 999999999,
|
||||
"time_window": 60,
|
||||
|
@ -9,7 +9,7 @@ local schema_desc = [[{
|
||||
"enum": ["GET", "PUT", "POST", "DELETE"]
|
||||
}
|
||||
},
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"type": "object"
|
||||
},
|
||||
"upstream": {
|
||||
@ -22,21 +22,13 @@ local schema_desc = [[{
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"nodes",
|
||||
"type"
|
||||
]
|
||||
"required": ["nodes", "type"]
|
||||
},
|
||||
"uri": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"methods",
|
||||
"plugin_config",
|
||||
"upstream",
|
||||
"uri"
|
||||
]
|
||||
"required": ["upstream", "uri"]
|
||||
}]]
|
||||
|
||||
|
||||
|
@ -14,7 +14,7 @@ local _M = {
|
||||
--[[
|
||||
{
|
||||
"id": "ShunFeng",
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"key-auth": {
|
||||
"key": "dddxxyyy"
|
||||
}
|
||||
@ -41,7 +41,7 @@ local function plugin_consumer()
|
||||
|
||||
for _, consumer in ipairs(consumers.values) do
|
||||
-- log.warn("consumer: ", require("cjson").encode(consumer))
|
||||
for name, conf in pairs(consumer.value.plugin_config) do
|
||||
for name, conf in pairs(consumer.value.plugins) do
|
||||
if not plugins[name] then
|
||||
plugins[name] = {
|
||||
nodes = {},
|
||||
|
@ -102,7 +102,7 @@ end
|
||||
function _M.filter(user_routes)
|
||||
-- todo: reuse table
|
||||
local plugins = core.table.new(#local_supported_plugins * 2, 0)
|
||||
local user_plugin_conf = user_routes.value.plugin_config
|
||||
local user_plugin_conf = user_routes.value.plugins
|
||||
|
||||
for _, plugin_obj in ipairs(local_supported_plugins) do
|
||||
local name = plugin_obj.name
|
||||
@ -120,10 +120,10 @@ end
|
||||
|
||||
function _M.merge_service_route(service_conf, route_conf)
|
||||
local changed = false
|
||||
if route_conf.value.plugin_config and
|
||||
core.table.nkeys(route_conf.value.plugin_config) then
|
||||
for name, conf in pairs(route_conf.value.plugin_config) do
|
||||
service_conf.value.plugin_config[name] = conf
|
||||
if route_conf.value.plugins and
|
||||
core.table.nkeys(route_conf.value.plugins) then
|
||||
for name, conf in pairs(route_conf.value.plugins) do
|
||||
service_conf.value.plugins[name] = conf
|
||||
end
|
||||
changed = true
|
||||
end
|
||||
|
@ -26,7 +26,7 @@
|
||||
curl http://127.0.0.1:2379/v2/keys/apisix/consumers/ShunFeng -X PUT -d value='
|
||||
{
|
||||
"id": "ShunFeng",
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"key-auth": {
|
||||
"key": "keykey"
|
||||
}
|
||||
@ -42,7 +42,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"key-auth": {}
|
||||
},
|
||||
"upstream": {
|
||||
@ -88,7 +88,7 @@ $ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
|
@ -28,7 +28,7 @@ Two steps are required:
|
||||
curl http://127.0.0.1:2379/v2/keys/apisix/consumers/ShunFeng -X PUT -d value='
|
||||
{
|
||||
"id": "ShunFeng",
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"key-auth": {
|
||||
"key": "keykey"
|
||||
}
|
||||
@ -44,7 +44,7 @@ Two steps are required:
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"key-auth": {}
|
||||
},
|
||||
"upstream": {
|
||||
@ -92,7 +92,7 @@ $ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
|
@ -24,7 +24,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-conn": {
|
||||
"conn": 1,
|
||||
"burst": 0,
|
||||
@ -71,7 +71,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
|
@ -24,7 +24,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-conn": {
|
||||
"conn": 1,
|
||||
"burst": 0,
|
||||
@ -73,7 +73,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
|
@ -21,7 +21,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-count": {
|
||||
"count": 2,
|
||||
"time_window": 60,
|
||||
@ -83,7 +83,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
|
@ -18,7 +18,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-count": {
|
||||
"count": 2,
|
||||
"time_window": 60,
|
||||
@ -82,7 +82,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
|
@ -20,7 +20,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-req": {
|
||||
"rate": 1,
|
||||
"burst": 2,
|
||||
@ -71,7 +71,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
|
@ -20,7 +20,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"limit-req": {
|
||||
"rate": 1,
|
||||
"burst": 2,
|
||||
@ -72,7 +72,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/index.html",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
},
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
|
@ -21,7 +21,7 @@ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
|
||||
"methods": ["GET"],
|
||||
"uri": "/hello",
|
||||
"id": 1,
|
||||
"plugin_config": {
|
||||
"plugins": {
|
||||
"prometheus":{}
|
||||
},
|
||||
"upstream": {
|
||||
|
@ -19,7 +19,7 @@ __DATA__
|
||||
ngx.HTTP_PUT,
|
||||
[[{
|
||||
"methods": ["GET"],
|
||||
"plugin_config": {},
|
||||
"plugins": {},
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
@ -35,7 +35,7 @@ __DATA__
|
||||
"GET"
|
||||
],
|
||||
"uri": "/index.html",
|
||||
"plugin_config": {},
|
||||
"plugins": {},
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
@ -77,7 +77,7 @@ passed
|
||||
"GET"
|
||||
],
|
||||
"uri": "/index.html",
|
||||
"plugin_config": {},
|
||||
"plugins": {},
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
@ -161,7 +161,7 @@ GET /t
|
||||
ngx.HTTP_POST,
|
||||
[[{
|
||||
"methods": ["GET"],
|
||||
"plugin_config": {},
|
||||
"plugins": {},
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
@ -177,7 +177,7 @@ GET /t
|
||||
"GET"
|
||||
],
|
||||
"uri": "/index.html",
|
||||
"plugin_config": {},
|
||||
"plugins": {},
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
|
@ -173,7 +173,7 @@ qr/module 'apisix.plugins.not-exist-plugin' not found/
|
||||
|
||||
local filter_plugins = plugin.filter({
|
||||
value = {
|
||||
plugin_config = {
|
||||
plugins = {
|
||||
["example-plugin"] = {i = 1, s = "s", t = {1, 2}},
|
||||
["new-plugin"] = {a = "a"},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user