Authenticate to the server if needed. Can raise ConnectionFailure or OperationFailure.
(self, reauthenticate: bool = False)
| 496 | return result |
| 497 | |
| 498 | async def authenticate(self, reauthenticate: bool = False) -> None: |
| 499 | """Authenticate to the server if needed. |
| 500 | |
| 501 | Can raise ConnectionFailure or OperationFailure. |
| 502 | """ |
| 503 | # CMAP spec says to publish the ready event only after authenticating |
| 504 | # the connection. |
| 505 | if reauthenticate: |
| 506 | if self.performed_handshake: |
| 507 | # Existing auth_ctx is stale, remove it. |
| 508 | self.auth_ctx = None |
| 509 | self.ready = False |
| 510 | if not self.ready: |
| 511 | creds = self.opts._credentials |
| 512 | if creds: |
| 513 | from pymongo.asynchronous import auth |
| 514 | |
| 515 | await auth.authenticate(creds, self, reauthenticate=reauthenticate) |
| 516 | self.ready = True |
| 517 | duration = time.monotonic() - self.creation_time |
| 518 | if self.enabled_for_cmap: |
| 519 | assert self.listeners is not None |
| 520 | self.listeners.publish_connection_ready(self.address, self.id, duration) |
| 521 | if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG): |
| 522 | _debug_log( |
| 523 | _CONNECTION_LOGGER, |
| 524 | message=_ConnectionStatusMessage.CONN_READY, |
| 525 | clientId=self._client_id, |
| 526 | serverHost=self.address[0], |
| 527 | serverPort=self.address[1], |
| 528 | driverConnectionId=self.id, |
| 529 | durationMS=duration, |
| 530 | ) |
| 531 | |
| 532 | def validate_session( |
| 533 | self, client: Optional[AsyncMongoClient[Any]], session: Optional[AsyncClientSession] |
no test coverage detected