HEX
Server: Apache
System: Linux hp3-stn-1011028.hostingp3.local 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: csh958633 (951153)
PHP: 8.3.30
Disabled: shell_exec,exec,system,popen,set_time_limit
Upload Files
File: //usr/share/ruby/vendor_ruby/puppet/ssl/certificate_authority/autosign_command.rb
require 'puppet/ssl/certificate_authority'

# This class wraps a given command and invokes it with a CSR name and body to
# determine if the given CSR should be autosigned
#
# @api private
class Puppet::SSL::CertificateAuthority::AutosignCommand

  class CheckFailure < Puppet::Error; end

  def initialize(path)
    @path = path
  end

  # Run the autosign command with the given CSR name as an argument and the
  # CSR body on stdin.
  #
  # @param csr [String] The CSR name to check for autosigning
  # @return [true, false] If the CSR should be autosigned
  def allowed?(csr)
    name = csr.name
    cmd = [@path, name]

    output = Puppet::FileSystem::Tempfile.open('puppet-csr') do |csr_file|
      csr_file.write(csr.to_s)
      csr_file.flush

      execute_options = {:stdinfile => csr_file.path, :combine => true, :failonfail => false}
      Puppet::Util::Execution.execute(cmd, execute_options)
    end

    output.chomp!

    Puppet.debug "Autosign command '#{@path}' exit status: #{output.exitstatus}"
    Puppet.debug "Autosign command '#{@path}' output: #{output}"

    case output.exitstatus
    when 0
      true
    else
      false
    end
  end
end