123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Crypt::KMS::Azure::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/azure/credentials.rb

Overview

::Mongo::Crypt::KMS::Azure KMS Credentials object contains credentials for using ::Mongo::Crypt::KMS::Azure 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::Azure 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/azure/credentials.rb', line 61

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

  if opts[:access_token]
    @access_token = opts[:access_token]
  else
    @tenant_id = validate_param(:tenant_id, opts, FORMAT_HINT)
    @client_id = validate_param(:client_id, opts, FORMAT_HINT)
    @client_secret = validate_param(:client_secret, opts, FORMAT_HINT)
    @identity_platform_endpoint = validate_param(
      :identity_platform_endpoint, opts, FORMAT_HINT, required: false
    )
  end
end

Instance Attribute Details

#access_tokenString | nil (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/azure/credentials.rb', line 41

attr_reader :access_token

#client_idString (readonly)

Returns:

[ GitHub ]

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

attr_reader :client_id

#client_secretString (readonly)

Returns:

[ GitHub ]

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

attr_reader :client_secret

#identity_platform_endpointString | nil (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/azure/credentials.rb', line 38

attr_reader :identity_platform_endpoint

#tenant_idString (readonly)

Returns:

[ GitHub ]

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

attr_reader :tenant_id

Instance Method Details

#to_documentBSON::Document

Convert credentials object to a BSON document in libmongocrypt format.

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/azure/credentials.rb', line 80

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

  if access_token
    BSON::Document.new({ accessToken: access_token })
  else
    BSON::Document.new(
      {
        tenantId: @tenant_id,
        clientId: @client_id,
        clientSecret: @client_secret
      }
    ).tap do |bson|
      unless identity_platform_endpoint.nil?
        bson.update({ identityPlatformEndpoint: identity_platform_endpoint })
      end
    end
  end
end