class ChefDK::Policyfile::PolicyfileLocationSpecification
A PolicyfileLocationSpecification
specifies where a policyfile lock is to be fetched from. Using this information, it provides a fetcher that is capable loading the policyfile lock.
@attr_reader [String] name The name of the policyfile @attr_reader [Hash] source_options
Options describing how to get the policyfile lock
Constants
- LOCATION_TYPES
Attributes
Public Class Methods
Initialize a location spec
@param name [String] the name of the policyfile @param source_options
[Hash] options describing where the policyfile lock lives @param storage_config
[Policyfile::StorageConfig] @param chef_config
[Chef::Config] chef config that will be used when communication
with a chef server is required
# File lib/chef-dk/policyfile/policyfile_location_specification.rb, line 50 def initialize(name, source_options, storage_config, chef_config = nil) @name = name @source_options = source_options @storage_config = storage_config @ui = nil @chef_config = chef_config end
Public Instance Methods
Applies source options from a lock file. This is used to make sure that the same policyfile lock is loaded that was locked
@param options_from_lock [Hash] The source options loaded from a policyfile lock
# File lib/chef-dk/policyfile/policyfile_location_specification.rb, line 123 def apply_locked_source_options(options_from_lock) fetcher.apply_locked_source_options(options_from_lock) end
Check the options provided when craeting this class for errors
@return [Array<String>] A list of errors found
# File lib/chef-dk/policyfile/policyfile_location_specification.rb, line 91 def errors error_messages = [] if LOCATION_TYPES.all? { |l| source_options[l].nil? } error_messages << "include_policy must use one of the following sources: #{LOCATION_TYPES.join(", ")}" else unless fetcher.nil? error_messages += fetcher.errors end end error_messages end
@return A policyfile lock fetcher compatible with the given source_options
# File lib/chef-dk/policyfile/policyfile_location_specification.rb, line 64 def fetcher @fetcher ||= begin if source_options[:path] && !source_options[:git] Policyfile::LocalLockFetcher.new(name, source_options, storage_config) elsif source_options[:remote] Policyfile::RemoteLockFetcher.new(name, source_options) elsif source_options[:server] Policyfile::ChefServerLockFetcher.new(name, source_options, chef_config) elsif source_options[:git] Policyfile::GitLockFetcher.new(name, source_options, storage_config) else raise ChefDK::InvalidPolicyfileLocation.new( "Invalid policyfile lock location type. The supported locations are: #{LOCATION_TYPES.join(", ")}" ) end end end
Fetches and loads the policyfile lock
@return [PolicyfileLock] the loaded policyfile lock
# File lib/chef-dk/policyfile/policyfile_location_specification.rb, line 108 def policyfile_lock @policyfile_lock ||= begin PolicyfileLock.new(storage_config, ui: ui).build_from_lock_data(fetcher.lock_data) end end
@return The revision id from the fetched lock
# File lib/chef-dk/policyfile/policyfile_location_specification.rb, line 59 def revision_id fetcher.lock_data["revision_id"] end
@return [Hash] The source_options
that describe how to fetch this exact lock again
# File lib/chef-dk/policyfile/policyfile_location_specification.rb, line 115 def source_options_for_lock fetcher.source_options_for_lock end
@return [True] if there were no errors with the provided source_options
@return [False] if there were errors with the provided source_options
# File lib/chef-dk/policyfile/policyfile_location_specification.rb, line 84 def valid? errors.empty? end