-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
982dc07
CRUD Support in Driver for Prefix/Suffix/Substring Indexes
blink1073 6ae88a7
update the changelog
blink1073 253684d
switch to pymongocrypt master
blink1073 f7266ff
update locked version of libmongocrypt
blink1073 98ddc35
Add a note about required pymongocrypt version
blink1073 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
"""**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, | ||
), | ||
) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we required to call this
TEXTPREVIEW
instead of calling itTEXT
and designating "feature preview"?There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.