123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Crypt::KMS::AWS::Credentials Private

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

Overview

::Mongo::Crypt::KMS::AWS KMS Credentials object contains credentials for using ::Mongo::Crypt::KMS::AWS KMS provider.

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) ⇒ Credentials

Creates an ::Mongo::Crypt::KMS::AWS KMS credentials object form a parameters hash.

Parameters:

Options Hash (opts):

Raises:

  • (ArgumentError)

    If required options are missing or incorrectly formatted.

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/credentials.rb', line 53

def initialize(opts)
  @opts = opts
  return if empty?

  @access_key_id = validate_param(:access_key_id, opts, FORMAT_HINT)
  @secret_access_key = validate_param(:secret_access_key, opts, FORMAT_HINT)
  @session_token = validate_param(:session_token, opts, FORMAT_HINT, required: false)
end

Instance Attribute Details

#access_key_idString (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/credentials.rb', line 29

attr_reader :access_key_id

#secret_access_keyString (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/credentials.rb', line 32

attr_reader :secret_access_key

#session_tokenString | nil (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/credentials.rb', line 35

attr_reader :session_token

Instance Method Details

#to_documentBSON::Document

Convert credentials object to a BSON document in libmongocrypt format.

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/aws/credentials.rb', line 65

def to_document
  return BSON::Document.new if empty?

  BSON::Document.new({
                       accessKeyId: access_key_id,
                       secretAccessKey: secret_access_key,
                     }).tap do |bson|
    bson.update({ sessionToken: session_token }) unless session_token.nil?
  end
end