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

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-v2.19/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) ⇒ 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.

Returns:

Raises:



41
42
43
44
45
46
47
48
49
50
51
# File 'build/ruby-driver-v2.19/lib/mongo/crypt/kms/azure/credentials_retriever.rb', line 41

def self.fetch_access_token(extra_headers: {}, metadata_host: nil)
  uri, req = prepare_request(extra_headers, )
  parsed_response = fetch_response(uri, req)
  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