class Mongo::Crypt::KMS::AWS::MasterKeyDocument

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

@api private

Constants

FORMAT_HINT

Attributes

endpoint[R]

@return [ String | nil ] AWS KMS endpoint.

key[R]

@return [ String ] AWS KMS key.

region[R]

@return [ String ] AWS region.

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 AWS KMS provider.

@option opts [ String ] :region AWS region. @option opts [ String ] :key AWS KMS key. @option opts [ String | nil ] :endpoint AWS KMS endpoint, optional.

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

# File lib/mongo/crypt/kms/aws/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
  @region = validate_param(:region, opts, FORMAT_HINT)
  @key = validate_param(:key, opts, FORMAT_HINT)
  @endpoint = validate_param(:endpoint, 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 ] AWS KMS master key document in libmongocrypt format.

# File lib/mongo/crypt/kms/aws/master_document.rb, line 63
def to_document
  BSON::Document.new({
    provider: 'aws',
    region: region,
    key: key,
  }).tap do |bson|
    unless endpoint.nil?
      bson.update({ endpoint: endpoint })
    end
  end
end