Class: Kitchen::Driver::Azure::AzureCliToken

Inherits:
TokenProvider show all
Defined in:
lib/kitchen/driver/azure/token_provider.rb

Overview

Reuses whatever the Azure CLI is already signed in as.

Constant Summary

Constants inherited from TokenProvider

TokenProvider::EXPIRY_MARGIN

Instance Attribute Summary

Attributes inherited from TokenProvider

#environment

Instance Method Summary collapse

Methods inherited from TokenProvider

#access_token, #authorization_header, #initialize

Constructor Details

This class inherits a constructor from Kitchen::Driver::Azure::TokenProvider

Instance Method Details

#fetch_tokenArray(String, Integer)

Returns:

  • (Array(String, Integer))

Raises:



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/kitchen/driver/azure/token_provider.rb', line 222

def fetch_token
  stdout, stderr, status = Open3.capture3(
    "az", "account", "get-access-token",
    "--resource", environment.token_audience,
    "--output", "json"
  )

  unless status.success?
    raise OperationError.new("Could not acquire an Azure access token via `az account get-access-token`. Run `az login` first. (#{stderr.strip})")
  end

  payload = JSON.parse(stdout)
  [payload.fetch("accessToken"), cli_expiry(payload)]
rescue Errno::ENOENT
  raise OperationError.new("The Azure CLI (`az`) was not found on PATH, and no other Azure credentials were configured.")
rescue JSON::ParserError, KeyError
  raise OperationError.new("Could not understand the response from `az account get-access-token`.")
end