mirror of
https://github.com/inspec/inspec
synced 2024-11-22 12:43:07 +00:00
move rule execution and ID-fixing out
Signed-off-by: Dominik Richter <dominik@vulcanosec.com>
This commit is contained in:
parent
f64f15ee6b
commit
8181ee038e
1 changed files with 34 additions and 26 deletions
|
@ -13,8 +13,8 @@ module Vulcano
|
|||
# IDs to each example group
|
||||
# TODO: remove this once IDs are in rspec-core
|
||||
def describe(sth, &block)
|
||||
r = Rule.describe(sth, &block)
|
||||
set_rspec_ids(r)
|
||||
@checks ||= []
|
||||
@checks.push(['describe', [sth], block])
|
||||
end
|
||||
|
||||
# redirect all regular method calls to the
|
||||
|
@ -23,23 +23,6 @@ module Vulcano
|
|||
VulcanoRule.__send__(m, *a, &b)
|
||||
end
|
||||
|
||||
def self.registry
|
||||
@rules ||= {}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Attach an ID attribute to the
|
||||
# metadata of all examples
|
||||
# TODO: remove this once IDs are in rspec-core
|
||||
def set_rspec_ids(obj)
|
||||
obj.examples.each {|ex|
|
||||
ex.metadata[:id] = @id
|
||||
}
|
||||
obj.children.each {|c|
|
||||
set_rspec_ids(c)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,13 +37,15 @@ end
|
|||
module Vulcano::DSL
|
||||
|
||||
def rule id, &block
|
||||
existing = Vulcano::Rule.registry[id]
|
||||
if existing.nil?
|
||||
Vulcano::Rule.registry[id] = Vulcano::Rule.new(id, &block)
|
||||
else
|
||||
p "RULE #{id} was found: #{existing}"
|
||||
# TODO: alter existing rule
|
||||
end
|
||||
r = Vulcano::Rule.new(id, &block)
|
||||
execute_rule(r)
|
||||
# existing = Vulcano::Rule.registry[id]
|
||||
# if existing.nil?
|
||||
#
|
||||
# else
|
||||
# p "RULE #{id} was found: #{existing}"
|
||||
# # TODO: alter existing rule
|
||||
# end
|
||||
end
|
||||
|
||||
def require_rules id, &block
|
||||
|
@ -76,6 +61,29 @@ module Vulcano::DSL
|
|||
|
||||
private
|
||||
|
||||
# Attach an ID attribute to the
|
||||
# metadata of all examples
|
||||
# TODO: remove this once IDs are in rspec-core
|
||||
def set_rspec_ids(obj, id)
|
||||
obj.examples.each {|ex|
|
||||
ex.metadata[:id] = id
|
||||
}
|
||||
obj.children.each {|c|
|
||||
set_rspec_ids(c, id)
|
||||
}
|
||||
end
|
||||
|
||||
def execute_rule r
|
||||
checks = r.instance_variable_get(:@checks)
|
||||
id = r.instance_variable_get(:@id)
|
||||
checks.each do |m,a,b|
|
||||
cres = ::Vulcano::Rule.__send__(m, *a, &b)
|
||||
if m=='describe'
|
||||
set_rspec_ids(cres, id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_spec_files_for_profile id
|
||||
base_path = '/etc/vulcanosec/tests'
|
||||
path = File.join( base_path, id )
|
||||
|
|
Loading…
Reference in a new issue