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
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Support for Outer Profile DSL plugins This is called when an unknown method is encountered “bare” in a control file - outside of a control or describe block.
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/inspec/dsl.rb', line 31
def method_missing(method_name, *arguments, &block)
registry = Inspec::Plugin::V2::Registry.instance
hook = registry.find_activators(plugin_type: :outer_profile_dsl, activator_name: method_name).first
if hook
hook.activate
self.class.include(hook.implementation_class)
send(method_name, *arguments, &block)
else
super
end
end
|
Class Method Details
.filter_included_controls(context, profile, &block) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/inspec/dsl.rb', line 77
def self.filter_included_controls(context, profile, &block)
mock = Inspec::Backend.create(Inspec::Config.mock)
include_ctx = Inspec::ProfileContext.for_profile(profile, mock)
include_ctx.load(block) if block_given?
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
|
.load_spec_files_for_profile(bind_context, opts, &block) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/inspec/dsl.rb', line 51
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?
raise " Cannot load '\#{profile_id}' since it is not listed as a dependency of \#{bind_context.profile_name}.\n\n Dependencies available from this context are:\n \#{dependencies.list.keys.join(\"\\n \")}\n EOF\n end\n\n # Do not load any controls if the profile is not supported\n return unless dep_entry.profile.supports_platform?\n\n context = dep_entry.profile.runner_context\n # if we don't want all the rules, then just make 1 pass to get all rule_IDs\n # that we want to keep from the original\n filter_included_controls(context, dep_entry.profile, &block) unless opts[:include_all]\n # interpret the block and skip/modify as required\n context.load(block) if block_given?\n bind_context.add_subcontext(context)\nend\n"
|
Instance Method Details
#include_controls(id, &block) ⇒ Object
Also known as:
include_rules
11
12
13
14
|
# File 'lib/inspec/dsl.rb', line 11
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
6
7
8
9
|
# File 'lib/inspec/dsl.rb', line 6
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
|
#require_resource(options = {}) ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/inspec/dsl.rb', line 19
def require_resource(options = {})
raise "You must specify a specific resource name when calling require_resource()" if options[:resource].nil?
from_profile = options[:profile] || profile_name
target_name = options[:as] || options[:resource]
res = resource_class(from_profile, options[:resource])
add_resource(target_name, res)
end
|