Class: Inspec::Runner
- Inherits:
-
Object
- Object
- Inspec::Runner
- Extended by:
- Forwardable
- Defined in:
- lib/inspec/runner.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #add_content(test, libs) ⇒ Object
- #add_profile(profile, options = {}) ⇒ Object
- #add_target(target, options = {}) ⇒ Object
- #configure_transport ⇒ Object
- #create_context ⇒ Object
-
#initialize(conf = {}) ⇒ Runner
constructor
A new instance of Runner.
- #normalize_map(hm) ⇒ Object
- #tests ⇒ Object
Constructor Details
#initialize(conf = {}) ⇒ Runner
Returns a new instance of Runner.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/inspec/runner.rb', line 19 def initialize(conf = {}) @rules = {} @profile_id = conf[:id] @conf = conf.dup @conf[:logger] ||= Logger.new(nil) @test_collector = @conf.delete(:test_collector) || begin require 'inspec/runner_rspec' RunnerRspec.new(@conf) end configure_transport end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
18 19 20 |
# File 'lib/inspec/runner.rb', line 18 def backend @backend end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
18 19 20 |
# File 'lib/inspec/runner.rb', line 18 def rules @rules end |
Instance Method Details
#add_content(test, libs) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/inspec/runner.rb', line 74 def add_content(test, libs) content = test[:content] return if content.nil? || content.empty? # load all libraries ctx = create_context libs.each do |lib| ctx.load(lib[:content].to_s, lib[:ref], lib[:line] || 1) ctx.reload_dsl end # evaluate the test content ctx.load(content, test[:ref], test[:line] || 1) # process the resulting rules ctx.rules.each do |rule_id, rule| register_rule(rule_id, rule) end end |
#add_profile(profile, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/inspec/runner.rb', line 49 def add_profile(profile, = {}) return unless [:ignore_supports] || profile..supports_transport?(@backend) libs = profile.libraries.map do |k, v| { ref: k, content: v } end profile.tests.each do |ref, content| r = profile.source_reader.target.abs_path(ref) test = { ref: r, content: content } add_content(test, libs) end end |
#add_target(target, options = {}) ⇒ Object
64 65 66 67 68 |
# File 'lib/inspec/runner.rb', line 64 def add_target(target, = {}) profile = Inspec::Profile.for_target(target, ) fail "Could not resolve #{target} to valid input." if profile.nil? add_profile(profile) end |
#configure_transport ⇒ Object
45 46 47 |
# File 'lib/inspec/runner.rb', line 45 def configure_transport @backend = Inspec::Backend.create(@conf) end |
#create_context ⇒ Object
70 71 72 |
# File 'lib/inspec/runner.rb', line 70 def create_context Inspec::ProfileContext.new(@profile_id, @backend) end |
#normalize_map(hm) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/inspec/runner.rb', line 37 def normalize_map(hm) res = {} hm.each {|k, v| res[k.to_s] = v } res end |
#tests ⇒ Object
33 34 35 |
# File 'lib/inspec/runner.rb', line 33 def tests @test_collector.tests end |