lib/bundles/inspec-compliance/target.rb in inspec-1.9.0 vs lib/bundles/inspec-compliance/target.rb in inspec-1.10.0
- old
+ new
@@ -11,11 +11,11 @@
# similar to `inspec exec http://localhost:2134/owners/%base%/compliance/%ssh%/tar --user %token%`
module Compliance
class Fetcher < Fetchers::Url
name 'compliance'
priority 500
- def self.resolve(target) # rubocop:disable PerceivedComplexity, Metrics/CyclomaticComplexity
+ def self.resolve(target) # rubocop:disable PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize
uri = if target.is_a?(String) && URI(target).scheme == 'compliance'
URI(target)
elsif target.respond_to?(:key?) && target.key?(:compliance)
URI("compliance://#{target[:compliance]}")
end
@@ -27,11 +27,11 @@
profile_fetch_url = target[:url]
config = {}
else
# check if we have a compliance token
config = Compliance::Configuration.new
- if config['token'].nil?
+ if config['token'].nil? && config['refresh_token'].nil?
if config['server_type'] == 'automate'
server = 'automate'
msg = 'inspec compliance login_automate https://your_automate_server --user USER --ent ENT --dctoken DCTOKEN or --usertoken USERTOKEN'
else
server = 'compliance'
@@ -53,9 +53,12 @@
if !Compliance::API.exist?(config, profile)
fail Inspec::FetcherFailure, "The compliance profile #{profile} was not found on the configured compliance server"
end
profile_fetch_url = Compliance::API.target_url(config, profile)
end
+ # We need to pass the token to the fetcher
+ config['token'] = Compliance::API.get_token(config)
+
new(profile_fetch_url, config)
rescue URI::Error => _e
nil
end