apisix
apisix copied to clipboard
feat: As a user, I want to check the subordinate relationship in the Admin API
Description
See https://github.com/apache/apisix/blob/dbe7eeebba06229d4a8df75263f2a78301cc1ca0/apisix/stream/router/ip_port.lua#L82
We need to check the subordinate relationship in the Admin API, including:
- validate if the stream route with superior id exists and its protocol matches the subordinate
- when deleting a stream route, check if it is referenced by another stream route
Hello @spacewander @lijing-21
if this is still open, please consider my solution.
May be replacing code from line 79 to line number 84 in apisix/apisix/stream/router/ip_port.lua with below code may solve this issue:
local route = item.value
if route.protocol and route.protocol.superior_id then
local admin_api = require("apisix.admin").check_http_admin()
if not admin_api then
ngx.log(ngx.ERR, "failed to get http admin node")
goto CONTINUE
end
local route_id = route.id
local superior_id = route.protocol.superior_id
local res, err = admin_api:get("/stream/routes/" .. superior_id)
if not res then
ngx.log(ngx.ERR, "failed to fetch superior stream route: ", err)
goto CONTINUE
end
if res.body.data and res.body.data.protocol == route.protocol then
ngx.log(ngx.INFO, "matched stream route with superior id: ", superior_id)
else
ngx.log(ngx.ERR, "failed to match stream route with superior id: ", superior_id)
goto CONTINUE
end
-- TODO: when deleting a stream route, check if it is referenced by another stream route
end
please, give me feedback on this.
You could submit a PR with test added to it.
You could submit a PR with test added to it.
@spacewander @starsz @navendu-pottekkat Please check #9116