MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / _check_user_provided

Method _check_user_provided

test/__init__.py:374–395  ·  view source on GitHub ↗

Return True if db_user/db_password is already an admin user.

(self)

Source from the content-addressed store, hash-verified

372 return auth_type in auth_mechs
373
374 def _check_user_provided(self):
375 """Return True if db_user/db_password is already an admin user."""
376 client: MongoClient = pymongo.MongoClient(
377 host,
378 port,
379 username=db_user,
380 password=db_pwd,
381 **self.default_client_options,
382 )
383
384 try:
385 return db_user in _all_users(client.admin)
386 except pymongo.errors.OperationFailure as e:
387 assert e.details is not None
388 msg = e.details.get("errmsg", "")
389 if e.code == 18 or "auth fails" in msg:
390 # Auth failed.
391 return False
392 else:
393 raise
394 finally:
395 client.close()
396
397 def _server_started_with_auth(self):
398 # MongoDB >= 2.0

Callers 1

_init_clientMethod · 0.95

Calls 4

closeMethod · 0.95
_all_usersFunction · 0.70
MongoClientMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected