class Inspec::Resources::MysqlConf

Public Class Methods

new(conf_path = nil) click to toggle source
# File lib/inspec/resources/mysql_conf.rb, line 53
def initialize(conf_path = nil)
  @conf_path = conf_path || inspec.mysql.conf_path
  @files_contents = {}
  @content = nil
  @params = nil
  read_content
end

Public Instance Methods

abs_path(dir, f) click to toggle source
# File lib/inspec/resources/mysql_conf.rb, line 114
def abs_path(dir, f)
  return f if f.start_with? "/"

  File.join(dir, f)
end
content() click to toggle source
# File lib/inspec/resources/mysql_conf.rb, line 61
def content
  @content ||= read_content
end
include_files(reldir, conf) click to toggle source
# File lib/inspec/resources/mysql_conf.rb, line 104
def include_files(reldir, conf)
  files = conf.scan(/^!include\s+(.*)\s*/).flatten.compact.map { |x| abs_path(reldir, x) }
  dirs = conf.scan(/^!includedir\s+(.*)\s*/).flatten.compact.map { |x| abs_path(reldir, x) }
  dirs.map do |dir|
    # @TODO: non local glob
    files += find_files(dir, depth: 1, type: "file")
  end
  files
end
method_missing(name) click to toggle source
# File lib/inspec/resources/mysql_conf.rb, line 74
def method_missing(name)
  @params || read_content
  @params[name.to_s]
end
params(*opts) click to toggle source
# File lib/inspec/resources/mysql_conf.rb, line 65
def params(*opts)
  @params || read_content
  res = @params
  opts.each do |opt|
    res = res[opt] unless res.nil?
  end
  MysqlConfEntry.new(opts, res)
end
read_content() click to toggle source
# File lib/inspec/resources/mysql_conf.rb, line 79
def read_content
  @content = ""
  @params = {}

  to_read = [@conf_path]
  until to_read.empty?
    cur_file = to_read[0]
    raw_conf = read_file(cur_file)
    @content += raw_conf

    params = SimpleConfig.new(raw_conf).params
    @params = @params.deep_merge(params)

    to_read = to_read.drop(1)
    # see if there is more stuff to include

    dir = File.dirname(cur_file)
    to_read += include_files(dir, raw_conf).find_all do |fp|
      not @files_contents.key? fp
    end
  end
  #
  @content
end
read_file(path) click to toggle source
# File lib/inspec/resources/mysql_conf.rb, line 120
def read_file(path)
  @files_contents[path] ||= read_file_content(path)
end
to_s() click to toggle source
# File lib/inspec/resources/mysql_conf.rb, line 124
def to_s
  "MySQL Configuration"
end