Sha256: 46f9b661ba88ea6e97466be987d1717e1210684508b55052c8fc353e83068c84

Contents?: true

Size: 1.47 KB

Versions: 232

Compression:

Stored size: 1.47 KB

Contents

require 'puppet/provider/exec'

Puppet::Type.type(:exec).provide :posix, :parent => Puppet::Provider::Exec do
  has_feature :umask
  confine :feature => :posix
  defaultfor :feature => :posix

  desc <<-EOT
    Executes external binaries directly, without passing through a shell or
    performing any interpolation. This is a safer and more predictable way
    to execute most commands, but prevents the use of globbing and shell
    built-ins (including control logic like "for" and "if" statements).
  EOT

  # Verify that we have the executable
  def checkexe(command)
    exe = extractexe(command)

    if File.expand_path(exe) == exe
      if !Puppet::FileSystem.exist?(exe)
        raise ArgumentError, "Could not find command '#{exe}'"
      elsif !File.file?(exe)
        raise ArgumentError, "'#{exe}' is a #{File.ftype(exe)}, not a file"
      elsif !File.executable?(exe)
        raise ArgumentError, "'#{exe}' is not executable"
      end
      return
    end

    if resource[:path]
      Puppet::Util.withenv :PATH => resource[:path].join(File::PATH_SEPARATOR) do
        return if which(exe)
      end
    end

    # 'which' will only return the command if it's executable, so we can't
    # distinguish not found from not executable
    raise ArgumentError, "Could not find command '#{exe}'"
  end

  def run(command, check = false)
    if resource[:umask]
      Puppet::Util::withumask(resource[:umask]) { super(command, check) }
    else
      super(command, check)
    end
  end
end

Version data entries

232 entries across 232 versions & 2 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/provider/exec/posix.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/provider/exec/posix.rb
puppet-4.10.12 lib/puppet/provider/exec/posix.rb
puppet-4.10.12-x86-mingw32 lib/puppet/provider/exec/posix.rb
puppet-4.10.12-x64-mingw32 lib/puppet/provider/exec/posix.rb
puppet-4.10.12-universal-darwin lib/puppet/provider/exec/posix.rb
puppet-4.10.11 lib/puppet/provider/exec/posix.rb
puppet-4.10.11-x86-mingw32 lib/puppet/provider/exec/posix.rb
puppet-4.10.11-x64-mingw32 lib/puppet/provider/exec/posix.rb
puppet-4.10.11-universal-darwin lib/puppet/provider/exec/posix.rb
puppet-4.10.10 lib/puppet/provider/exec/posix.rb
puppet-4.10.10-x86-mingw32 lib/puppet/provider/exec/posix.rb
puppet-4.10.10-x64-mingw32 lib/puppet/provider/exec/posix.rb
puppet-4.10.10-universal-darwin lib/puppet/provider/exec/posix.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/provider/exec/posix.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/provider/exec/posix.rb
puppet-4.10.9 lib/puppet/provider/exec/posix.rb
puppet-4.10.9-x86-mingw32 lib/puppet/provider/exec/posix.rb
puppet-4.10.9-x64-mingw32 lib/puppet/provider/exec/posix.rb
puppet-4.10.9-universal-darwin lib/puppet/provider/exec/posix.rb