Class: WebConsole::Whitelist

Inherits:
Object
  • Object
show all
Defined in:
lib/web_console/whitelist.rb

Overview

Whitelist of allowed networks that can access Web Console.

Networks are represented by standard IPAddr and can be either IPv4 or IPv6 networks.

Constant Summary collapse

ALWAYS_WHITELISTED_NETWORKS =

IPv4 and IPv6 localhost should be always whitelisted.

%w( 127.0.0.0/8 ::1 )

Instance Method Summary collapse

Constructor Details

#initialize(networks = nil) ⇒ Whitelist

Returns a new instance of Whitelist.



14
15
16
# File 'lib/web_console/whitelist.rb', line 14

def initialize(networks = nil)
  @networks = normalize_networks(networks).map(&method(:coerce_network_to_ipaddr)).uniq
end

Instance Method Details

#include?(network) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/web_console/whitelist.rb', line 18

def include?(network)
  @networks.any? { |whitelist| whitelist.include?(network.to_s) }
rescue IPAddr::InvalidAddressError
  false
end

#to_sObject



24
25
26
# File 'lib/web_console/whitelist.rb', line 24

def to_s
  @networks.map(&method(:human_readable_ipaddr)).join(", ")
end