mirror of
https://github.com/inspec/inspec
synced 2024-11-30 16:39:20 +00:00
Merge pull request #1348 from chef/chris-rock/use-cached-compliance
use cached profile for compliance dependencies if vendored
This commit is contained in:
commit
db96fe04b7
1 changed files with 32 additions and 23 deletions
|
@ -13,7 +13,7 @@ module Compliance
|
||||||
class Fetcher < Fetchers::Url
|
class Fetcher < Fetchers::Url
|
||||||
name 'compliance'
|
name 'compliance'
|
||||||
priority 500
|
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 = if target.is_a?(String) && URI(target).scheme == 'compliance'
|
||||||
URI(target)
|
URI(target)
|
||||||
elsif target.respond_to?(:key?) && target.key?(:compliance)
|
elsif target.respond_to?(:key?) && target.key?(:compliance)
|
||||||
|
@ -22,6 +22,11 @@ module Compliance
|
||||||
|
|
||||||
return nil if uri.nil?
|
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
|
# check if we have a compliance token
|
||||||
config = Compliance::Configuration.new
|
config = Compliance::Configuration.new
|
||||||
if config['token'].nil?
|
if config['token'].nil?
|
||||||
|
@ -48,7 +53,9 @@ EOF
|
||||||
if !Compliance::API.exist?(config, profile)
|
if !Compliance::API.exist?(config, profile)
|
||||||
fail Inspec::FetcherFailure, "The compliance profile #{profile} was not found on the configured compliance server"
|
fail Inspec::FetcherFailure, "The compliance profile #{profile} was not found on the configured compliance server"
|
||||||
end
|
end
|
||||||
new(target_url(profile, config), config)
|
profile_fetch_url = target_url(profile, config)
|
||||||
|
end
|
||||||
|
new(profile_fetch_url, config)
|
||||||
rescue URI::Error => _e
|
rescue URI::Error => _e
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
@ -63,12 +70,14 @@ EOF
|
||||||
target
|
target
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
|
||||||
# We want to save compliance: in the lockfile rather than url: to
|
# We want to save compliance: in the lockfile rather than url: to
|
||||||
# make sure we go back through the ComplianceAPI handling.
|
# make sure we go back through the Compliance API handling.
|
||||||
#
|
|
||||||
def resolved_source
|
def resolved_source
|
||||||
{ compliance: supermarket_profile_name }
|
@resolved_source ||= {
|
||||||
|
compliance: compliance_profile_name,
|
||||||
|
url: @target,
|
||||||
|
sha256: sha256,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
@ -77,7 +86,7 @@ EOF
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def supermarket_profile_name
|
def compliance_profile_name
|
||||||
m = %r{^#{@config['server']}/owners/(?<owner>[^/]+)/compliance/(?<id>[^/]+)/tar$}.match(@target)
|
m = %r{^#{@config['server']}/owners/(?<owner>[^/]+)/compliance/(?<id>[^/]+)/tar$}.match(@target)
|
||||||
"#{m[:owner]}/#{m[:id]}"
|
"#{m[:owner]}/#{m[:id]}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue