Class: Lemans::Config::NetworkPolicy
- Inherits:
-
Object
- Object
- Lemans::Config::NetworkPolicy
- Defined in:
- lib/lemans/config/network_policy.rb
Overview
:nodoc:
Constant Summary collapse
- MODES =
%w[none allowlist public].freeze
Instance Attribute Summary collapse
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Class Method Summary collapse
Instance Method Summary collapse
-
#domains ⇒ Object
Backends allowlist domains and IP ranges through separate APIs.
-
#initialize(mode = "public", hosts = nil) ⇒ NetworkPolicy
constructor
A new instance of NetworkPolicy.
- #ip_targets ⇒ Object
Constructor Details
#initialize(mode = "public", hosts = nil) ⇒ NetworkPolicy
Returns a new instance of NetworkPolicy.
31 32 33 34 |
# File 'lib/lemans/config/network_policy.rb', line 31 def initialize(mode = "public", hosts = nil) @mode = mode.to_s @hosts = hosts end |
Instance Attribute Details
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
29 30 31 |
# File 'lib/lemans/config/network_policy.rb', line 29 def hosts @hosts end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
29 30 31 |
# File 'lib/lemans/config/network_policy.rb', line 29 def mode @mode end |
Class Method Details
.from_config(data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lemans/config/network_policy.rb', line 15 def from_config(data) return if data.nil? mode = (data["mode"] || "public").to_s raise ConfigError, "#{mode.inspect} is not a network mode (#{MODES.join(", ")})" unless MODES.include?(mode) hosts = data["hosts"] raise ConfigError, "network.hosts is only meaningful with mode: allowlist" if mode != "allowlist" && hosts raise ConfigError, "network.hosts must be provided with mode: allowlist" if mode == "allowlist" && Array(hosts).empty? new(mode, hosts) end |
Instance Method Details
#domains ⇒ Object
Backends allowlist domains and IP ranges through separate APIs.
37 |
# File 'lib/lemans/config/network_policy.rb', line 37 def domains = partitioned_hosts.last |
#ip_targets ⇒ Object
39 |
# File 'lib/lemans/config/network_policy.rb', line 39 def ip_targets = partitioned_hosts.first |