Class: AzureInfo::Account
Instance Method Summary collapse
-
#az_account_show ⇒ Object
looks like az configure stores settings in ~/.azure/config.
- #get(name) ⇒ Object
- #raise_empty_error(command) ⇒ Object
- #raise_status_error(command) ⇒ Object
Methods inherited from Base
Instance Method Details
#az_account_show ⇒ Object
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 az_account_show 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) az_account_show[name] end |
#raise_empty_error(command) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/azure_info/account.rb', line 37 def raise_empty_error(command) =<<~EOL The '#{command}' return a blank string. Something went wrong. Try running it manually and confirm it returns json. EOL raise Error.new() end |
#raise_status_error(command) ⇒ Object
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) =<<~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() end |