mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03: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
|
# IDs to each example group
|
||||||
# TODO: remove this once IDs are in rspec-core
|
# TODO: remove this once IDs are in rspec-core
|
||||||
def describe(sth, &block)
|
def describe(sth, &block)
|
||||||
r = Rule.describe(sth, &block)
|
@checks ||= []
|
||||||
set_rspec_ids(r)
|
@checks.push(['describe', [sth], block])
|
||||||
end
|
end
|
||||||
|
|
||||||
# redirect all regular method calls to the
|
# redirect all regular method calls to the
|
||||||
|
@ -23,23 +23,6 @@ module Vulcano
|
||||||
VulcanoRule.__send__(m, *a, &b)
|
VulcanoRule.__send__(m, *a, &b)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,13 +37,15 @@ end
|
||||||
module Vulcano::DSL
|
module Vulcano::DSL
|
||||||
|
|
||||||
def rule id, &block
|
def rule id, &block
|
||||||
existing = Vulcano::Rule.registry[id]
|
r = Vulcano::Rule.new(id, &block)
|
||||||
if existing.nil?
|
execute_rule(r)
|
||||||
Vulcano::Rule.registry[id] = Vulcano::Rule.new(id, &block)
|
# existing = Vulcano::Rule.registry[id]
|
||||||
else
|
# if existing.nil?
|
||||||
p "RULE #{id} was found: #{existing}"
|
#
|
||||||
# TODO: alter existing rule
|
# else
|
||||||
end
|
# p "RULE #{id} was found: #{existing}"
|
||||||
|
# # TODO: alter existing rule
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_rules id, &block
|
def require_rules id, &block
|
||||||
|
@ -76,6 +61,29 @@ module Vulcano::DSL
|
||||||
|
|
||||||
private
|
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
|
def get_spec_files_for_profile id
|
||||||
base_path = '/etc/vulcanosec/tests'
|
base_path = '/etc/vulcanosec/tests'
|
||||||
path = File.join( base_path, id )
|
path = File.join( base_path, id )
|
||||||
|
|
Loading…
Reference in a new issue