mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
update mysql_conf to work with new find_files
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
1345c1d017
commit
58fa9bc6c7
1 changed files with 15 additions and 6 deletions
|
@ -27,6 +27,8 @@ end
|
||||||
class MysqlConf < Vulcano.resource(1)
|
class MysqlConf < Vulcano.resource(1)
|
||||||
name 'mysql_conf'
|
name 'mysql_conf'
|
||||||
|
|
||||||
|
include FindFiles
|
||||||
|
|
||||||
def initialize(conf_path)
|
def initialize(conf_path)
|
||||||
@conf_path = conf_path
|
@conf_path = conf_path
|
||||||
@files_contents = {}
|
@files_contents = {}
|
||||||
|
@ -68,7 +70,8 @@ class MysqlConf < Vulcano.resource(1)
|
||||||
|
|
||||||
to_read = [@conf_path]
|
to_read = [@conf_path]
|
||||||
until to_read.empty?
|
until to_read.empty?
|
||||||
raw_conf = read_file(to_read[0])
|
cur_file = to_read[0]
|
||||||
|
raw_conf = read_file(cur_file)
|
||||||
@content += raw_conf
|
@content += raw_conf
|
||||||
|
|
||||||
params = ParseConfig.new(raw_conf).params
|
params = ParseConfig.new(raw_conf).params
|
||||||
|
@ -77,7 +80,8 @@ class MysqlConf < Vulcano.resource(1)
|
||||||
to_read = to_read.drop(1)
|
to_read = to_read.drop(1)
|
||||||
# see if there is more stuff to include
|
# see if there is more stuff to include
|
||||||
|
|
||||||
to_read += include_files(conf).find_all do |fp|
|
dir = File.dirname(cur_file)
|
||||||
|
to_read += include_files(dir, raw_conf).find_all do |fp|
|
||||||
not @files_contents.key? fp
|
not @files_contents.key? fp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -85,16 +89,21 @@ class MysqlConf < Vulcano.resource(1)
|
||||||
@content
|
@content
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_files(conf)
|
def include_files(reldir, conf)
|
||||||
files = conf.scan(/^!include\s+(.*)\s*/).flatten.compact
|
files = conf.scan(/^!include\s+(.*)\s*/).flatten.compact.map { |x| abs_path(reldir, x) }
|
||||||
dirs = conf.scan(/^!includedir\s+(.*)\s*/).flatten.compact
|
dirs = conf.scan(/^!includedir\s+(.*)\s*/).flatten.compact.map { |x| abs_path(reldir, x) }
|
||||||
dirs.map do |dir|
|
dirs.map do |dir|
|
||||||
# @TODO: non local glob
|
# @TODO: non local glob
|
||||||
files += FindFiles.find(dir, depth: 1, type: 'file')
|
files += find_files(dir, depth: 1, type: 'file')
|
||||||
end
|
end
|
||||||
files
|
files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def abs_path(dir, f)
|
||||||
|
return f if f.start_with? '/'
|
||||||
|
File.join(dir, f)
|
||||||
|
end
|
||||||
|
|
||||||
def read_file(path)
|
def read_file(path)
|
||||||
@files_contents[path] ||= vulcano.file(path).content
|
@files_contents[path] ||= vulcano.file(path).content
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue