Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#9440) exec resource: set path param to path fact #9445

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/provider/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ def extractexe(command)
def validatecmd(command)
exe = extractexe(command)
# if we're not fully qualified, require a path
self.fail _("'%{exe}' is not qualified and no path was specified. Please qualify the command or specify a path.") % { exe: exe } if !absolute_path?(exe) and resource[:path].nil?
self.fail _("'%{exe}' is not qualified and no path was specified. Please qualify the command or specify a path.") % { exe: exe } if !absolute_path?(exe) && (resource[:path].nil? || resource[:path].empty?)
end
end
4 changes: 3 additions & 1 deletion lib/puppet/type/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ def sync
newparam(:path) do
desc "The search path used for command execution.
Commands must be fully qualified if no path is specified. Paths
can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list."
can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list. Defaults to the `path` fact."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR but we shouldn't use PATH_SEPARATOR because reference docs are generated on Linux, so the type reference will be wrong for Windows. I think we call out "use ';' on Windows, otherwise ':' everywhere else" in other doc strings.


defaultto Puppet.runtime[:facter].value('path')

# Support both arrays and colon-separated fields.
def value=(*values)
Expand Down
5 changes: 1 addition & 4 deletions spec/unit/provider/exec/posix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ def make_exe

describe "#validatecmd" do
it "should fail if no path is specified and the command is not fully qualified" do
bastelfreak marked this conversation as resolved.
Show resolved Hide resolved
expect { provider.validatecmd("foo") }.to raise_error(
Puppet::Error,
"'foo' is not qualified and no path was specified. Please qualify the command or specify a path."
)
expect(provider.validatecmd('foo')).to eq(nil)
end

it "should pass if a path is given" do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/provider/exec/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
end

describe "#validatecmd" do
it "should fail if the command isn't absolute and there is no path" do
expect { provider.validatecmd('foo') }.to raise_error(Puppet::Error, /'foo' is not qualified and no path was specified/)
it "should not fail if the command isn't absolute and there is no path" do
expect(provider.validatecmd('foo')).to eq(nil)
end

it "should not fail if the command is absolute and there is no path" do
Expand Down
14 changes: 0 additions & 14 deletions spec/unit/provider/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ def echo_from_ruby_exit_1(message)
end

context "when validating the command" do
it "redacts the arguments if the command is relative" do
joshcooper marked this conversation as resolved.
Show resolved Hide resolved
expect {
apply_compiled_manifest(<<-MANIFEST)
exec { 'echo':
command => Sensitive.new('echo #{supersecret}')
}
MANIFEST
}.to raise_error do |err|
expect(err).to be_a(Puppet::Error)
expect(err.message).to match(/'echo' is not qualified and no path was specified. Please qualify the command or specify a path./)
expect(err.message).to_not match(/#{supersecret}/)
end
end

it "redacts the arguments if the command is a directory" do
dir = tmpdir('exec')
apply_compiled_manifest(<<-MANIFEST)
Expand Down
5 changes: 0 additions & 5 deletions spec/unit/type/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,6 @@ def instance(path)
let :abs do make_absolute('/bin/echo') end
let :path do make_absolute('/bin') end

it "should fail with relative command and no path" do
expect { type.new(:command => rel) }.
to raise_error Puppet::Error, /no path was specified/
end

it "should accept a relative command with a path" do
expect(type.new(:command => rel, :path => path)).to be
end
Expand Down
Loading