inspec/lib/inspec/fetcher.rb
Clinton Wolfe 628b9fb78b Explicitly require the compliance fetcher
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2020-03-02 17:33:56 -05:00

46 lines
1.1 KiB
Ruby

require "inspec/plugin/v1"
module Inspec
class FetcherRegistry < PluginRegistry
def resolve(target)
if fetcher_specified?(target)
super(target)
else
Inspec::Log.debug("Assuming default supermarket source for #{target}")
super(with_default_fetcher(target))
end
end
NON_FETCHER_KEYS = %i{name version_constraint cwd backend cache sha256}.freeze
def fetcher_specified?(target)
# Only set a default for Hash-based (i.e. from
# inspec.yml/inspec.lock) targets
return true unless target.respond_to?(:keys)
!(target.keys - NON_FETCHER_KEYS).empty?
end
def with_default_fetcher(target)
target.merge({ supermarket: target[:name] })
end
end
module Fetcher
Registry = FetcherRegistry.new
end
def self.fetcher(version)
if version != 1
raise "Only fetcher version 1 is supported!"
end
Inspec::Plugins::Fetcher
end
end
# TODO: remove. require up, not down.
require "inspec/fetcher/local"
require "inspec/fetcher/url"
require "inspec/fetcher/git"
require "plugins/inspec-compliance/lib/inspec-compliance/api"