class Inspec::Resources::EtcHosts
Constants
- DEFAULT_UNIX_PATH
- DEFAULT_WINDOWS_PATH
Attributes
params[R]
Public Class Methods
new(hosts_path = nil)
click to toggle source
# File lib/inspec/resources/etc_hosts.rb, line 27 def initialize(hosts_path = nil) content = read_file_content(hosts_path || default_hosts_file_path) @params = parse_conf(content.lines) end
Public Instance Methods
to_s()
click to toggle source
# File lib/inspec/resources/etc_hosts.rb, line 39 def to_s "Hosts File" end
Private Instance Methods
comment?()
click to toggle source
# File lib/inspec/resources/etc_hosts.rb, line 53 def comment? parse_options = { comment_char: "#", standalone_comments: false } ->(data) { parse_comment_line(data, parse_options).first.empty? } end
default_hosts_file_path()
click to toggle source
# File lib/inspec/resources/etc_hosts.rb, line 45 def default_hosts_file_path inspec.os.windows? ? DEFAULT_WINDOWS_PATH : DEFAULT_UNIX_PATH end
format_data()
click to toggle source
# File lib/inspec/resources/etc_hosts.rb, line 63 def format_data ->(data) { %w{ip_address primary_name all_host_names}.zip(data).to_h } end
parse_conf(lines)
click to toggle source
# File lib/inspec/resources/etc_hosts.rb, line 49 def parse_conf(lines) lines.reject(&:empty?).reject(&comment?).map(&parse_data).map(&format_data) end
parse_data()
click to toggle source
# File lib/inspec/resources/etc_hosts.rb, line 59 def parse_data ->(data) { [data.split[0], data.split[1], data.split[1..-1]] } end