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

change: adjust response format for V3 feature #7630

Merged
merged 9 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
13 changes: 7 additions & 6 deletions apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,15 @@ local function load_full_data(self, dir_res, headers)
self:upgrade_version(item.modifiedIndex)

else
if not dir_res.nodes then
dir_res.nodes = {}
local values = (dir_res and dir_res.nodes) or dir_res
tzssangglass marked this conversation as resolved.
Show resolved Hide resolved
if not values then
values = {}
end

self.values = new_tab(#dir_res.nodes, 0)
self.values_hash = new_tab(0, #dir_res.nodes)
self.values = new_tab(#values, 0)
self.values_hash = new_tab(0, #values)

for _, item in ipairs(dir_res.nodes) do
for _, item in ipairs(values) do
local key = short_key(self, item.key)
local data_valid = true
if type(item.value) ~= "table" then
Expand Down Expand Up @@ -302,7 +303,7 @@ local function sync_data(self)
return false, err
end

local dir_res, headers = res.body.node or {}, res.headers
local dir_res, headers = res.body.list or {}, res.headers
log.debug("readdir key: ", self.key, " res: ",
json.delay_encode(dir_res))
if not dir_res then
Expand Down
2 changes: 1 addition & 1 deletion conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ apisix:
admin_ssl_cert_key: "" # Path of your self-signed server side key.
admin_ssl_ca_cert: "" # Path of your self-signed ca cert.The CA is used to sign all admin api callers' certificates.

#admin_api_version: v3 # The version of admin api, latest version is v3.
admin_api_version: v3 # The version of admin api, latest version is v3.

# Default token when use API to call for Admin API.
# *NOTE*: Highly recommended to modify this value to protect APISIX's Admin API.
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/admin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ HTTP/1.1 200 OK
Date: Thu, 26 Dec 2019 08:17:49 GMT
...

{"node":{"value":{"username":"jack","plugins":{"key-auth":{"key":"auth-one"},"limit-count":{"time_window":60,"count":2,"rejected_code":503,"key":"remote_addr","policy":"local"}}},"createdIndex":64,"key":"\/apisix\/consumers\/jack","modifiedIndex":64},"prevNode":{"value":"{\"username\":\"jack\",\"plugins\":{\"key-auth\":{\"key\":\"auth-one\"},\"limit-count\":{\"time_window\":60,\"count\":2,\"rejected_code\":503,\"key\":\"remote_addr\",\"policy\":\"local\"}}}","createdIndex":63,"key":"\/apisix\/consumers\/jack","modifiedIndex":63},"action":"set"}
{"node":{"value":{"username":"jack","plugins":{"key-auth":{"key":"auth-one"},"limit-count":{"time_window":60,"count":2,"rejected_code":503,"key":"remote_addr","policy":"local"}}},"createdIndex":64,"key":"\/apisix\/consumers\/jack","modifiedIndex":64},"prevNode":{"value":"{\"username\":\"jack\",\"plugins\":{\"key-auth\":{\"key\":\"auth-one\"},\"limit-count\":{\"time_window\":60,\"count\":2,\"rejected_code\":503,\"key\":\"remote_addr\",\"policy\":\"local\"}}}","createdIndex":63,"key":"\/apisix\/consumers\/jack","modifiedIndex":63}}
```

Since `v2.2`, we can bind multiple authentication plugins to the same consumer.
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server
{"node":{"value":{"uri":"\/user\/*","upstream": {"service_name": "USER-SERVICE", "type": "roundrobin", "discovery_type": "eureka"}},"createdIndex":61925,"key":"\/apisix\/routes\/1","modifiedIndex":61925},"action":"create"}
{"node":{"value":{"uri":"\/user\/*","upstream": {"service_name": "USER-SERVICE", "type": "roundrobin", "discovery_type": "eureka"}},"createdIndex":61925,"key":"\/apisix\/routes\/1","modifiedIndex":61925}}
```

Because the upstream interface URL may have conflict, usually in the gateway by prefix to distinguish:
Expand Down
3 changes: 1 addition & 2 deletions docs/en/latest/discovery/consul_kv.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ The format response as below:
"status": 1
},
"key": "/apisix/routes/1"
},
"action": "set"
}
}
```

Expand Down
12 changes: 4 additions & 8 deletions docs/en/latest/discovery/nacos.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ The formatted response as below:
"priority": 0,
"uri": "\/nacos\/*"
}
},
"action": "set"
}
}
```

