Class: Armrest::Api::Auth::CLI

Inherits:
Base
  • Object
show all
Defined in:
lib/armrest/api/auth/cli.rb

Defined Under Namespace

Classes: CliError, Error

Constant Summary

Constants inherited from Base

Base::HTTP_READ_METHODS, Base::HTTP_WRITE_METHODS, Base::MAX_RETRIES

Instance Method Summary collapse

Methods inherited from Base

#append_api_version, #build_request, #headers, #http, #initialize, #request, #send_request, #set_headers!, #standarize_path, #url, #with_open_timeout

Methods included from Settings

#client_id, #client_secret, #endpoint, #group, #location, #resource, #subscription_id, #tenant_id

Methods included from HandleResponse

#load_json, #ok?

Methods included from Logging

#default_logger, #logger, #logger=

Constructor Details

This class inherits a constructor from Armrest::Api::Base

Instance Method Details

#credsObject



20
21
22
23
# File 'lib/armrest/api/auth/cli.rb', line 20

def creds
  data = get_access_token
  data.deep_transform_keys { |k| k.underscore } # to normalize the structure to the other classes
end

#get_access_tokenObject

The az cli command itself has it’s own caching. So dont think we need to handle caching



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/armrest/api/auth/cli.rb', line 26

def get_access_token
  command = "az account get-access-token -o json"
  if resource.include?("vault.azure.net")
    command += " --scope https://vault.azure.net/.default"
  end
  logger.debug "command: #{command}"
  out = `#{command}`
  if $?.success?
    JSON.load(out)
  else
    raise CliError, 'Error acquiring token from the Azure az CLI'
  end
end