Skip to content

Commit b7288e5

Browse files
author
Johan De Wit
committed
[x509 user] Use $external db for this type of users
1 parent f1062ad commit b7288e5

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

lib/puppet/provider/mongodb_user/mongodb.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def self.instances
1919

2020
users = JSON.parse out
2121

22+
Puppet.debug("XXXXXXXX In self.instances, retrieved users: #{users}")
23+
2224
users.map do |user|
2325
new(name: user['_id'],
2426
ensure: :present,
@@ -36,6 +38,7 @@ def self.instances
3638

3739
# Assign prefetched users based on username and database, not on id and name
3840
def self.prefetch(resources)
41+
Puppet.debug("XXXXXXXXXXX in prefetch: got following instances: #{instances}")
3942
users = instances
4043
resources.each do |name, resource|
4144
provider = users.find { |user| user.username == resource[:username] && user.database == resource[:database] }
@@ -58,30 +61,27 @@ def create
5861
roles: role_hashes(@resource[:roles], @resource[:database]),
5962
}
6063

61-
# is this still needed / we only support verion 4 and higher
62-
if mongo_4? || mongo_5? || mongo_6?
63-
case @resource[:auth_mechanism]
64-
when :scram_sha_256 # rubocop:disable Naming/VariableNumber
65-
command[:mechanisms] = ['SCRAM-SHA-256']
66-
command[:pwd] = @resource[:password]
67-
command[:digestPassword] = true
68-
when :scram_sha_1 # rubocop:disable Naming/VariableNumber
69-
command[:mechanisms] = ['SCRAM-SHA-1']
70-
command[:pwd] = password_hash
71-
command[:digestPassword] = false
72-
when :x509
73-
command[:mechanisms] = ['MONGODB-X509']
74-
else
75-
command[:pwd] = password_hash
76-
command[:digestPassword] = false
77-
78-
end
64+
case @resource[:auth_mechanism]
65+
when :scram_sha_256 # rubocop:disable Naming/VariableNumber
66+
command[:mechanisms] = ['SCRAM-SHA-256']
67+
command[:pwd] = @resource[:password]
68+
command[:digestPassword] = true
69+
when :scram_sha_1 # rubocop:disable Naming/VariableNumber
70+
command[:mechanisms] = ['SCRAM-SHA-1']
71+
command[:pwd] = password_hash
72+
command[:digestPassword] = false
73+
when :x509
74+
command[:mechanisms] = ['MONGODB-X509']
75+
else
76+
command[:pwd] = password_hash
77+
command[:digestPassword] = false
7978
end
8079

81-
Puppet.debug("XXXXXXXXXX about to create user with command: #{command}")
8280
if @resource[:auth_mechanism] == :x509
83-
mongo_eval("db.getSiblingDB(\"$external\").runCommand(#{command.to_json}}", @resource[:database])
81+
Puppet.debug("XXXXXXXXXX about to create X509 user with command: #{command}")
82+
mongo_eval("db.getSiblingDB(\"$external\").runCommand(#{command.to_json})", @resource[:database])
8483
else
84+
Puppet.debug("XXXXXXXXXX about to create regular user with command: #{command}")
8585
mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
8686
end
8787
else

0 commit comments

Comments
 (0)