Advertisement
Guest User

Untitled

a guest
Sep 14th, 2020
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. from boto3 import Session
  2. from pymongo import MongoClient
  3. from pymongo.encryption_options import AutoEncryptionOpts
  4. from bson.binary import STANDARD
  5. from bson.codec_options import CodecOptions
  6. from pymongo.encryption import ClientEncryption
  7. import os
  8.  
  9. region_name = 'us-east-1'
  10. session = Session(region_name=region_name)
  11. credentials = session.get_credentials()
  12. current_credentials = credentials.get_frozen_credentials()
  13.  
  14. access_key = current_credentials.access_key
  15. secret_key = current_credentials.secret_key
  16. session_token = current_credentials.token
  17.  
  18. os.environ['AWS_ACCESS_KEY_ID'] = access_key
  19. os.environ['AWS_SECRET_ACCESS_KEY'] = secret_key
  20. os.environ['AWS_SESSION_TOKEN'] = session_token
  21.  
  22. kms_providers = {
  23.     "aws": {
  24.         "accessKeyId": access_key,
  25.         "secretAccessKey": secret_key
  26.     }
  27. }
  28.  
  29. client = MongoClient('mongodb://localhost:27017/')
  30.  
  31. key_vault_namespace = "encryption.__keyVault"
  32.  
  33. fle_opts = AutoEncryptionOpts(
  34.     kms_providers,
  35.     key_vault_namespace
  36. )
  37.  
  38. client_encryption = ClientEncryption(
  39.     kms_providers,
  40.     key_vault_namespace,
  41.     client,
  42.     CodecOptions(uuid_representation=STANDARD)
  43. )
  44. data_key_id = client_encryption.create_data_key("aws", master_key={
  45.     'region': region_name,
  46.     'key': 'ARN',
  47. })
  48. print(data_key_id)
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement