class Nexaas::Throttle::Configuration

Attributes

assets_extensions[RW]

An array of file extensions considered to be asset-related. Values are strings that will be matched against the request path. Paths that match will be not be throttled. Example: [“css”, “js”, “jpeg”, “jpg”, “png”] @return [Array]

ignored_user_agents[RW]

An array of User Agents that should be ignored by the throttler. Values are regexes that will be matched against the request User-Agent. Example: [/[Gg]oogle/, /Amazon/] @return [Array]

limit[RW]

How many requests a consumer can do during a window until he starts being throttled. Example: 60 @return [Integer]

period[RW]

The size of the throttle window. Example: 1.minute, 1.hour, 60(s) @return [Integer]

redis_options[R]

Redis hash configuration with the following default values:

- host      => localhost
- port      => 6379
- db        => 0
- namespace => nexaas:throttle

@return [Hash]

request_identifier[RW]

The class that will handle request identification. Each application handle with different domains on identifying a request, so they have to provide information on who is the requester based on their domain. This class MUST have the following interface: MyRequestIdentifier#initialize(request) MyRequestIdentifier#token Where MyRequestIdentifier#token must be a UNIQUE identifier from the requester. @return [Class]

throttle[RW]

Whether or not requests are throttled. @return [Boolean]

throttleable?[RW]

Whether or not requests are throttled. @return [Boolean]

track[RW]

Whether or not requests are tracked. @return [Boolean]

trackable?[RW]

Whether or not requests are tracked. @return [Boolean]

Public Class Methods

new() click to toggle source
# File lib/nexaas/throttle/configuration.rb, line 56
def initialize
  @throttle = true
  @track = true
  @period = 1.minute
  @limit = 60
  @request_identifier = nil
  @redis_options = default_redis_options
  @ignored_user_agents = nil
  @assets_extensions = %w[css js jpg jpeg png gif woff ttf svg]
end

Public Instance Methods

check!() click to toggle source
# File lib/nexaas/throttle/configuration.rb, line 67
def check!
  required_options.each do |option|
    raise ArgumentError, "You must provide a `#{option}` configuration." if send(option).blank?
  end
end
redis_options=(options) click to toggle source
# File lib/nexaas/throttle/configuration.rb, line 73
def redis_options=(options)
  options ||= {}
  @redis_options = default_redis_options.merge(options)
end

Private Instance Methods

default_redis_options() click to toggle source
# File lib/nexaas/throttle/configuration.rb, line 84
def default_redis_options
  {
    host: "localhost",
    port: 6379,
    db: 0,
    namespace: "nexaas:throttle"
  }
end
required_options() click to toggle source
# File lib/nexaas/throttle/configuration.rb, line 80
def required_options
  %w(period limit request_identifier redis_options)
end