Expand Down Expand Up @@ -148,8 +147,7 @@ The formatted response as below:
"priority": 0,
"uri": "\/nacosWithNamespaceId\/*"
}
},
"action": "set"
}
}
```

Expand Down Expand Up @@ -197,8 +195,7 @@ The formatted response as below:
"priority": 0,
"uri": "\/nacosWithGroupName\/*"
}
},
"action": "set"
}
}
```

Expand Down Expand Up @@ -248,7 +245,6 @@ The formatted response as below:
"priority": 0,
"uri": "\/nacosWithNamespaceIdAndGroupName\/*"
}
},
"action": "set"
}
}
```
1 change: 0 additions & 1 deletion docs/en/latest/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ This response indicates that APISIX is running successfully:
```json
{
"count":0,
"action":"get",
"node":{
"key":"/apisix/services",
"nodes":[],
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/internal/testing-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ ONLY:
--- config
...
--- response_body
{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/upstreams","nodes":[]}}
{"count":0,"node":{"dir":true,"key":"/apisix/upstreams","nodes":[]}}
```

### Executing Shell Commands
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/plugins/grpc-transcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Response:

```
# 200
# {"node":{"value":{"create_time":1643879753,"update_time":1643883085,"content":"CmgKEnByb3RvL2ltcG9ydC5wcm90bxIDcGtnIhoKBFVzZXISEgoEbmFtZRgBIAEoCVIEbmFtZSIeCghSZXNwb25zZRISCgRib2R5GAEgASgJUgRib2R5QglaBy4vcHJvdG9iBnByb3RvMwq9AQoPcHJvdG8vc3JjLnByb3RvEgpoZWxsb3dvcmxkGhJwcm90by9pbXBvcnQucHJvdG8iPAoHUmVxdWVzdBIdCgR1c2VyGAEgASgLMgkucGtnLlVzZXJSBHVzZXISEgoEYm9keRgCIAEoCVIEYm9keTI5CgpUZXN0SW1wb3J0EisKA1J1bhITLmhlbGxvd29ybGQuUmVxdWVzdBoNLnBrZy5SZXNwb25zZSIAQglaBy4vcHJvdG9iBnByb3RvMw=="},"key":"\/apisix\/proto\/1"},"action":"set"}
# {"node":{"value":{"create_time":1643879753,"update_time":1643883085,"content":"CmgKEnByb3RvL2ltcG9ydC5wcm90bxIDcGtnIhoKBFVzZXISEgoEbmFtZRgBIAEoCVIEbmFtZSIeCghSZXNwb25zZRISCgRib2R5GAEgASgJUgRib2R5QglaBy4vcHJvdG9iBnByb3RvMwq9AQoPcHJvdG8vc3JjLnByb3RvEgpoZWxsb3dvcmxkGhJwcm90by9pbXBvcnQucHJvdG8iPAoHUmVxdWVzdBIdCgR1c2VyGAEgASgLMgkucGtnLlVzZXJSBHVzZXISEgoEYm9keRgCIAEoCVIEYm9keTI5CgpUZXN0SW1wb3J0EisKA1J1bhITLmhlbGxvd29ybGQuUmVxdWVzdBoNLnBrZy5SZXNwb25zZSIAQglaBy4vcHJvdG9iBnByb3RvMw=="},"key":"\/apisix\/proto\/1"}}
```

Now, we can enable the `grpc-transcode` Plugin to a specific Route:
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/terminology/route.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server

{"node":{"value":{"uri":"\/index.html","upstream":{"nodes":{"127.0.0.1:1980":1},"type":"roundrobin"}},"createdIndex":61925,"key":"\/apisix\/routes\/1","modifiedIndex":61925},"action":"create"}
{"node":{"value":{"uri":"\/index.html","upstream":{"nodes":{"127.0.0.1:1980":1},"type":"roundrobin"}},"createdIndex":61925,"key":"\/apisix\/routes\/1","modifiedIndex":61925}}
```

A successful response indicates that the route was created.
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/latest/admin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ HTTP/1.1 200 OK
Date: Thu, 26 Dec 2019 08:17:49 GMT
...

{"node":{"value":{"username":"jack","plugins":{"key-auth":{"key":"auth-one"},"limit-count":{"time_window":60,"count":2,"rejected_code":503,"key":"remote_addr","policy":"local"}}},"createdIndex":64,"key":"\/apisix\/consumers\/jack","modifiedIndex":64},"prevNode":{"value":"{\"username\":\"jack\",\"plugins\":{\"key-auth\":{\"key\":\"auth-one\"},\"limit-count\":{\"time_window\":60,\"count\":2,\"rejected_code\":503,\"key\":\"remote_addr\",\"policy\":\"local\"}}}","createdIndex":63,"key":"\/apisix\/consumers\/jack","modifiedIndex":63},"action":"set"}
{"node":{"value":{"username":"jack","plugins":{"key-auth":{"key":"auth-one"},"limit-count":{"time_window":60,"count":2,"rejected_code":503,"key":"remote_addr","policy":"local"}}},"createdIndex":64,"key":"\/apisix\/consumers\/jack","modifiedIndex":64},"prevNode":{"value":"{\"username\":\"jack\",\"plugins\":{\"key-auth\":{\"key\":\"auth-one\"},\"limit-count\":{\"time_window\":60,\"count\":2,\"rejected_code\":503,\"key\":\"remote_addr\",\"policy\":\"local\"}}}","createdIndex":63,"key":"\/apisix\/consumers\/jack","modifiedIndex":63}}
```

从 `v2.2` 版本之后,同一个 consumer 可以绑定多个认证插件。
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/latest/discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server
{"node":{"value":{"uri":"\/user\/*","upstream": {"service_name": "USER-SERVICE", "type": "roundrobin", "discovery_type": "eureka"}},"createdIndex":61925,"key":"\/apisix\/routes\/1","modifiedIndex":61925},"action":"create"}
{"node":{"value":{"uri":"\/user\/*","upstream": {"service_name": "USER-SERVICE", "type": "roundrobin", "discovery_type": "eureka"}},"createdIndex":61925,"key":"\/apisix\/routes\/1","modifiedIndex":61925}}
```

因为上游的接口 URL 可能会有冲突,通常会在网关通过前缀来进行区分:
Expand Down
12 changes: 4 additions & 8 deletions docs/zh/latest/discovery/nacos.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f
"priority": 0,
"uri": "\/nacos\/*"
}
},
"action": "set"
}
}
```

Expand Down Expand Up @@ -150,8 +149,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f
"priority": 0,
"uri": "\/nacosWithNamespaceId\/*"
}
},
"action": "set"
}
}
```

