Class: ChefDK::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}
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-dk/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 Server 11.x, where cookbooks are stored by x.y.z version numbers.
59
60
61
|
# File 'lib/chef-dk/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-dk/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-dk/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-dk/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-dk/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-dk/policyfile/cookbook_locks.rb', line 63
def version
@version
end
|
Instance Method Details
#build_from_lock_data(lock_data) ⇒ Object
115
116
117
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 115
def build_from_lock_data(lock_data)
raise NotImplementedError, "#{self.class} must override #build_from_lock_data with a specific implementation"
end
|
#chefignore ⇒ Object
160
161
162
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 160
def chefignore
@chefignore ||= Chef::Cookbook::Chefignore.new(File.join(cookbook_path, "chefignore"))
end
|
#cookbook_loader ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 151
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
|
# File 'lib/chef-dk/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
102
103
104
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 102
def cookbook_path
raise NotImplementedError, "#{self.class} must override #cookbook_path with a specific implementation"
end
|
#cookbook_version ⇒ Object
147
148
149
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 147
def cookbook_version
@cookbook_version ||= cookbook_loader.cookbook_version
end
|
#dependencies ⇒ Object
88
89
90
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 88
def dependencies
cookbook_location_spec.dependencies
end
|
#gather_profile_data ⇒ Object
92
93
94
95
96
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 92
def gather_profile_data
@identifier ||= identifiers.content_identifier
@dotted_decimal_identifier ||= identifiers.dotted_decimal_identifier
@version ||= identifiers.semver_version
end
|
#identifier_updated? ⇒ Boolean
131
132
133
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 131
def identifier_updated?
false
end
|
#identifiers ⇒ Object
98
99
100
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 98
def identifiers
@identifiers ||= CookbookProfiler::Identifiers.new(cookbook_version)
end
|
#install_locked ⇒ Object
78
79
80
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 78
def install_locked
cookbook_location_spec.ensure_cached
end
|
#installed? ⇒ Boolean
74
75
76
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 74
def installed?
cookbook_location_spec.installed?
end
|
#lock_data ⇒ Object
111
112
113
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 111
def lock_data
raise NotImplementedError, "#{self.class} must override #lock_data a specific implementation"
end
|
#refresh! ⇒ Object
123
124
125
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 123
def refresh!
raise NotImplementedError, "#{self.class} must override #refresh! with a specific implementation"
end
|
#symbolize_source_options_keys(source_options_from_json) ⇒ Object
139
140
141
142
143
144
145
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 139
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
106
107
108
109
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 106
def to_lock
validate!
lock_data
end
|
#updated? ⇒ Boolean
127
128
129
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 127
def updated?
false
end
|
#validate! ⇒ Object
119
120
121
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 119
def validate!
raise NotImplementedError, "#{self.class} must override #validate! with a specific implementation"
end
|
#version_updated? ⇒ Boolean
135
136
137
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 135
def version_updated?
false
end
|