Class: ChefCLI::Policyfile::CookbookLock
Overview
Base class for CookbookLock implementations
Constant Summary
collapse
- REQUIRED_LOCK_DATA_KEYS =
%w{version identifier dotted_decimal_identifier cache_key source_options}.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
#cache_path, #policyfile_expanded_path, #policyfile_filename, #policyfile_lock_expanded_path, #relative_paths_root
Constructor Details
#initialize(name, storage_config) ⇒ CookbookLock
Returns a new instance of CookbookLock.
65
66
67
68
69
70
71
72
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 65
def initialize(name, storage_config)
@name = name
@version = nil
@source_options = nil
@identifier = nil
@dotted_decimal_identifier = nil
@storage_config = storage_config
end
|
Instance Attribute Details
#dotted_decimal_identifier ⇒ Object
A string in “X.Y.Z” version number format that uniquely identifies the cookbook version. This is for compatibility with Chef Infra Server 11.x, where cookbooks are stored by x.y.z version numbers.
59
60
61
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 59
def dotted_decimal_identifier
@dotted_decimal_identifier
end
|
#identifier ⇒ Object
A string that uniquely identifies the cookbook version. If not explicitly set, an identifier is generated based on the cookbook’s content.
54
55
56
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 54
def identifier
@identifier
end
|
#name ⇒ Object
The cookbook name (without any version or other info suffixed)
44
45
46
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 44
def name
@name
end
|
#source_options ⇒ Object
Options specifying the source and revision of this cookbook. These can be passed to a CookbookLocationSpecification to create an object that can install the same revision of the cookbook on another machine.
49
50
51
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 49
def source_options
@source_options
end
|
#storage_config ⇒ Object
Returns the value of attribute storage_config.
61
62
63
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 61
def storage_config
@storage_config
end
|
#version ⇒ Object
Returns the value of attribute version.
63
64
65
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 63
def version
@version
end
|
Instance Method Details
#build_from_lock_data(lock_data) ⇒ Object
116
117
118
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 116
def build_from_lock_data(lock_data)
raise NotImplementedError, "#{self.class} must override #build_from_lock_data with a specific implementation"
end
|
#chefignore ⇒ Object
161
162
163
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 161
def chefignore
@chefignore ||= Chef::Cookbook::Chefignore.new(File.join(cookbook_path, "chefignore"))
end
|
#cookbook_loader ⇒ Object
152
153
154
155
156
157
158
159
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 152
def cookbook_loader
@cookbook_loader ||=
begin
loader = Chef::Cookbook::CookbookVersionLoader.new(cookbook_path, chefignore)
loader.load!
loader
end
end
|
#cookbook_location_spec ⇒ Object
82
83
84
85
86
87
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 82
def cookbook_location_spec
raise InvalidCookbookLockData, "Cannot create CookbookLocationSpecification for #{name} without version" if version.nil?
raise InvalidCookbookLockData, "Cannot create CookbookLocationSpecification for #{name} without source options" if source_options.nil?
@location_spec ||= CookbookLocationSpecification.new(name, "= #{version}", source_options, storage_config)
end
|
#cookbook_path ⇒ Object
103
104
105
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 103
def cookbook_path
raise NotImplementedError, "#{self.class} must override #cookbook_path with a specific implementation"
end
|
#cookbook_version ⇒ Object
148
149
150
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 148
def cookbook_version
@cookbook_version ||= cookbook_loader.cookbook_version
end
|
#dependencies ⇒ Object
89
90
91
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 89
def dependencies
cookbook_location_spec.dependencies
end
|
#gather_profile_data ⇒ Object
93
94
95
96
97
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 93
def gather_profile_data
@identifier ||= identifiers.content_identifier
@dotted_decimal_identifier ||= identifiers.dotted_decimal_identifier
@version ||= identifiers.semver_version
end
|
#identifier_updated? ⇒ Boolean
132
133
134
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 132
def identifier_updated?
false
end
|
#identifiers ⇒ Object
99
100
101
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 99
def identifiers
@identifiers ||= CookbookProfiler::Identifiers.new(cookbook_version)
end
|
#install_locked ⇒ Object
78
79
80
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 78
def install_locked
cookbook_location_spec.ensure_cached
end
|
#installed? ⇒ Boolean
74
75
76
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 74
def installed?
cookbook_location_spec.installed?
end
|
#lock_data ⇒ Object
112
113
114
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 112
def lock_data
raise NotImplementedError, "#{self.class} must override #lock_data a specific implementation"
end
|
#refresh! ⇒ Object
124
125
126
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 124
def refresh!
raise NotImplementedError, "#{self.class} must override #refresh! with a specific implementation"
end
|
#symbolize_source_options_keys(source_options_from_json) ⇒ Object
140
141
142
143
144
145
146
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 140
def symbolize_source_options_keys(source_options_from_json)
source_options_from_json ||= {}
source_options_from_json.inject({}) do |normalized_source_opts, (key, value)|
normalized_source_opts[key.to_sym] = value
normalized_source_opts
end
end
|
#to_lock ⇒ Object
107
108
109
110
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 107
def to_lock
validate!
lock_data
end
|
#updated? ⇒ Boolean
128
129
130
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 128
def updated?
false
end
|
#validate! ⇒ Object
120
121
122
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 120
def validate!
raise NotImplementedError, "#{self.class} must override #validate! with a specific implementation"
end
|
#version_updated? ⇒ Boolean
136
137
138
|
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 136
def version_updated?
false
end
|