Class: Gitlab::Auth::IpRateLimiter
- Inherits:
-
Object
- Object
- Gitlab::Auth::IpRateLimiter
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/auth/ip_rate_limiter.rb
Instance Attribute Summary collapse
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
Instance Method Summary collapse
- #banned? ⇒ Boolean
-
#initialize(ip) ⇒ IpRateLimiter
constructor
A new instance of IpRateLimiter.
- #register_fail! ⇒ Object
- #reset! ⇒ Object
- #trusted_ip? ⇒ Boolean
Constructor Details
#initialize(ip) ⇒ IpRateLimiter
Returns a new instance of IpRateLimiter.
10 11 12 |
# File 'lib/gitlab/auth/ip_rate_limiter.rb', line 10 def initialize(ip) @ip = ip end |
Instance Attribute Details
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
8 9 10 |
# File 'lib/gitlab/auth/ip_rate_limiter.rb', line 8 def ip @ip end |
Instance Method Details
#banned? ⇒ Boolean
30 31 32 33 34 |
# File 'lib/gitlab/auth/ip_rate_limiter.rb', line 30 def banned? return false if skip_rate_limit? Rack::Attack::Allow2Ban.banned?(ip) end |
#register_fail! ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/gitlab/auth/ip_rate_limiter.rb', line 20 def register_fail! return false if skip_rate_limit? # Allow2Ban.filter will return false if this IP has not failed too often yet Rack::Attack::Allow2Ban.filter(ip, config) do # We return true to increment the count for this IP true end end |
#reset! ⇒ Object
14 15 16 17 18 |
# File 'lib/gitlab/auth/ip_rate_limiter.rb', line 14 def reset! return if skip_rate_limit? Rack::Attack::Allow2Ban.reset(ip, config) end |
#trusted_ip? ⇒ Boolean
36 37 38 |
# File 'lib/gitlab/auth/ip_rate_limiter.rb', line 36 def trusted_ip? trusted_ips.any? { |netmask| netmask.include?(ip) } end |