-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: validate the subordinate and check reference when deleting and adding… #8219
Changes from 56 commits
5d10f41
734b43f
4f13eed
f0f6ff9
9168493
cc276f7
7db5790
34f79d2
4dde2e9
cba2083
94cdf53
b6cc11e
bb5a2a5
f04b2c5
475007e
527110c
9f08dbb
02709ab
4ecd49f
3c7d4d3
dee8669
5aec5cb
1ae67e6
9f56771
71c0f89
2fc55c9
e1894f8
63f4d7b
775fff0
f322e4f
b5dba07
d69ce76
f6d98e2
a64bb1e
2854be0
ed245b5
c15e3e6
49609a7
3205a75
0cbd892
573578d
09e34e7
8ab326c
9b1533d
63ff87f
11315d8
23d4ace
5f4c836
aafaaf2
be47504
9289dd7
3f85069
d9f3a0a
dbd0e02
1517c85
cd17fcc
401ba10
2c0a1b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,17 +14,41 @@ | |
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
-- | ||
local require = require | ||
local core = require("apisix.core") | ||
local utils = require("apisix.admin.utils") | ||
local iterate_values = require("apisix.core.config_util").iterate_values | ||
local stream_route_checker = require("apisix.stream.router.ip_port").stream_route_checker | ||
local routes = require("apisix.stream.router.ip_port").routes | ||
local tostring = tostring | ||
local table = table | ||
|
||
|
||
local _M = { | ||
version = 0.1, | ||
need_v3_filter = true, | ||
} | ||
|
||
local function check_router_refer(items, id) | ||
local warn_message = nil | ||
local refer_list = core.tablepool.fetch("refer_list", #items, 0) | ||
for _, item in iterate_values(items) do | ||
if item.value == nil then | ||
goto CONTINUE | ||
end | ||
local route = item.value | ||
if route.protocol and route.protocol.superior_id and route.protocol.superior_id == id then | ||
table.insert(refer_list, item["key"]) | ||
end | ||
::CONTINUE:: | ||
end | ||
if #refer_list > 0 then | ||
warn_message = "/stream_routes/" .. id .. " is referred by " | ||
.. table.concat(refer_list,",") | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
core.tablepool.release("refer_list", refer_list) | ||
return warn_message | ||
end | ||
|
||
local function check_conf(id, conf, need_id) | ||
if not conf then | ||
|
@@ -142,6 +166,14 @@ function _M.delete(id) | |
return 400, {error_msg = "missing stream route id"} | ||
end | ||
|
||
local items, _ = routes() | ||
if items ~= nil then | ||
local warn_message = check_router_refer(items, id) | ||
if warn_message ~= nil then | ||
return 400, warn_message | ||
end | ||
end | ||
|
||
local key = "/stream_routes/" .. id | ||
-- core.log.info("key: ", key) | ||
local res, err = core.etcd.delete(key) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -607,3 +607,51 @@ GET /t | |
{"error_msg":"unknown protocol [xxx]"} | ||
passed | ||
{"error_msg":"property \"faults\" validation failed: wrong type: expected array, got string"} | ||
--- no_error_log | ||
[error] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need three blank lines between test cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
|
||
|
||
=== TEST 17: put reference route + delete | ||
--- extra_yaml_config | ||
xrpc: | ||
protocols: | ||
- name: pingpong | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/stream_routes/12', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"remote_addr": "127.0.0.1", | ||
"desc": "test-refer", | ||
"upstream": { | ||
"nodes": { | ||
"127.0.0.1:8080": 1 | ||
}, | ||
"type": "roundrobin" | ||
}, | ||
"protocol": { | ||
"name": "pingpong", | ||
"superior_id": "1" | ||
} | ||
}]] | ||
) | ||
if code > 300 then | ||
ngx.status = code | ||
ngx.print(body) | ||
return | ||
end | ||
ngx.sleep(2) | ||
|
||
local code2, message = t('/apisix/admin/stream_routes/1', ngx.HTTP_DELETE) | ||
ngx.say("[delete] code: ", code2, " message: ", message) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
[delete] code: 400 message: /stream_routes/1 is referred by /apisix/stream_routes/12 | ||
--- no_error_log | ||
[error] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does module "apisix.router" export the filter function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry