class Inspec::Resources::PostgresHbaConf
Attributes
conf_file[R]
params[R]
Public Class Methods
new(hba_conf_path = nil)
click to toggle source
@todo add checks to ensure that we have data in our file
# File lib/inspec/resources/postgres_hba_conf.rb, line 22 def initialize(hba_conf_path = nil) @conf_file = hba_conf_path || File.join(inspec.postgres.conf_dir, "pg_hba.conf") @content = "" @params = {} read_content end
Public Instance Methods
to_s()
click to toggle source
# File lib/inspec/resources/postgres_hba_conf.rb, line 39 def to_s "Postgres Hba Config #{@conf_file}" end
Private Instance Methods
clean_conf_file(conf_file = @conf_file)
click to toggle source
# File lib/inspec/resources/postgres_hba_conf.rb, line 45 def clean_conf_file(conf_file = @conf_file) data = read_file_content(conf_file).to_s.lines content = [] data.each do |line| line.chomp! content << line unless line.match(/^\s*#/) || line.empty? end content end
parse_conf(content)
click to toggle source
# File lib/inspec/resources/postgres_hba_conf.rb, line 69 def parse_conf(content) content.map do |line| parse_line(line) end.compact end
parse_line(line)
click to toggle source
# File lib/inspec/resources/postgres_hba_conf.rb, line 75 def parse_line(line) x = line.split(/\s+/) { "type" => x[0], "database" => x[1], "user" => x[2], "address" => x[3], "auth_method" => x[4], "auth_params" => ("" if x.length == 4) || x[5..-1].join(" "), } end
read_content(config_file = @conf_file)
click to toggle source
# File lib/inspec/resources/postgres_hba_conf.rb, line 55 def read_content(config_file = @conf_file) # @todo use SimpleConfig here if we can # ^\s*(\S+)\s+(\S+)\s+(\S+)\s(?:(\d*.\d*.\d*.\d*\/\d*)|(::\/\d+))\s+(\S+)\s*(.*)?\s*$ @content = clean_conf_file(config_file) @params = parse_conf(@content) @params.each do |line| if line["type"] == "local" line["auth_method"] = line["address"] line["address"] = "" end end end