Method: Inspec::DSL.filter_included_controls

Defined in:
lib/inspec/dsl.rb

.filter_included_controls(context, profile, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/inspec/dsl.rb', line 55

def self.filter_included_controls(context, profile, &block)
  mock = Inspec::Backend.create({ backend: 'mock' })
  include_ctx = Inspec::ProfileContext.for_profile(profile, mock, {})
  include_ctx.load(block) if block_given?
  # remove all rules that were not registered
  context.all_rules.each do |r|
    id = Inspec::Rule.rule_id(r)
    fid = Inspec::Rule.profile_id(r) + '/' + id
    unless include_ctx.rules[id] || include_ctx.rules[fid]
      context.remove_rule(fid)
    end
  end
end