2019-06-11 22:24:35 +00:00
|
|
|
require "uri"
|
|
|
|
require "inspec/fetcher"
|
|
|
|
require "fetchers/url"
|
2016-02-08 19:06:07 +00:00
|
|
|
|
|
|
|
# InSpec Target Helper for Supermarket
|
|
|
|
module Supermarket
|
2016-09-08 09:11:44 +00:00
|
|
|
class Fetcher < Inspec.fetcher(1)
|
2019-06-11 22:24:35 +00:00
|
|
|
name "supermarket"
|
2016-02-22 01:18:02 +00:00
|
|
|
priority 500
|
2016-02-08 19:06:07 +00:00
|
|
|
|
2016-02-22 01:18:02 +00:00
|
|
|
def self.resolve(target, opts = {})
|
2019-06-11 22:24:35 +00:00
|
|
|
supermarket_uri, supermarket_server = if target.is_a?(String) && URI(target).scheme == "supermarket"
|
2016-09-09 09:21:54 +00:00
|
|
|
[target, Supermarket::API::SUPERMARKET_URL]
|
|
|
|
elsif target.respond_to?(:key?) && target.key?(:supermarket)
|
|
|
|
supermarket_server = target[:supermarket_url] || Supermarket::API::SUPERMARKET_URL
|
|
|
|
["supermarket://#{target[:supermarket]}", supermarket_server]
|
|
|
|
end
|
|
|
|
return nil unless supermarket_uri
|
|
|
|
return nil unless Supermarket::API.exist?(supermarket_uri, supermarket_server)
|
2019-07-09 00:20:30 +00:00
|
|
|
|
2016-09-09 09:21:54 +00:00
|
|
|
tool_info = Supermarket::API.find(supermarket_uri, supermarket_server)
|
2019-06-11 22:24:35 +00:00
|
|
|
resolve_next(tool_info["tool_source_url"], opts)
|
2016-08-11 18:45:56 +00:00
|
|
|
rescue URI::Error
|
2016-02-22 01:18:02 +00:00
|
|
|
nil
|
2016-02-08 19:06:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2019-06-11 22:24:35 +00:00
|
|
|
"Chef Compliance Profile Loader"
|
2016-02-08 19:06:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|