Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from boto3 import Session
- from pymongo import MongoClient
- from pymongo.encryption_options import AutoEncryptionOpts
- from bson.binary import STANDARD
- from bson.codec_options import CodecOptions
- from pymongo.encryption import ClientEncryption
- import os
- region_name = 'us-east-1'
- session = Session(region_name=region_name)
- credentials = session.get_credentials()
- current_credentials = credentials.get_frozen_credentials()
- access_key = current_credentials.access_key
- secret_key = current_credentials.secret_key
- session_token = current_credentials.token
- os.environ['AWS_ACCESS_KEY_ID'] = access_key
- os.environ['AWS_SECRET_ACCESS_KEY'] = secret_key
- os.environ['AWS_SESSION_TOKEN'] = session_token
- kms_providers = {
- "aws": {
- "accessKeyId": access_key,
- "secretAccessKey": secret_key
- }
- }
- client = MongoClient('mongodb://localhost:27017/')
- key_vault_namespace = "encryption.__keyVault"
- fle_opts = AutoEncryptionOpts(
- kms_providers,
- key_vault_namespace
- )
- client_encryption = ClientEncryption(
- kms_providers,
- key_vault_namespace,
- client,
- CodecOptions(uuid_representation=STANDARD)
- )
- data_key_id = client_encryption.create_data_key("aws", master_key={
- 'region': region_name,
- 'key': 'ARN',
- })
- print(data_key_id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement