You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by we...@apache.org on 2020/08/24 01:17:39 UTC
[apisix] branch master updated: change: use draft7 of JSON Schema
for limit count pulgin (#2102)
This is an automated email from the ASF dual-hosted git repository.
wenming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 415f922 change: use draft7 of JSON Schema for limit count pulgin (#2102)
415f922 is described below
commit 415f9221e22db0cd599926ca3b5f98a55f2693b4
Author: YuanSheng Wang <me...@gmail.com>
AuthorDate: Mon Aug 24 09:17:31 2020 +0800
change: use draft7 of JSON Schema for limit count pulgin (#2102)
---
apisix/plugins/limit-count.lua | 63 +++++++++++++++++++++++++++---------------
t/plugin/limit-count-redis.t | 2 +-
2 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/apisix/plugins/limit-count.lua b/apisix/plugins/limit-count.lua
index 3e9d4af..216b82d 100644
--- a/apisix/plugins/limit-count.lua
+++ b/apisix/plugins/limit-count.lua
@@ -34,27 +34,51 @@ local schema = {
enum = {"remote_addr", "server_addr", "http_x_real_ip",
"http_x_forwarded_for"},
},
- rejected_code = {type = "integer", minimum = 200, maximum = 600,
- default = 503},
+ rejected_code = {
+ type = "integer", minimum = 200, maximum = 600,
+ default = 503
+ },
policy = {
type = "string",
enum = {"local", "redis"},
- },
- redis_host = {
- type = "string", minLength = 2
- },
- redis_port = {
- type = "integer", minimum = 1
- },
- redis_password = {
- type = "string", minLength = 0
- },
- redis_timeout = {
- type = "integer", minimum = 1
- },
+ default = "local",
+ }
},
- additionalProperties = false,
required = {"count", "time_window", "key"},
+ dependencies = {
+ policy = {
+ oneOf = {
+ {
+ properties = {
+ policy = {
+ enum = {"local"},
+ },
+ },
+ },
+ {
+ properties = {
+ policy = {
+ enum = {"redis"},
+ },
+ redis_host = {
+ type = "string", minLength = 2
+ },
+ redis_port = {
+ type = "integer", minimum = 1, default = 6379,
+ },
+ redis_password = {
+ type = "string", minLength = 0,
+ },
+ redis_timeout = {
+ type = "integer", minimum = 1,
+ default = 1000,
+ },
+ },
+ required = {"redis_host"},
+ }
+ }
+ }
+ }
}
@@ -72,17 +96,10 @@ function _M.check_schema(conf)
return false, err
end
- if not conf.policy then
- conf.policy = "local"
- end
-
if conf.policy == "redis" then
if not conf.redis_host then
return false, "missing valid redis option host"
end
-
- conf.redis_port = conf.redis_port or 6379
- conf.redis_timeout = conf.redis_timeout or 1000
end
return true
diff --git a/t/plugin/limit-count-redis.t b/t/plugin/limit-count-redis.t
index 6959af9..f87478f 100644
--- a/t/plugin/limit-count-redis.t
+++ b/t/plugin/limit-count-redis.t
@@ -71,7 +71,7 @@ __DATA__
GET /t
--- error_code: 400
--- response_body
-{"error_msg":"failed to check the configuration of plugin limit-count err: missing valid redis option host"}
+{"error_msg":"failed to check the configuration of plugin limit-count err: failed to validate dependent schema for \"policy\": value should match only one schema, but matches none"}
--- no_error_log
[error]