Sha256: 121ade2645dfa926202a548fa274fec2cdf32f9cbf9d6d6c6eb140bbeff369ca

Contents?: true

Size: 1.3 KB

Versions: 25

Compression:

Stored size: 1.3 KB

Contents

require 'puppet/indirector/terminus'
require 'puppet/util'

class Puppet::Indirector::Exec < Puppet::Indirector::Terminus
  # Look for external node definitions.
  def find(request)
    # Run the command.
    unless output = query(request.key)
      return nil
    end

    # Translate the output to ruby.
    output
  end

  private

  # Proxy the execution, so it's easier to test.
  def execute(command, arguments)
    Puppet::Util.execute(command,arguments)
  end

  # Call the external command and see if it returns our output.
  def query(name)
    external_command = command

    # Make sure it's an arry
    raise Puppet::DevError, "Exec commands must be an array" unless external_command.is_a?(Array)

    # Make sure it's fully qualified.
    raise ArgumentError, "You must set the exec parameter to a fully qualified command" unless external_command[0][0] == File::SEPARATOR[0]

    # Add our name to it.
    external_command << name
    begin
      output = execute(external_command, :combine => false)
    rescue Puppet::ExecutionFailure => detail
      raise Puppet::Error, "Failed to find #{name} via exec: #{detail}"
    end

    if output =~ /\A\s*\Z/ # all whitespace
      Puppet.debug "Empty response for #{name} from exec #{self.name} terminus"
      return nil
    else
      return output
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
puppet-2.6.18 lib/puppet/indirector/exec.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
puppet-2.6.17 lib/puppet/indirector/exec.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
puppet-2.6.16 lib/puppet/indirector/exec.rb
puppet-2.6.15 lib/puppet/indirector/exec.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
puppet-2.6.14 lib/puppet/indirector/exec.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
supply_drop-0.6.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
supply_drop-0.6.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/indirector/exec.rb
puppet-2.6.13 lib/puppet/indirector/exec.rb
puppet-2.7.8 lib/puppet/indirector/exec.rb
puppet-2.7.6 lib/puppet/indirector/exec.rb
puppet-2.6.12 lib/puppet/indirector/exec.rb
puppet-2.7.5 lib/puppet/indirector/exec.rb