Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
dbc4670
PYTHON-3053 Key Management API
blink1073 Jun 2, 2022
f086908
wip implementation
blink1073 Jun 2, 2022
60d6dd0
wip implementation
blink1073 Jun 3, 2022
6686479
wip implementation
blink1073 Jun 6, 2022
3218ecd
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 Jun 16, 2022
5a0e737
wip
blink1073 Jun 16, 2022
40887d7
implement rewrap_many_data_key
blink1073 Jun 16, 2022
025998c
wip
blink1073 Jun 17, 2022
bbd5b71
wip
blink1073 Jun 17, 2022
56c9b59
wip implementation
blink1073 Jun 17, 2022
c9571a1
wip
blink1073 Jun 17, 2022
64bf896
wip
blink1073 Jun 17, 2022
cd7a004
clean up placeholder map
blink1073 Jun 17, 2022
5e030d8
clean up placeholder map
blink1073 Jun 17, 2022
97e3618
lint
blink1073 Jun 21, 2022
a3afa23
update docstring
blink1073 Jun 21, 2022
6a147cb
use my libmongocrypt
blink1073 Jun 21, 2022
81f6c3a
debug
blink1073 Jun 21, 2022
fa87648
try again
blink1073 Jun 21, 2022
32efb29
add support for rewrap_many_data_key
blink1073 Jun 21, 2022
e5f7c5a
handle RewrapManyDataKeyOpts
blink1073 Jun 21, 2022
f3c97ec
fix handling of existing opts object
blink1073 Jun 21, 2022
4ebc8f1
fix rewrapmanydatakey
blink1073 Jun 21, 2022
58ed247
fix method name
blink1073 Jun 21, 2022
02d7588
remove unnecessary method
blink1073 Jun 21, 2022
68a346c
handle key material and UUIDs
blink1073 Jun 21, 2022
a6f3277
remove extra file and fix handling of empty result
blink1073 Jun 21, 2022
e8dfc55
add handling of int keys
blink1073 Jun 21, 2022
e441861
cleanup
blink1073 Jun 22, 2022
60a8de9
more cleanup
blink1073 Jun 22, 2022
9bd804e
fix variable name
blink1073 Jun 22, 2022
5aa606d
fix variable usage
blink1073 Jun 22, 2022
c463441
encode local key
blink1073 Jun 22, 2022
7339896
try again
blink1073 Jun 22, 2022
5f5f379
unpack the bulk api result
blink1073 Jun 22, 2022
7f6d541
set TLS paths earlier
blink1073 Jun 22, 2022
4d6606b
use parse_bulk_write_result
blink1073 Jun 22, 2022
001041d
fix rewrapmanydatakey bulk write
blink1073 Jun 22, 2022
4c7a62c
fix rawbson lookup
blink1073 Jun 22, 2022
470b7f9
handle a none result
blink1073 Jun 22, 2022
57fb108
add kmip tls options
blink1073 Jun 22, 2022
f8a069c
fix handling of tls
blink1073 Jun 22, 2022
405dcd3
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 Jun 22, 2022
60e627b
fix variable name
blink1073 Jun 22, 2022
e251252
fix missing import
blink1073 Jun 23, 2022
f325c58
fix import and refactor
blink1073 Jun 23, 2022
907f000
fix missing import
blink1073 Jun 23, 2022
27a59a6
fix variable and bulkwriteresult usage
blink1073 Jun 23, 2022
1e10cea
make the empy result acknowledged
blink1073 Jun 23, 2022
8bb5252
add missing field
blink1073 Jun 23, 2022
4a92f5c
update docstrings and remove unneeded logic
blink1073 Jun 23, 2022
267faa0
Handle PYTHON-3314 and PYTHON-3307
blink1073 Jun 23, 2022
cba0f41
fix handling of empty bulk_write_result
blink1073 Jun 23, 2022
6ca8efd
Add Unique Index on keyAltNames Prose test
blink1073 Jun 23, 2022
9b060b4
fix lint
blink1073 Jun 23, 2022
429f39d
PYTHON-3313 Cache AWS Credentials Where Possible
blink1073 Jun 24, 2022
426c828
Revert "PYTHON-3313 Cache AWS Credentials Where Possible"
blink1073 Jun 24, 2022
5fc7029
address review
blink1073 Jun 27, 2022
c0e79b1
address review
blink1073 Jun 27, 2022
f568c2a
address review
blink1073 Jun 27, 2022
1f41d16
update spec files
blink1073 Jun 27, 2022
5f5eb0c
add untracked files
blink1073 Jun 27, 2022
e24a070
add placeholders from DRIVERS-2373
blink1073 Jun 28, 2022
9f216db
clean up tests
blink1073 Jun 28, 2022
fc47a85
handle deleteKey tests
blink1073 Jun 28, 2022
7c38623
use default raw_bson codec options
blink1073 Jun 28, 2022
52034ac
debug
blink1073 Jun 28, 2022
044b3f7
more debug
blink1073 Jun 28, 2022
cc1885e
fix the wrapper
blink1073 Jun 28, 2022
3699eb7
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 Jun 28, 2022
3411c23
sync with unified tests
blink1073 Jun 29, 2022
899c933
add new unified tests
blink1073 Jun 29, 2022
28d0492
address review
blink1073 Jun 29, 2022
61e7d82
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 Jun 29, 2022
f8b75d7
remove unused import
blink1073 Jun 29, 2022
18403ea
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 Jun 29, 2022
df9bcb5
use pymongocrypt from checkout
blink1073 Jun 29, 2022
08bcfbc
clean up handling of uuids
blink1073 Jun 30, 2022
5b4a7bf
clean up handling of uuids
blink1073 Jun 30, 2022
53a2cc8
clean up data_key_id handling
blink1073 Jun 30, 2022
49d3534
remove unused import
blink1073 Jun 30, 2022
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
blink1073 committed Jun 17, 2022
commit 64bf8966718f5f4aee084449ab0e6844d4dfc246
27 changes: 23 additions & 4 deletions pymongo/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,11 +840,30 @@ def remove_key_alt_name(self, id: Binary, key_alt_name: str) -> Any:
:Returns:
The removal result.
"""
update = {"$pull": {"keyAltNames": key_alt_name}}
reply = self._key_vault_coll.find_one_and_update({"_id": id}, update)
pipeline = [
{
"$set": {
"keyAltNames": {
"$cond": [
{"$eq": ["$keyAltNames", [key_alt_name]]},
"$$REMOVE",
{
"$filter": {
"input": "$keyAltNames",
"cond": {"$ne": ["$$this", key_alt_name]},
}
},
]
}
}
}
]
reply = self._key_vault_coll.find_one_and_update({"_id": id}, pipeline)
# Ensure keyAltNames field is removed if it would otherwise be empty.
if reply:
pass
if reply and not reply["keyAltNames"]:
update = {"$unset": {"keyAltNames": True}}
reply = self._key_vault_coll.find_one_and_update({"_id": id}, update)
return reply

def get_key_by_alt_name(self, key_alt_name: str) -> Any:
"""Get a key document in the key vault collection that has the given ``key_alt_name``.
Expand Down
30 changes: 8 additions & 22 deletions test/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@
unittest,
)
from test.test_bulk import BulkTestBase
from test.unified_format import generate_test_classes
from test.unified_format import (
AWS_CREDS,
AZURE_CREDS,
GCP_CREDS,
KMIP,
KMS_PROVIDERS,
generate_test_classes,
)
from test.utils import (
AllowListEventListener,
OvertCommandListener,
Expand Down Expand Up @@ -79,9 +86,6 @@ def get_client_opts(client):
return client._MongoClient__options


KMS_PROVIDERS = {"local": {"key": b"\x00" * 96}}


class TestAutoEncryptionOpts(PyMongoTestCase):
@unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed")
@unittest.skipUnless(os.environ.get("TEST_CRYPT_SHARED"), "crypt_shared lib is not installed")
Expand Down Expand Up @@ -547,11 +551,6 @@ def test_with_statement(self):


# Spec tests
AWS_CREDS = {
"accessKeyId": os.environ.get("FLE_AWS_KEY", ""),
"secretAccessKey": os.environ.get("FLE_AWS_SECRET", ""),
}

AWS_TEMP_CREDS = {
"accessKeyId": os.environ.get("CSFLE_AWS_TEMP_ACCESS_KEY_ID", ""),
"secretAccessKey": os.environ.get("CSFLE_AWS_TEMP_SECRET_ACCESS_KEY", ""),
Expand All @@ -562,19 +561,6 @@ def test_with_statement(self):
"accessKeyId": os.environ.get("CSFLE_AWS_TEMP_ACCESS_KEY_ID", ""),
"secretAccessKey": os.environ.get("CSFLE_AWS_TEMP_SECRET_ACCESS_KEY", ""),
}

AZURE_CREDS = {
"tenantId": os.environ.get("FLE_AZURE_TENANTID", ""),
"clientId": os.environ.get("FLE_AZURE_CLIENTID", ""),
"clientSecret": os.environ.get("FLE_AZURE_CLIENTSECRET", ""),
}

GCP_CREDS = {
"email": os.environ.get("FLE_GCP_EMAIL", ""),
"privateKey": os.environ.get("FLE_GCP_PRIVATEKEY", ""),
}

KMIP = {"endpoint": os.environ.get("FLE_KMIP_ENDPOINT", "localhost:5698")}
KMS_TLS_OPTS = {"kmip": {"tlsCAFile": CA_PEM, "tlsCertificateKeyFile": CLIENT_PEM}}


Expand Down
30 changes: 29 additions & 1 deletion test/unified_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,36 @@
IS_INTERRUPTED = False


# Shared KMS data.
KMS_PROVIDERS = {"local": {"key": b"\x00" * 96}}
AWS_CREDS = {
"accessKeyId": os.environ.get("FLE_AWS_KEY", ""),
"secretAccessKey": os.environ.get("FLE_AWS_SECRET", ""),
}
AZURE_CREDS = {
"tenantId": os.environ.get("FLE_AZURE_TENANTID", ""),
"clientId": os.environ.get("FLE_AZURE_CLIENTID", ""),
"clientSecret": os.environ.get("FLE_AZURE_CLIENTSECRET", ""),
}

GCP_CREDS = {
"email": os.environ.get("FLE_GCP_EMAIL", ""),
"privateKey": os.environ.get("FLE_GCP_PRIVATEKEY", ""),
}
KMIP = {"endpoint": os.environ.get("FLE_KMIP_ENDPOINT", "localhost:5698")}


PLACEHOLDER_MAP = {
"/clientEncryptionOpts/kmsProviders/local/key": b"\x00" * 96,
"/clientEncryptionOpts/kmsProviders/local/key": KMS_PROVIDERS["local"]["key"],
"/clientEncryptionOpts/kmsProviders/aws/accessKeyId": AWS_CREDS["accessKeyId"],
"/clientEncryptionOpts/kmsProviders/aws/secretAccessKey": AWS_CREDS["secretAccessKey"],
"/clientEncryptionOpts/kmsProviders/azure/tenantId": AZURE_CREDS["tenantId"],
"/clientEncryptionOpts/kmsProviders/azure/tenantId": AZURE_CREDS["tenantId"],
"/clientEncryptionOpts/kmsProviders/azure/clientId": AZURE_CREDS["clientId"],
"/clientEncryptionOpts/kmsProviders/azure/clientSecret": AZURE_CREDS["clientSecret"],
"/clientEncryptionOpts/kmsProviders/gcp/email": GCP_CREDS["email"],
"/clientEncryptionOpts/kmsProviders/gcp/privateKey": GCP_CREDS["privateKey"],
"/clientEncryptionOpts/kmsProviders/kmip/endpoint": KMIP["endpoint"],
}


Expand Down