Class: ChefCLI::Policyfile::PolicyfileLocationSpecification
- Inherits:
-
Object
- Object
- ChefCLI::Policyfile::PolicyfileLocationSpecification
- Defined in:
- lib/chef-cli/policyfile/policyfile_location_specification.rb
Overview
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.
Constant Summary collapse
- LOCATION_TYPES =
%i{path remote server git}.freeze
Instance Attribute Summary collapse
-
#chef_config ⇒ Object
readonly
Returns the value of attribute chef_config.
-
#name ⇒ String
readonly
The name of the policyfile.
-
#source_options ⇒ Hash
readonly
Options describing how to get the policyfile lock.
-
#storage_config ⇒ Object
readonly
Returns the value of attribute storage_config.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
Instance Method Summary collapse
-
#apply_locked_source_options(options_from_lock) ⇒ Object
Applies source options from a lock file.
-
#errors ⇒ Array<String>
Check the options provided when creating this class for errors.
-
#fetcher ⇒ Object
A policyfile lock fetcher compatible with the given source_options.
-
#initialize(name, source_options, storage_config, chef_config = nil) ⇒ PolicyfileLocationSpecification
constructor
Initialize a location spec.
-
#policyfile_lock ⇒ PolicyfileLock
Fetches and loads the policyfile lock.
-
#revision_id ⇒ Object
The revision id from the fetched lock.
-
#source_options_for_lock ⇒ Hash
The source_options that describe how to fetch this exact lock again.
- #valid? ⇒ True, False
Constructor Details
#initialize(name, source_options, storage_config, chef_config = nil) ⇒ PolicyfileLocationSpecification
Initialize a location spec
50 51 52 53 54 55 56 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 50 def initialize(name, , storage_config, chef_config = nil) @name = name @source_options = @storage_config = storage_config @ui = nil @chef_config = chef_config end |
Instance Attribute Details
#chef_config ⇒ Object (readonly)
Returns the value of attribute chef_config.
38 39 40 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 38 def chef_config @chef_config end |
#name ⇒ String (readonly)
The name of the policyfile
33 34 35 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 33 def name @name end |
#source_options ⇒ Hash (readonly)
Options describing how to get the policyfile lock
33 34 35 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 33 def @source_options end |
#storage_config ⇒ Object (readonly)
Returns the value of attribute storage_config.
37 38 39 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 37 def storage_config @storage_config end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
39 40 41 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 39 def ui @ui end |
Instance Method Details
#apply_locked_source_options(options_from_lock) ⇒ Object
Applies source options from a lock file. This is used to make sure that the same policyfile lock is loaded that was locked
119 120 121 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 119 def () fetcher.() end |
#errors ⇒ Array<String>
Check the options provided when creating this class for errors
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 89 def errors = [] if LOCATION_TYPES.all? { |l| [l].nil? } << "include_policy must use one of the following sources: #{LOCATION_TYPES.join(", ")}" else unless fetcher.nil? += fetcher.errors end end end |
#fetcher ⇒ Object
Returns A policyfile lock fetcher compatible with the given source_options.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 64 def fetcher @fetcher ||= if [:path] && ![:git] Policyfile::LocalLockFetcher.new(name, , storage_config) elsif [:remote] Policyfile::RemoteLockFetcher.new(name, ) elsif [:server] Policyfile::ChefServerLockFetcher.new(name, , chef_config) elsif [:git] Policyfile::GitLockFetcher.new(name, , storage_config) else raise ChefCLI::InvalidPolicyfileLocation.new( "Invalid policyfile lock location type. The supported locations are: #{LOCATION_TYPES.join(", ")}" ) end end |
#policyfile_lock ⇒ PolicyfileLock
Fetches and loads the policyfile lock
106 107 108 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 106 def policyfile_lock @policyfile_lock ||= PolicyfileLock.new(storage_config, ui:).build_from_lock_data(fetcher.lock_data) end |
#revision_id ⇒ Object
Returns The revision id from the fetched lock.
59 60 61 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 59 def revision_id fetcher.lock_data["revision_id"] end |
#source_options_for_lock ⇒ Hash
Returns The source_options that describe how to fetch this exact lock again.
111 112 113 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 111 def fetcher. end |
#valid? ⇒ True, False
82 83 84 |
# File 'lib/chef-cli/policyfile/policyfile_location_specification.rb', line 82 def valid? errors.empty? end |