-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
894878f
commit c36ea77
Showing
7 changed files
with
179 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,40 @@ | ||
local constants = require "kong.constants" | ||
|
||
return { | ||
fields = { | ||
limit = { required = true, type = "number" }, | ||
period = { required = true, type = "string", enum = constants.RATELIMIT.PERIODS } | ||
} | ||
second = { type = "number" }, | ||
minute = { type = "number" }, | ||
hour = { type = "number" }, | ||
day = { type = "number" }, | ||
month = { type = "number" }, | ||
year = { type = "number" } | ||
}, | ||
on_insert = function(plugin_t, dao, schema) | ||
local ordered_periods = { "second", "minute", "hour", "day", "month", "year"} | ||
local has_value | ||
local invalid_order | ||
local invalid_value | ||
for i, v in ipairs(ordered_periods) do | ||
if plugin_t[v] then | ||
has_value = true | ||
if plugin_t[v] <=0 then | ||
invalid_value = "Value for "..v.." must be greater than zero" | ||
else | ||
for t = i, #ordered_periods do | ||
if plugin_t[ordered_periods[t]] and plugin_t[ordered_periods[t]] < plugin_t[v] then | ||
invalid_order = "The value for "..ordered_periods[t].." cannot be lower than the value for "..v | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if not has_value then | ||
return false, "You need to set at least one limit: second, minute, hour, day, month, year" | ||
elseif invalid_value then | ||
return false, invalid_value | ||
elseif invalid_order then | ||
return false, invalid_order | ||
end | ||
|
||
return true | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters