class Mongo::Crypt::KMS::Azure::MasterKeyDocument

Azure KMS master key document object contains KMS master key parameters.

@api private

Constants

FORMAT_HINT

Attributes

key_name[R]

@return [ String ] Azure KMS key name.

key_vault_endpoint[R]

@return [ String ] Azure key vault endpoint.

key_version[R]

@return [ String | nil ] Azure KMS key version.

Public Class Methods

new(opts) click to toggle source

Creates a master key document object form a parameters hash.

@param [ Hash ] opts A hash that contains master key options for

the Azure KMS provider.

@option opts [ String ] :key_vault_endpoint Azure key vault endpoint. @option opts [ String ] :key_name Azure KMS key name. @option opts [ String | nil ] :key_version Azure KMS key version, optional.

@raise [ ArgumentError ] If required options are missing or incorrectly.

# File lib/mongo/crypt/kms/azure/master_document.rb, line 49
def initialize(opts)
  unless opts.is_a?(Hash)
    raise ArgumentError.new(
      'Key document options must contain a key named :master_key with a Hash value'
    )
  end
  @key_vault_endpoint = validate_param(:key_vault_endpoint, opts, FORMAT_HINT)
  @key_name = validate_param(:key_name, opts, FORMAT_HINT)
  @key_version = validate_param(:key_version, opts, FORMAT_HINT, required: false)
end

Public Instance Methods

to_document() click to toggle source

Convert master key document object to a BSON document in libmongocrypt format.

@return [ BSON::Document ] Azure KMS credentials in libmongocrypt format.

# File lib/mongo/crypt/kms/azure/master_document.rb, line 63
def to_document
  BSON::Document.new({
    provider: 'azure',
    keyVaultEndpoint: key_vault_endpoint,
    keyName: key_name,
  }).tap do |bson|
    unless key_version.nil?
      bson.update({ keyVersion: key_version })
    end
  end
end