Skip to content

Commit 8ed663f

Browse files
author
Ashley Penney
committed
Merge pull request puppetlabs#320 from apenney/fix-suid
(FM-486) Fix deprecated Puppet::Util::SUIDManager.run_and_capture
2 parents 0796eb9 + 878bf49 commit 8ed663f

File tree

2 files changed

+37
-19
lines changed
  • lib/puppet/provider/postgresql_psql
  • spec/unit/puppet/provider/postgresql_psql

2 files changed

+37
-19
lines changed

lib/puppet/provider/postgresql_psql/ruby.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ def command()
1616
return nil
1717
end
1818

19-
output, status = run_unless_sql_command(resource[:unless])
19+
if Puppet::PUPPETVERSION.to_f < 4
20+
output, status = run_unless_sql_command(resource[:unless])
21+
else
22+
output = run_unless_sql_command(resource[:unless])
23+
status = output.exitcode
24+
end
2025

2126
if status != 0
27+
puts status
2228
self.fail("Error evaluating 'unless' clause: '#{output}'")
2329
end
2430
result_count = output.strip.to_i
@@ -61,10 +67,24 @@ def run_sql_command(sql)
6167

6268
if resource[:cwd]
6369
Dir.chdir resource[:cwd] do
64-
Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group])
70+
run_command(command, resource[:psql_user], resource[:psql_group])
6571
end
6672
else
73+
run_command(command, resource[:psql_user], resource[:psql_group])
74+
end
75+
end
76+
77+
def run_command(command, user, group)
78+
if Puppet::PUPPETVERSION.to_f < 4
6779
Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group])
80+
else
81+
Puppet::Util::Execution.execute(command, {:uid => resource[:psql_user],
82+
:gid => resource[:psql_group],
83+
:failonfail=>false,
84+
:combine=>true,
85+
:override_locale=>true,
86+
:custom_environment=>{}
87+
})
6888
end
6989
end
7090

spec/unit/puppet/provider/postgresql_psql/ruby_spec.rb

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
let(:attributes) do { :db => 'spec_db' } end
1414

1515
it "executes with the given psql_path on the given DB" do
16-
expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with(
17-
['psql', '-d', attributes[:db], '-t', '-c', 'SELECT something'],
18-
'postgres',
19-
'postgres'
20-
)
16+
expect(provider).to receive(:run_command).with(['psql', '-d',
17+
attributes[:db], '-t', '-c', 'SELECT something'], 'postgres',
18+
'postgres')
19+
2120
provider.run_sql_command("SELECT something")
2221
end
2322
end
@@ -32,11 +31,10 @@
3231

3332
it "executes with the given psql_path on the given DB" do
3433
expect(Dir).to receive(:chdir).with(attributes[:cwd]).and_yield
35-
expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with(
36-
[attributes[:psql_path], '-d', attributes[:db], '-t', '-c', 'SELECT something'],
37-
attributes[:psql_user],
38-
attributes[:psql_group]
39-
)
34+
expect(provider).to receive(:run_command).with([attributes[:psql_path],
35+
'-d', attributes[:db], '-t', '-c', 'SELECT something'],
36+
attributes[:psql_user], attributes[:psql_group])
37+
4038
provider.run_sql_command("SELECT something")
4139
end
4240
end
@@ -46,11 +44,10 @@
4644
} end
4745

4846
it "executes with the given search_path" do
49-
expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with(
50-
['psql', '-t', '-c', 'set search_path to schema1; SELECT something'],
51-
'postgres',
52-
'postgres'
53-
)
47+
expect(provider).to receive(:run_command).with(['psql', '-t', '-c',
48+
'set search_path to schema1; SELECT something'],
49+
'postgres', 'postgres')
50+
5451
provider.run_sql_command("SELECT something")
5552
end
5653
end
@@ -60,11 +57,12 @@
6057
} end
6158

6259
it "executes with the given search_path" do
63-
expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with(
64-
['psql', '-t', '-c', 'set search_path to schema1,schema2; SELECT something'],
60+
expect(provider).to receive(:run_command).with(['psql', '-t', '-c',
61+
'set search_path to schema1,schema2; SELECT something'],
6562
'postgres',
6663
'postgres'
6764
)
65+
6866
provider.run_sql_command("SELECT something")
6967
end
7068
end

0 commit comments

Comments
 (0)