mirror of
https://github.com/inspec/inspec
synced 2024-11-22 12:43:07 +00:00
api: change check -> rule
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
e86cd978eb
commit
1247dd7bc7
2 changed files with 15 additions and 15 deletions
|
@ -59,7 +59,7 @@ module Vulcano
|
|||
find_all{|line,idx| line =~ /^[^"#]*describe.*do(\s|$)/ }.
|
||||
map{|x| x[1]+1 }
|
||||
|
||||
unless meta['checks'][''].nil?
|
||||
unless meta['rules'][''].nil?
|
||||
@log.error "Please configure IDs for all rules."
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,7 @@ module Vulcano
|
|||
valid = false
|
||||
}
|
||||
|
||||
meta['checks'].each do |k,v|
|
||||
meta['rules'].each do |k,v|
|
||||
if v['impact'].nil?
|
||||
invalid.("Missing impact for rule #{k}")
|
||||
else
|
||||
|
@ -85,21 +85,21 @@ module Vulcano
|
|||
private
|
||||
|
||||
def add_specs_in_folder path
|
||||
allchecks = {}
|
||||
allrules = {}
|
||||
|
||||
Dir["#{path}/spec/*_spec.rb"].each do |specfile|
|
||||
rel_path = specfile.sub(File.join(path,''), '')
|
||||
specs = SpecFile.from_file(specfile)
|
||||
allchecks[rel_path] = sanitize_specfile_json(specs.vulcano_meta)
|
||||
allrules[rel_path] = sanitize_specfile_json(specs.vulcano_meta)
|
||||
end
|
||||
|
||||
res = Metadata.for_path(path, @log).dict
|
||||
res['checks'] = allchecks
|
||||
res['rules'] = allrules
|
||||
@profiles = res
|
||||
end
|
||||
|
||||
def sanitize_specfile_json j
|
||||
j['checks'].each do |k,v|
|
||||
j['rules'].each do |k,v|
|
||||
v['title'] = k if v['title'].nil?
|
||||
v['desc'] = "" if v['desc'].nil?
|
||||
v['impact'] = 1.0 if v['impact'].nil?
|
||||
|
|
|
@ -33,7 +33,7 @@ module Vulcano
|
|||
|
||||
def vulcano_meta
|
||||
# helper methods (which we don't expose)
|
||||
def rule2check(rule)
|
||||
def rule2dict(rule)
|
||||
d = nil
|
||||
d = rule.desc.gsub(/\s*\n\s*/, ' ').strip unless rule.desc.nil?
|
||||
{
|
||||
|
@ -42,21 +42,21 @@ module Vulcano
|
|||
"desc" => d
|
||||
}
|
||||
end
|
||||
def rules2checks(rules)
|
||||
checks = {}
|
||||
def rules2dict(rules)
|
||||
res = {}
|
||||
rules.map do |rule|
|
||||
nu = rule2check(rule)
|
||||
if checks[rule.id].nil?
|
||||
checks[rule.id] = nu
|
||||
nu = rule2dict(rule)
|
||||
if res[rule.id].nil?
|
||||
res[rule.id] = nu
|
||||
else
|
||||
Log.error(
|
||||
"Not redefining rule id #{rule.id}:\n"+
|
||||
"-- #{checks[rule.id]}\n"+
|
||||
"-- #{res[rule.id]}\n"+
|
||||
"++ #{nu}\n"
|
||||
)
|
||||
end
|
||||
end
|
||||
checks
|
||||
res
|
||||
end
|
||||
def mOr(m, other)
|
||||
(m.nil? || m[1].nil?) ? other : m[1]
|
||||
|
@ -66,7 +66,7 @@ module Vulcano
|
|||
{
|
||||
"title" => mOr(header.match(/^# title: (.*)$/), 'untitled'),
|
||||
"copyright" => mOr(header.match(/^# copyright: (.*)$/), 'All rights reserved'),
|
||||
"checks" => rules2checks(@rules)
|
||||
"rules" => rules2dict(@rules)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue