azure_info 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/azure_info/account.rb +1 -1
- data/lib/azure_info/configure.rb +61 -7
- data/lib/azure_info/version.rb +1 -1
- metadata +1 -2
- data/lib/azure_info/base.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4ae9c9490f68fe1f75f04f8c4ad05adb4c4c3ddbe4723563e33739723c13f64
|
4
|
+
data.tar.gz: f463b07527a94b6851fefa659e568a9d4d59c1d0496dd136e62067a8bdf8d4f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/azure_info/account.rb
CHANGED
data/lib/azure_info/configure.rb
CHANGED
@@ -3,20 +3,74 @@
|
|
3
3
|
# az configure --defaults location=westus2 group=MyResourceGroup
|
4
4
|
#
|
5
5
|
module AzureInfo
|
6
|
-
class Configure
|
6
|
+
class Configure
|
7
7
|
def get(name)
|
8
|
-
item =
|
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
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
data/lib/azure_info/version.rb
CHANGED
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.
|
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
|
data/lib/azure_info/base.rb
DELETED
@@ -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
|