9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/puppet/pops/loader/task_instantiator.rb', line 9
def self.create(loader, typed_name, source_refs)
name = typed_name.name
basename = typed_name.name_parts[1] || 'init'
dirname = File.dirname(source_refs[0])
metadata_files, executables = source_refs.partition { |source_ref| source_ref.end_with?('.json') }
metadata_file = metadata_files.find { |source_ref| File.basename(source_ref, '.json') == basename }
metadata = Puppet::Module::Task.read_metadata(metadata_file) || {}
files = Puppet::Module::Task.find_files(name, dirname, metadata, executables)
task = { 'name' => name, 'metadata' => metadata, 'files' => files }
begin
unless metadata['parameters'].is_a?(Hash) || metadata['parameters'].nil?
msg = _('Failed to load metadata for task %{name}: \'parameters\' must be a hash') % { name: name }
raise Puppet::ParseError.new(msg, metadata_file)
end
task['parameters'] = convert_types(metadata['parameters'])
Types::TypeFactory.task.from_hash(task)
rescue Types::TypeAssertionError => ex
msg = _('Failed to load metadata for task %{name}: %{reason}') % { name: name, reason: ex.message }
raise Puppet::ParseError.new(msg, metadata_file)
end
end
|