Class: Gitlab::Auth::IpRateLimiter

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/auth/ip_rate_limiter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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

#ipObject (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

Returns:

  • (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