Skip to content

Commit

Permalink
[x509 user] Use $external db for this type of users
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan De Wit committed Aug 17, 2023
1 parent f1062ad commit 76d8480
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions lib/puppet/provider/mongodb_user/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,27 @@ def create
roles: role_hashes(@resource[:roles], @resource[:database]),
}

# is this still needed / we only support verion 4 and higher
if mongo_4? || mongo_5? || mongo_6?
case @resource[:auth_mechanism]
when :scram_sha_256 # rubocop:disable Naming/VariableNumber
command[:mechanisms] = ['SCRAM-SHA-256']
command[:pwd] = @resource[:password]
command[:digestPassword] = true
when :scram_sha_1 # rubocop:disable Naming/VariableNumber
command[:mechanisms] = ['SCRAM-SHA-1']
command[:pwd] = password_hash
command[:digestPassword] = false
when :x509
command[:mechanisms] = ['MONGODB-X509']
else
command[:pwd] = password_hash
command[:digestPassword] = false

end
case @resource[:auth_mechanism]
when :scram_sha_256 # rubocop:disable Naming/VariableNumber
command[:mechanisms] = ['SCRAM-SHA-256']
command[:pwd] = @resource[:password]
command[:digestPassword] = true
when :scram_sha_1 # rubocop:disable Naming/VariableNumber
command[:mechanisms] = ['SCRAM-SHA-1']
command[:pwd] = password_hash
command[:digestPassword] = false
when :x509
command[:mechanisms] = ['MONGODB-X509']
else
command[:pwd] = password_hash
command[:digestPassword] = false
end

Puppet.debug("XXXXXXXXXX about to create user with command: #{command}")
if @resource[:auth_mechanism] == :x509
Puppet.debug("XXXXXXXXXX about to create X509 user with command: #{command}")
mongo_eval("db.getSiblingDB(\"$external\").runCommand(#{command.to_json}}", @resource[:database])
else
Puppet.debug("XXXXXXXXXX about to create regular user with command: #{command}")
mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
end
else
Expand Down

0 comments on commit 76d8480

Please sign in to comment.