Class: Compliance::Fetcher

Inherits:
Fetchers::Url show all
Defined in:
lib/bundles/inspec-compliance/target.rb

Constant Summary

Constants inherited from Fetchers::Url

Fetchers::Url::MIME_TYPES

Instance Attribute Summary

Attributes inherited from Fetchers::Url

#archive, #files

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Fetchers::Url

download_archive, #initialize, transform

Constructor Details

This class inherits a constructor from Fetchers::Url

Class Method Details

.resolve(target, opts = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bundles/inspec-compliance/target.rb', line 17

def self.resolve(target, opts = {})
  # check for local scheme compliance://
  uri = URI(target)
  return nil unless URI(uri).scheme == 'compliance'

  # check if we have a compliance token
  config = Compliance::Configuration.new
  return nil if config['token'].nil?

  # verifies that the target e.g base/ssh exists
  profile = uri.host + uri.path
  Compliance::API.exist?(profile)

  opts['user'] = config['token']
  super(target_url(config, profile), opts)
rescue URI::Error => _e
  nil
end

.target_url(config, profile) ⇒ Object



36
37
38
39
# File 'lib/bundles/inspec-compliance/target.rb', line 36

def self.target_url(config, profile)
  owner, id = profile.split('/')
  "#{config['server']}/owners/#{owner}/compliance/#{id}/tar"
end

Instance Method Details

#to_sObject



41
42
43
# File 'lib/bundles/inspec-compliance/target.rb', line 41

def to_s
  'Chef Compliance Profile Loader'
end