lib/inspec/runner.rb in inspec-0.24.0 vs lib/inspec/runner.rb in inspec-0.25.0
- old
+ new
@@ -8,26 +8,31 @@
require 'uri'
require 'inspec/backend'
require 'inspec/profile_context'
require 'inspec/profile'
require 'inspec/metadata'
+require 'inspec/secrets'
# spec requirements
module Inspec
class Runner # rubocop:disable Metrics/ClassLength
extend Forwardable
- attr_reader :backend, :rules
+ attr_reader :backend, :rules, :attributes
def initialize(conf = {})
@rules = {}
@conf = conf.dup
@conf[:logger] ||= Logger.new(nil)
@test_collector = @conf.delete(:test_collector) || begin
require 'inspec/runner_rspec'
RunnerRspec.new(@conf)
end
+ # list of profile attributes
+ @attributes = []
+
+ load_attributes(@conf)
configure_transport
end
def tests
@test_collector.tests
@@ -43,10 +48,25 @@
def configure_transport
@backend = Inspec::Backend.create(@conf)
end
+ # determine all attributes before the execution, fetch data from secrets backend
+ def load_attributes(options)
+ attributes = {}
+ # read endpoints for secrets eg. yml file
+ secrets_targets = options['attrs']
+ unless secrets_targets.nil?
+ secrets_targets.each do |target|
+ secrets = Inspec::SecretsBackend.resolve(target)
+ # merge hash values
+ attributes = attributes.merge(secrets.attributes) unless secrets.nil? || secrets.attributes.nil?
+ end
+ end
+ options['attributes'] = attributes
+ end
+
def add_target(target, options = {})
profile = Inspec::Profile.for_target(target, options)
fail "Could not resolve #{target} to valid input." if profile.nil?
add_profile(profile, options)
end
@@ -107,9 +127,12 @@
end
# evaluate the test content
tests = [tests] unless tests.is_a? Array
tests.each { |t| add_test_to_context(t, ctx) }
+
+ # merge all collect all attributes
+ @attributes |= ctx.attributes
# process the resulting rules
filter_controls(ctx.rules, options[:controls]).each do |rule_id, rule|
register_rule(rule_id, rule)
end