Sha256: 8c0bc8fb1d963806b52c38d5c027860da23bc70e18f5d524645a2dfcb4953731

Contents?: true

Size: 1.6 KB

Versions: 16

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Display a prompt and wait for a response.
#
# > **Note:** Not available in apply block
Puppet::Functions.create_function(:prompt) do
  # @param prompt The prompt to display.
  # @param options A hash of additional options.
  # @option options [Boolean] sensitive Disable echo back and mark the response as sensitive.
  #   The returned value will be wrapped by the `Sensitive` data type. To access the raw
  #   value, use the `unwrap` function (i.e. `$sensitive_value.unwrap`).
  # @return The response to the prompt.
  # @example Prompt the user if plan execution should continue
  #   $response = prompt('Continue executing plan? [Y\N]')
  # @example Prompt the user for sensitive information
  #   $password = prompt('Enter your password', 'sensitive' => true)
  #   out::message("Password is: ${password.unwrap}")
  dispatch :prompt do
    param 'String', :prompt
    optional_param 'Hash[String[1], Any]', :options
    return_type 'Variant[String, Sensitive]'
  end

  def prompt(prompt, options = {})
    unless Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue
        .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
                              action: 'prompt')
    end

    options = options.transform_keys(&:to_sym)

    executor = Puppet.lookup(:bolt_executor)
    # Send analytics report
    executor.report_function_call(self.class.name)

    response = executor.prompt(prompt, options)

    if options[:sensitive]
      Puppet::Pops::Types::PSensitiveType::Sensitive.new(response)
    else
      response
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
bolt-3.3.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-3.1.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-3.0.1 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-3.0.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.44.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.42.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.40.2 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.40.1 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.38.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.37.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.36.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.35.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.34.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.33.2 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.33.1 bolt-modules/prompt/lib/puppet/functions/prompt.rb
bolt-2.32.0 bolt-modules/prompt/lib/puppet/functions/prompt.rb