Class: WebConsole::Whitelist
- Inherits:
-
Object
- Object
- WebConsole::Whitelist
- 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
- #include?(network) ⇒ Boolean
-
#initialize(networks = nil) ⇒ Whitelist
constructor
A new instance of Whitelist.
- #to_s ⇒ Object
Constructor Details
#initialize(networks = nil) ⇒ Whitelist
Returns a new instance of Whitelist.
12 13 14 |
# File 'lib/web_console/whitelist.rb', line 12 def initialize(networks = nil) @networks = normalize_networks(networks).map(&method(:coerce_network_to_ipaddr)).uniq end |
Instance Method Details
#include?(network) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/web_console/whitelist.rb', line 16 def include?(network) @networks.any? { |whitelist| whitelist.include?(network.to_s) } rescue IPAddr::InvalidAddressError false end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/web_console/whitelist.rb', line 22 def to_s @networks.map(&method(:human_readable_ipaddr)).join(', ') end |