123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Crypt::KMS::AWS::MasterKeyDocument Private

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/mongo/crypt/kms/aws/master_document.rb

Overview

::Mongo::Crypt::KMS::AWS KMS master key document object contains ::Mongo::Crypt::KMS master key parameters.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::Mongo::Crypt::KMS::Validations - Included

#validate_param

Validate if a ::Mongo::Crypt::KMS parameter is valid.

#validate_tls_options

Validate KMS TLS options.

Constructor Details

.new(opts) ⇒ MasterKeyDocument

Creates a master key document object form a parameters hash.

Parameters:

Options Hash (opts):

Raises:

  • (ArgumentError)

    If required options are missing or incorrectly.

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/master_document.rb', line 48

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
  @region = validate_param(:region, opts, FORMAT_HINT)
  @key = validate_param(:key, opts, FORMAT_HINT)
  @endpoint = validate_param(:endpoint, opts, FORMAT_HINT, required: false)
end

Instance Attribute Details

#endpointString | nil (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/master_document.rb', line 34

attr_reader :endpoint

#keyString (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/master_document.rb', line 31

attr_reader :key

#regionString (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/master_document.rb', line 28

attr_reader :region

Instance Method Details

#to_documentBSON::Document

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

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/master_document.rb', line 62

def to_document
  BSON::Document.new({
                       provider: 'aws',
                       region: region,
                       key: key,
                     }).tap do |bson|
    bson.update({ endpoint: endpoint }) unless endpoint.nil?
  end
end