Expand Down Expand Up @@ -200,8 +198,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/3 -H 'X-API-KEY: edd1c9f034335f
"priority": 0,
"uri": "\/nacosWithGroupName\/*"
}
},
"action": "set"
}
}
```

Expand Down Expand Up @@ -252,7 +249,6 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/4 -H 'X-API-KEY: edd1c9f034335f
"priority": 0,
"uri": "\/nacosWithNamespaceIdAndGroupName\/*"
}
},
"action": "set"
}
}
```
1 change: 0 additions & 1 deletion docs/zh/latest/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ curl "http://127.0.0.1:9080/apisix/admin/services/" -H 'X-API-KEY: edd1c9f034335
```json
{
"count":0,
"action":"get",
"node":{
"key":"/apisix/services",
"nodes":[],
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/latest/plugins/grpc-transcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ chmod +x ./upload_pb.py

```
# 200
# {"node":{"value":{"create_time":1643879753,"update_time":1643883085,"content":"CmgKEnByb3RvL2ltcG9ydC5wcm90bxIDcGtnIhoKBFVzZXISEgoEbmFtZRgBIAEoCVIEbmFtZSIeCghSZXNwb25zZRISCgRib2R5GAEgASgJUgRib2R5QglaBy4vcHJvdG9iBnByb3RvMwq9AQoPcHJvdG8vc3JjLnByb3RvEgpoZWxsb3dvcmxkGhJwcm90by9pbXBvcnQucHJvdG8iPAoHUmVxdWVzdBIdCgR1c2VyGAEgASgLMgkucGtnLlVzZXJSBHVzZXISEgoEYm9keRgCIAEoCVIEYm9keTI5CgpUZXN0SW1wb3J0EisKA1J1bhITLmhlbGxvd29ybGQuUmVxdWVzdBoNLnBrZy5SZXNwb25zZSIAQglaBy4vcHJvdG9iBnByb3RvMw=="},"key":"\/apisix\/proto\/1"},"action":"set"}
# {"node":{"value":{"create_time":1643879753,"update_time":1643883085,"content":"CmgKEnByb3RvL2ltcG9ydC5wcm90bxIDcGtnIhoKBFVzZXISEgoEbmFtZRgBIAEoCVIEbmFtZSIeCghSZXNwb25zZRISCgRib2R5GAEgASgJUgRib2R5QglaBy4vcHJvdG9iBnByb3RvMwq9AQoPcHJvdG8vc3JjLnByb3RvEgpoZWxsb3dvcmxkGhJwcm90by9pbXBvcnQucHJvdG8iPAoHUmVxdWVzdBIdCgR1c2VyGAEgASgLMgkucGtnLlVzZXJSBHVzZXISEgoEYm9keRgCIAEoCVIEYm9keTI5CgpUZXN0SW1wb3J0EisKA1J1bhITLmhlbGxvd29ybGQuUmVxdWVzdBoNLnBrZy5SZXNwb25zZSIAQglaBy4vcHJvdG9iBnByb3RvMw=="},"key":"\/apisix\/proto\/1"}}
```

现在我们可以在指定路由中启用 `grpc-transcode` 插件:
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/latest/terminology/route.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server

{"node":{"value":{"uri":"\/index.html","upstream":{"nodes":{"127.0.0.1:1980":1},"type":"roundrobin"}},"createdIndex":61925,"key":"\/apisix\/routes\/1","modifiedIndex":61925},"action":"create"}
{"node":{"value":{"uri":"\/index.html","upstream":{"nodes":{"127.0.0.1:1980":1},"type":"roundrobin"}},"createdIndex":61925,"key":"\/apisix\/routes\/1","modifiedIndex":61925}}
```

