Class: AzureInfo::Account

Inherits:
Base
  • Object
show all
Defined in:
lib/azure_info/account.rb

Instance Method Summary collapse

Methods inherited from Base

#az_installed?, #env_vars, #env_vars_set?, #error_message, #format_list, #show_error

Instance Method Details

#az_account_showObject

looks like az configure stores settings in ~/.azure/config



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/azure_info/account.rb', line 8

def 
  return  if 

  if az_installed?
    command = "az account show --output json"
    out = `#{command}`.strip

    raise_status_error(command) unless $?.success?
    raise_empty_error(command) if out.strip == ""

     = JSON.load(out)
  else
    if env_vars_set?
      {}
    else
      error_message
    end
  end
end

#get(name) ⇒ Object



3
4
5
# File 'lib/azure_info/account.rb', line 3

def get(name)
  [name]
end

#raise_empty_error(command) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/azure_info/account.rb', line 41

def raise_empty_error(command)
  message ="    The '\#{command}' return a blank string.\n    Something went wrong. Try running it manually and confirm it returns json.\n  EOL\n  error_message(message)\nend\n"

#raise_status_error(command) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/azure_info/account.rb', line 28

def raise_status_error(command)
  message ="    ERROR: error running '\#{command}'.\n    Maybe you havent ran `az login` or configured ~/.azure manually.\n    You can configure az login non-interactively with\n\n        az login --service-principal --username USERNAME --password PASSWORD --tenant TENANT\n\n    Per https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli?view=azure-cli-latest#sign-in-using-a-service-principal\n  EOL\n  error_message(message)\nend\n"