Class: Mongo::Crypt::KMS::Azure::MasterKeyDocument Private

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
lib/mongo/crypt/kms/azure/master_document.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Constant Summary collapse

FORMAT_HINT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"Azure key document  must be in the format: " +
"{ key_vault_endpoint: 'KEY_VAULT_ENDPOINT', key_name: 'KEY_NAME' }"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validations

#validate_param, validate_tls_options

Constructor Details

#initialize(opts) ⇒ MasterKeyDocument

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a master key document object form a parameters hash.

Parameters:

  • opts (Hash)

    A hash that contains master key options for the Azure KMS provider.

Options Hash (opts):

  • :key_vault_endpoint (String)

    Azure key vault endpoint.

  • :key_name (String)

    Azure KMS key name.

  • :key_version (String | nil)

    Azure KMS key version, optional.

Raises:

  • (ArgumentError)

    If required options are missing or incorrectly.



49
50
51
52
53
54
55
56
57
58
# 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

Instance Attribute Details

#key_nameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Azure KMS key name.

Returns:

  • (String)

    Azure KMS key name.



32
33
34
# File 'lib/mongo/crypt/kms/azure/master_document.rb', line 32

def key_name
  @key_name
end

#key_vault_endpointString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Azure key vault endpoint.

Returns:

  • (String)

    Azure key vault endpoint.



29
30
31
# File 'lib/mongo/crypt/kms/azure/master_document.rb', line 29

def key_vault_endpoint
  @key_vault_endpoint
end

#key_versionString | nil (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Azure KMS key version.

Returns:

  • (String | nil)

    Azure KMS key version.



35
36
37
# File 'lib/mongo/crypt/kms/azure/master_document.rb', line 35

def key_version
  @key_version
end

Instance Method Details

#to_documentBSON::Document

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:

  • (BSON::Document)

    Azure KMS credentials in libmongocrypt format.



63
64
65
66
67
68
69
70
71
72
73
# 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