Skip to content
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

Closed
Closed
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
5d10f41
validate the subordinate and check reference when deleting a stream …
Oct 31, 2022
734b43f
validate the subordinate and check reference when deleting a stream …
Oct 31, 2022
4f13eed
validate the subordinate and check reference when deleting a stream …
Oct 31, 2022
f0f6ff9
validate the subordinate and check reference when deleting a stream …
Oct 31, 2022
9168493
add test cases to check res.refer
Nov 1, 2022
cc276f7
fix cache in refer
Nov 1, 2022
7db5790
fix some bugs
Nov 2, 2022
34f79d2
fix (ci check fail)
Nov 3, 2022
4dde2e9
fix (ci check fail)
Nov 3, 2022
cba2083
format
Nov 4, 2022
94cdf53
another imp no etcd
Nov 5, 2022
b6cc11e
another imp no etcd
Nov 5, 2022
bb5a2a5
fix errors in CI stage
Nov 6, 2022
f04b2c5
style:
Nov 7, 2022
475007e
revise tablepool
Nov 7, 2022
527110c
Update stream_routes.lua
biakewe Nov 8, 2022
9f08dbb
drop trailing whitespace
Nov 9, 2022
02709ab
fix test case
Nov 9, 2022
4ecd49f
fix test case
Nov 9, 2022
3c7d4d3
fix test case
Nov 9, 2022
dee8669
fix test case
Nov 9, 2022
5aec5cb
fix APISIX.PM
Nov 10, 2022
1ae67e6
fix APISIX.PM
Nov 10, 2022
9f56771
debug
Nov 10, 2022
71c0f89
Get stream_routes from etcd directly
Nov 11, 2022
2fc55c9
Get stream_routes from etcd directly
Nov 11, 2022
e1894f8
Update stream-routes.t
biakewe Nov 11, 2022
63f4d7b
update
Nov 14, 2022
775fff0
Merge branch 'check-the-subordinate-relationship' of https://github.c…
Nov 14, 2022
f322e4f
Validate if the protocol matches the subordinate only if the stream r…
Nov 14, 2022
b5dba07
Validate if the protocol matches the subordinate only if the stream r…
Nov 14, 2022
d69ce76
Validate if the protocol matches the subordinate only if the stream r…
Nov 14, 2022
f6d98e2
fix
Nov 14, 2022
a64bb1e
fix
Nov 14, 2022
2854be0
fix
Nov 14, 2022
ed245b5
fix
Nov 14, 2022
c15e3e6
fix
Nov 14, 2022
49609a7
fix
Nov 14, 2022
3205a75
fix
Nov 14, 2022
0cbd892
debug test case
Nov 14, 2022
573578d
debug test case
Nov 14, 2022
09e34e7
debug test case
Nov 14, 2022
8ab326c
update
Nov 14, 2022
9b1533d
fix indent
Nov 15, 2022
63ff87f
no-etcd implementation
Nov 16, 2022
11315d8
no-etcd implementation
Nov 16, 2022
23d4ace
no-etcd implementation
Nov 16, 2022
5f4c836
update test case
Nov 17, 2022
aafaaf2
update test case
Nov 17, 2022
be47504
update init
Nov 17, 2022
9289dd7
update init
Nov 17, 2022
3f85069
update init
Nov 17, 2022
d9f3a0a
update admin.init
Nov 18, 2022
dbd0e02
update admin.init
Nov 18, 2022
1517c85
update
Nov 21, 2022
cd17fcc
Merge branch 'master' into check-the-subordinate-relationship
biakewe Nov 23, 2022
401ba10
update
Nov 24, 2022
2c0a1b1
Merge branch 'check-the-subordinate-relationship' of https://github.c…
Nov 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apisix/admin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-- limitations under the License.
--
local require = require
local filter = require("apisix.router").filter
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry

local core = require("apisix.core")
local route = require("apisix.utils.router")
local plugin = require("apisix.plugin")
Expand Down Expand Up @@ -351,6 +352,11 @@ function _M.init_worker()
return
end

if local_conf.apisix.stream_proxy then
local router_stream = require("apisix.stream.router.ip_port")
router_stream.stream_init_worker(filter)
end

router = route.new(uri_route)
events = require("resty.worker.events")

Expand Down
32 changes: 32 additions & 0 deletions apisix/admin/stream_routes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add core.tablepool.release("refer_list",refer_list) before return nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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)
Expand Down
48 changes: 48 additions & 0 deletions t/admin/stream-routes.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need three blank lines between test cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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]