class ChefCLI::Policyfile::LocalLockFetcher
A policyfile lock fetcher that can read a lock from a local disk
def abs_path
def abs_path Pathname.new(source_options[:path]).expand_path(storage_config.relative_paths_root) end
def apply_locked_source_options(options_from_lock)
-
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 content
def content IO.read(path) end
def errors
-
(Array
- A list of errors found)
def errors error_messages = [] [:path].each do |key| error_messages << "include_policy for #{name} is missing key #{key}" unless source_options[key] end error_messages end
def initialize(name, source_options, storage_config)
-
storage_config
(StorageConfig
) -- -
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, storage_config) @name = name @source_options = source_options @storage_config = storage_config end
def lock_data
-
(String)
- of the policyfile lock data
def lock_data FFI_Yajl::Parser.new.parse(content).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"] if !cookbook_path.nil? cookbook_lock["source_options"]["path"] = transform_path(cookbook_path) end end end end
def path
def path @path ||= begin path = abs_path if path.directory? path = path.join("#{name}.lock.json") if !path.file? raise ChefCLI::LocalPolicyfileLockNotFound.new( "Expected to find file #{name}.lock.json inside #{source_options[:path]}. If the file name is different than this, provide the file name as part of the path.") end else if !path.file? raise ChefCLI::LocalPolicyfileLockNotFound.new( "The provided path #{source_options[:path]} does not exist.") end end path end end
def source_options_for_lock
-
(Hash)
- The source_options that describe how to fetch this exact lock again
def source_options_for_lock source_options end
def transform_path(path_to_transform)
-
(Pathname)
- Path to dependent cookbook relative to the current cookbook/Policyfile.
Parameters:
-
path_to_transform
(String
) -- Path to dependent cookbook.
def transform_path(path_to_transform) cur_path = Pathname.new(storage_config.relative_paths_root) include_path = Pathname.new(path).dirname include_path.relative_path_from(cur_path).join(path_to_transform).to_s end
def valid?
-
(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