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

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
build/ruby-driver-master/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 Credentials object contains credentials for using AWS KMS provider.

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 KMS provider options must be in the format: " +
"{ access_key_id: 'YOUR-ACCESS-KEY-ID', secret_access_key: 'SECRET-ACCESS-KEY' }"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validations

#validate_param, validate_tls_options

Constructor Details

#initialize(opts) ⇒ Credentials

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 an AWS KMS credentials object form a parameters hash.

Parameters:

  • opts (Hash)

    A hash that contains credentials for AWS KMS provider

Options Hash (opts):

  • :access_key_id (String)

    AWS access key id.

  • :secret_access_key (String)

    AWS secret access key.

  • :session_token (String | nil)

    AWS session token, optional.

Raises:

  • (ArgumentError)

    If required options are missing or incorrectly formatted.



51
52
53
54
55
# File 'build/ruby-driver-master/lib/mongo/crypt/kms/aws.rb', line 51

def initialize(opts)
  @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)

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 access key.

Returns:

  • (String)

    AWS access key.



30
31
32
# File 'build/ruby-driver-master/lib/mongo/crypt/kms/aws.rb', line 30

def access_key_id
  @access_key_id
end

#secret_access_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 secret access key.

Returns:

  • (String)

    AWS secret access key.



33
34
35
# File 'build/ruby-driver-master/lib/mongo/crypt/kms/aws.rb', line 33

def secret_access_key
  @secret_access_key
end

#session_tokenString | 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 session token.

Returns:

  • (String | nil)

    AWS session token.



36
37
38
# File 'build/ruby-driver-master/lib/mongo/crypt/kms/aws.rb', line 36

def session_token
  @session_token
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 credentials object to a BSON document in libmongocrypt format.

Returns:

  • (BSON::Document)

    AWS KMS credentials in libmongocrypt format.



60
61
62
63
64
65
66
67
68
69
# File 'build/ruby-driver-master/lib/mongo/crypt/kms/aws.rb', line 60

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