Beispiel #1
0
#  Ensure this works: python -c "import pymongocrypt; print(pymongocrypt.libmongocrypt_version())"
#
#  If mongocryptd is not running: "pymongo.errors.EncryptionError: localhost:27020: [Errno 111] Connection refused"

import base64
import pymongo
from pymongo import MongoClient
from pymongo.encryption_options import AutoEncryptionOpts
import pymongocrypt
from bson import binary
from bson.binary import (Binary, JAVA_LEGACY, STANDARD, UUID_SUBTYPE)
from bson.codec_options import CodecOptions

OPTS = CodecOptions(uuid_representation=STANDARD)

print(pymongocrypt.libmongocrypt_version())

client = MongoClient("localhost", 27017)

# ** A LOCAL TEST KEY SHOULD NEVER BE USED IN PRODUCTION, ONLY FOR DEVELOPMENT **

# Test key material generated on Mac & Linux with: echo $(head -c 96 /dev/urandom | base64 | tr -d '\n')
local_key = 'CgOcoan3c/wm2c+WsOO6fXOUlJgd7SLQ1vl///aEFX6vXN9+7VOAP+iHKheZiYlB09ZS7CDcAQhlPeTeQNz03xiGbiCJJvl3uj4lnG+5i/udSLJAcwgtgtaedkFD0ROq'
key_bin = binary.Binary(base64.b64decode(local_key))
kms_providers = {'local': {'key': key_bin}}

print(
    "Please ensure mongocryptd is running (included in the standard enterprise download package)."
)

fle_opts = AutoEncryptionOpts(kms_providers,
 def test_libmongocrypt_version(self):
     self.assertVersionLike(pymongocrypt.libmongocrypt_version())