Class: Uninterruptible::NetworkRestrictions

Inherits:
Object
  • Object
show all
Defined in:
lib/uninterruptible/network_restrictions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ NetworkRestrictions

Returns a new instance of NetworkRestrictions.

Parameters:



6
7
8
9
# File 'lib/uninterruptible/network_restrictions.rb', line 6

def initialize(configuration)
  @configuration = configuration
  check_configuration!
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



3
4
5
# File 'lib/uninterruptible/network_restrictions.rb', line 3

def configuration
  @configuration
end

Instance Method Details

#connection_allowed_from?(client_address) ⇒ Boolean

Should the incoming connection be allowed to connect?

Parameters:

  • client_socket (TCPSocket)

    Incoming socket from the client connection

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/uninterruptible/network_restrictions.rb', line 14

def connection_allowed_from?(client_address)
  return true unless configuration.block_connections?
  allowed_networks.any? { |allowed_network| allowed_network.include?(client_address) }
end