
    &gl7                        S r SSKJr  SSKJrJrJrJr   SSKrSSKJ	r
  SrSSKJr  SS	KJr  SS
KJr  SSKJr  \(       a  SSKJrJr   " S S5      r " S S5      rg! \ a    Sr NFf = f)zSupport for automatic client-side field level encryption.

.. seealso:: This module is compatible with both the synchronous and asynchronous PyMongo APIs.
    )annotations)TYPE_CHECKINGAnyMappingOptionalN)synchronousTF)int64)validate_is_mapping)ConfigurationError)_parse_kms_tls_options)_AgnosticMongoClient_DocumentTypeArgc                  ~    \ rS rSrSr             S                               SS jjrSrg)AutoEncryptionOpts)   zBOptions to configure automatic client-side field level encryption.Nc                "   [         (       d  [        S5      eU(       a  [        SU5        Xl        Xl        Xl        Xl        X l        X0l        X@l	        XPl
        X`l        Xpl        Xl        U	c  S/n	Xl        [        U R                  [         5      (       d!  [#        S[%        U R                  5       35      e['        S U R                   5       5      (       d  U R                  R)                  S5        [+        U
5      U l        Xl        Xl        g)a  Options to configure automatic client-side field level encryption.

Automatic client-side field level encryption requires MongoDB >=4.2
enterprise or a MongoDB >=4.2 Atlas cluster. Automatic encryption is not
supported for operations on a database or view and will result in
error.

Although automatic encryption requires MongoDB >=4.2 enterprise or a
MongoDB >=4.2 Atlas cluster, automatic *decryption* is supported for all
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.asynchronous.encryption.AsyncClientEncryption` and :class:`~pymongo.encryption.ClientEncryption` classes.

See :ref:`automatic-client-side-encryption` for an example.

:param kms_providers: Map of KMS provider options. The `kms_providers`
    map values differ by provider:

      - `aws`: Map with "accessKeyId" and "secretAccessKey" as strings.
        These are the AWS access key ID and AWS secret access key used
        to generate KMS messages. An optional "sessionToken" may be
        included to support temporary AWS credentials.
      - `azure`: Map with "tenantId", "clientId", and "clientSecret" as
        strings. Additionally, "identityPlatformEndpoint" may also be
        specified as a string (defaults to 'login.microsoftonline.com').
        These are the Azure Active Directory credentials used to
        generate Azure Key Vault messages.
      - `gcp`: Map with "email" as a string and "privateKey"
        as `bytes` or a base64 encoded string.
        Additionally, "endpoint" may also be specified as a string
        (defaults to 'oauth2.googleapis.com'). These are the
        credentials used to generate Google Cloud KMS messages.
      - `kmip`: Map with "endpoint" as a host with required port.
        For example: ``{"endpoint": "example.com:443"}``.
      - `local`: Map with "key" as `bytes` (96 bytes in length) or
        a base64 encoded string which decodes
        to 96 bytes. "key" is the master key used to encrypt/decrypt
        data keys. This key should be generated and stored as securely
        as possible.

    KMS providers may be specified with an optional name suffix
    separated by a colon, for example "kmip:name" or "aws:name".
    Named KMS providers do not support :ref:`CSFLE on-demand credentials`.
    Named KMS providers enables more than one of each KMS provider type to be configured.
    For example, to configure multiple local KMS providers::

      kms_providers = {
          "local": {"key": local_kek1},        # Unnamed KMS provider.
          "local:myname": {"key": local_kek2}, # Named KMS provider with name "myname".
      }

:param key_vault_namespace: The namespace for the key vault collection.
    The key vault collection contains all data keys used for encryption
    and decryption. Data keys are stored as documents in this MongoDB
    collection. Data keys are protected with encryption by a KMS
    provider.
:param key_vault_client: By default, the key vault collection
    is assumed to reside in the same MongoDB cluster as the encrypted
    AsyncMongoClient/MongoClient. Use this option to route data key queries to a
    separate MongoDB cluster.
