Method: Compliance::Fetcher.resolve

Defined in:
lib/bundles/inspec-compliance/target.rb

.resolve(target) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bundles/inspec-compliance/target.rb', line 17

def self.resolve(target)
  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

  return nil if uri.nil?

  # check if we have a compliance token
  config = Compliance::Configuration.new
  if config['token'].nil?
    fail Inspec::FetcherFailure, <<EOF

Cannot fetch #{uri} because your compliance token has not been
configured.

Please login using

inspec compliance login https://your_compliance_server --user admin --insecure --token 'PASTE TOKEN HERE'
EOF
  end

  # verifies that the target e.g base/ssh exists
  profile = uri.host + uri.path
  if !Compliance::API.exist?(config, profile)
    fail Inpsec::FetcherFailure, "The compliance profile #{profile} was not found on the configured compliance server"
  end
  new(target_url(profile, config), config)
rescue URI::Error => _e
  nil
end