Skip to content

Commit

Permalink
feature: add managed fields in json schema for resources, such as cre…
Browse files Browse the repository at this point in the history
…ate_time and update_time (#2444)

* feature: add managed fields in jsonschema for resources, such as create_time and update_time
  • Loading branch information
nic-chen authored Oct 17, 2020
1 parent 6a543a9 commit a92331c
Show file tree
Hide file tree
Showing 6 changed files with 369 additions and 4 deletions.
21 changes: 17 additions & 4 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ local plugins_schema = {
type = "object"
}


local id_schema = {
anyOf = {
{
Expand All @@ -36,7 +35,6 @@ local id_schema = {
}
}


local host_def_pat = "^\\*?[0-9a-zA-Z-.]+$"
local host_def = {
type = "string",
Expand All @@ -56,6 +54,9 @@ local ip_def = {
}
_M.ip_def = ip_def

local timestamp_def = {
type = "integer",
}

local remote_addr_def = {
description = "client IP",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -506,7 +511,9 @@ _M.service = {
[".*"] = label_value_def
},
maxProperties = 16
}
},
create_time = timestamp_def,
update_time = timestamp_def
},
additionalProperties = false,
}
Expand All @@ -529,6 +536,8 @@ _M.consumer = {
},
maxProperties = 16
},
create_time = timestamp_def,
update_time = timestamp_def,
desc = {type = "string", maxLength = 256}
},
required = {"username"},
Expand Down Expand Up @@ -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"}},
Expand Down
64 changes: 64 additions & 0 deletions t/admin/consumers.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]
74 changes: 74 additions & 0 deletions t/admin/routes.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]
72 changes: 72 additions & 0 deletions t/admin/services.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]
74 changes: 74 additions & 0 deletions t/admin/ssl.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Loading

0 comments on commit a92331c

Please sign in to comment.