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

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
build/ruby-driver-v2.18/lib/mongo/crypt/kms/azure.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.



115
116
117
118
119
120
121
122
123
124
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/azure.rb', line 115

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.



98
99
100
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/azure.rb', line 98

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.



95
96
97
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/azure.rb', line 95

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.



101
102
103
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/azure.rb', line 101

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.



129
130
131
132
133
134
135
136
137
138
139
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/azure.rb', line 129

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