Class: Switchlet::Configuration
- Inherits:
-
Object
- Object
- Switchlet::Configuration
- Defined in:
- lib/switchlet/configuration.rb
Instance Attribute Summary collapse
-
#allowed_ips ⇒ Object
Returns the value of attribute allowed_ips.
-
#authenticate_block ⇒ Object
readonly
Returns the value of attribute authenticate_block.
-
#basic_auth_enabled ⇒ Object
Returns the value of attribute basic_auth_enabled.
-
#basic_auth_password ⇒ Object
Returns the value of attribute basic_auth_password.
-
#basic_auth_username ⇒ Object
Returns the value of attribute basic_auth_username.
Instance Method Summary collapse
- #authenticate_block? ⇒ Boolean
- #authenticate_with(&block) ⇒ Object
- #basic_auth_configured? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #ip_allowed?(ip_address) ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 16 17 |
# File 'lib/switchlet/configuration.rb', line 11 def initialize @basic_auth_enabled = false @basic_auth_username = nil @basic_auth_password = nil @allowed_ips = [] @authenticate_block = nil end |
Instance Attribute Details
#allowed_ips ⇒ Object
Returns the value of attribute allowed_ips.
8 9 10 |
# File 'lib/switchlet/configuration.rb', line 8 def allowed_ips @allowed_ips end |
#authenticate_block ⇒ Object (readonly)
Returns the value of attribute authenticate_block.
9 10 11 |
# File 'lib/switchlet/configuration.rb', line 9 def authenticate_block @authenticate_block end |
#basic_auth_enabled ⇒ Object
Returns the value of attribute basic_auth_enabled.
7 8 9 |
# File 'lib/switchlet/configuration.rb', line 7 def basic_auth_enabled @basic_auth_enabled end |
#basic_auth_password ⇒ Object
Returns the value of attribute basic_auth_password.
7 8 9 |
# File 'lib/switchlet/configuration.rb', line 7 def basic_auth_password @basic_auth_password end |
#basic_auth_username ⇒ Object
Returns the value of attribute basic_auth_username.
7 8 9 |
# File 'lib/switchlet/configuration.rb', line 7 def basic_auth_username @basic_auth_username end |
Instance Method Details
#authenticate_block? ⇒ Boolean
23 24 25 |
# File 'lib/switchlet/configuration.rb', line 23 def authenticate_block? !@authenticate_block.nil? end |
#authenticate_with(&block) ⇒ Object
19 20 21 |
# File 'lib/switchlet/configuration.rb', line 19 def authenticate_with(&block) @authenticate_block = block end |
#basic_auth_configured? ⇒ Boolean
27 28 29 |
# File 'lib/switchlet/configuration.rb', line 27 def basic_auth_configured? basic_auth_enabled && basic_auth_username && basic_auth_password end |
#ip_allowed?(ip_address) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/switchlet/configuration.rb', line 31 def ip_allowed?(ip_address) return true if allowed_ips.empty? allowed_ips.any? do |allowed_ip| if allowed_ip.include?("/") IPAddr.new(allowed_ip).include?(ip_address) else IPAddr.new(allowed_ip).include?(IPAddr.new(ip_address)) end end rescue IPAddr::InvalidAddressError false end |