Merge pull request #320 from apenney/fix-suid
(FM-486) Fix deprecated Puppet::Util::SUIDManager.run_and_capture
This commit is contained in:
commit
8ed663fff5
2 changed files with 37 additions and 19 deletions
|
@ -16,9 +16,15 @@ Puppet::Type.type(:postgresql_psql).provide(:ruby) do
|
|||
return nil
|
||||
end
|
||||
|
||||
if Puppet::PUPPETVERSION.to_f < 4
|
||||
output, status = run_unless_sql_command(resource[:unless])
|
||||
else
|
||||
output = run_unless_sql_command(resource[:unless])
|
||||
status = output.exitcode
|
||||
end
|
||||
|
||||
if status != 0
|
||||
puts status
|
||||
self.fail("Error evaluating 'unless' clause: '#{output}'")
|
||||
end
|
||||
result_count = output.strip.to_i
|
||||
|
@ -61,10 +67,24 @@ Puppet::Type.type(:postgresql_psql).provide(:ruby) do
|
|||
|
||||
if resource[:cwd]
|
||||
Dir.chdir resource[:cwd] do
|
||||
Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group])
|
||||
run_command(command, resource[:psql_user], resource[:psql_group])
|
||||
end
|
||||
else
|
||||
run_command(command, resource[:psql_user], resource[:psql_group])
|
||||
end
|
||||
end
|
||||
|
||||
def run_command(command, user, group)
|
||||
if Puppet::PUPPETVERSION.to_f < 4
|
||||
Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group])
|
||||
else
|
||||
Puppet::Util::Execution.execute(command, {:uid => resource[:psql_user],
|
||||
:gid => resource[:psql_group],
|
||||
:failonfail=>false,
|
||||
:combine=>true,
|
||||
:override_locale=>true,
|
||||
:custom_environment=>{}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,11 +13,10 @@ describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do
|
|||
let(:attributes) do { :db => 'spec_db' } end
|
||||
|
||||
it "executes with the given psql_path on the given DB" do
|
||||
expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with(
|
||||
['psql', '-d', attributes[:db], '-t', '-c', 'SELECT something'],
|
||||
'postgres',
|
||||
'postgres'
|
||||
)
|
||||
expect(provider).to receive(:run_command).with(['psql', '-d',
|
||||
attributes[:db], '-t', '-c', 'SELECT something'], 'postgres',
|
||||
'postgres')
|
||||
|
||||
provider.run_sql_command("SELECT something")
|
||||
end
|
||||
end
|
||||
|
@ -32,11 +31,10 @@ describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do
|
|||
|
||||
it "executes with the given psql_path on the given DB" do
|
||||
expect(Dir).to receive(:chdir).with(attributes[:cwd]).and_yield
|
||||
expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with(
|
||||
[attributes[:psql_path], '-d', attributes[:db], '-t', '-c', 'SELECT something'],
|
||||
attributes[:psql_user],
|
||||
attributes[:psql_group]
|
||||
)
|
||||
expect(provider).to receive(:run_command).with([attributes[:psql_path],
|
||||
'-d', attributes[:db], '-t', '-c', 'SELECT something'],
|
||||
attributes[:psql_user], attributes[:psql_group])
|
||||
|
||||
provider.run_sql_command("SELECT something")
|
||||
end
|
||||
end
|
||||
|
@ -46,11 +44,10 @@ describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do
|
|||
} end
|
||||
|
||||
it "executes with the given search_path" do
|
||||
expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with(
|
||||
['psql', '-t', '-c', 'set search_path to schema1; SELECT something'],
|
||||
'postgres',
|
||||
'postgres'
|
||||
)
|
||||
expect(provider).to receive(:run_command).with(['psql', '-t', '-c',
|
||||
'set search_path to schema1; SELECT something'],
|
||||
'postgres', 'postgres')
|
||||
|
||||
provider.run_sql_command("SELECT something")
|
||||
end
|
||||
end
|
||||
|
@ -60,11 +57,12 @@ describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do
|
|||
} end
|
||||
|
||||
it "executes with the given search_path" do
|
||||
expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with(
|
||||
['psql', '-t', '-c', 'set search_path to schema1,schema2; SELECT something'],
|
||||
expect(provider).to receive(:run_command).with(['psql', '-t', '-c',
|
||||
'set search_path to schema1,schema2; SELECT something'],
|
||||
'postgres',
|
||||
'postgres'
|
||||
)
|
||||
|
||||
provider.run_sql_command("SELECT something")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue