Class: Switchlet::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/switchlet/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_ipsObject

Returns the value of attribute allowed_ips.



8
9
10
# File 'lib/switchlet/configuration.rb', line 8

def allowed_ips
  @allowed_ips
end

#authenticate_blockObject (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_enabledObject

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_passwordObject

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_usernameObject

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

Returns:

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

Returns:

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

Returns:

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