File tree Expand file tree Collapse file tree 2 files changed +25
-17
lines changed
lib/puppet/provider/mongodb_user Expand file tree Collapse file tree 2 files changed +25
-17
lines changed Original file line number Diff line number Diff line change @@ -115,21 +115,17 @@ def password_hash=(_value)
115115 end
116116
117117 def password = ( value )
118- if mongo_26?
119- mongo_eval ( "db.changeUserPassword(#{ @resource [ :username ] . to_json } , #{ value . to_json } )" , @resource [ :database ] )
120- else
121- command = {
122- updateUser : @resource [ :username ] ,
123- pwd : @resource [ :password ] ,
124- digestPassword : true
125- }
126-
127- if mongo_4? || mongo_5? || mongo_6?
128- command [ :mechanisms ] = @resource [ :auth_mechanism ] == :scram_sha_256 ? [ 'SCRAM-SHA-256' ] : [ 'SCRAM-SHA-1' ] # rubocop:disable Naming/VariableNumber
129- end
130-
131- mongo_eval ( "db.runCommand(#{ command . to_json } )" , @resource [ :database ] )
118+ command = {
119+ updateUser : @resource [ :username ] ,
120+ pwd : @resource [ :password ] ,
121+ digestPassword : true
122+ }
123+
124+ if mongo_4? || mongo_5? || mongo_6?
125+ command [ :mechanisms ] = @resource [ :auth_mechanism ] == :scram_sha_256 ? [ 'SCRAM-SHA-256' ] : [ 'SCRAM-SHA-1' ] # rubocop:disable Naming/VariableNumber
132126 end
127+
128+ mongo_eval ( "db.runCommand(#{ command . to_json } )" , @resource [ :database ] )
133129 end
134130
135131 def roles = ( roles )
Original file line number Diff line number Diff line change @@ -30,10 +30,21 @@ function authRequired() {
3030}
3131
3232if ( authRequired ( ) ) {
33- < % - if @admin_auth_mechanism != 'x509' - % >
34- < % - if @replset - % >
33+ < % - if @replset - % >
3534 db . getMongo ( ) . setReadPref ( 'primaryPreferred' )
36- < % - end - % >
35+ < % - if @admin_auth_mechanism == 'x509' - % >
36+ try {
37+ db . getSiblingDB ( '$external' ) . auth (
38+ {
39+ mechanism : 'MONGODB-X509'
40+ }
41+ )
42+ }
43+ catch ( err ) {
44+ // This isn't catching authentication errors as I'd expect...
45+ throw ( err )
46+ }
47+ < % - else - % >
3748 try {
3849 var prev_db = db . getName ( )
3950 db = db . getSiblingDB ( 'admin' )
@@ -44,6 +55,7 @@ if (authRequired()) {
4455 // This isn't catching authentication errors as I'd expect...
4556 throw ( err )
4657 }
58+ < % - end - % >
4759 < % - end - % >
4860}
4961< % end - % >
You can’t perform that action at this time.
0 commit comments