Skip to content

Commit bbd5b76

Browse files
authored
Merge pull request #790 from kenyon/simplify-sensitive-handling
Convert `mongoshrc.js` template to EPP
2 parents b06dd82 + ca4080b commit bbd5b76

4 files changed

Lines changed: 8 additions & 20 deletions

File tree

manifests/db.pp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040
tries => $tries,
4141
}
4242

43-
if $password_hash =~ Sensitive[String] {
43+
if $password_hash {
4444
$hash = $password_hash.unwrap
45-
} elsif $password_hash {
46-
$hash = $password_hash
4745
} elsif $password {
4846
$hash = mongodb_password($user, $password)
4947
} else {

manifests/server.pp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,11 @@
430430
Class['mongodb::server::service'] -> Class['mongodb::server::config'] -> Class['mongodb::server::install']
431431
}
432432

433-
$admin_password_unsensitive = if $admin_password =~ Sensitive[String] {
434-
$admin_password.unwrap
435-
} else {
436-
$admin_password
437-
}
438433
if $create_admin and ($service_ensure == 'running' or $service_ensure == true) {
439434
mongodb::db { 'admin':
440435
user => $admin_username,
441436
auth_mechanism => $admin_auth_mechanism,
442-
password => $admin_password_unsensitive,
437+
password => $admin_password.unwrap,
443438
password_hash => $admin_password_hash,
444439
roles => $admin_roles,
445440
update_password => $admin_update_password,

manifests/server/config.pp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,10 @@
153153
}
154154
}
155155

156-
$admin_password_unsensitive = if $admin_password =~ Sensitive[String] {
157-
$admin_password.unwrap
158-
} else {
159-
$admin_password
160-
}
161156
if $handle_creds {
162157
file { $rcfile:
163158
ensure => file,
164-
content => template('mongodb/mongoshrc.js.erb'),
159+
content => epp("${module_name}/mongoshrc.js.epp"),
165160
owner => 'root',
166161
group => 'root',
167162
mode => '0600',
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function rsReconfigSettings(settings){
1616
return rs.reconfig(cfg)
1717
}
1818

19-
<% if @auth and @store_creds -%>
19+
<% if $mongodb::server::config::auth and $mongodb::server::config::store_creds { -%>
2020
function authRequired() {
2121
try {
2222
return rs.status().ok != 1;
@@ -29,12 +29,12 @@ function authRequired() {
2929
}
3030

3131
if (authRequired()) {
32-
<%- if @replset -%>
32+
<%- if $mongodb::server::config::replset { -%>
3333
db.getMongo().setReadPref('primaryPreferred')
34-
<%- end -%>
34+
<%- } -%>
3535
try {
3636
admin = db.getSiblingDB('admin')
37-
admin.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive.gsub('\\','\\\\\\\\').gsub("'","\\\\'") %>')
37+
admin.auth('<%= $mongodb::server::config::admin_username %>', '<%= $mongodb::server::config::admin_password.regsubst('\\\\','\\\\\\\\','G').regsubst("'","\\\\'",'G') %>')
3838
}
3939
catch (err) {
4040
// Silently ignore this error, we can't really do anything about it.
@@ -44,4 +44,4 @@ if (authRequired()) {
4444
// This is normal when setting up a new cluster/server.
4545
}
4646
}
47-
<% end -%>
47+
<% } -%>

0 commit comments

Comments
 (0)