class ChefCLI::Policyfile::RemoteLockFetcher

A policyfile lock fetcher that can read a lock from a remote location.

def apply_locked_source_options(options_from_lock)

Parameters:
  • options_from_lock (Hash) -- The source options loaded from a policyfile lock
def apply_locked_source_options(options_from_lock)
  # There are no options the lock could provide
end

def errors

Returns:
  • (Array) - A list of errors found
def errors
  error_messages = []
  [:remote].each do |key|
    error_messages << "include_policy for #{name} is missing key #{key}" unless source_options[key]
  end
  error_messages
end

def fetch_lock_data

def fetch_lock_data
  FFI_Yajl::Parser.parse(http_client.get(""))
rescue Net::ProtocolError => e
  if e.respond_to?(:response) && e.response.code.to_s == "404"
    raise ChefCLI::PolicyfileLockDownloadError.new("No remote policyfile lock '#{name}' found at #{http_client.url}")
  else
    raise ChefCLI::PolicyfileLockDownloadError.new("HTTP error attempting to fetch policyfile lock from #{http_client.url}")
  end
rescue => e
  raise e
end

def http_client

def http_client
  @http_client ||= Chef::HTTP.new(source_options[:remote])
end

def initialize(name, source_options)

Parameters:
  • source_options (Hash) -- A hash with a :path key pointing at the location
  • name (String) -- The name of the policyfile
def initialize(name, source_options)
  @name = name
  @source_options = source_options
end

def lock_data

Returns:
  • (String) - of the policyfile lock data
def lock_data
  fetch_lock_data.tap do |data|
    validate_revision_id(data["revision_id"], source_options)
    data["cookbook_locks"].each do |cookbook_name, cookbook_lock|
      cookbook_path = cookbook_lock["source_options"]["path"]
      unless cookbook_path.nil?
        raise ChefCLI::InvalidLockfile, "Invalid cookbook path: #{cookbook_path}. Remote Policyfiles should only use remote cookbooks."
      end
    end
  end
end

def source_options_for_lock

Returns:
  • (Hash) - The source_options that describe how to fetch this exact lock again
def source_options_for_lock
  source_options
end

def valid?

Returns:
  • (False) - if there were errors with the provided source_options
  • (True) - if there were no errors with the provided source_options
def valid?
  errors.empty?
end