Sha256: b932c9b2e4dfc610229b17d12c3b98c2f281b0a77019a9cd49a597f879609b23

Contents?: true

Size: 1.82 KB

Versions: 55

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

module Bolt
  class Task
    module Run
      module_function

      # TODO: we should probably use a Bolt::Task for this
      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

      def wrap_sensitive(task, params)
        if (spec = task.metadata['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

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

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

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
bolt-1.48.0 lib/bolt/task/run.rb
bolt-1.47.0 lib/bolt/task/run.rb
bolt-1.45.0 lib/bolt/task/run.rb
bolt-1.44.0 lib/bolt/task/run.rb
bolt-1.43.0 lib/bolt/task/run.rb
bolt-1.42.0 lib/bolt/task/run.rb
bolt-1.41.0 lib/bolt/task/run.rb
bolt-1.40.0 lib/bolt/task/run.rb
bolt-1.39.0 lib/bolt/task/run.rb
bolt-1.38.0 lib/bolt/task/run.rb
bolt-1.37.0 lib/bolt/task/run.rb
bolt-1.36.0 lib/bolt/task/run.rb
bolt-1.35.0 lib/bolt/task/run.rb
bolt-1.34.0 lib/bolt/task/run.rb
bolt-1.33.0 lib/bolt/task/run.rb