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: filter fields supported by all objects #7391

Merged
merged 3 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
76 changes: 70 additions & 6 deletions apisix/admin/v3_adapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ local request = require("apisix.core.request")
local response = require("apisix.core.response")
local table = require("apisix.core.table")
local tonumber = tonumber
local re_find = ngx.re.find
local pairs = pairs

local _M = {}

Expand Down Expand Up @@ -81,12 +83,7 @@ local function sort(l, r)
end


function _M.filter(body)
if not enable_v3() then
return
end

local args = request.get_uri_args()
local function pagination(body, args)
args.page = tonumber(args.page)
args.page_size = tonumber(args.page_size)
if not args.page or not args.page_size then
Expand Down Expand Up @@ -122,4 +119,71 @@ function _M.filter(body)
end


local function filter(body, args)
if not args.name and not args.label and not args.uri then
return
end

for i = #body.list, 1, -1 do
local name_matched = true
local label_matched = true
local uri_matched = true
if args.name then
name_matched = false
local matched = re_find(body.list[i].value.name, args.name, "jo")
if matched then
name_matched = true
end
end

if args.label then
label_matched = false
if body.list[i].value.labels then
for k, _ in pairs(body.list[i].value.labels) do
if k == args.label then
label_matched = true
break
end
end
end
end

if args.uri then
uri_matched = false
if body.list[i].value.uri then
local matched = re_find(body.list[i].value.uri, args.uri, "jo")
if matched then
uri_matched = true
end
end

if body.list[i].value.uris then
for _, uri in pairs(body.list[i].value.uris) do
if re_find(uri, args.uri, "jo") then
uri_matched = true
break
end
end
end
end

if not name_matched or not label_matched or not uri_matched then
table.remove(body.list, i)
end
end
end


function _M.filter(body)
if not enable_v3() then
return
end

local args = request.get_uri_args()

pagination(body, args)
filter(body, args)
end


return _M
Loading