Module: Inspec::DSL
- Defined in:
- lib/inspec/dsl_shared.rb,
lib/inspec/dsl.rb
Overview
Contains methods we would like in multiple DSL
Defined Under Namespace
Modules: RequireOverride
Class Method Summary collapse
- .filter_included_controls(context, profile, &block) ⇒ Object
- .load_spec_files_for_profile(bind_context, opts, &block) ⇒ Object
Instance Method Summary collapse
- #include_controls(id, &block) ⇒ Object (also: #include_rules)
- #require_controls(id, &block) ⇒ Object (also: #require_rules)
Class Method Details
.filter_included_controls(context, profile, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/inspec/dsl.rb', line 46 def self.filter_included_controls(context, profile, &block) include_ctx = profile.runner_context include_ctx.load(block) if block_given? # remove all rules that were not registered context.rules.keys.each do |id| unless include_ctx.rules[id] context.rules[id] = nil end end end |
.load_spec_files_for_profile(bind_context, opts, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/inspec/dsl.rb', line 21 def self.load_spec_files_for_profile(bind_context, opts, &block) dependencies = opts[:dependencies] profile_id = opts[:profile_id] dep_entry = dependencies.list[profile_id] if dep_entry.nil? fail <<EOF Cannot load #{profile_id} since it is not listed as a dependency of #{bind_context.profile_name}. Dependencies available from this context are: #{dependencies.list.keys.join("\n ")} EOF end context = dep_entry.profile.runner_context # if we don't want all the rules, then just make 1 pass to get all rule_IDs # that we want to keep from the original filter_included_controls(context, dep_entry.profile, &block) if !opts[:include_all] # interpret the block and skip/modify as required context.load(block) if block_given? bind_context.add_subcontext(context) end |
Instance Method Details
#include_controls(id, &block) ⇒ Object Also known as: include_rules
13 14 15 16 |
# File 'lib/inspec/dsl.rb', line 13 def include_controls(id, &block) opts = { profile_id: id, include_all: true, backend: @backend, conf: @conf, dependencies: @dependencies } ::Inspec::DSL.load_spec_files_for_profile(self, opts, &block) end |
#require_controls(id, &block) ⇒ Object Also known as: require_rules
8 9 10 11 |
# File 'lib/inspec/dsl.rb', line 8 def require_controls(id, &block) opts = { profile_id: id, include_all: false, backend: @backend, conf: @conf, dependencies: @dependencies } ::Inspec::DSL.load_spec_files_for_profile(self, opts, &block) end |