class Chef::Compliance::Fetcher::Automate

Constants

CONFIG

Public Class Methods

resolve(target) click to toggle source
# File lib/chef/compliance/fetcher/automate.rb, line 24
def self.resolve(target)
  uri = get_target_uri(target)
  return nil if uri.nil?

  config = CONFIG.dup

  # 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]
  else
    # verifies that the target e.g base/ssh exists
    profile = sanitize_profile_name(uri)
    owner, id = profile.split("/")
    profile_path = if target.respond_to?(:key?) && target.key?(:version)
                     "/compliance/profiles/#{owner}/#{id}/version/#{target[:version]}/tar"
                   else
                     "/compliance/profiles/#{owner}/#{id}/tar"
                   end

    url = URI(Chef::Config[:data_collector][:server_url])
    url.path = profile_path
    profile_fetch_url = url.to_s

    config["token"] = Chef::Config[:data_collector][:token]

  end

  new(profile_fetch_url, config)
rescue URI::Error => _e
  nil
end
sanitize_profile_name(profile) click to toggle source

returns a parsed url for `admin/profile` or `compliance://admin/profile` TODO: remove in future, copied from inspec to support older versions of inspec

# File lib/chef/compliance/fetcher/automate.rb, line 58
def self.sanitize_profile_name(profile)
  uri = if URI(profile).scheme == "compliance"
          URI(profile)
        else
          URI("compliance://#{profile}")
        end
  uri.to_s.sub(%r{^compliance:\/\/}, "")
end

Public Instance Methods

to_s() click to toggle source
# File lib/chef/compliance/fetcher/automate.rb, line 67
def to_s
  "#{ChefUtils::Dist::Automate::PRODUCT} for #{ChefUtils::Dist::Solo::PRODUCT} Fetcher"
end