api: change check -> rule

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-06-16 23:20:24 +02:00
parent e86cd978eb
commit 1247dd7bc7
2 changed files with 15 additions and 15 deletions

View file

@ -59,7 +59,7 @@ module Vulcano
find_all{|line,idx| line =~ /^[^"#]*describe.*do(\s|$)/ }. find_all{|line,idx| line =~ /^[^"#]*describe.*do(\s|$)/ }.
map{|x| x[1]+1 } map{|x| x[1]+1 }
unless meta['checks'][''].nil? unless meta['rules'][''].nil?
@log.error "Please configure IDs for all rules." @log.error "Please configure IDs for all rules."
end end
@ -68,7 +68,7 @@ module Vulcano
valid = false valid = false
} }
meta['checks'].each do |k,v| meta['rules'].each do |k,v|
if v['impact'].nil? if v['impact'].nil?
invalid.("Missing impact for rule #{k}") invalid.("Missing impact for rule #{k}")
else else
@ -85,21 +85,21 @@ module Vulcano
private private
def add_specs_in_folder path def add_specs_in_folder path
allchecks = {} allrules = {}
Dir["#{path}/spec/*_spec.rb"].each do |specfile| Dir["#{path}/spec/*_spec.rb"].each do |specfile|
rel_path = specfile.sub(File.join(path,''), '') rel_path = specfile.sub(File.join(path,''), '')
specs = SpecFile.from_file(specfile) specs = SpecFile.from_file(specfile)
allchecks[rel_path] = sanitize_specfile_json(specs.vulcano_meta) allrules[rel_path] = sanitize_specfile_json(specs.vulcano_meta)
end end
res = Metadata.for_path(path, @log).dict res = Metadata.for_path(path, @log).dict
res['checks'] = allchecks res['rules'] = allrules
@profiles = res @profiles = res
end end
def sanitize_specfile_json j 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['title'] = k if v['title'].nil?
v['desc'] = "" if v['desc'].nil? v['desc'] = "" if v['desc'].nil?
v['impact'] = 1.0 if v['impact'].nil? v['impact'] = 1.0 if v['impact'].nil?

View file

@ -33,7 +33,7 @@ module Vulcano
def vulcano_meta def vulcano_meta
# helper methods (which we don't expose) # helper methods (which we don't expose)
def rule2check(rule) def rule2dict(rule)
d = nil d = nil
d = rule.desc.gsub(/\s*\n\s*/, ' ').strip unless rule.desc.nil? d = rule.desc.gsub(/\s*\n\s*/, ' ').strip unless rule.desc.nil?
{ {
@ -42,21 +42,21 @@ module Vulcano
"desc" => d "desc" => d
} }
end end
def rules2checks(rules) def rules2dict(rules)
checks = {} res = {}
rules.map do |rule| rules.map do |rule|
nu = rule2check(rule) nu = rule2dict(rule)
if checks[rule.id].nil? if res[rule.id].nil?
checks[rule.id] = nu res[rule.id] = nu
else else
Log.error( Log.error(
"Not redefining rule id #{rule.id}:\n"+ "Not redefining rule id #{rule.id}:\n"+
"-- #{checks[rule.id]}\n"+ "-- #{res[rule.id]}\n"+
"++ #{nu}\n" "++ #{nu}\n"
) )
end end
end end
checks res
end end
def mOr(m, other) def mOr(m, other)
(m.nil? || m[1].nil?) ? other : m[1] (m.nil? || m[1].nil?) ? other : m[1]
@ -66,7 +66,7 @@ module Vulcano
{ {
"title" => mOr(header.match(/^# title: (.*)$/), 'untitled'), "title" => mOr(header.match(/^# title: (.*)$/), 'untitled'),
"copyright" => mOr(header.match(/^# copyright: (.*)$/), 'All rights reserved'), "copyright" => mOr(header.match(/^# copyright: (.*)$/), 'All rights reserved'),
"checks" => rules2checks(@rules) "rules" => rules2dict(@rules)
} }
end end