Fix for null insecure option

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
Nikita Mathur 2021-07-15 17:43:11 +05:30
parent ec76259eb1
commit b4ad811f05
4 changed files with 18 additions and 10 deletions

View file

@ -6,9 +6,9 @@ module Inspec
extend Forwardable
attr_reader :cache, :target, :fetcher
def initialize(target, cache)
def initialize(target, cache, opts = {})
@target = target
@fetcher = Inspec::Fetcher::Registry.resolve(target)
@fetcher = Inspec::Fetcher::Registry.resolve(target, opts)
if @fetcher.nil?
raise("Could not fetch inspec profile in #{target.inspect}.")

View file

@ -2,12 +2,12 @@ require "inspec/plugin/v1"
module Inspec
class FetcherRegistry < PluginRegistry
def resolve(target)
def resolve(target, opts = {})
if fetcher_specified?(target)
super(target)
super(target, opts)
else
Inspec::Log.debug("Assuming default supermarket source for #{target}")
super(with_default_fetcher(target))
super(with_default_fetcher(target), opts)
end
end

View file

@ -9,9 +9,13 @@ class PluginRegistry
#
# @param [String] target to resolve
# @return [Plugin] plugin instance if it can be resolved, nil otherwise
def resolve(target)
def resolve(target, opts = {})
modules.each do |m|
res = m.resolve(target)
res = if [Inspec::Fetcher::Url, Inspec::Fetcher::Git, Supermarket::Fetcher].include? m
m.resolve(target, opts)
else
m.resolve(target)
end
return res unless res.nil?
end
nil

View file

@ -18,9 +18,9 @@ module Inspec
class Profile
extend Forwardable
def self.resolve_target(target, cache)
def self.resolve_target(target, cache, opts = {})
Inspec::Log.debug "Resolve #{target} into cache #{cache.path}"
Inspec::CachedFetcher.new(target, cache)
Inspec::CachedFetcher.new(target, cache, opts)
end
# Check if the profile contains a vendored cache, move content into global cache
@ -70,7 +70,11 @@ module Inspec
def self.for_target(target, opts = {})
opts[:vendor_cache] ||= Cache.new
fetcher = resolve_target(target, opts[:vendor_cache])
config = {}
unless opts[:runner_conf].nil? || opts[:runner_conf].empty?
config = opts[:runner_conf].respond_to?(:final_options) ? opts[:runner_conf].final_options : opts[:runner_conf]
end
fetcher = resolve_target(target, opts[:vendor_cache], config)
for_fetcher(fetcher, opts)
end