class Chef::ConfigFetcher

Attributes

config_location[R]

Public Class Methods

new(config_location) click to toggle source
# File lib/chef/config_fetcher.rb, line 11
def initialize(config_location)
  @config_location = config_location
end

Public Instance Methods

config_missing?() click to toggle source
# File lib/chef/config_fetcher.rb, line 54
def config_missing?
  return false if remote_config?

  # Check if the config file exists
  Pathname.new(config_location).realpath.to_s
  false
rescue Errno::ENOENT
  true
end
expanded_path() click to toggle source
# File lib/chef/config_fetcher.rb, line 15
def expanded_path
  if config_location.nil? || remote_config?
    config_location
  else
    File.expand_path(config_location)
  end
end
fetch_json() click to toggle source
# File lib/chef/config_fetcher.rb, line 23
def fetch_json
  config_data = read_config
  begin
    Chef::JSONCompat.from_json(config_data)
  rescue Chef::Exceptions::JSON::ParseError => error
    Chef::Application.fatal!("Could not parse the provided JSON file (#{config_location}): " + error.message)
  end
end
fetch_remote_config() click to toggle source
# File lib/chef/config_fetcher.rb, line 40
def fetch_remote_config
  http.get("")
rescue SocketError, SystemCallError, Net::HTTPServerException => error
  Chef::Application.fatal!("Cannot fetch config '#{config_location}': '#{error.class}: #{error.message}")
end
http() click to toggle source
# File lib/chef/config_fetcher.rb, line 64
def http
  Chef::HTTP::Simple.new(config_location)
end
read_config() click to toggle source
# File lib/chef/config_fetcher.rb, line 32
def read_config
  if remote_config?
    fetch_remote_config
  else
    read_local_config
  end
end
read_local_config() click to toggle source
# File lib/chef/config_fetcher.rb, line 46
def read_local_config
  ::File.read(config_location)
rescue Errno::ENOENT
  Chef::Application.fatal!("Cannot load configuration from #{config_location}")
rescue Errno::EACCES
  Chef::Application.fatal!("Permissions are incorrect on #{config_location}. Please chmod a+r #{config_location}")
end
remote_config?() click to toggle source
# File lib/chef/config_fetcher.rb, line 68
def remote_config?
  !!(config_location =~ %r{^(http|https)://})
end