:param schema_map: Map of collection namespace ("db.coll") to
    JSON Schema.  By default, a collection's JSONSchema is periodically
    polled with the listCollections command. But a JSONSchema may be
    specified locally with the schemaMap option.

    **Supplying a `schema_map` provides more security than relying on
    JSON Schemas obtained from the server. It protects against a
    malicious server advertising a false JSON Schema, which could trick
    the client into sending unencrypted data that should be
    encrypted.**

    Schemas supplied in the schemaMap only apply to configuring
    automatic encryption for client side encryption. Other validation
    rules in the JSON schema will not be enforced by the driver and
    will result in an error.
:param bypass_auto_encryption: If ``True``, automatic
    encryption will be disabled but automatic decryption will still be
    enabled. Defaults to ``False``.
:param mongocryptd_uri: The MongoDB URI used to connect
    to the *local* mongocryptd process. Defaults to
    ``'mongodb://localhost:27020'``.
:param mongocryptd_bypass_spawn: If ``True``, the encrypted
    AsyncMongoClient/MongoClient will not attempt to spawn the mongocryptd process.
    Defaults to ``False``.
:param mongocryptd_spawn_path: Used for spawning the
    mongocryptd process. Defaults to ``'mongocryptd'`` and spawns
    mongocryptd from the system path.
:param mongocryptd_spawn_args: A list of string arguments to
    use when spawning the mongocryptd process. Defaults to
    ``['--idleShutdownTimeoutSecs=60']``. If the list does not include
    the ``idleShutdownTimeoutSecs`` option then
    ``'--idleShutdownTimeoutSecs=60'`` will be added.
:param kms_tls_options:  A map of KMS provider names to TLS
    options to use when creating secure connections to KMS providers.
    Accepts the same TLS options as
    :class:`pymongo.mongo_client.AsyncMongoClient` and :class:`pymongo.mongo_client.MongoClient`. For example, to
    override the system default CA file::

      kms_tls_options={'kmip': {'tlsCAFile': certifi.where()}}

    Or to supply a client certificate::

      kms_tls_options={'kmip': {'tlsCertificateKeyFile': 'client.pem'}}
:param crypt_shared_lib_path: Override the path to load the crypt_shared library.
:param crypt_shared_lib_required: If True, raise an error if libmongocrypt is
    unable to load the crypt_shared library.
:param bypass_query_analysis: If ``True``, disable automatic analysis
    of outgoing commands. Set `bypass_query_analysis` to use explicit
    encryption on indexed fields without the MongoDB Enterprise Advanced
    licensed crypt_shared library.
:param encrypted_fields_map: Map of collection namespace ("db.coll") to documents
    that described the encrypted fields for Queryable Encryption. For example::

        {
          "db.encryptedCollection": {
              "escCollection": "enxcol_.encryptedCollection.esc",
              "ecocCollection": "enxcol_.encryptedCollection.ecoc",
              "fields": [
                  {
                      "path": "firstName",
                      "keyId": Binary.from_uuid(UUID('00000000-0000-0000-0000-000000000000')),
                      "bsonType": "string",
                      "queries": {"queryType": "equality"}
                  },
                  {
                      "path": "ssn",
                      "keyId": Binary.from_uuid(UUID('04104104-1041-0410-4104-104104104104')),
                      "bsonType": "string"
                  }
              ]
          }
        }
:param key_expiration_ms: The cache expiration time for data encryption keys.
    Defaults to ``None`` which defers to libmongocrypt's default which is currently 60000.
    Set to 0 to disable key expiration.

.. versionchanged:: 4.12
   Added the `key_expiration_ms` parameter.
.. versionchanged:: 4.2
   Added the `encrypted_fields_map`, `crypt_shared_lib_path`, `crypt_shared_lib_required`,
   and `bypass_query_analysis` parameters.

.. versionchanged:: 4.0
   Added the `kms_tls_options` parameter and the "kmip" KMS provider.

.. versionadded:: 3.9
zclient side encryption requires the pymongocrypt library: install a compatible version with: python -m pip install 'pymongo[encryption]'encrypted_fields_mapNz--idleShutdownTimeoutSecs=60z+mongocryptd_spawn_args must be a list, not c              3  ,   #    U  H
  nS U;   v   M     g7f)idleShutdownTimeoutSecsN ).0ss     _C:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/encryption_options.py	<genexpr>.AutoEncryptionOpts.__init__.<locals>.<genexpr>   s     X;Wa,1;Ws   )_HAVE_PYMONGOCRYPTr   r
   _encrypted_fields_map_crypt_shared_lib_path_crypt_shared_lib_required_kms_providers_key_vault_namespace_key_vault_client_schema_map_bypass_auto_encryption_mongocryptd_uri_mongocryptd_bypass_spawn_mongocryptd_spawn_path_mongocryptd_spawn_args
isinstancelist	TypeErrortypeanyappendr   _kms_ssl_contexts_bypass_query_analysis_key_expiration_ms)selfkms_providerskey_vault_namespacekey_vault_client
schema_mapbypass_auto_encryptionmongocryptd_urimongocryptd_bypass_spawnmongocryptd_spawn_pathmongocryptd_spawn_argskms_tls_optionscrypt_shared_lib_pathcrypt_shared_lib_requiredbypass_query_analysisr   key_expiration_mss                   r   __init__AutoEncryptionOpts.__init__,   s   L "!$> 
   68LM%9"&;#*C'+$7!!1%'=$ /)A&'=$!)&D%E"'=$$66===d4C_C_>`=ab  X4;W;WXXX((//0NO!7!H&;#"3    )r$   r0   r   r   r   r1   r"   r!   r    r/   r&   r(   r'   r%   r#   )NNFzmongodb://localhost:27020FmongocryptdNNNFFNN) r3   zMapping[str, Any]r4   strr5   z0Optional[_AgnosticMongoClient[_DocumentTypeArg]]r6   Optional[Mapping[str, Any]]r7   boolr8   rE   r9   rG   r:   rE   r;   zOptional[list[str]]r<   rF   r=   zOptional[str]r>   rG   r?   rG   r   rF   r@   Optional[int]returnNone)__name__
__module____qualname____firstlineno____doc__rA   __static_attributes__r   rC   r   r   r   )   s    L NR26',:).&36:7;/3*/&+<@+/!E4(E4 !E4 K	E4
 0E4 !%E4 E4 #'E4 !$E4 !4E4 5E4  -E4 $(E4  $E4 :E4  )!E4" 
#E4 E4rC   r   c                  Z    \ rS rSrSr     S           SS jjr\S	S j5       rSrg)
	RangeOpts   zAOptions to configure encrypted queries using the range algorithm.Nc                @    X0l         X@l        Xl        X l        XPl        g)aw  Options to configure encrypted queries using the range algorithm.

:param sparsity: An integer.
:param trim_factor: An integer.
:param min: A BSON scalar value corresponding to the type being queried.
:param max: A BSON scalar value corresponding to the type being queried.
:param precision: An integer, may only be set for double or decimal128 types.

.. versionadded:: 4.4
N)minmaxsparsitytrim_factor	precision)r2   rW   rX   rU   rV   rY   s         r   rA   RangeOpts.__init__   s    $  &"rC   c                   0 nSU R                   (       a   [        R                  " U R                   5      OS 4SU R                  4SU R                  4SU R
                  4SU R                  44 H  u  p#Uc  M
  X1U'   M     U$ )NrW   
trimFactorrY   rU   rV   )rW   r	   Int64rX   rY   rU   rV   )r2   dockvs       r   documentRangeOpts.document  sy    t}}T]]3$O4++,$..)DHHDHH
DA }A
 
rC   )rV   rU   rY   rW   rX   )NNNNN)rW   rH   rX   rH   rU   Optional[Any]rV   rc   rY   rH   rI   rJ   )rI   zdict[str, Any])	rK   rL   rM   rN   rO   rA   propertyra   rP   r   rC   r   rR   rR      si    K #'%)!!#'## ## 	#
 # !# 
#0  rC   rR   )rO   
__future__r   typingr   r   r   r   pymongocryptr   _r   ImportErrorbsonr	   pymongo.commonr
   pymongo.errorsr   pymongo.uri_parser_sharedr   pymongo.typingsr   r   r   rR   r   rC   r   <module>ro      sk    # 8 8 .  . - <FH4 H4V' 'm  s   A A)(A)