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.
63
64
65
66
67
68
69
70
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 63
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.
57
58
59
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 57
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.
52
53
54
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 52
def identifier
@identifier
end
|
#name ⇒ Object
The cookbook name (without any version or other info suffixed)
42
43
44
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 42
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.
47
48
49
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 47
def source_options
@source_options
end
|
#storage_config ⇒ Object
Returns the value of attribute storage_config.
59
60
61
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 59
def storage_config
@storage_config
end
|
#version ⇒ Object
Returns the value of attribute version.
61
62
63
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 61
def version
@version
end
|
Instance Method Details
#build_from_lock_data(lock_data) ⇒ Object
108
109
110
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 108
def build_from_lock_data(lock_data)
raise NotImplementedError, "#{self.class} must override #build_from_lock_data with a specific implementation"
end
|
#chefignore ⇒ Object
153
154
155
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 153
def chefignore
@chefignore ||= Chef::Cookbook::Chefignore.new(File.join(cookbook_path, "chefignore"))
end
|
#cookbook_loader ⇒ Object
144
145
146
147
148
149
150
151
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 144
def cookbook_loader
@cookbook_loader ||=
begin
loader = Chef::Cookbook::CookbookVersionLoader.new(cookbook_path, chefignore)
loader.load!
loader
end
end
|
#cookbook_location_spec ⇒ Object
80
81
82
83
84
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 80
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
100
101
102
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 100
def cookbook_path
raise NotImplementedError, "#{self.class} must override #to_lock with a specific implementation"
end
|
#cookbook_version ⇒ Object
140
141
142
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 140
def cookbook_version
@cookbook_version ||= cookbook_loader.cookbook_version
end
|
#dependencies ⇒ Object
86
87
88
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 86
def dependencies
cookbook_location_spec.dependencies
end
|
#gather_profile_data ⇒ Object
90
91
92
93
94
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 90
def gather_profile_data
@identifier ||= identifiers.content_identifier
@dotted_decimal_identifier ||= identifiers.dotted_decimal_identifier
@version ||= identifiers.semver_version
end
|
#identifier_updated? ⇒ Boolean
124
125
126
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 124
def identifier_updated?
false
end
|
#identifiers ⇒ Object
96
97
98
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 96
def identifiers
@identifiers ||= CookbookProfiler::Identifiers.new(cookbook_version)
end
|
#install_locked ⇒ Object
76
77
78
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 76
def install_locked
cookbook_location_spec.ensure_cached
end
|
#installed? ⇒ Boolean
72
73
74
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 72
def installed?
cookbook_location_spec.installed?
end
|
#refresh! ⇒ Object
116
117
118
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 116
def refresh!
raise NotImplementedError, "#{self.class} must override #refresh! with a specific implementation"
end
|
#symbolize_source_options_keys(source_options_from_json) ⇒ Object
132
133
134
135
136
137
138
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 132
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
104
105
106
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 104
def to_lock
raise NotImplementedError, "#{self.class} must override #to_lock with a specific implementation"
end
|
#updated? ⇒ Boolean
120
121
122
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 120
def updated?
false
end
|
#validate! ⇒ Object
112
113
114
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 112
def validate!
raise NotImplementedError, "#{self.class} must override #validate! with a specific implementation"
end
|
#version_updated? ⇒ Boolean
128
129
130
|
# File 'lib/chef-dk/policyfile/cookbook_locks.rb', line 128
def version_updated?
false
end
|