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.
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/inspec/dsl.rb', line 34
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
.load_spec_files_for_profile(bind_context, opts, &block) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/inspec/dsl.rb', line 54
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 <<~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
return unless dep_entry.profile.supports_platform?
context = dep_entry.profile.runner_context
filter_included_controls(context, dep_entry.profile, &block) if !opts[:include_all]
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
14
15
16
17
|
# File 'lib/inspec/dsl.rb', line 14
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
9
10
11
12
|
# File 'lib/inspec/dsl.rb', line 9
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
22
23
24
25
26
27
28
29
|
# File 'lib/inspec/dsl.rb', line 22
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
|