From b8213f28176c77352a7e36f0db4ebd1b1e9213ed Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 27 Aug 2024 10:50:44 -0400 Subject: [PATCH] PYTHON-4698 Rename the async ClientEncryption to AsyncClientEncryption (#1816) --- pymongo/asynchronous/encryption.py | 14 +++++++------- pymongo/encryption_options.py | 2 +- tools/synchro.py | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pymongo/asynchronous/encryption.py b/pymongo/asynchronous/encryption.py index 8b63525f2..93484541e 100644 --- a/pymongo/asynchronous/encryption.py +++ b/pymongo/asynchronous/encryption.py @@ -304,7 +304,7 @@ class _EncryptionIO(AsyncMongoCryptCallback): # type: ignore[misc] class RewrapManyDataKeyResult: - """Result object returned by a :meth:`~ClientEncryption.rewrap_many_data_key` operation. + """Result object returned by a :meth:`~AsyncClientEncryption.rewrap_many_data_key` operation. .. versionadded:: 4.2 """ @@ -316,7 +316,7 @@ class RewrapManyDataKeyResult: def bulk_write_result(self) -> Optional[BulkWriteResult]: """The result of the bulk write operation used to update the key vault collection with one or more rewrapped data keys. If - :meth:`~ClientEncryption.rewrap_many_data_key` does not find any matching keys to rewrap, + :meth:`~AsyncClientEncryption.rewrap_many_data_key` does not find any matching keys to rewrap, no bulk write operation will be executed and this field will be ``None``. """ @@ -506,7 +506,7 @@ def _create_mongocrypt_options(**kwargs: Any) -> MongoCryptOptions: return opts -class ClientEncryption(Generic[_DocumentType]): +class AsyncClientEncryption(Generic[_DocumentType]): """Explicit client-side field level encryption.""" def __init__( @@ -519,7 +519,7 @@ class ClientEncryption(Generic[_DocumentType]): ) -> None: """Explicit client-side field level encryption. - The ClientEncryption class encapsulates explicit operations on a key + The AsyncClientEncryption class encapsulates explicit operations on a key vault collection that cannot be done directly on an AsyncMongoClient. Similar to configuring auto encryption on an AsyncMongoClient, it is constructed with an AsyncMongoClient (to a MongoDB cluster containing the key vault @@ -1126,7 +1126,7 @@ class ClientEncryption(Generic[_DocumentType]): result = await self._key_vault_coll.bulk_write(replacements) return RewrapManyDataKeyResult(result) - async def __aenter__(self) -> ClientEncryption[_DocumentType]: + async def __aenter__(self) -> AsyncClientEncryption[_DocumentType]: return self async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: @@ -1134,7 +1134,7 @@ class ClientEncryption(Generic[_DocumentType]): def _check_closed(self) -> None: if self._encryption is None: - raise InvalidOperation("Cannot use closed ClientEncryption") + raise InvalidOperation("Cannot use closed AsyncClientEncryption") async def close(self) -> None: """Release resources. @@ -1142,7 +1142,7 @@ class ClientEncryption(Generic[_DocumentType]): Note that using this class in a with-statement will automatically call :meth:`close`:: - with ClientEncryption(...) as client_encryption: + with AsyncClientEncryption(...) as client_encryption: encrypted = client_encryption.encrypt(value, ...) decrypted = client_encryption.decrypt(encrypted) diff --git a/pymongo/encryption_options.py b/pymongo/encryption_options.py index 3b0d32a4b..df1302650 100644 --- a/pymongo/encryption_options.py +++ b/pymongo/encryption_options.py @@ -70,7 +70,7 @@ class AutoEncryptionOpts: users. To configure automatic *decryption* without automatic *encryption* set ``bypass_auto_encryption=True``. Explicit encryption and explicit decryption is also supported for all users - with the :class:`~pymongo.encryption.ClientEncryption` class. + with the :class:`~pymongo.asynchronous.encryption.AsyncClientEncryption` and :class:`~pymongo.encryption.ClientEncryption` classes. See :ref:`automatic-client-side-encryption` for an example. diff --git a/tools/synchro.py b/tools/synchro.py index 0c2aff130..65ff3bfe0 100644 --- a/tools/synchro.py +++ b/tools/synchro.py @@ -58,6 +58,7 @@ replacements = { "_AsyncGridOutChunkIterator": "GridOutChunkIterator", "_a_grid_in_property": "_grid_in_property", "_a_grid_out_property": "_grid_out_property", + "AsyncClientEncryption": "ClientEncryption", "AsyncMongoCryptCallback": "MongoCryptCallback", "AsyncExplicitEncrypter": "ExplicitEncrypter", "AsyncAutoEncrypter": "AutoEncrypter",