Skip to content

Commit

Permalink
Merge pull request #726 from stevenpost/provider_cleanup_safe
Browse files Browse the repository at this point in the history
Provider cleanup (safe part)
  • Loading branch information
witjoh authored Apr 3, 2024
2 parents fa0db53 + 729d3d3 commit ba8fb13
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 25 deletions.
3 changes: 1 addition & 2 deletions lib/facter/is_master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
require 'yaml'

def mongod_conf_file
locations = ['/etc/mongod.conf', '/etc/mongodb.conf']
locations.find { |location| File.exist? location }
'/etc/mongod.conf'
end

def get_options_from_hash_config(config)
Expand Down
16 changes: 5 additions & 11 deletions lib/puppet/provider/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ def mongoshrc_file
end

def self.mongod_conf_file
if File.exist? '/etc/mongod.conf'
'/etc/mongod.conf'
else
'/etc/mongodb.conf'
end
'/etc/mongod.conf'
end

def self.mongo_conf
Expand All @@ -42,8 +38,7 @@ def self.mongo_conf
'tlscert' => config['net.tls.certificateKeyFile'],
'tlsca' => config['net.tls.CAFile'],
'auth' => config['security.authorization'],
'shardsvr' => config['sharding.clusterRole'],
'confsvr' => config['sharding.clusterRole']
'clusterRole' => config['sharding.clusterRole'],
}
end

Expand Down Expand Up @@ -120,13 +115,12 @@ def self.conn_string
end

port = config.fetch('port')
shardsvr = config.fetch('shardsvr')
confsvr = config.fetch('confsvr')
cluster_role = config.fetch('clusterRole')
port_real = if port
port
elsif !port && (confsvr.eql?('configsvr') || confsvr.eql?('true'))
elsif cluster_role.eql?('configsvr')
27_019
elsif !port && (shardsvr.eql?('shardsvr') || shardsvr.eql?('true'))
elsif cluster_role.eql?('shardsvr')
27_018
else
27_017
Expand Down
4 changes: 0 additions & 4 deletions lib/puppet/provider/mongodb_replset/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,6 @@ def self.mongo_command(command, host = nil, retries = 4)
raise
end

# Hack to avoid non-json empty sets
output = '{}' if output == "null\n"
output = '{}' if output == "\nnull\n"

# Parse the JSON output and return
JSON.parse(output)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class { 'mongodb::globals':
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'root' }
it { is_expected.to be_mode 600 }
it { is_expected.to contain 'db.auth(\'admin\', \'password\')' }
it { is_expected.to contain 'admin.auth(\'admin\', \'password\')' }
end

describe command("mongosh admin --quiet --eval \"load('/root/.mongoshrc.js');EJSON.stringify(db.getUser('admin')['customData'])\"") do
Expand Down
6 changes: 3 additions & 3 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
it { is_expected.to contain_class('mongodb::repo') }
it { is_expected.not_to contain_file(config_file).with_content(%r{fork}) }

it { is_expected.to contain_file('/root/.mongoshrc.js').with_ensure('file').without_content(%r{db\.auth}) }
it { is_expected.to contain_file('/root/.mongoshrc.js').with_ensure('file').without_content(%r{admin\.auth}) }
it { is_expected.not_to contain_exec('fix dbpath permissions') }
end

Expand Down Expand Up @@ -265,7 +265,7 @@
with_owner('root').
with_group('root').
with_mode('0600').
with_content(%r{db\.auth\('admin', 'password'\)})
with_content(%r{admin\.auth\('admin', 'password'\)})
}
end

Expand All @@ -276,7 +276,7 @@
}
end

it { is_expected.to contain_file('/root/.mongoshrc.js').with_ensure('file').without_content(%r{db\.auth}) }
it { is_expected.to contain_file('/root/.mongoshrc.js').with_ensure('file').without_content(%r{admin\.auth}) }
end
end

Expand Down
6 changes: 2 additions & 4 deletions templates/mongoshrc.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ if (authRequired()) {
db.getMongo().setReadPref('primaryPreferred')
<%- end -%>
try {
var prev_db = db.getName()
db = db.getSiblingDB('admin')
db.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive %>')
db = db.getSiblingDB(prev_db)
admin = db.getSiblingDB('admin')
admin.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive %>')
}
catch (err) {
// Silently ignore this error, we can't really do anything about it.
Expand Down

0 comments on commit ba8fb13

Please sign in to comment.