mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-05 05:27:35 +08:00
feature: add managed fields in json schema for resources, such as create_time and update_time (#2444)
* feature: add managed fields in jsonschema for resources, such as create_time and update_time
This commit is contained in:
parent
6a543a98a2
commit
a92331c27a
@ -25,7 +25,6 @@ local plugins_schema = {
|
||||
type = "object"
|
||||
}
|
||||
|
||||
|
||||
local id_schema = {
|
||||
anyOf = {
|
||||
{
|
||||
@ -36,7 +35,6 @@ local id_schema = {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
local host_def_pat = "^\\*?[0-9a-zA-Z-.]+$"
|
||||
local host_def = {
|
||||
type = "string",
|
||||
@ -56,6 +54,9 @@ local ip_def = {
|
||||
}
|
||||
_M.ip_def = ip_def
|
||||
|
||||
local timestamp_def = {
|
||||
type = "integer",
|
||||
}
|
||||
|
||||
local remote_addr_def = {
|
||||
description = "client IP",
|
||||
@ -285,6 +286,8 @@ local nodes_schema = {
|
||||
local upstream_schema = {
|
||||
type = "object",
|
||||
properties = {
|
||||
create_time = timestamp_def,
|
||||
update_time = timestamp_def,
|
||||
nodes = nodes_schema,
|
||||
retries = {
|
||||
type = "integer",
|
||||
@ -391,6 +394,8 @@ _M.upstream_hash_header_schema = {
|
||||
_M.route = {
|
||||
type = "object",
|
||||
properties = {
|
||||
create_time = timestamp_def,
|
||||
update_time = timestamp_def,
|
||||
uri = {type = "string", minLength = 1, maxLength = 4096},
|
||||
uris = {
|
||||
type = "array",
|
||||
@ -506,7 +511,9 @@ _M.service = {
|
||||
[".*"] = label_value_def
|
||||
},
|
||||
maxProperties = 16
|
||||
}
|
||||
},
|
||||
create_time = timestamp_def,
|
||||
update_time = timestamp_def
|
||||
},
|
||||
additionalProperties = false,
|
||||
}
|
||||
@ -529,6 +536,8 @@ _M.consumer = {
|
||||
},
|
||||
maxProperties = 16
|
||||
},
|
||||
create_time = timestamp_def,
|
||||
update_time = timestamp_def,
|
||||
desc = {type = "string", maxLength = 256}
|
||||
},
|
||||
required = {"username"},
|
||||
@ -593,7 +602,11 @@ _M.ssl = {
|
||||
type = "integer",
|
||||
enum = {1, 0},
|
||||
default = 1
|
||||
}
|
||||
},
|
||||
validity_end = timestamp_def,
|
||||
validity_start = timestamp_def,
|
||||
create_time = timestamp_def,
|
||||
update_time = timestamp_def
|
||||
},
|
||||
oneOf = {
|
||||
{required = {"sni", "key", "cert"}},
|
||||
|
@ -322,3 +322,67 @@ GET /t
|
||||
{"error_msg":"not supported `POST` method for consumer"}
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 10: add consumer with create_time and update_time(pony)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/admin/consumers',
|
||||
ngx.HTTP_PUT,
|
||||
[[{
|
||||
"username":"pony",
|
||||
"desc": "new consumer",
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670
|
||||
}]],
|
||||
[[{
|
||||
"node": {
|
||||
"value": {
|
||||
"username": "pony",
|
||||
"desc": "new consumer",
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670
|
||||
}
|
||||
},
|
||||
"action": "set"
|
||||
}]]
|
||||
)
|
||||
|
||||
ngx.status = code
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 11: delete test consumer(pony)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
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.status = code
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
@ -2326,3 +2326,77 @@ GET /t
|
||||
{"error_msg":"invalid configuration: property \"labels\" validation failed: failed to validate env (matching \".*\"): wrong type: expected string, got table"}
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 63: create route with create_time and update_time(id : 1)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/admin/routes/1',
|
||||
ngx.HTTP_PUT,
|
||||
[[{
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
},
|
||||
"type": "roundrobin"
|
||||
},
|
||||
"uri": "/index.html",
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670
|
||||
}]],
|
||||
[[{
|
||||
"node": {
|
||||
"value": {
|
||||
"uri": "/index.html",
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
},
|
||||
"type": "roundrobin"
|
||||
},
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670
|
||||
},
|
||||
"key": "/apisix/routes/1"
|
||||
},
|
||||
"action": "set"
|
||||
}]]
|
||||
)
|
||||
|
||||
ngx.status = code
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 64: delete test route(id : 1)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message = t('/apisix/admin/routes/1',
|
||||
ngx.HTTP_DELETE,
|
||||
nil,
|
||||
[[{
|
||||
"action": "delete"
|
||||
}]]
|
||||
)
|
||||
ngx.say("[delete] code: ", code, " message: ", message)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
[delete] code: 200 message: passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
@ -1317,3 +1317,75 @@ GET /t
|
||||
{"error_msg":"invalid configuration: property \"labels\" validation failed: failed to validate env (matching \".*\"): wrong type: expected string, got table"}
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 36: create service with create_time and update_time(id: 1)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/admin/services/1',
|
||||
ngx.HTTP_PUT,
|
||||
[[{
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
},
|
||||
"type": "roundrobin",
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670
|
||||
}
|
||||
}]],
|
||||
[[{
|
||||
"node": {
|
||||
"value": {
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
},
|
||||
"type": "roundrobin",
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670
|
||||
}
|
||||
},
|
||||
"key": "/apisix/services/1"
|
||||
},
|
||||
"action": "set"
|
||||
}]]
|
||||
)
|
||||
|
||||
ngx.status = code
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 37: delete test service(id: 1)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message = t('/apisix/admin/services/1',
|
||||
ngx.HTTP_DELETE,
|
||||
nil,
|
||||
[[{
|
||||
"action": "delete"
|
||||
}]]
|
||||
)
|
||||
ngx.say("[delete] code: ", code, " message: ", message)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
[delete] code: 200 message: passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
@ -617,3 +617,77 @@ GET /t
|
||||
{"error_msg":"invalid configuration: property \"labels\" validation failed: failed to validate env (matching \".*\"): wrong type: expected string, got table"}
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 17: create ssl with manage fields(id: 1)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local core = require("apisix.core")
|
||||
local t = require("lib.test_admin")
|
||||
|
||||
local ssl_cert = t.read_file("conf/cert/apisix.crt")
|
||||
local ssl_key = t.read_file("conf/cert/apisix.key")
|
||||
local data = {
|
||||
cert = ssl_cert,
|
||||
key = ssl_key,
|
||||
sni = "test.com",
|
||||
create_time = 1602883670,
|
||||
update_time = 1602893670,
|
||||
validity_start = 1602873670,
|
||||
validity_end = 1603893670
|
||||
}
|
||||
|
||||
local code, body = t.test('/apisix/admin/ssl/1',
|
||||
ngx.HTTP_PUT,
|
||||
core.json.encode(data),
|
||||
[[{
|
||||
"node": {
|
||||
"value": {
|
||||
"sni": "test.com",
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670,
|
||||
"validity_start": 1602873670,
|
||||
"validity_end": 1603893670
|
||||
},
|
||||
"key": "/apisix/ssl/1"
|
||||
},
|
||||
"action": "set"
|
||||
}]]
|
||||
)
|
||||
|
||||
ngx.status = code
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 18: delete test ssl(id: 1)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message = t('/apisix/admin/ssl/1',
|
||||
ngx.HTTP_DELETE,
|
||||
nil,
|
||||
[[{
|
||||
"action": "delete"
|
||||
}]]
|
||||
)
|
||||
ngx.say("[delete] code: ", code, " message: ", message)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
[delete] code: 200 message: passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
@ -1803,3 +1803,71 @@ GET /t
|
||||
{"error_msg":"invalid configuration: property \"labels\" validation failed: failed to validate env (matching \".*\"): wrong type: expected string, got table"}
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 54: create upstream with create_time and update_time(id: 1)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/admin/upstreams/1',
|
||||
ngx.HTTP_PUT,
|
||||
[[{
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
},
|
||||
"type": "roundrobin",
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670
|
||||
}]],
|
||||
[[{
|
||||
"node": {
|
||||
"value": {
|
||||
"nodes": {
|
||||
"127.0.0.1:8080": 1
|
||||
},
|
||||
"type": "roundrobin",
|
||||
"create_time": 1602883670,
|
||||
"update_time": 1602893670
|
||||
},
|
||||
"key": "/apisix/upstreams/1"
|
||||
},
|
||||
"action": "set"
|
||||
}]]
|
||||
)
|
||||
|
||||
ngx.status = code
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 55: delete test upstream(id: 1)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, message = t('/apisix/admin/upstreams/1',
|
||||
ngx.HTTP_DELETE,
|
||||
nil,
|
||||
[[{
|
||||
"action": "delete"
|
||||
}]]
|
||||
)
|
||||
ngx.say("[delete] code: ", code, " message: ", message)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
[delete] code: 200 message: passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
Loading…
Reference in New Issue
Block a user