Class: AzIdentity::Identity::ManagedIdentityClient

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/az_identity/identity/managed_identity_client.rb

Constant Summary

Constants inherited from BaseClient

BaseClient::DEFAULT_TIMEOUT_S

Instance Attribute Summary collapse

Attributes inherited from BaseClient

#credentials

Instance Method Summary collapse

Methods inherited from BaseClient

#fetch_credentials_if_needed, #refresh_needed?

Methods included from AzureEnvironment

#authority_url, #redis_resource, #storage_resource

Constructor Details

#initialize(options = {}) ⇒ ManagedIdentityClient

Returns a new instance of ManagedIdentityClient.



16
17
18
19
20
# File 'lib/az_identity/identity/managed_identity_client.rb', line 16

def initialize(options = {})
  super()
  @environment = options[:environment]
  @resource = options[:resource] || storage_resource(@environment)
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



14
15
16
# File 'lib/az_identity/identity/managed_identity_client.rb', line 14

def resource
  @resource
end

Instance Method Details

#fetch_credentialsObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/az_identity/identity/managed_identity_client.rb', line 22

def fetch_credentials
  url = "#{identity_endpoint}?api-version=#{api_version}&resource=#{CGI.escape(resource)}"

  client_id = ENV.fetch('AZURE_CLIENT_ID', nil)
  url += "&client_id=#{client_id}" if client_id

  headers = { 'Metadata' => 'true' }
  headers['X-IDENTITY-HEADER'] = ENV['IDENTITY_HEADER'] if ENV['IDENTITY_HEADER']

  response = get(url, headers: headers)
  process_token_response(response)
end