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