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

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

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

"AWS key document  must be in the format: " +
"{ region: 'REGION', key: 'KEY' }"

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

Options Hash (opts):

  • :region (String)

    AWS region.

  • :key (String)

    AWS KMS key.

  • :endpoint (String | nil)

    AWS KMS endpoint, optional.

Raises:

  • (ArgumentError)

    If required options are missing or incorrectly.



107
108
109
110
111
112
113
114
115
116
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/aws.rb', line 107

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)

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

Returns:

  • (String | nil)

    AWS KMS endpoint.



93
94
95
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/aws.rb', line 93

def endpoint
  @endpoint
end

#keyString (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 AWS KMS key.

Returns:

  • (String)

    AWS KMS key.



90
91
92
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/aws.rb', line 90

def key
  @key
end

#regionString (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 AWS region.

Returns:

  • (String)

    AWS region.



87
88
89
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/aws.rb', line 87

def region
  @region
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)

    AWS KMS master key document in libmongocrypt format.



121
122
123
124
125
126
127
128
129
130
131
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/aws.rb', line 121

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