Module: Mongoid::Tasks::Encryption
Overview
This module contains helper methods for data encryption.
Instance Method Summary collapse
-
#create_data_key(client_name: nil, kms_provider_name: nil, key_alt_name: nil) ⇒ Hash
Create a data encryption key for the given kms provider using the auto_encryption_options from the client’s configuration.
Instance Method Details
#create_data_key(client_name: nil, kms_provider_name: nil, key_alt_name: nil) ⇒ Hash
Create a data encryption key for the given kms provider using the auto_encryption_options from the client’s configuration.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mongoid/tasks/encryption.rb', line 24 def create_data_key(client_name: nil, kms_provider_name: nil, key_alt_name: nil) kms_provider_name, kms_providers, key_vault_namespace = prepare_arguments( kms_provider_name, client_name ) key_vault_client = Mongoid::Clients.default.with(database: key_vault_namespace.split('.').first) client_encryption = Mongo::ClientEncryption.new( key_vault_client, key_vault_namespace: key_vault_namespace, kms_providers: kms_providers ) client_encryption_opts = {}.tap do |opts| opts[:key_alt_names] = [key_alt_name] if key_alt_name end data_key_id = client_encryption.create_data_key(kms_provider_name, client_encryption_opts) { key_id: Base64.strict_encode64(data_key_id.data), kms_provider: kms_provider_name, key_vault_namespace: key_vault_namespace, key_alt_name: key_alt_name }.compact end |