Class: WebShield::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/web_shield/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
# File 'lib/web_shield/config.rb', line 8

def initialize
  @shields = []
  @shield_counter = 0
  @id_prefix = Time.now.to_f.to_s

  @user_parser = Proc.new {|req| req.ip }
  @blocked_response = Proc.new {|req| [429, {}, ['Too Many Requests']] }
  @logger = Logger.new($stdout)
end

Instance Attribute Details

#blocked_responseObject

Returns the value of attribute blocked_response.



5
6
7
# File 'lib/web_shield/config.rb', line 5

def blocked_response
  @blocked_response
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/web_shield/config.rb', line 5

def logger
  @logger
end

#shieldsObject (readonly)

Returns the value of attribute shields.



6
7
8
# File 'lib/web_shield/config.rb', line 6

def shields
  @shields
end

#storeObject

Returns the value of attribute store.



5
6
7
# File 'lib/web_shield/config.rb', line 5

def store
  @store
end

#user_parserObject

Returns the value of attribute user_parser.



5
6
7
# File 'lib/web_shield/config.rb', line 5

def user_parser
  @user_parser
end

Instance Method Details

#build_shield(path_matcher, options, shield_class = ThrottleShield) ⇒ Object

return shield



35
36
37
38
39
40
# File 'lib/web_shield/config.rb', line 35

def build_shield(path_matcher, options, shield_class = ThrottleShield)
  shield_class.new(generate_id, path_matcher, options, self).tap do |shield|
    shields << shield
    logger.info("Build #{shield.shield_name} #{path_matcher} #{options}")
  end
end