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(tests, libs, options = {}) ⇒ Object
- #add_profile(profile, options = {}) ⇒ Object
- #add_target(target, options = {}) ⇒ Object
- #configure_transport ⇒ Object
- #create_context(options = {}) ⇒ 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(tests, libs, options = {}) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/inspec/runner.rb', line 76 def add_content(tests, libs, = {}) return if tests.nil? || tests.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 tests = [tests] unless tests.is_a? Array tests.each { |t| add_test_to_context(t, ctx) } # process the resulting rules filter_controls(ctx.rules, [:controls]).each do |rule_id, rule| register_rule(rule_id, rule) end end |
#add_profile(profile, options = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/inspec/runner.rb', line 55 def add_profile(profile, = {}) return unless [:ignore_supports] || profile..supports_transport?(@backend) @test_collector.add_profile(profile) libs = profile.libraries.map do |k, v| { ref: k, content: v } end tests = profile.tests.map do |ref, content| r = profile.source_reader.target.abs_path(ref) { ref: r, content: content } end add_content(tests, libs, ) end |
#add_target(target, options = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/inspec/runner.rb', line 49 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(options = {}) ⇒ Object
72 73 74 |
# File 'lib/inspec/runner.rb', line 72 def create_context( = {}) Inspec::ProfileContext.new(@profile_id, @backend, @conf.merge()) 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 |