Skip to content

Commit

Permalink
feat: remove useless field in Admin API v3 (apache#7778)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 authored and Liu-Junlin committed Nov 4, 2022
1 parent 76aab85 commit 377f9dc
Show file tree
Hide file tree
Showing 50 changed files with 1,653 additions and 1,882 deletions.
3 changes: 1 addition & 2 deletions apisix/admin/consumers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ local core = require("apisix.core")
local plugins = require("apisix.admin.plugins")
local utils = require("apisix.admin.utils")
local plugin = require("apisix.plugin")
local v3_adapter = require("apisix.admin.v3_adapter")
local pairs = pairs

local _M = {
version = 0.1,
need_v3_filter = true,
}


Expand Down Expand Up @@ -103,7 +103,6 @@ function _M.get(consumer_name)
end

utils.fix_count(res.body, consumer_name)
v3_adapter.filter(res.body)
return res.status, res.body
end

Expand Down
3 changes: 1 addition & 2 deletions apisix/admin/global_rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
local core = require("apisix.core")
local utils = require("apisix.admin.utils")
local schema_plugin = require("apisix.admin.plugins").check_schema
local v3_adapter = require("apisix.admin.v3_adapter")
local type = type
local tostring = tostring


local _M = {
version = 0.1,
need_v3_filter = true,
}


Expand Down Expand Up @@ -98,7 +98,6 @@ function _M.get(id)
end

utils.fix_count(res.body, id)
v3_adapter.filter(res.body)
return res.status, res.body
end

Expand Down
5 changes: 5 additions & 0 deletions apisix/admin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ local function run()
else
core.response.set_header("X-API-VERSION", "v2")
end
if resource.need_v3_filter then
data = v3_adapter.filter(data)
end

data = strip_etcd_resp(data)

core.response.exit(code, data)
end
end
Expand Down
3 changes: 1 addition & 2 deletions apisix/admin/plugin_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ local core = require("apisix.core")
local get_routes = require("apisix.router").http_routes
local utils = require("apisix.admin.utils")
local schema_plugin = require("apisix.admin.plugins").check_schema
local v3_adapter = require("apisix.admin.v3_adapter")
local type = type
local tostring = tostring
local ipairs = ipairs


local _M = {
need_v3_filter = true,
}


Expand Down Expand Up @@ -98,7 +98,6 @@ function _M.get(id)
end

utils.fix_count(res.body, id)
v3_adapter.filter(res.body)
return res.status, res.body
end

Expand Down
3 changes: 1 addition & 2 deletions apisix/admin/proto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ local utils = require("apisix.admin.utils")
local get_routes = require("apisix.router").http_routes
local get_services = require("apisix.http.service").services
local compile_proto = require("apisix.plugins.grpc-transcode.proto").compile_proto
local v3_adapter = require("apisix.admin.v3_adapter")
local tostring = tostring


local _M = {
version = 0.1,
need_v3_filter = true,
}


Expand Down Expand Up @@ -100,7 +100,6 @@ function _M.get(id)
end

utils.fix_count(res.body, id)
v3_adapter.filter(res.body)
return res.status, res.body
end

Expand Down
3 changes: 1 addition & 2 deletions apisix/admin/routes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ local core = require("apisix.core")
local apisix_upstream = require("apisix.upstream")
local schema_plugin = require("apisix.admin.plugins").check_schema
local utils = require("apisix.admin.utils")
local v3_adapter = require("apisix.admin.v3_adapter")
local tostring = tostring
local type = type
local loadstring = loadstring


local _M = {
version = 0.2,
need_v3_filter = true,
}


Expand Down Expand Up @@ -204,7 +204,6 @@ function _M.get(id)
end

utils.fix_count(res.body, id)
v3_adapter.filter(res.body)
return res.status, res.body
end

Expand Down
3 changes: 1 addition & 2 deletions apisix/admin/services.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ local get_routes = require("apisix.router").http_routes
local apisix_upstream = require("apisix.upstream")
local schema_plugin = require("apisix.admin.plugins").check_schema
local utils = require("apisix.admin.utils")
local v3_adapter = require("apisix.admin.v3_adapter")
local tostring = tostring
local ipairs = ipairs
local type = type
Expand All @@ -28,6 +27,7 @@ local loadstring = loadstring

local _M = {
version = 0.3,
need_v3_filter = true,
}


Expand Down Expand Up @@ -147,7 +147,6 @@ function _M.get(id)
end

utils.fix_count(res.body, id)
v3_adapter.filter(res.body)
return res.status, res.body
end

Expand Down
3 changes: 1 addition & 2 deletions apisix/admin/ssl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
local core = require("apisix.core")
local utils = require("apisix.admin.utils")
local apisix_ssl = require("apisix.ssl")
local v3_adapter = require("apisix.admin.v3_adapter")
local tostring = tostring
local type = type

local _M = {
version = 0.1,
need_v3_filter = true,
}


Expand Down Expand Up @@ -108,7 +108,6 @@ function _M.get(id)
end

utils.fix_count(res.body, id)
v3_adapter.filter(res.body)
return res.status, res.body
end

Expand Down
3 changes: 1 addition & 2 deletions apisix/admin/stream_routes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
local core = require("apisix.core")
local utils = require("apisix.admin.utils")
local stream_route_checker = require("apisix.stream.router.ip_port").stream_route_checker
local v3_adapter = require("apisix.admin.v3_adapter")
local tostring = tostring


local _M = {
version = 0.1,
need_v3_filter = true,
}


Expand Down Expand Up @@ -115,7 +115,6 @@ function _M.get(id)
end

utils.fix_count(res.body, id)
v3_adapter.filter(res.body)
return res.status, res.body
end

Expand Down
3 changes: 1 addition & 2 deletions apisix/admin/upstreams.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ local get_routes = require("apisix.router").http_routes
local get_services = require("apisix.http.service").services
local apisix_upstream = require("apisix.upstream")
local utils = require("apisix.admin.utils")
local v3_adapter = require("apisix.admin.v3_adapter")
local tostring = tostring
local ipairs = ipairs
local type = type


local _M = {
version = 0.2,
need_v3_filter = true,
}


Expand Down Expand Up @@ -100,7 +100,6 @@ function _M.get(id)
end

utils.fix_count(res.body, id)
v3_adapter.filter(res.body)
return res.status, res.body
end

Expand Down
29 changes: 27 additions & 2 deletions apisix/admin/v3_adapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

local fetch_local_conf = require("apisix.core.config_local").local_conf
local try_read_attr = require("apisix.core.table").try_read_attr
local deepcopy = require("apisix.core.table").deepcopy
local log = require("apisix.core.log")
local request = require("apisix.core.request")
local response = require("apisix.core.response")
Expand Down Expand Up @@ -180,9 +181,33 @@ function _M.filter(body)
end

local args = request.get_uri_args()
local processed_body = deepcopy(body)

pagination(body, args)
filter(body, args)
if processed_body.deleted then
processed_body.node = nil
end

-- strip node wrapping for single query, create, and update scenarios.
if processed_body.node then
processed_body = processed_body.node
end

-- filter and paging logic for list query only
if processed_body.list then
filter(processed_body, args)

-- calculate the total amount of filtered data
processed_body.total = processed_body.list and #processed_body.list or 0

pagination(processed_body, args)

-- remove the count field returned by etcd
-- we don't need a field that reflects the length of the currently returned data,
-- it doesn't make sense
processed_body.count = nil
end

return processed_body
end


Expand Down
85 changes: 39 additions & 46 deletions t/admin/consumers.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ __DATA__
"desc": "new consumer"
}]],
[[{
"node": {
"value": {
"username": "jack",
"desc": "new consumer"
}
}
"value": {
"username": "jack",
"desc": "new consumer"
},
"key": "/apisix/consumers/jack"
}]]
)

