Sha256: b48acf53a7a4c73b0ea68fcaa07da59c757c07da4086e609b0a9b738aefcd4a4

Contents?: true

Size: 1.55 KB

Versions: 367

Compression:

Stored size: 1.55 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}'") % { exe: exe }
      elsif !File.file?(exe)
        raise ArgumentError, _("'%{exe}' is a %{klass}, not a file") % { exe: exe, klass: File.ftype(exe) }
      elsif !File.executable?(exe)
        raise ArgumentError, _("'%{exe}' is not executable") % { exe: exe }
      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}'") % { exe: 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

367 entries across 367 versions & 2 rubygems

Version Path
puppet-6.23.0 lib/puppet/provider/exec/posix.rb
puppet-6.23.0-x86-mingw32 lib/puppet/provider/exec/posix.rb
puppet-6.23.0-x64-mingw32 lib/puppet/provider/exec/posix.rb
puppet-6.23.0-universal-darwin lib/puppet/provider/exec/posix.rb
puppet-6.22.1 lib/puppet/provider/exec/posix.rb
puppet-6.22.1-x86-mingw32 lib/puppet/provider/exec/posix.rb
puppet-6.22.1-x64-mingw32 lib/puppet/provider/exec/posix.rb
puppet-6.22.1-universal-darwin lib/puppet/provider/exec/posix.rb
puppet-7.6.1 lib/puppet/provider/exec/posix.rb
puppet-7.6.1-x86-mingw32 lib/puppet/provider/exec/posix.rb
puppet-7.6.1-x64-mingw32 lib/puppet/provider/exec/posix.rb
puppet-7.6.1-universal-darwin lib/puppet/provider/exec/posix.rb
puppet-7.5.0 lib/puppet/provider/exec/posix.rb
puppet-7.5.0-x86-mingw32 lib/puppet/provider/exec/posix.rb
puppet-7.5.0-x64-mingw32 lib/puppet/provider/exec/posix.rb
puppet-7.5.0-universal-darwin lib/puppet/provider/exec/posix.rb
puppet-7.4.1 lib/puppet/provider/exec/posix.rb
puppet-7.4.1-x86-mingw32 lib/puppet/provider/exec/posix.rb
puppet-7.4.1-x64-mingw32 lib/puppet/provider/exec/posix.rb
puppet-7.4.1-universal-darwin lib/puppet/provider/exec/posix.rb