Skip to content

Commit 4158dc1

Browse files
committed
Remove user config for container gateway backup
1 parent 808153a commit 4158dc1

2 files changed

Lines changed: 6 additions & 18 deletions

File tree

lib/foreman_maintain/concerns/base_database.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ def query_csv(sql, config = configuration)
5757
def psql(query, config = configuration)
5858
if ping(config)
5959
if local?
60-
execute(psql_command(config),
61-
:stdin => query,
62-
:hidden_patterns => [config['password']],
63-
:user => 'postgres')
60+
execute("runuser - postgres -c '#{psql_command(config)}' -c '#{query}'")
6461
else
6562
execute(psql_command(config),
6663
:stdin => query,
@@ -73,9 +70,7 @@ def psql(query, config = configuration)
7370

7471
def ping(config = configuration)
7572
if local?
76-
execute?(psql_command(config) + ' -c "SELECT 1 as ping"',
77-
:hidden_patterns => [config['password']],
78-
:user => 'postgres')
73+
execute?("runuser - postgres -c '#{psql_command(config)}' -c 'SELECT 1 as ping'")
7974
else
8075
execute?(psql_command(config) + ' -c "SELECT 1 as ping"',
8176
:hidden_patterns => [config['password']])
@@ -85,8 +80,7 @@ def ping(config = configuration)
8580
def dump_db(file, config = configuration)
8681
if local?
8782
execute!("chown -R postgres:postgres #{File.dirname(file)}")
88-
execute!(dump_command(config) + " -f #{file}",
89-
:hidden_patterns => [config['password']], :user => 'postgres')
83+
execute!("runuser - postgres -c '#{dump_command(config)} -f #{file}'")
9084
else
9185
execute!(dump_command(config) + " -f #{file}", :hidden_patterns => [config['password']])
9286
end
@@ -146,7 +140,7 @@ def db_version(config = configuration)
146140
# Note - t removes headers, -A removes alignment whitespace
147141
server_version_cmd = psql_command(config) + ' -c "SHOW server_version" -t -A'
148142
if local?
149-
version_string = execute!(server_version_cmd, :hidden_patterns => [config['password']], :user => 'postgres')
143+
version_string = execute!("runuser - postgres -c '#{server_version_cmd}'")
150144
else
151145
version_string = execute!(server_version_cmd, :hidden_patterns => [config['password']])
152146
end

lib/foreman_maintain/utils/command_runner.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@ class CommandRunner
88
attr_reader :logger, :command
99

1010
def initialize(logger, command, options)
11-
options.validate_options!(
12-
:stdin, :hidden_patterns, :interactive, :valid_exit_statuses, :user
13-
)
11+
options.validate_options!(:stdin, :hidden_patterns, :interactive, :valid_exit_statuses)
1412
options[:valid_exit_statuses] ||= [0]
1513
@logger = logger
1614
@user = options[:user]
17-
@command = if @user && !@user.empty?
18-
"runuser -u #{@user} -- " + command
19-
else
20-
command
21-
end
15+
@command = command
2216
@stdin = options[:stdin]
2317
@hidden_patterns = Array(options[:hidden_patterns]).compact
2418
@interactive = options[:interactive]

0 commit comments

Comments
 (0)