18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/legion/extensions/identity/entra/managed_identity/runners/token.rb', line 18
def acquire_managed_token(resource: 'https://graph.microsoft.com', client_id: nil, **)
log.debug("ManagedIdentity::Token.acquire: resource=#{resource}")
params = {
'api-version' => IMDS_API_VERSION,
'resource' => resource
}
params['client_id'] = client_id if client_id
response = imds_connection.get('metadata/identity/oauth2/token', params)
body = response.body.to_s.empty? ? {} : json_load(response.body)
unless response.success?
log.warn("ManagedIdentity::Token.acquire: IMDS returned #{response.status}")
return { error: "http_#{response.status}",
description: body[:error_description] || response.reason_phrase }
end
log.info('ManagedIdentity::Token.acquire: token acquired from IMDS')
{ result: body }
rescue StandardError => e
handle_exception(e, level: :error, operation: 'managed_identity.token.acquire')
{ error: 'request_failed', description: e.message }
end
|