Module: Chef::DSL::Audit

Included in:
Recipe
Defined in:
lib/chef/dsl/audit.rb

Instance Method Summary collapse

Instance Method Details

#control_group(*args, &block) ⇒ Object

Can encompass tests in a control block or describe block Adds the controls group and block (containing controls to execute) to the runner's list of pending examples


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/dsl/audit.rb', line 27

def control_group(*args, &block)
  raise Chef::Exceptions::NoAuditsProvided unless block

  name = args[0]
  if name.nil? || name.empty?
    raise Chef::Exceptions::AuditNameMissing
  elsif run_context.audits.has_key?(name)
    raise Chef::Exceptions::AuditControlGroupDuplicate.new(name)
  end

  # This DSL will only work in the Recipe class because that exposes the cookbook_name
  cookbook_name = self.cookbook_name
   = {
      cookbook_name: cookbook_name,
      cookbook_version: run_context.cookbook_collection[cookbook_name].version,
      recipe_name: recipe_name,
      line_number: block.source_location[1],
  }

  run_context.audits[name] = Struct.new(:args, :block, :metadata).new(args, block, )
end