Module: Bolt::Task::Run

Defined in:
lib/bolt/task/run.rb

Class Method Summary collapse

Class Method Details

.run_task(task, targets, params, options, executor) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bolt/task/run.rb', line 41

def run_task(task, targets, params, options, executor)
  if targets.empty?
    Bolt::ResultSet.new([])
  else
    result = executor.run_task(targets, task, params, options, [], :trace)

    if !result.ok && !options[:catch_errors]
      raise Bolt::RunFailure.new(result, 'run_task', task.name)
    end
    result
  end
end

.validate_params(task_signature, params) ⇒ Object

TODO: we should probably use a Bolt::Task for this



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bolt/task/run.rb', line 9

def validate_params(task_signature, params)
  task_signature.runnable_with?(params) do |mismatch_message|
    raise Bolt::ValidationError, mismatch_message
  end || (raise Bolt::ValidationError, 'Task parameters do not match')

  unless Puppet::Pops::Types::TypeFactory.data.instance?(params)
    # generate a helpful error message about the type-mismatch between the type Data
    # and the actual type of use_args
    use_args_t = Puppet::Pops::Types::TypeCalculator.infer_set(params)
    desc = Puppet::Pops::Types::TypeMismatchDescriber.singleton.describe_mismatch(
      'Task parameters are not of type Data. run_task()',
      Puppet::Pops::Types::TypeFactory.data, use_args_t
    )
    raise Bolt::ValidationError, desc
  end
  nil
end

.wrap_sensitive(task, params) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bolt/task/run.rb', line 27

def wrap_sensitive(task, params)
  if (spec = task.['parameters'])
    params.each_with_object({}) do |(param, val), wrapped|
      wrapped[param] = if spec.dig(param, 'sensitive')
                         Puppet::Pops::Types::PSensitiveType::Sensitive.new(val)
                       else
                         val
                       end
    end
  else
    params
  end
end