Method: Chef::Compliance::Fetcher::ChefServer.resolve

Defined in:
lib/chef/compliance/fetcher/chef_server.rb

.resolve(target) ⇒ Object

Accepts URLs to compliance profiles in one of two forms:

  • a String URL with a compliance scheme, like “compliance://namespace/profile_name”

  • a Hash with a key of ‘compliance` and a value like “compliance/profile_name” and optionally a `version` key with a String value



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chef/compliance/fetcher/chef_server.rb', line 26

def self.resolve(target)
  profile_uri = get_target_uri(target)
  return nil if profile_uri.nil?

  organization = Chef::Config[:chef_server_url].split("/").last
  owner = profile_uri.user ? "#{profile_uri.user}@#{profile_uri.host}" : profile_uri.host
  version = target[:version] if target.respond_to?(:key?)

  path_parts = [""]
  path_parts << "compliance" if chef_server_reporter? || chef_server_fetcher?
  path_parts << "organizations"
  path_parts << organization
  path_parts << "owners"
  path_parts << owner
  path_parts << "compliance"
  path_parts << profile_uri.path
  path_parts << "version/#{version}" if version
  path_parts << "tar"

  target_url = URI(Chef::Config[:chef_server_url])
  target_url.path = File.join(path_parts)
  Chef::Log.info("Fetching profile from: #{target_url}")

  new(target_url, CONFIG)
rescue URI::Error => _e
  nil
end