@@ -101,8 +101,7 @@ def self.mongosh_cmd(db, host, cmd)
101101 end
102102
103103 args += [ '--eval' , cmd ]
104- out = mongosh ( args )
105- out
104+ mongosh ( args )
106105 end
107106
108107 def self . conn_string
@@ -141,17 +140,10 @@ def self.db_ismaster
141140 cmd_ismaster = mongoshrc_file + cmd_ismaster if mongoshrc_file
142141 db = 'admin'
143142
144- full_command = if mongoshrc_file
145- mongoshrc_file + cmd_ismaster
146- else
147- cmd_ismaster
148- end
149143 begin
150- 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
151145 rescue StandardError => e
152- if self . auth_enabled && e . message =~ %r{Authentication failed}
153- res = mongosh_cmd ( db , conn_string , 'db.isMaster().ismaster' ) . to_s . chomp
154- end
146+ res = mongosh_cmd ( db , conn_string , 'db.isMaster().ismaster' ) . to_s . chomp if auth_enabled && e . message =~ %r{Authentication failed}
155147 end
156148
157149 res . eql? ( 'true' )
@@ -167,23 +159,18 @@ def self.auth_enabled(config = nil)
167159 end
168160
169161 def self . rs_initiated?
162+ # TODO: not used yet, generates a stack level to deep error
170163 cmd_status = "rs.status('localhost').set"
171164 cmd_status = mongoshrc_file + cmd_status if mongoshrc_file
172165 db = 'admin'
173- 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
174167
175168 # Retry command without authentication when mongorc_file is set and authentication failed
176- if mongorc_file && res =~ %r{Authentication failed}
177- res = mongosh_cmd ( db , conn_string , "rs.status('localhost').set" ) . to_s . chomp
178- end
169+ res = mongosh_cmd ( db , conn_string , "rs.status('localhost').set" ) . to_s . chomp if mongorc_file && res =~ %r{Authentication failed}
179170
180171 res == @resource [ :name ]
181172 end
182173
183- def rs_initiated?
184- self . rs_initiated?
185- end
186-
187174 # Mongo Command Wrapper
188175 def self . mongo_eval ( cmd , db = 'admin' , retries = 10 , host = nil )
189176 retry_count = retries
@@ -201,7 +188,7 @@ def self.mongo_eval(cmd, db = 'admin', retries = 10, host = nil)
201188 rescue StandardError => e
202189 # When using the rc file, we get this eror because in most cases the admin user is not created yet
203190 # Can/must we move this out of the resue block ?
204- if self . auth_enabled && e . message =~ %r{Authentication failed}
191+ if auth_enabled && e . message =~ %r{Authentication failed}
205192 out = if host
206193 mongosh_cmd ( db , host , no_auth_cmd )
207194 else
0 commit comments