Class: ChefCLI::Policyfile::ChefServerLockFetcher
- Inherits:
-
Object
- Object
- ChefCLI::Policyfile::ChefServerLockFetcher
- Defined in:
- lib/chef-cli/policyfile/chef_server_lock_fetcher.rb
Overview
A policyfile lock fetcher that can read a lock from a chef server
Instance Attribute Summary collapse
-
#chef_config ⇒ Object
Returns the value of attribute chef_config.
-
#name ⇒ Object
Returns the value of attribute name.
-
#source_options ⇒ Object
Returns the value of attribute source_options.
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.
-
#initialize(name, source_options, chef_config) ⇒ ChefServerLockFetcher
constructor
Initialize a LocalLockFetcher.
-
#lock_data ⇒ String
Of the policyfile lock data.
-
#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, chef_config) ⇒ ChefServerLockFetcher
Initialize a LocalLockFetcher
along with :policy_name and either :policy_group or :policy_revision_id. If :policy_name is not provided, name is used.
56 57 58 59 60 61 62 |
# File 'lib/chef-cli/policyfile/chef_server_lock_fetcher.rb', line 56 def initialize(name, , chef_config) @name = name @source_options = @chef_config = chef_config @source_options[:policy_name] ||= name end |
Instance Attribute Details
#chef_config ⇒ Object
Returns the value of attribute chef_config.
29 30 31 |
# File 'lib/chef-cli/policyfile/chef_server_lock_fetcher.rb', line 29 def chef_config @chef_config end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/chef-cli/policyfile/chef_server_lock_fetcher.rb', line 27 def name @name end |
#source_options ⇒ Object
Returns the value of attribute source_options.
28 29 30 |
# File 'lib/chef-cli/policyfile/chef_server_lock_fetcher.rb', line 28 def @source_options 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
98 99 100 101 102 103 104 105 |
# File 'lib/chef-cli/policyfile/chef_server_lock_fetcher.rb', line 98 def () = .inject({}) do |acc, (key, value)| acc[key.to_sym] = value acc end .merge!() raise ChefCLI::InvalidLockfile, "Invalid source_options provided from lock data: #{.inspect}" unless valid? end |
#errors ⇒ Array<String>
Check the options provided when creating this class for errors
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/chef-cli/policyfile/chef_server_lock_fetcher.rb', line 73 def errors = [] %i{server policy_name}.each do |key| << "include_policy for #{name} is missing key #{key}" unless [key] end if %i{policy_revision_id policy_group}.all? { |key| [key].nil? } << "include_policy for #{name} must specify policy_revision_id or policy_group" end end |
#lock_data ⇒ String
Returns of the policyfile lock data.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/chef-cli/policyfile/chef_server_lock_fetcher.rb', line 108 def lock_data @lock_data ||= fetch_lock_data.tap do |data| data["cookbook_locks"].each do |cookbook_name, cookbook_lock| cookbook_lock["source_options"] = { "chef_server_artifact" => server, "identifier" => cookbook_lock["identifier"], } end end end |
#source_options_for_lock ⇒ Hash
Returns The source_options that describe how to fetch this exact lock again.
88 89 90 91 92 |
# File 'lib/chef-cli/policyfile/chef_server_lock_fetcher.rb', line 88 def .merge({ policy_revision_id: lock_data["revision_id"], }) end |
#valid? ⇒ True, False
66 67 68 |
# File 'lib/chef-cli/policyfile/chef_server_lock_fetcher.rb', line 66 def valid? errors.empty? end |