class Uninterruptible::NetworkRestrictions
Attributes
configuration[R]
Public Class Methods
new(configuration)
click to toggle source
@param [Uninterruptible::Configuration] configuration Object with allowed_networks
configuration
# File lib/uninterruptible/network_restrictions.rb, line 6 def initialize(configuration) @configuration = configuration check_configuration! end
Public Instance Methods
connection_allowed_from?(client_address)
click to toggle source
Should the incoming connection be allowed to connect?
@param [TCPSocket] client_socket Incoming socket from the client connection
# 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
Private Instance Methods
allowed_networks()
click to toggle source
Parse the list of allowed networks from the configuration and turn them into IPAddr objects
@return [Array<IPAddr>] Parsed list of IP networks
# File lib/uninterruptible/network_restrictions.rb, line 24 def allowed_networks @allowed_networks ||= configuration.allowed_networks.map do |network| IPAddr.new(network) end end
check_configuration!()
click to toggle source
Check the configuration parameters for network restrictions
@raise [Uninterruptible::ConfigurationError] Correct options are not set for network restrictions
# File lib/uninterruptible/network_restrictions.rb, line 33 def check_configuration! if configuration.block_connections? && !configuration.bind.start_with?('tcp://') raise ConfigurationError, "Network restrictions can only be used on TCP servers" end end