class ChefCLI::Policyfile::CachedCookbook

upstream canonical source and stored (presumed unmodified).
CachedCookbook objects represent a cookbook that has been fetched from an

def build_from_lock_data(lock_data)

def build_from_lock_data(lock_data)
  assert_required_keys_valid!(lock_data)
  @version = lock_data["version"]
  @identifier = lock_data["identifier"]
  @dotted_decimal_identifier = lock_data["dotted_decimal_identifier"]
  @cache_key = lock_data["cache_key"]
  @origin = lock_data["origin"]
  @source_options = symbolize_source_options_keys(lock_data["source_options"])
end

def cookbook_path

def cookbook_path
  if cache_key.nil?
    raise MissingCookbookLockData, "Cannot locate cached cookbook `#{name}' because the `cache_key' attribute is not set"
  end
  File.join(cache_path, cache_key)
end

def initialize(name, storage_config)

def initialize(name, storage_config)
  @name = name
  @version = nil
  @origin = nil
  @source_options = nil
  @cache_key = nil
  @identifier = nil
  @dotted_decimal_identifier = nil
  @storage_config = storage_config
end

def lock_data

def lock_data
  {
    "version" => version,
    "identifier" => identifier,
    "dotted_decimal_identifier" => dotted_decimal_identifier,
    "cache_key" => cache_key,
    "origin" => origin,
    "source_options" => source_options,
  }
end

def refresh!

mutated, though, then a CachedCookbookModified exception is raised.
the data generally should have no affect. If the cookbook has been
We do not expect the cookbook to get mutated out-of-band, so refreshing
def refresh!
  # This behavior fits better with the intent of the #validate! method,
  # but we cannot check for modifications there because the user may be
  # setting custom identifiers.
  if @identifier && identifiers.content_identifier != @identifier
    message = "Cached cookbook `#{name}' (#{version}) has been modified since the lockfile was generated. " +
      "Cached cookbooks cannot be modified. (full path: `#{cookbook_path}')"
    raise CachedCookbookModified, message
  end
end

def validate!

def validate!
  if cache_key.nil?
    raise CachedCookbookNotFound, "Cookbook `#{name}' does not have a `cache_key` set, cannot locate cookbook"
  end
  unless File.exist?(cookbook_path)
    raise CachedCookbookNotFound, "Cookbook `#{name}' not found at expected cache location `#{cache_key}' (full path: `#{cookbook_path}')"
  end
end