azure_info 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 646dd5f9bdd9dde86186dfbe79c9830f0350580f22ee314ddd25a5e35ad4542e
4
- data.tar.gz: 4d40f19ff4c6d1651871d43436c7e8901ce917fa75c1cf506a3c4ba132ecf530
3
+ metadata.gz: e4ae9c9490f68fe1f75f04f8c4ad05adb4c4c3ddbe4723563e33739723c13f64
4
+ data.tar.gz: f463b07527a94b6851fefa659e568a9d4d59c1d0496dd136e62067a8bdf8d4f3
5
5
  SHA512:
6
- metadata.gz: 2a9dc4214da271076da2f09dea0388d9a27ec32e3fb120e4d0b8197d46c17aaf941514cb46a01d9567a1f7e2c6f0357fc1bac60d5d08adeae86b156fd0f471f1
7
- data.tar.gz: 8aeee66d296a7c30fad2ecce720c85c6fc41d83d8d23e9ad21e49ed0e6b50e8858348340e2057bcbc42e9760c5230aa27aec9ada09cedb523a3d9daa509c68b9
6
+ metadata.gz: 5ea982a5564f29622a740324a6459ea316f4b174ef6723e4e1859ea6f8ed759909a930dda066d3680989972d2358a721e3d2ab57c28c62db6c554fce155c4b57
7
+ data.tar.gz: a82b55909878ea8bf6a00db2829762fb6c0632c0ef9d59b336cd8c8bc6ffa087526a52aacca18a883ba416b742be8ebb8ed6c09ba754fde4997127e33cde865f
data/CHANGELOG.md CHANGED
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.1.4] - 2021-12-27
7
+ - [#4](https://github.com/boltops-tools/azure_info/pull/4) improve error message when az cli not installed
8
+
6
9
  ## [0.1.3] - 2021-12-27
7
10
  - [#3](https://github.com/boltops-tools/azure_info/pull/3) improve error message when az cli not installed
8
11
  - comment about what is used in the account and configure object
@@ -1,5 +1,5 @@
1
1
  module AzureInfo
2
- class Account < Base
2
+ class Account
3
3
  def get(name)
4
4
  az_account_show[name]
5
5
  end
@@ -3,20 +3,74 @@
3
3
  # az configure --defaults location=westus2 group=MyResourceGroup
4
4
  #
5
5
  module AzureInfo
6
- class Configure < Base
6
+ class Configure
7
7
  def get(name)
8
- item = az_configure_list_defaults.find do |i|
8
+ item = azure_configs.find do |i|
9
9
  i["name"] == name
10
10
  end
11
11
  item["value"] if item
12
12
  end
13
13
 
14
+ private
14
15
  # looks like az configure stores settings in ~/.azure/config
15
- def az_configure_list_defaults
16
- return @az_configure_list_defaults if @az_configure_list_defaults
17
- check_az_installed!
18
- out = `az configure --list-defaults --output json`.strip
19
- @az_configure_list_defaults = JSON.load(out)
16
+ def azure_configs
17
+ if az_installed?
18
+ return @azure_configs if @azure_configs
19
+ out = `az configure --list-defaults --output json`.strip
20
+ @azure_configs = JSON.load(out)
21
+ else
22
+ if env_vars_set?
23
+ []
24
+ else
25
+ error_message
26
+ end
27
+ end
28
+ end
29
+
30
+ def az_installed?
31
+ system("type az > /dev/null 2>&1")
32
+ end
33
+
34
+ def env_vars
35
+ %w[
36
+ ARM_CLIENT_ID
37
+ ARM_CLIENT_SECRET
38
+ ARM_LOCATION
39
+ ARM_SUBSCRIPTION_ID
40
+ ARM_TENANT_ID
41
+ ]
42
+ end
43
+
44
+ def env_vars_set?
45
+ env_vars.all? { |var| ENV[var] }
46
+ end
47
+
48
+ def error_message
49
+ all_vars = format_list(env_vars)
50
+ unset_vars = format_list(env_vars.reject { |var| ENV[var] })
51
+ message = <<~EOL
52
+ ERROR: az is not installed. Please install the az command and configure it.
53
+ AzureInfo uses it to detect azure resource group, location, subscription id, and tenant id.
54
+
55
+ You can also configure these environment variables instead of installing the az cli.
56
+
57
+ #{all_vars}
58
+
59
+ Currently, the unset vars are:
60
+
61
+ #{unset_vars}
62
+
63
+ EOL
64
+ if ENV['AZ_INFO_RAISE_ERROR']
65
+ raise Error.new(message)
66
+ else
67
+ puts message
68
+ exit 1
69
+ end
70
+ end
71
+
72
+ def format_list(vars)
73
+ vars.map { |var| " #{var}" }.join("\n")
20
74
  end
21
75
  end
22
76
  end
@@ -1,3 +1,3 @@
1
1
  module AzureInfo
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -29,7 +29,6 @@ files:
29
29
  - bin/setup
30
30
  - lib/azure_info.rb
31
31
  - lib/azure_info/account.rb
32
- - lib/azure_info/base.rb
33
32
  - lib/azure_info/configure.rb
34
33
  - lib/azure_info/version.rb
35
34
  homepage: https://github.com/boltops-tools/azure_info
@@ -1,26 +0,0 @@
1
- module AzureInfo
2
- class Base
3
- def check_az_installed!
4
- installed = system("type az > /dev/null 2>&1")
5
- return if installed
6
- message = <<~EOL
7
- ERROR: az is not installed. Please install the az command and configure it.
8
- AzureInfo uses it to detect azure resource group, location, subscription id, and tenant id.
9
-
10
- You can also configure these environment variables instead of installing the az cli.
11
-
12
- ARM_CLIENT_ID
13
- ARM_CLIENT_SECRET
14
- ARM_SUBSCRIPTION_ID
15
- ARM_TENANT_ID
16
-
17
- EOL
18
- if ENV['AZ_INFO_RAISE_ERROR']
19
- raise Error.new(message)
20
- else
21
- puts message
22
- exit 1
23
- end
24
- end
25
- end
26
- end