Skip to content

Commit deecc0f

Browse files
committed
User info is definitely available on secondary nodes
Not doing this causes Puppet to display changes when adding secondary users.
1 parent 9a77eb7 commit deecc0f

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

lib/puppet/provider/mongodb_user/mongodb.rb

+17-22
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,23 @@
99
def self.instances
1010
require 'json'
1111

12-
if db_ismaster
13-
script = 'EJSON.stringify(db.system.users.find().toArray())'
14-
# A hack to prevent prefetching failures until admin user is created
15-
script = "try {#{script}} catch (e) { if (e.message.match(/requires authentication/) || e.message.match(/not authorized on admin/)) { 'not authorized on admin' } else {throw e}}" if auth_enabled
16-
17-
out = mongo_eval(script)
18-
return [] if auth_enabled && (out.include?('requires authentication') || out.include?('not authorized on admin'))
19-
20-
users = JSON.parse out
21-
22-
users.map do |user|
23-
new(name: user['_id'],
24-
ensure: :present,
25-
username: user['user'],
26-
database: user['db'],
27-
roles: from_roles(user['roles'], user['db']),
28-
password_hash: user['credentials']['MONGODB-CR'],
29-
scram_credentials: user['credentials']['SCRAM-SHA-1'])
30-
end
31-
else
32-
Puppet.warning 'User info is available only from master host'
33-
[]
12+
script = 'EJSON.stringify(db.system.users.find().toArray())'
13+
# A hack to prevent prefetching failures until admin user is created
14+
script = "try {#{script}} catch (e) { if (e.message.match(/requires authentication/) || e.message.match(/not authorized on admin/)) { 'not authorized on admin' } else {throw e}}" if auth_enabled
15+
16+
out = mongo_eval(script)
17+
return [] if auth_enabled && (out.include?('requires authentication') || out.include?('not authorized on admin'))
18+
19+
users = JSON.parse out
20+
21+
users.map do |user|
22+
new(name: user['_id'],
23+
ensure: :present,
24+
username: user['user'],
25+
database: user['db'],
26+
roles: from_roles(user['roles'], user['db']),
27+
password_hash: user['credentials']['MONGODB-CR'],
28+
scram_credentials: user['credentials']['SCRAM-SHA-1'])
3429
end
3530
end
3631

0 commit comments

Comments
 (0)