当我们接收到成功应答,表示该 Route 已成功创建。
Expand Down
37 changes: 12 additions & 25 deletions t/admin/consumers.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ __DATA__
"username": "jack",
"desc": "new consumer"
}
},
"action": "set"
}
}]]
)

Expand Down Expand Up @@ -96,8 +95,7 @@ passed
}
}
}
},
"action": "set"
}
}]]
)

Expand Down Expand Up @@ -139,8 +137,7 @@ passed
}
}
}
},
"action": "get"
}
}]]
)

Expand All @@ -164,10 +161,8 @@ passed
ngx.sleep(0.3)
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/consumers/jack',
ngx.HTTP_DELETE,
nil,
[[{"action": "delete"}]]
)
ngx.HTTP_DELETE
)

ngx.status = code
ngx.say(body)
Expand All @@ -189,11 +184,8 @@ passed
local t = require("lib.test_admin").test
local code = t('/apisix/admin/consumers/not_found',
ngx.HTTP_DELETE,
nil,
[[{
"action": "delete"
}]]
)
nil
)
ngx.say("[delete] code: ", code)
}
}
Expand Down Expand Up @@ -221,8 +213,7 @@ GET /t
"value": {
"id": "jack"
}
},
"action": "set"
}
}]]
)

Expand Down Expand Up @@ -267,8 +258,7 @@ GET /t
"version":"v2"
}
}
},
"action": "set"
}
}]]
)

Expand Down Expand Up @@ -360,8 +350,7 @@ GET /t
"create_time": 1602883670,
"update_time": 1602893670
}
},
"action": "set"
}
}]]
)

Expand All @@ -385,10 +374,8 @@ passed
ngx.sleep(0.3)
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/consumers/pony',
ngx.HTTP_DELETE,
nil,
[[{"action": "delete"}]]
)
ngx.HTTP_DELETE
)

ngx.status = code
ngx.say(body)
Expand Down
8 changes: 4 additions & 4 deletions t/admin/consumers2.t
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ __DATA__
}
}
--- response_body
{"action":"set","node":{"key":"/apisix/consumers/jack","value":{"username":"jack"}}}
{"node":{"key":"/apisix/consumers/jack","value":{"username":"jack"}}}



Expand Down Expand Up @@ -98,7 +98,7 @@ __DATA__
}
}
--- response_body
{"action":"get","node":{"key":"/apisix/consumers/jack","value":{"username":"jack"}}}
{"node":{"key":"/apisix/consumers/jack","value":{"username":"jack"}}}



Expand All @@ -124,7 +124,7 @@ __DATA__
}
}
--- response_body
{"action":"delete","deleted":"1","key":"/apisix/consumers/jack","node":{}}
{"deleted":"1","key":"/apisix/consumers/jack","node":{}}



Expand All @@ -150,7 +150,7 @@ __DATA__
}
}
--- response_body
{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/consumers","nodes":[]}}
{"count":0,"list":[]}



Expand Down
Loading