mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
fix code complexity lint
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
0d5ee00ac5
commit
486c5fde1c
3 changed files with 46 additions and 38 deletions
|
@ -69,39 +69,36 @@ class ApacheConf < Vulcano.resource(1)
|
|||
@params.merge!(params)
|
||||
|
||||
to_read = to_read.drop(1)
|
||||
# see if there is more config files to include
|
||||
include_files = params['Include'] || []
|
||||
include_files_optional = params['IncludeOptional'] || []
|
||||
|
||||
required = []
|
||||
include_files.each do |f|
|
||||
id = File.join(@conf_dir, f)
|
||||
required.push(FindFiles.find(id, depth: 1, type: 'file'))
|
||||
end
|
||||
|
||||
required.flatten!
|
||||
to_read += required.find_all do |fp|
|
||||
not @files_contents.key? fp
|
||||
end
|
||||
|
||||
optional = []
|
||||
include_files_optional.each do |f|
|
||||
id = File.join(@conf_dir, f)
|
||||
optional.push(FindFiles.find(id, depth: 1, type: 'file'))
|
||||
end
|
||||
|
||||
optional.flatten!
|
||||
to_read += optional.find_all do |fp|
|
||||
to_read += include_files(params).find_all do |fp|
|
||||
not @files_contents.key? fp
|
||||
end
|
||||
end
|
||||
|
||||
# fiter comments
|
||||
@content = filter_comments @content
|
||||
|
||||
@content
|
||||
end
|
||||
|
||||
def include_files(params)
|
||||
# see if there is more config files to include
|
||||
include_files = params['Include'] || []
|
||||
include_files_optional = params['IncludeOptional'] || []
|
||||
|
||||
required = []
|
||||
include_files.each do |f|
|
||||
id = File.join(@conf_dir, f)
|
||||
required.push(FindFiles.find(id, depth: 1, type: 'file'))
|
||||
end
|
||||
|
||||
optional = []
|
||||
include_files_optional.each do |f|
|
||||
id = File.join(@conf_dir, f)
|
||||
optional.push(FindFiles.find(id, depth: 1, type: 'file'))
|
||||
end
|
||||
|
||||
required.flatten! + optional.flatten!
|
||||
end
|
||||
|
||||
def read_file(path)
|
||||
@files_contents[path] ||= vulcano.file(path).content
|
||||
end
|
||||
|
|
|
@ -76,12 +76,8 @@ class MysqlConf < Vulcano.resource(1)
|
|||
|
||||
to_read = to_read.drop(1)
|
||||
# see if there is more stuff to include
|
||||
include_files = raw_conf.scan(/^!include\s+(.*)\s*/).flatten.compact
|
||||
include_dirs = raw_conf.scan(/^!includedir\s+(.*)\s*/).flatten.compact
|
||||
include_dirs.map do |include_dir|
|
||||
include_files += FindFiles.find(include_dir, depth: 1, type: 'file')
|
||||
end
|
||||
to_read += include_files.find_all do |fp|
|
||||
|
||||
to_read += include_files(conf).find_all do |fp|
|
||||
not @files_contents.key? fp
|
||||
end
|
||||
end
|
||||
|
@ -89,6 +85,16 @@ class MysqlConf < Vulcano.resource(1)
|
|||
@content
|
||||
end
|
||||
|
||||
def include_files(conf)
|
||||
files = conf.scan(/^!include\s+(.*)\s*/).flatten.compact
|
||||
dirs = conf.scan(/^!includedir\s+(.*)\s*/).flatten.compact
|
||||
dirs.map do |dir|
|
||||
# @TODO: non local glob
|
||||
files += FindFiles.find(dir, depth: 1, type: 'file')
|
||||
end
|
||||
files
|
||||
end
|
||||
|
||||
def read_file(path)
|
||||
@files_contents[path] ||= vulcano.file(path).content
|
||||
end
|
||||
|
|
|
@ -54,20 +54,25 @@ class PostgresConf < Vulcano.resource(1)
|
|||
|
||||
to_read = to_read.drop(1)
|
||||
# see if there is more config files to include
|
||||
include_files = params['include'] || []
|
||||
include_files += params['include_if_exists'] || []
|
||||
dirs = params['include_dir'] || []
|
||||
dirs.each do |dir|
|
||||
dir = File.join(@conf_dir, dir) if dir[0] != '/'
|
||||
include_files += FindFiles.find(dir, depth: 1, type: 'file')
|
||||
end
|
||||
to_read += include_files.find_all do |fp|
|
||||
|
||||
to_read += include_files(params).find_all do |fp|
|
||||
not @files_contents.key? fp
|
||||
end
|
||||
end
|
||||
@content
|
||||
end
|
||||
|
||||
def include_files(params)
|
||||
include_files = params['include'] || []
|
||||
include_files += params['include_if_exists'] || []
|
||||
dirs = params['include_dir'] || []
|
||||
dirs.each do |dir|
|
||||
dir = File.join(@conf_dir, dir) if dir[0] != '/'
|
||||
include_files += FindFiles.find(dir, depth: 1, type: 'file')
|
||||
end
|
||||
include_files
|
||||
end
|
||||
|
||||
def read_file(path)
|
||||
@files_contents[path] ||= vulcano.file(path).content
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue