-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5328 CRUD Support in Driver for Prefix/Suffix/Substring Indexes #2521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
982dc07
6ae88a7
253684d
f7266ff
98ddc35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ | |
from pymongo.asynchronous.pool import AsyncBaseConnection | ||
from pymongo.common import CONNECT_TIMEOUT | ||
from pymongo.daemon import _spawn_daemon | ||
from pymongo.encryption_options import AutoEncryptionOpts, RangeOpts | ||
from pymongo.encryption_options import AutoEncryptionOpts, RangeOpts, TextOpts | ||
from pymongo.errors import ( | ||
ConfigurationError, | ||
EncryptedCollectionError, | ||
|
@@ -516,6 +516,11 @@ class Algorithm(str, enum.Enum): | |
|
||
.. versionadded:: 4.4 | ||
""" | ||
TEXTPREVIEW = "TextPreview" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we required to call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, following the pattern we used for RANGEPREVIEW, to ensure that if the semantics change it won't do so silently. |
||
"""**BETA** - TextPreview. | ||
|
||
.. versionadded:: 4.15 | ||
""" | ||
|
||
|
||
class QueryType(str, enum.Enum): | ||
|
@@ -541,6 +546,24 @@ class QueryType(str, enum.Enum): | |
.. versionadded:: 4.4 | ||
""" | ||
|
||
PREFIXPREVIEW = "prefixPreview" | ||
"""**BETA** - Used to encrypt a value for a prefixPreview query. | ||
|
||
.. versionadded:: 4.15 | ||
""" | ||
|
||
SUFFIXPREVIEW = "suffixPreview" | ||
"""**BETA** - Used to encrypt a value for a suffixPreview query. | ||
|
||
.. versionadded:: 4.15 | ||
""" | ||
|
||
SUBSTRINGPREVIEW = "substringPreview" | ||
"""**BETA** - Used to encrypt a value for a substringPreview query. | ||
|
||
.. versionadded:: 4.15 | ||
""" | ||
|
||
|
||
def _create_mongocrypt_options(**kwargs: Any) -> MongoCryptOptions: | ||
# For compat with pymongocrypt <1.13, avoid setting the default key_expiration_ms. | ||
|
@@ -876,6 +899,7 @@ async def _encrypt_helper( | |
contention_factor: Optional[int] = None, | ||
range_opts: Optional[RangeOpts] = None, | ||
is_expression: bool = False, | ||
text_opts: Optional[TextOpts] = None, | ||
) -> Any: | ||
self._check_closed() | ||
if isinstance(key_id, uuid.UUID): | ||
|
@@ -895,6 +919,12 @@ async def _encrypt_helper( | |
range_opts.document, | ||
codec_options=self._codec_options, | ||
) | ||
text_opts_bytes = None | ||
if text_opts: | ||
text_opts_bytes = encode( | ||
text_opts.document, | ||
codec_options=self._codec_options, | ||
) | ||
with _wrap_encryption_errors(): | ||
encrypted_doc = await self._encryption.encrypt( | ||
value=doc, | ||
|
@@ -905,6 +935,7 @@ async def _encrypt_helper( | |
contention_factor=contention_factor, | ||
range_opts=range_opts_bytes, | ||
is_expression=is_expression, | ||
text_opts=text_opts_bytes, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing |
||
) | ||
return decode(encrypted_doc)["v"] | ||
|
||
|
@@ -917,6 +948,7 @@ async def encrypt( | |
query_type: Optional[str] = None, | ||
contention_factor: Optional[int] = None, | ||
range_opts: Optional[RangeOpts] = None, | ||
text_opts: Optional[TextOpts] = None, | ||
) -> Binary: | ||
"""Encrypt a BSON value with a given key and algorithm. | ||
|
||
|
@@ -937,9 +969,14 @@ async def encrypt( | |
used. | ||
:param range_opts: Index options for `range` queries. See | ||
:class:`RangeOpts` for some valid options. | ||
:param text_opts: Index options for `textPreview` queries. See | ||
:class:`TextOpts` for some valid options. | ||
|
||
:return: The encrypted value, a :class:`~bson.binary.Binary` with subtype 6. | ||
|
||
.. versionchanged:: 4.9 | ||
Added the `text_opts` parameter. | ||
|
||
.. versionchanged:: 4.9 | ||
Added the `range_opts` parameter. | ||
|
||
|
@@ -960,6 +997,7 @@ async def encrypt( | |
contention_factor=contention_factor, | ||
range_opts=range_opts, | ||
is_expression=False, | ||
text_opts=text_opts, | ||
), | ||
) | ||
|
||
|