@@ -141,11 +141,10 @@ def self.db_ismaster
141141 db = 'admin'
142142
143143 begin
144- res = mongosh_cmd ( db , conn_string , cmd_ismaster ) . to_s . split ( %r{\n } ) . last . chomp
144+ res = mongosh_cmd ( db , conn_string , cmd_ismaster ) . to_s . split ( %r{\n } ) . last . chomp
145145 rescue StandardError => e
146- if mongorc_file && res =~ %r{Authentication failed}
147- res = mongosh_cmd ( db , conn_string , 'db.isMaster().ismaster' ) . to_s . chomp
148- end
146+ res = mongosh_cmd ( db , conn_string , 'db.isMaster().ismaster' ) . to_s . chomp if auth_enabled && e . message =~ %r{Authentication failed}
147+ end
149148
150149 res . eql? ( 'true' )
151150 end
@@ -160,23 +159,18 @@ def self.auth_enabled(config = nil)
160159 end
161160
162161 def self . rs_initiated?
162+ # TODO: not used yet, generates a stack level to deep error
163163 cmd_status = "rs.status('localhost').set"
164164 cmd_status = mongoshrc_file + cmd_status if mongoshrc_file
165165 db = 'admin'
166- res = mongosh_cmd ( db , conn_string , cmd_ismaster ) . to_s . split ( %r{\n } ) . last . chomp
166+ res = mongosh_cmd ( db , conn_string , cmd_status ) . to_s . split ( %r{\n } ) . last . chomp
167167
168168 # Retry command without authentication when mongorc_file is set and authentication failed
169- if mongorc_file && res =~ %r{Authentication failed}
170- res = mongosh_cmd ( db , conn_string , "rs.status('localhost').set" ) . to_s . chomp
171- end
169+ res = mongosh_cmd ( db , conn_string , "rs.status('localhost').set" ) . to_s . chomp if mongorc_file && res =~ %r{Authentication failed}
172170
173171 res == @resource [ :name ]
174172 end
175173
176- def rs_initiated?
177- self . rs_initiated?
178- end
179-
180174 # Mongo Command Wrapper
181175 def self . mongo_eval ( cmd , db = 'admin' , retries = 10 , host = nil )
182176 retry_count = retries
@@ -194,7 +188,7 @@ def self.mongo_eval(cmd, db = 'admin', retries = 10, host = nil)
194188 rescue StandardError => e
195189 # When using the rc file, we get this eror because in most cases the admin user is not created yet
196190 # Can/must we move this out of the resue block ?
197- if self . auth_enabled && e . message =~ %r{Authentication failed}
191+ if auth_enabled && e . message =~ %r{Authentication failed}
198192 out = if host
199193 mongosh_cmd ( db , host , no_auth_cmd )
200194 else
@@ -227,31 +221,4 @@ def self.mongo_version
227221 def mongo_version
228222 self . class . mongo_version
229223 end
230-
231- def self . mongo_4?
232- v = mongo_version
233- !v [ %r{^4\. } ] . nil?
234- end
235-
236- def mongo_4?
237- self . class . mongo_4?
238- end
239-
240- def self . mongo_5?
241- v = mongo_version
242- !v [ %r{^5\. } ] . nil?
243- end
244-
245- def mongo_5?
246- self . class . mongo_5?
247- end
248-
249- def self . mongo_6?
250- v = mongo_version
251- !v [ %r{^6\. } ] . nil?
252- end
253-
254- def mongo_6?
255- self . class . mongo_6?
256- end
257224end
0 commit comments