Class: AzIdentity::Identity::WorkloadIdentityClient

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/az_identity/identity/workload_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 = {}) ⇒ WorkloadIdentityClient

Returns a new instance of WorkloadIdentityClient.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/az_identity/identity/workload_identity_client.rb', line 12

def initialize(options = {})
  super()
  @environment = options[:environment]
  @resource = options[:resource] || storage_resource(@environment)
  @authority = ENV['AZURE_AUTHORITY_HOST'] || authority_url(@environment)
  @tenant_id = ENV.fetch('AZURE_TENANT_ID', nil)
  @client_id = ENV.fetch('AZURE_CLIENT_ID', nil)
  @token_file = ENV.fetch('AZURE_FEDERATED_TOKEN_FILE', nil)

  normalize_authority!
end

Instance Attribute Details

#authorityObject

Returns the value of attribute authority.



10
11
12
# File 'lib/az_identity/identity/workload_identity_client.rb', line 10

def authority
  @authority
end

#client_idObject

Returns the value of attribute client_id.



10
11
12
# File 'lib/az_identity/identity/workload_identity_client.rb', line 10

def client_id
  @client_id
end

#environmentObject

Returns the value of attribute environment.



10
11
12
# File 'lib/az_identity/identity/workload_identity_client.rb', line 10

def environment
  @environment
end

#resourceObject

Returns the value of attribute resource.



10
11
12
# File 'lib/az_identity/identity/workload_identity_client.rb', line 10

def resource
  @resource
end

#tenant_idObject

Returns the value of attribute tenant_id.



10
11
12
# File 'lib/az_identity/identity/workload_identity_client.rb', line 10

def tenant_id
  @tenant_id
end

#token_fileObject

Returns the value of attribute token_file.



10
11
12
# File 'lib/az_identity/identity/workload_identity_client.rb', line 10

def token_file
  @token_file
end

Instance Method Details

#fetch_credentialsObject



24
25
26
27
28
29
30
31
# File 'lib/az_identity/identity/workload_identity_client.rb', line 24

def fetch_credentials
  return unless federated_credentials_available?

  response = post(token_endpoint, body: token_request_body)
  process_token_response(response)
rescue ::Faraday::Error => e
  raise FetchCredentialsError, e.to_s
end