Class: Mongo::Crypt::KMS::Azure::CredentialsRetriever Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/crypt/kms/azure/credentials_retriever.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.

This class retrieves Azure credentials using Azure metadata host. This should be used when the driver is used on the Azure environment.

Constant Summary collapse

DEFAULT_HOST =

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.

Default host to obtain Azure metadata.

'169.254.169.254'

Class Method Summary collapse

Class Method Details

.fetch_access_token(extra_headers: {}, metadata_host: nil, timeout_holder: nil) ⇒ KMS::Azure::AccessToken

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.

Fetches Azure credentials from Azure metadata host.

Parameters:

  • extra_headers (Hash) (defaults to: {})

    Extra headers to be passed to the request. This is used for testing.

  • metadata_host (String | nil) (defaults to: nil)

    Azure metadata host. This is used for testing.

  • timeout_holder (CsotTimeoutHolder | nil) (defaults to: nil)

    CSOT timeout.

Returns:

Raises:

  • (KMS::CredentialsNotFound)

    If credentials could not be found.

  • Error::TimeoutError if credentials cannot be retrieved within the timeout.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mongo/crypt/kms/azure/credentials_retriever.rb', line 44

def self.fetch_access_token(extra_headers: {}, metadata_host: nil, timeout_holder: nil)
  uri, req = prepare_request(extra_headers, )
  parsed_response = fetch_response(uri, req, timeout_holder)
  Azure::AccessToken.new(
    parsed_response.fetch('access_token'),
    Integer(parsed_response.fetch('expires_in'))
  )
rescue KeyError, ArgumentError => e
  raise KMS::CredentialsNotFound,
        "Azure metadata response is invalid: '#{parsed_response}'; #{e.class}: #{e.message}"
end