lib/inspec/runner.rb in inspec-4.1.4.preview vs lib/inspec/runner.rb in inspec-4.2.0.preview
- old
+ new
@@ -7,11 +7,10 @@
require 'uri'
require 'inspec/backend'
require 'inspec/profile_context'
require 'inspec/profile'
require 'inspec/metadata'
-require 'inspec/secrets'
require 'inspec/config'
require 'inspec/dependencies/cache'
# spec requirements
module Inspec
@@ -30,11 +29,11 @@
# ```
#
class Runner
extend Forwardable
- attr_reader :backend, :rules, :inputs
+ attr_reader :backend, :rules
def attributes
Inspec.deprecate(:rename_attributes_to_inputs, "Don't call runner.attributes, call runner.inputs")
inputs
end
@@ -55,14 +54,21 @@
@test_collector = @conf.delete(:test_collector) || begin
require 'inspec/runner_rspec'
RunnerRspec.new(@conf)
end
- # list of profile inputs
- @inputs = {}
+ # About reading inputs:
+ # @conf gets passed around a lot, eventually to
+ # Inspec::InputRegistry.register_external_inputs.
+ #
+ # @conf may contain the key :attributes or :inputs, which is to be a Hash
+ # of values passed in from the Runner API.
+ # This is how kitchen-inspec and the audit_cookbook pass in inputs.
+ #
+ # @conf may contain the key :attrs or :input_file, which is to be an Array
+ # of file paths, each a YAML file. This how --input-file works.
- load_inputs(@conf)
configure_transport
end
def tests
@test_collector.tests
@@ -99,11 +105,10 @@
next
end
@test_collector.add_profile(requirement.profile)
end
- @inputs = profile.runner_context.inputs if @inputs.empty?
tests = profile.collect_tests
all_controls += tests unless tests.nil?
end
all_controls.each do |rule|
@@ -147,39 +152,10 @@
# dont output anything if we want a report
render_output(@run_data) unless @conf['report']
@test_collector.exit_code
end
- # determine all inputs before the execution, fetch data from secrets backend
- def load_inputs(options)
- # TODO: - rename :attributes - it is user-visible
- options[:attributes] ||= {}
-
- if options.key?(:attrs)
- Inspec.deprecate(:rename_attributes_to_inputs, 'Use --input-file on the command line instead of --attrs.')
- options[:input_file] = options.delete(:attrs)
- end
- secrets_targets = options[:input_file]
- return options[:attributes] if secrets_targets.nil?
-
- secrets_targets.each do |target|
- validate_inputs_file_readability!(target)
-
- secrets = Inspec::SecretsBackend.resolve(target)
- if secrets.nil?
- raise Inspec::Exceptions::SecretsBackendNotFound,
- "Cannot find parser for inputs file '#{target}'. " \
- 'Check to make sure file has the appropriate extension.'
- end
-
- next if secrets.inputs.nil?
- options[:attributes].merge!(secrets.inputs)
- end
-
- options[:attributes]
- end
-
#
# add_target allows the user to add a target whose tests will be
# run when the user calls the run method.
#
# A target is a path or URL that points to a profile. Using this
@@ -207,11 +183,11 @@
def add_target(target, _opts = [])
profile = Inspec::Profile.for_target(target,
vendor_cache: @cache,
backend: @backend,
controls: @controls,
- inputs: @conf[:attributes]) # TODO: read form :inputs here (user visible)
+ runner_conf: @conf)
raise "Could not resolve #{target} to valid input." if profile.nil?
@target_profiles << profile if supports_profile?(profile)
end
def supports_profile?(profile)
@@ -296,25 +272,9 @@
examples = checks.flat_map do |m, a, b|
get_check_example(m, a, b)
end.compact
examples.each { |e| @test_collector.add_test(e, rule) }
- end
-
- def validate_inputs_file_readability!(target)
- unless File.exist?(target)
- raise Inspec::Exceptions::InputsFileDoesNotExist,
- "Cannot find input file '#{target}'. " \
- 'Check to make sure file exists.'
- end
-
- unless File.readable?(target)
- raise Inspec::Exceptions::InputsFileNotReadable,
- "Cannot read input file '#{target}'. " \
- 'Check to make sure file is readable.'
- end
-
- true
end
def rspec_skipped_block(arg, opts, message)
@test_collector.example_group(*arg, opts) do
# Send custom `it` block to RSpec