Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions manifests/db.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@
tries => $tries,
}

if $password_hash =~ Sensitive[String] {
if $password_hash {
$hash = $password_hash.unwrap
} elsif $password_hash {
$hash = $password_hash
} elsif $password {
$hash = mongodb_password($user, $password)
} else {
Expand Down
7 changes: 1 addition & 6 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,11 @@
Class['mongodb::server::service'] -> Class['mongodb::server::config'] -> Class['mongodb::server::install']
}

$admin_password_unsensitive = if $admin_password =~ Sensitive[String] {
$admin_password.unwrap
} else {
$admin_password
}
if $create_admin and ($service_ensure == 'running' or $service_ensure == true) {
mongodb::db { 'admin':
user => $admin_username,
auth_mechanism => $admin_auth_mechanism,
password => $admin_password_unsensitive,
password => $admin_password.unwrap,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why unwrap here, although mongodb::db accepts Sensitive?

unwrap should be the absolute Exception!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I was just removing the unnecessary unwrap logic above. We could push the unwrap into mongodb::db, looks like that would be equivalent. Looks like it still needs to be unwrapped for use in mongodb_user. @cocker-cc do you want to provide a PR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

password_hash => $admin_password_hash,
roles => $admin_roles,
update_password => $admin_update_password,
Expand Down
7 changes: 1 addition & 6 deletions manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,10 @@
}
}

$admin_password_unsensitive = if $admin_password =~ Sensitive[String] {
$admin_password.unwrap
} else {
$admin_password
}
if $handle_creds {
file { $rcfile:
ensure => file,
content => template('mongodb/mongoshrc.js.erb'),
content => epp("${module_name}/mongoshrc.js.epp"),
owner => 'root',
group => 'root',
mode => '0600',
Expand Down
10 changes: 5 additions & 5 deletions templates/mongoshrc.js.erb → templates/mongoshrc.js.epp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function rsReconfigSettings(settings){
return rs.reconfig(cfg)
}

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

if (authRequired()) {
<%- if @replset -%>
<%- if $mongodb::server::config::replset { -%>
db.getMongo().setReadPref('primaryPreferred')
<%- end -%>
<%- } -%>
try {
admin = db.getSiblingDB('admin')
admin.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive.gsub('\\','\\\\\\\\').gsub("'","\\\\'") %>')
admin.auth('<%= $mongodb::server::config::admin_username %>', '<%= $mongodb::server::config::admin_password.regsubst('\\\\','\\\\\\\\','G').regsubst("'","\\\\'",'G') %>')
}
catch (err) {
// Silently ignore this error, we can't really do anything about it.
Expand All @@ -44,4 +44,4 @@ if (authRequired()) {
// This is normal when setting up a new cluster/server.
}
}
<% end -%>
<% } -%>
Loading