Merge pull request #1348 from chef/chris-rock/use-cached-compliance

use cached profile for compliance dependencies if vendored
This commit is contained in:
Christoph Hartmann 2016-12-08 10:31:51 +00:00 committed by GitHub
commit db96fe04b7

View file

@ -13,7 +13,7 @@ module Compliance
class Fetcher < Fetchers::Url
name 'compliance'
priority 500
def self.resolve(target) # rubocop:disable PerceivedComplexity
def self.resolve(target) # rubocop:disable PerceivedComplexity, Metrics/CyclomaticComplexity
uri = if target.is_a?(String) && URI(target).scheme == 'compliance'
URI(target)
elsif target.respond_to?(:key?) && target.key?(:compliance)
@ -22,6 +22,11 @@ module Compliance
return nil if uri.nil?
# we have detailed information available in our lockfile, no need to ask the server
if target.respond_to?(:key?) && target.key?(:url)
profile_fetch_url = target[:url]
config = {}
else
# check if we have a compliance token
config = Compliance::Configuration.new
if config['token'].nil?
@ -48,7 +53,9 @@ EOF
if !Compliance::API.exist?(config, profile)
fail Inspec::FetcherFailure, "The compliance profile #{profile} was not found on the configured compliance server"
end
new(target_url(profile, config), config)
profile_fetch_url = target_url(profile, config)
end
new(profile_fetch_url, config)
rescue URI::Error => _e
nil
end
@ -63,12 +70,14 @@ EOF
target
end
#
# We want to save compliance: in the lockfile rather than url: to
# make sure we go back through the Compliance API handling.
#
def resolved_source
{ compliance: supermarket_profile_name }
@resolved_source ||= {
compliance: compliance_profile_name,
url: @target,
sha256: sha256,
}
end
def to_s
@ -77,7 +86,7 @@ EOF
private
def supermarket_profile_name
def compliance_profile_name
m = %r{^#{@config['server']}/owners/(?<owner>[^/]+)/compliance/(?<id>[^/]+)/tar$}.match(@target)
"#{m[:owner]}/#{m[:id]}"
end