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 @az_account_show if @az_account_show

  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 == ""

    @az_account_show = 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 =<<~EOL
    The '#{command}' return a blank string.
    Something went wrong. Try running it manually and confirm it returns json.
  EOL
  error_message(message)
end

#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 =<<~EOL
    ERROR: error running '#{command}'.
    Maybe you havent ran `az login` or configured ~/.azure manually.
    You can configure az login non-interactively with

        az login --service-principal --username USERNAME --password PASSWORD --tenant TENANT

    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
  EOL
  error_message(message)
end