mirror of
https://github.com/inspec/inspec
synced 2024-11-27 15:10:44 +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,17 +22,22 @@ module Compliance
|
||||||
|
|
||||||
return nil if uri.nil?
|
return nil if uri.nil?
|
||||||
|
|
||||||
# check if we have a compliance token
|
# we have detailed information available in our lockfile, no need to ask the server
|
||||||
config = Compliance::Configuration.new
|
if target.respond_to?(:key?) && target.key?(:url)
|
||||||
if config['token'].nil?
|
profile_fetch_url = target[:url]
|
||||||
if config['server_type'] == 'automate'
|
config = {}
|
||||||
server = 'automate'
|
else
|
||||||
msg = 'inspec compliance login_automate https://your_automate_server --user USER --ent ENT --dctoken DCTOKEN or --usertoken USERTOKEN'
|
# check if we have a compliance token
|
||||||
else
|
config = Compliance::Configuration.new
|
||||||
server = 'compliance'
|
if config['token'].nil?
|
||||||
msg = "inspec compliance login https://your_compliance_server --user admin --insecure --token 'PASTE TOKEN HERE' "
|
if config['server_type'] == 'automate'
|
||||||
end
|
server = 'automate'
|
||||||
fail Inspec::FetcherFailure, <<EOF
|
msg = 'inspec compliance login_automate https://your_automate_server --user USER --ent ENT --dctoken DCTOKEN or --usertoken USERTOKEN'
|
||||||
|
else
|
||||||
|
server = 'compliance'
|
||||||
|
msg = "inspec compliance login https://your_compliance_server --user admin --insecure --token 'PASTE TOKEN HERE' "
|
||||||
|
end
|
||||||
|
fail Inspec::FetcherFailure, <<EOF
|
||||||
|
|
||||||
Cannot fetch #{uri} because your #{server} token has not been
|
Cannot fetch #{uri} because your #{server} token has not been
|
||||||
configured.
|
configured.
|
||||||
|
@ -41,14 +46,16 @@ Please login using
|
||||||
|
|
||||||
#{msg}
|
#{msg}
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
|
||||||
# verifies that the target e.g base/ssh exists
|
# verifies that the target e.g base/ssh exists
|
||||||
profile = uri.host + uri.path
|
profile = uri.host + uri.path
|
||||||
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
|
||||||
|
profile_fetch_url = target_url(profile, config)
|
||||||
end
|
end
|
||||||
new(target_url(profile, config), config)
|
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