class Inspec::Resources::EtcHostsAllow
Attributes
params[R]
Public Class Methods
new(hosts_allow_path = nil)
click to toggle source
# File lib/inspec/resources/etc_hosts_allow_deny.rb, line 22 def initialize(hosts_allow_path = nil) @conf_path = hosts_allow_path || "/etc/hosts.allow" @content = nil @params = nil read_content end
Public Instance Methods
to_s()
click to toggle source
# File lib/inspec/resources/etc_hosts_allow_deny.rb, line 36 def to_s "hosts.allow Configuration" end
Private Instance Methods
parse_conf(content)
click to toggle source
# File lib/inspec/resources/etc_hosts_allow_deny.rb, line 62 def parse_conf(content) content.map do |line| data, = parse_comment_line(line, comment_char: "#", standalone_comments: false) parse_line(data) unless data == "" end.compact end
parse_line(line)
click to toggle source
# File lib/inspec/resources/etc_hosts_allow_deny.rb, line 69 def parse_line(line) daemon, clients_and_options = line.split(/:\s+/, 2) daemon = daemon.strip clients_and_options ||= "" clients, options = clients_and_options.split(/\s+:\s+/, 2) client_list = clients.split(/,/).map(&:strip) options ||= "" options_list = options.split(/:\s+/).map(&:strip) { "daemon" => daemon, "client_list" => client_list, "options" => options_list, } end
read_content()
click to toggle source
# File lib/inspec/resources/etc_hosts_allow_deny.rb, line 42 def read_content @content = "" @params = {} @content = split_daemons(read_file(@conf_path)) @params = parse_conf(@content) end
read_file(conf_path = @conf_path)
click to toggle source
# File lib/inspec/resources/etc_hosts_allow_deny.rb, line 87 def read_file(conf_path = @conf_path) read_file_content(conf_path).lines end
split_daemons(content)
click to toggle source
# File lib/inspec/resources/etc_hosts_allow_deny.rb, line 49 def split_daemons(content) split_daemons_list = [] content.each do |line| data, = parse_comment_line(line, comment_char: "#", standalone_comments: false) next unless data != "" data.split(":")[0].split(",").each do |daemon| split_daemons_list.push("#{daemon} : " + line.split(":", 2)[1]) end end split_daemons_list end