Class: AzureInfo::Account

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

Instance Method Summary collapse

Methods inherited from Base

#check_az_installed!

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
# File 'lib/azure_info/account.rb', line 8

def 
  return @az_account_show if @az_account_show
  check_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)
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

Raises:



37
38
39
40
41
42
43
# File 'lib/azure_info/account.rb', line 37

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
  raise Error.new(message)
end

#raise_status_error(command) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/azure_info/account.rb', line 21

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
  raise Error.new(message)
end