apisix icon indicating copy to clipboard operation
apisix copied to clipboard

feat: As a user, I want to check the subordinate relationship in the Admin API

Open spacewander opened this issue 3 years ago • 3 comments

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:

  1. validate if the stream route with superior id exists and its protocol matches the subordinate
  2. when deleting a stream route, check if it is referenced by another stream route

spacewander avatar Apr 27 '22 01:04 spacewander

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.

ro4i7 avatar Mar 12 '23 14:03 ro4i7

You could submit a PR with test added to it.

spacewander avatar Mar 13 '23 03:03 spacewander

You could submit a PR with test added to it.

@spacewander @starsz @navendu-pottekkat Please check #9116

ro4i7 avatar Mar 20 '23 11:03 ro4i7