Explicit client-side field level encryption. The ClientEncryption class encapsulates explicit operations on a key vault collection that cannot be done directly on a MongoClient. Similar to configuring auto encryption on a MongoClient, it is constructed with a MongoCl
(
self,
kms_providers: Mapping[str, Any],
key_vault_namespace: str,
key_vault_client: MongoClient[_DocumentTypeArg],
codec_options: CodecOptions[_DocumentTypeArg],
kms_tls_options: Optional[Mapping[str, Any]] = None,
key_expiration_ms: Optional[int] = None,
)
| 586 | """Explicit client-side field level encryption.""" |
| 587 | |
| 588 | def __init__( |
| 589 | self, |
| 590 | kms_providers: Mapping[str, Any], |
| 591 | key_vault_namespace: str, |
| 592 | key_vault_client: MongoClient[_DocumentTypeArg], |
| 593 | codec_options: CodecOptions[_DocumentTypeArg], |
| 594 | kms_tls_options: Optional[Mapping[str, Any]] = None, |
| 595 | key_expiration_ms: Optional[int] = None, |
| 596 | ) -> None: |
| 597 | """Explicit client-side field level encryption. |
| 598 | |
| 599 | The ClientEncryption class encapsulates explicit operations on a key |
| 600 | vault collection that cannot be done directly on a MongoClient. Similar |
| 601 | to configuring auto encryption on a MongoClient, it is constructed with |
| 602 | a MongoClient (to a MongoDB cluster containing the key vault |
| 603 | collection), KMS provider configuration, and keyVaultNamespace. It |
| 604 | provides an API for explicitly encrypting and decrypting values, and |
| 605 | creating data keys. It does not provide an API to query keys from the |
| 606 | key vault collection, as this can be done directly on the MongoClient. |
| 607 | |
| 608 | See `explicit client-side encryption <https://www.mongodb.com/docs/manual/core/csfle/fundamentals/manual-encryption/#csfle-explicit-encryption>`_ for an example. |
| 609 | |
| 610 | :param kms_providers: Map of KMS provider options. The `kms_providers` |
| 611 | map values differ by provider: |
| 612 | |
| 613 | - `aws`: Map with "accessKeyId" and "secretAccessKey" as strings. |
| 614 | These are the AWS access key ID and AWS secret access key used |
| 615 | to generate KMS messages. An optional "sessionToken" may be |
| 616 | included to support temporary AWS credentials. |
| 617 | - `azure`: Map with "tenantId", "clientId", and "clientSecret" as |
| 618 | strings. Additionally, "identityPlatformEndpoint" may also be |
| 619 | specified as a string (defaults to 'login.microsoftonline.com'). |
| 620 | These are the Azure Active Directory credentials used to |
| 621 | generate Azure Key Vault messages. |
| 622 | - `gcp`: Map with "email" as a string and "privateKey" |
| 623 | as `bytes` or a base64 encoded string. |
| 624 | Additionally, "endpoint" may also be specified as a string |
| 625 | (defaults to 'oauth2.googleapis.com'). These are the |
| 626 | credentials used to generate Google Cloud KMS messages. |
| 627 | - `kmip`: Map with "endpoint" as a host with required port. |
| 628 | For example: ``{"endpoint": "example.com:443"}``. |
| 629 | - `local`: Map with "key" as `bytes` (96 bytes in length) or |
| 630 | a base64 encoded string which decodes |
| 631 | to 96 bytes. "key" is the master key used to encrypt/decrypt |
| 632 | data keys. This key should be generated and stored as securely |
| 633 | as possible. |
| 634 | |
| 635 | KMS providers may be specified with an optional name suffix |
| 636 | separated by a colon, for example "kmip:name" or "aws:name". |
| 637 | Named KMS providers do not support `CSFLE on-demand credentials <https://www.mongodb.com/docs/manual/core/csfle/tutorials/aws/aws-automatic/?interface=driver&language=python#use-automatic-client-side-field-level-encryption-with-aws>`_. |
| 638 | :param key_vault_namespace: The namespace for the key vault collection. |
| 639 | The key vault collection contains all data keys used for encryption |
| 640 | and decryption. Data keys are stored as documents in this MongoDB |
| 641 | collection. Data keys are protected with encryption by a KMS |
| 642 | provider. |
| 643 | :param key_vault_client: A MongoClient connected to a MongoDB cluster |
| 644 | containing the `key_vault_namespace` collection. |
| 645 | :param codec_options: An instance of |
nothing calls this directly
no test coverage detected