Expand Down Expand Up @@ -85,17 +84,16 @@ passed
}
}]],
[[{
"node": {
"value": {
"username": "jack",
"desc": "new consumer",
"plugins": {
"key-auth": {
"key": "auth-one"
}
"value": {
"username": "jack",
"desc": "new consumer",
"plugins": {
"key-auth": {
"key": "auth-one"
}
}
}
},
"key": "/apisix/consumers/jack"
}]]
)

Expand Down Expand Up @@ -127,17 +125,16 @@ passed
ngx.HTTP_GET,
nil,
[[{
"node": {
"value": {
"username": "jack",
"desc": "new consumer",
"plugins": {
"key-auth": {
"key": "auth-one"
}
"value": {
"username": "jack",
"desc": "new consumer",
"plugins": {
"key-auth": {
"key": "auth-one"
}
}
}
},
"key": "/apisix/consumers/jack"
}]]
)

Expand Down Expand Up @@ -209,10 +206,8 @@ GET /t
"id":"jack"
}]],
[[{
"node": {
"value": {
"id": "jack"
}
"value": {
"id": "jack"
}
}]]
)
Expand Down Expand Up @@ -248,17 +243,16 @@ GET /t
}
}]],
[[{
"node": {
"value": {
"username": "jack",
"desc": "new consumer",
"labels": {
"build":"16",
"env":"production",
"version":"v2"
}
"value": {
"username": "jack",
"desc": "new consumer",
"labels": {
"build":"16",
"env":"production",
"version":"v2"
}
}
},
"key": "/apisix/consumers/jack"
}]]
)

Expand Down Expand Up @@ -343,14 +337,13 @@ GET /t
"update_time": 1602893670
}]],
[[{
"node": {
"value": {
"username": "pony",
"desc": "new consumer",
"create_time": 1602883670,
"update_time": 1602893670
}
}
"value": {
"username": "pony",
"desc": "new consumer",
"create_time": 1602883670,
"update_time": 1602893670
},
"key": "/apisix/consumers/pony"
}]]
)

Expand Down
Loading

0 comments on commit 377f9dc

Please sign in to comment.