Browse Source

[Minor] Ratelimit: fix getting values from custom routines; silence logging

tags/1.7.0
Andrew Lewis 6 years ago
parent
commit
8c045e1416
1 changed files with 7 additions and 5 deletions
  1. 7
    5
      src/plugins/lua/ratelimit.lua

+ 7
- 5
src/plugins/lua/ratelimit.lua View File

@@ -182,7 +182,7 @@ local function load_scripts(cfg, ev_base)
end

local limit_parser
local function parse_string_limit(lim)
local function parse_string_limit(lim, no_error)
local function parse_time_suffix(s)
if s == 's' then
return 1
@@ -238,7 +238,9 @@ local function parse_string_limit(lim)
return t[2], t[1]
end

rspamd_logger.errx(rspamd_config, 'bad limit: %s', lim)
if not no_error then
rspamd_logger.errx(rspamd_config, 'bad limit: %s', lim)
end

return nil
end
@@ -534,7 +536,7 @@ local function ratelimit_cb(task)
local res = custom_keywords[settings[k]]['get_limit'](task)
if type(res) == 'string' then res = {res} end
for _, r in ipairs(res) do
local plim, size = parse_string_limit(r)
local plim, size = parse_string_limit(r, true)
if plim then
table.insert(args, {{plim, size}, rk})
else
@@ -555,11 +557,11 @@ local function ratelimit_cb(task)
local res = custom_keywords[settings[k]]['get_limit'](task)
if type(res) == 'string' then res = {res} end
for _, r in ipairs(res) do
local plim, size = parse_string_limit(r)
local plim, size = parse_string_limit(r, true)
if plim then
table.insert(args, {{plim, size}, rate_key})
else
local rkey = string.match(settings[k], 'redis:(.*)')
local rkey = string.match(r, 'redis:(.*)')
if rkey then
table.insert(redis_keys, rkey)
redis_keys_rev[#redis_keys] = rate_key

Loading…
Cancel
Save