Skip to content

Commit 396e076

Browse files
ianballouekohl
authored andcommitted
Refs #37325 - use container gateway DB password only when needed
1 parent 0f1d3b2 commit 396e076

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

manifests/plugin/container_gateway.pp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,22 @@
5656
if $manage_postgresql and $database_backend == 'postgres' {
5757
include postgresql::server
5858
$_postgresql_user = pick($postgresql_user, $foreman_proxy::user)
59-
postgresql::server::db { $postgresql_database:
60-
user => $_postgresql_user,
61-
password => postgresql::postgresql_password(
62-
$_postgresql_user,
63-
$postgresql_password.lest || {
64-
extlib::cache_data('container_gateway_cache_data', 'db_password', extlib::random_password(32))
65-
}
66-
),
67-
encoding => 'utf8',
68-
locale => 'C.utf8',
59+
if $postgresql_password {
60+
postgresql::server::db { $postgresql_database:
61+
user => $_postgresql_user,
62+
password => postgresql::postgresql_password(
63+
$_postgresql_user,
64+
$postgresql_password
65+
),
66+
encoding => 'utf8',
67+
locale => 'C.utf8',
68+
}
69+
} else {
70+
postgresql::server::db { $postgresql_database:
71+
user => $_postgresql_user,
72+
encoding => 'utf8',
73+
locale => 'C.utf8',
74+
}
6975
}
7076
}
7177
}

spec/classes/foreman_proxy__plugin__container_gateway_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
':enabled: https',
1515
":pulp_endpoint: https://#{facts[:fqdn]}",
1616
':sqlite_db_path: /var/lib/foreman-proxy/smart_proxy_container_gateway.db',
17-
':db_connection_string: postgres://:@:/container_gateway'
17+
':db_connection_string: postgres:///container_gateway'
1818
])
1919
end
2020
end

templates/plugin/container_gateway.yml.erb

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,17 @@
66
<% if scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") -%>
77
:sqlite_timeout: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") %>
88
<% end -%>
9-
<% if scope.lookupvar('foreman_proxy::plugin::container_gateway::database_backend') == 'postgres' -%>
10-
:db_connection_string: <%= [
11-
scope.lookupvar('foreman_proxy::plugin::container_gateway::database_backend'),
12-
'://',
13-
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_user'),
14-
':',
15-
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_password'),
16-
'@',
17-
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_host'),
18-
':',
19-
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_port'),
20-
'/',
21-
scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_database')
22-
].join %>
23-
<% end -%>
24-
<% if scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend") == 'sqlite' -%>
25-
:db_connection_string: <%=
26-
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend")}://" \
27-
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_db_path")}"
28-
%>
29-
<% end -%>
9+
<%-
10+
case scope.lookupvar('foreman_proxy::plugin::container_gateway::database_backend')
11+
when 'postgres'
12+
uri = URI("postgres://")
13+
uri.user = scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_user')
14+
uri.password = scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_password')
15+
uri.host = scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_host')
16+
uri.port = scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_port')
17+
uri.path = "/#{scope.lookupvar('foreman_proxy::plugin::container_gateway::postgresql_database')}"
18+
when 'sqlite'
19+
uri = "sqlite://#{scope.lookupvar('foreman_proxy::plugin::container_gateway::sqlite_db_path')}"
20+
end
21+
-%>
22+
:db_connection_string: <%= uri %>

0 commit comments

Comments
 (0)