mirror of
https://github.com/discourse/discourse.git
synced 2025-04-14 19:06:49 +08:00
DEV: Extract global admin api rate limiting into a dedicated method.
* We have a use case for overriding the rate limiting logic in a plugin.
This commit is contained in:
parent
6e3f249aea
commit
d1af89e3b3
@ -81,12 +81,7 @@ class Auth::DefaultCurrentUserProvider
|
||||
raise Discourse::InvalidAccess.new(I18n.t('invalid_api_credentials'), nil, custom_message: "invalid_api_credentials") unless current_user
|
||||
raise Discourse::InvalidAccess if current_user.suspended? || !current_user.active
|
||||
@env[API_KEY_ENV] = true
|
||||
|
||||
# we do not run this rate limiter while profiling
|
||||
if Rails.env != "profile"
|
||||
limiter_min = RateLimiter.new(nil, "admin_api_min_#{api_key}", GlobalSetting.max_admin_api_reqs_per_key_per_minute, 60)
|
||||
limiter_min.performed!
|
||||
end
|
||||
rate_limit_admin_api_requests(api_key)
|
||||
end
|
||||
|
||||
# user api key handling
|
||||
@ -296,4 +291,17 @@ class Auth::DefaultCurrentUserProvider
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rate_limit_admin_api_requests(api_key)
|
||||
return if Rails.env == "profile"
|
||||
|
||||
RateLimiter.new(
|
||||
nil,
|
||||
"admin_api_min_#{api_key}",
|
||||
GlobalSetting.max_admin_api_reqs_per_key_per_minute,
|
||||
60
|
||||
).performed!
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user