Class: Lemans::Config::NetworkPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/lemans/config/network_policy.rb

Overview

:nodoc:

Constant Summary collapse

MODES =
%w[none allowlist public].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#hostsObject (readonly)

Returns the value of attribute hosts.



29
30
31
# File 'lib/lemans/config/network_policy.rb', line 29

def hosts
  @hosts
end

#modeObject (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

Raises:



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

#domainsObject

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_targetsObject



39
# File 'lib/lemans/config/network_policy.rb', line 39

def ip_targets = partitioned_hosts.first