Module: Rack::Attack::InstantiableFail2Ban

Includes:
InspectWithOptions, PeriodIntrospection
Included in:
Fail2Ban
Defined in:
lib/rack/attack_extensions.rb

Overview

Make it instantiable like Throttle so we can introspect it

Constant Summary collapse

MANDATORY_OPTIONS =
[:limit, :period, :type].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InspectWithOptions

#inspect_with_options

Methods included from PeriodIntrospection

#time_range

Instance Attribute Details

#bantimeObject (readonly)

Returns the value of attribute bantime.



260
261
262
# File 'lib/rack/attack_extensions.rb', line 260

def bantime
  @bantime
end

#limitObject (readonly)

Returns the value of attribute limit.



260
261
262
# File 'lib/rack/attack_extensions.rb', line 260

def limit
  @limit
end

#nameObject (readonly)

Returns the value of attribute name.



260
261
262
# File 'lib/rack/attack_extensions.rb', line 260

def name
  @name
end

#periodObject (readonly)

Returns the value of attribute period.



260
261
262
# File 'lib/rack/attack_extensions.rb', line 260

def period
  @period
end

#typeObject (readonly)

Returns the value of attribute type.



260
261
262
# File 'lib/rack/attack_extensions.rb', line 260

def type
  @type
end

Instance Method Details

#initialize(name, options) ⇒ Object



261
262
263
264
265
266
267
268
269
270
# File 'lib/rack/attack_extensions.rb', line 261

def initialize(name, options)
  @name = name
  MANDATORY_OPTIONS.each do |opt|
    raise ArgumentError.new("Must pass #{opt.inspect} option") unless options[opt]
  end
  @limit   = options[:limit]
  @period  = options[:period].respond_to?(:call) ? options[:period] : options[:period].to_i
  @bantime = options[:bantime]   or raise ArgumentError, "Must pass bantime option"
  @type    = options[:type]
end

#optionsObject



275
276
277
278
279
280
# File 'lib/rack/attack_extensions.rb', line 275

def options
  {
    period: period,
    limit:  limit,
  }
end