Class: Puppet::Module::Task Private
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: Error, InvalidFile, InvalidMetadata, InvalidName, InvalidTask, TaskNotFound
Constant Summary collapse
- FORBIDDEN_EXTENSIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w{.conf .md}
- MOUNTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[files lib scripts tasks]
Instance Attribute Summary collapse
- #metadata_file ⇒ Object readonly private
- #module ⇒ Object readonly private
- #name ⇒ Object readonly private
Class Method Summary collapse
- .find_files(name, directory, metadata, executables, envname = nil) ⇒ Object private
- .is_task_name?(name) ⇒ Boolean private
- .is_tasks_executable_filename?(name) ⇒ Boolean private
- .is_tasks_file?(path) ⇒ Boolean private
-
.is_tasks_filename?(path) ⇒ Boolean
private
Determine whether a file has a legal name for either a task’s executable or metadata file.
- .is_tasks_metadata_filename?(name) ⇒ Boolean private
- .read_metadata(file) ⇒ Object private
- .tasks_in_module(pup_module) ⇒ Object private
Instance Method Summary collapse
- #==(other) ⇒ Object private
- #files ⇒ Object private
-
#initialize(pup_module, task_name, module_executables, metadata_file = nil) ⇒ Task
constructor
private
file paths must be relative to the modules task directory.
- #metadata ⇒ Object private
- #validate ⇒ Object private
Constructor Details
#initialize(pup_module, task_name, module_executables, metadata_file = nil) ⇒ Task
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
file paths must be relative to the modules task directory
222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/puppet/module/task.rb', line 222 def initialize(pup_module, task_name, module_executables, = nil) if !Puppet::Module::Task.is_task_name?(task_name) raise InvalidName, _("Task names must start with a lowercase letter and be composed of only lowercase letters, numbers, and underscores") end name = task_name == "init" ? pup_module.name : "#{pup_module.name}::#{task_name}" @module = pup_module @name = name @metadata_file = @module_executables = module_executables || [] end |
Instance Attribute Details
#metadata_file ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
219 220 221 |
# File 'lib/puppet/module/task.rb', line 219 def @metadata_file end |
#module ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
219 220 221 |
# File 'lib/puppet/module/task.rb', line 219 def module @module end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
219 220 221 |
# File 'lib/puppet/module/task.rb', line 219 def name @name end |
Class Method Details
.find_files(name, directory, metadata, executables, envname = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
193 194 195 196 |
# File 'lib/puppet/module/task.rb', line 193 def self.find_files(name, directory, , executables, envname = nil) # PXP agent relies on 'impls' (which is the task file) being first if there is no metadata find_implementations(name, directory, , executables) + find_extra_files(, envname) end |
.is_task_name?(name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 54 |
# File 'lib/puppet/module/task.rb', line 51 def self.is_task_name?(name) return true if name =~ /^[a-z][a-z0-9_]*$/ return false end |
.is_tasks_executable_filename?(name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
202 203 204 |
# File 'lib/puppet/module/task.rb', line 202 def self.is_tasks_executable_filename?(name) is_tasks_filename?(name) && !name.end_with?('.json') end |
.is_tasks_file?(path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
56 57 58 |
# File 'lib/puppet/module/task.rb', line 56 def self.is_tasks_file?(path) File.file?(path) && is_tasks_filename?(path) end |
.is_tasks_filename?(path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine whether a file has a legal name for either a task’s executable or metadata file.
61 62 63 64 65 66 67 68 |
# File 'lib/puppet/module/task.rb', line 61 def self.is_tasks_filename?(path) name_less_extension = File.basename(path, '.*') return false if not is_task_name?(name_less_extension) FORBIDDEN_EXTENSIONS.each do |ext| return false if path.end_with?(ext) end return true end |
.is_tasks_metadata_filename?(name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
198 199 200 |
# File 'lib/puppet/module/task.rb', line 198 def self.(name) is_tasks_filename?(name) && name.end_with?('.json') end |
.read_metadata(file) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/puppet/module/task.rb', line 235 def self.(file) if file content = Puppet::FileSystem.read(file, :encoding => 'utf-8') content.empty? ? {} : Puppet::Util::Json.load(content) end rescue SystemCallError, IOError => err msg = _("Error reading metadata: %{message}" % {message: err.}) raise InvalidMetadata.new(msg, 'puppet.tasks/unreadable-metadata') rescue Puppet::Util::Json::ParseError => err raise InvalidMetadata.new(err., 'puppet.tasks/unparseable-metadata') end |
.tasks_in_module(pup_module) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/puppet/module/task.rb', line 206 def self.tasks_in_module(pup_module) task_files = Dir.glob(File.join(pup_module.tasks_directory, '*')) .keep_if { |f| is_tasks_file?(f) } module_executables = task_files.reject(&method(:is_tasks_metadata_filename?)).map.to_a tasks = task_files.group_by { |f| task_name_from_path(f) } tasks.map do |task, executables| new_with_files(pup_module, task, executables, module_executables) end end |
Instance Method Details
#==(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
260 261 262 263 |
# File 'lib/puppet/module/task.rb', line 260 def ==(other) self.name == other.name && self.module == other.module end |
#files ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
251 252 253 |
# File 'lib/puppet/module/task.rb', line 251 def files @files ||= self.class.find_files(@name, @module.tasks_directory, , @module_executables, environment_name) end |
#metadata ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
247 248 249 |
# File 'lib/puppet/module/task.rb', line 247 def @metadata ||= self.class.(@metadata_file) end |
#validate ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
255 256 257 258 |
# File 'lib/puppet/module/task.rb', line 255 def validate files true end |