Create a new client over SSL/TLS if necessary.
(self, host, port, authenticate=True, directConnection=None, **kwargs)
| 1007 | return client |
| 1008 | |
| 1009 | def _async_mongo_client(self, host, port, authenticate=True, directConnection=None, **kwargs): |
| 1010 | """Create a new client over SSL/TLS if necessary.""" |
| 1011 | host = host or client_context.host |
| 1012 | port = port or client_context.port |
| 1013 | client_options: dict = client_context.default_client_options.copy() |
| 1014 | if client_context.replica_set_name and not directConnection: |
| 1015 | client_options["replicaSet"] = client_context.replica_set_name |
| 1016 | if directConnection is not None: |
| 1017 | client_options["directConnection"] = directConnection |
| 1018 | client_options.update(kwargs) |
| 1019 | |
| 1020 | uri = _connection_string(host) |
| 1021 | auth_mech = kwargs.get("authMechanism", "") |
| 1022 | if client_context.auth_enabled and authenticate and auth_mech != "MONGODB-OIDC": |
| 1023 | # Only add the default username or password if one is not provided. |
| 1024 | res = parse_uri(uri) |
| 1025 | if ( |
| 1026 | not res["username"] |
| 1027 | and not res["password"] |
| 1028 | and "username" not in client_options |
| 1029 | and "password" not in client_options |
| 1030 | ): |
| 1031 | client_options["username"] = db_user |
| 1032 | client_options["password"] = db_pwd |
| 1033 | client = MongoClient(uri, port, **client_options) |
| 1034 | if client._options.connect: |
| 1035 | client._connect() |
| 1036 | self.addCleanup(client.close) |
| 1037 | return client |
| 1038 | |
| 1039 | @classmethod |
| 1040 | def unmanaged_single_client_noauth( |
no test coverage detected