FEATURE: Shorten setting name to max_reqs

So it is consistent with other settings
This commit is contained in:
Sam 2018-01-22 13:18:30 +11:00
parent 83a346cd68
commit f26ff290c3
3 changed files with 26 additions and 26 deletions

View File

@ -176,10 +176,10 @@ max_user_api_reqs_per_day = 2880
max_admin_api_reqs_per_key_per_minute = 60
max_requests_per_ip_per_minute = 200
max_requests_per_ip_per_10_seconds = 50
max_reqs_per_ip_per_minute = 200
max_reqs_per_ip_per_10_seconds = 50
# global rate limiter will simply warn if the limit is exceeded, can be warn+block, warn, block or none
max_requests_per_ip_mode = none
max_reqs_per_ip_mode = none
# bypass rate limiting any IP resolved as a private IP
max_requests_rate_limit_on_private = false
max_reqs_rate_limit_on_private = false

View File

@ -156,21 +156,21 @@ class Middleware::RequestTracker
def rate_limit(env)
if (
GlobalSetting.max_requests_per_ip_mode == "block" ||
GlobalSetting.max_requests_per_ip_mode == "warn" ||
GlobalSetting.max_requests_per_ip_mode == "warn+block"
GlobalSetting.max_reqs_per_ip_mode == "block" ||
GlobalSetting.max_reqs_per_ip_mode == "warn" ||
GlobalSetting.max_reqs_per_ip_mode == "warn+block"
)
ip = Rack::Request.new(env).ip
if !GlobalSetting.max_requests_rate_limit_on_private
if !GlobalSetting.max_reqs_rate_limit_on_private
return false if is_private_ip?(ip)
end
limiter10 = RateLimiter.new(
nil,
"global_ip_limit_10_#{ip}",
GlobalSetting.max_requests_per_ip_per_10_seconds,
GlobalSetting.max_reqs_per_ip_per_10_seconds,
10,
global: true
)
@ -178,7 +178,7 @@ class Middleware::RequestTracker
limiter60 = RateLimiter.new(
nil,
"global_ip_limit_60_#{ip}",
GlobalSetting.max_requests_per_ip_per_10_seconds,
GlobalSetting.max_reqs_per_ip_per_10_seconds,
10,
global: true
)
@ -190,11 +190,11 @@ class Middleware::RequestTracker
limiter60.performed!
rescue RateLimiter::LimitExceeded
if (
GlobalSetting.max_requests_per_ip_mode == "warn" ||
GlobalSetting.max_requests_per_ip_mode == "warn+block"
GlobalSetting.max_reqs_per_ip_mode == "warn" ||
GlobalSetting.max_reqs_per_ip_mode == "warn+block"
)
Rails.logger.warn("Global IP rate limit exceeded for #{ip}: #{type} second rate limit, uri: #{env["REQUEST_URI"]}")
!(GlobalSetting.max_requests_per_ip_mode == "warn")
!(GlobalSetting.max_reqs_per_ip_mode == "warn")
else
true
end

View File

@ -105,7 +105,7 @@ describe Middleware::RequestTracker do
end
it "does nothing by default" do
global_setting :max_requests_per_ip_per_10_seconds, 1
global_setting :max_reqs_per_ip_per_10_seconds, 1
status, _ = middleware.call(env)
status, _ = middleware.call(env)
@ -114,9 +114,9 @@ describe Middleware::RequestTracker do
end
it "blocks private IPs if not skipped" do
global_setting :max_requests_per_ip_per_10_seconds, 1
global_setting :max_requests_per_ip_mode, 'warn+block'
global_setting :max_requests_rate_limit_on_private, true
global_setting :max_reqs_per_ip_per_10_seconds, 1
global_setting :max_reqs_per_ip_mode, 'warn+block'
global_setting :max_reqs_rate_limit_on_private, true
env1 = env("REMOTE_ADDR" => "127.0.0.2")
@ -128,9 +128,9 @@ describe Middleware::RequestTracker do
end
it "does nothing for private IPs if skipped" do
global_setting :max_requests_per_ip_per_10_seconds, 1
global_setting :max_requests_per_ip_mode, 'warn+block'
global_setting :max_requests_rate_limit_on_private, false
global_setting :max_reqs_per_ip_per_10_seconds, 1
global_setting :max_reqs_per_ip_mode, 'warn+block'
global_setting :max_reqs_rate_limit_on_private, false
env1 = env("REMOTE_ADDR" => "127.0.3.1")
@ -142,8 +142,8 @@ describe Middleware::RequestTracker do
end
it "does warn if rate limiter is enabled via warn+block" do
global_setting :max_requests_per_ip_per_10_seconds, 1
global_setting :max_requests_per_ip_mode, 'warn+block'
global_setting :max_reqs_per_ip_per_10_seconds, 1
global_setting :max_reqs_per_ip_mode, 'warn+block'
status, _ = middleware.call(env)
status, _ = middleware.call(env)
@ -153,8 +153,8 @@ describe Middleware::RequestTracker do
end
it "does warn if rate limiter is enabled" do
global_setting :max_requests_per_ip_per_10_seconds, 1
global_setting :max_requests_per_ip_mode, 'warn'
global_setting :max_reqs_per_ip_per_10_seconds, 1
global_setting :max_reqs_per_ip_mode, 'warn'
status, _ = middleware.call(env)
status, _ = middleware.call(env)
@ -164,8 +164,8 @@ describe Middleware::RequestTracker do
end
it "does block if rate limiter is enabled" do
global_setting :max_requests_per_ip_per_10_seconds, 1
global_setting :max_requests_per_ip_mode, 'block'
global_setting :max_reqs_per_ip_per_10_seconds, 1
global_setting :max_reqs_per_ip_mode, 'block'
env1 = env("REMOTE_ADDR" => "1.1.1.1")
env2 = env("REMOTE_ADDR" => "1.1.1.2")