azure-armrest 0.3.13 → 0.4.0
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/CHANGES +9 -0
- data/lib/azure/armrest.rb +1 -0
- data/lib/azure/armrest/armrest_service.rb +8 -14
- data/lib/azure/armrest/configuration.rb +42 -42
- data/lib/azure/armrest/subscription_service.rb +35 -0
- data/lib/azure/armrest/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27744a66e69a816479bb6dc1d7a2bb5070d42717
|
4
|
+
data.tar.gz: b1ded209d9ff4e9c8bde0981e55c5b95586a4511
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6aaa5ae7fd87a32a0727e0965e84ece73ae426159ce9f49c54c6cd90e23ddc6f4939df8eda1f45ee5a8543f0fce7399dd5870fbddf87f556aa38ea3ec93fe5d3
|
7
|
+
data.tar.gz: 8dc378aa589e06f5d45c387356d83f23ed489796bab3289c9443344514d3726d467b6085047c37260235bee908857280739f3efa9bae59f0e340d141cda7199b
|
data/CHANGES
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
= 0.4.0 - 8-Dec-2016
|
2
|
+
* The Configuration constructor no longer requires a subscription ID. However,
|
3
|
+
the presence of a subscription ID is still required for almost all Service
|
4
|
+
classes. The verification now happens later, within the Service constructor.
|
5
|
+
* Added the SubscriptionService class. This does not require a subscription ID
|
6
|
+
in advance, so you can get a list of subscriptions for a tenant.
|
7
|
+
* The Configuration#subscription_id= and Configuration#proxy= writer methods
|
8
|
+
now have custom implementations.
|
9
|
+
|
1
10
|
= 0.3.13 - 30-Nov-2016
|
2
11
|
* Fixed the Billing::Usage model class name.
|
3
12
|
* Updated the Billing::Usage#list method so that it returns an ArmrestCollection
|
data/lib/azure/armrest.rb
CHANGED
@@ -27,6 +27,7 @@ require 'azure/armrest/configuration'
|
|
27
27
|
require 'azure/armrest/exception'
|
28
28
|
require 'azure/armrest/armrest_collection'
|
29
29
|
require 'azure/armrest/armrest_service'
|
30
|
+
require 'azure/armrest/subscription_service'
|
30
31
|
require 'azure/armrest/resource_group_based_service'
|
31
32
|
require 'azure/armrest/resource_group_based_subservice'
|
32
33
|
require 'azure/armrest/storage_account_service'
|
@@ -41,6 +41,10 @@ module Azure
|
|
41
41
|
@service_name = service_name
|
42
42
|
@provider = options[:provider] || default_provider
|
43
43
|
|
44
|
+
if configuration.subscription_id.nil?
|
45
|
+
raise ArgumentError, 'subscription_id must be specified for this Service class'
|
46
|
+
end
|
47
|
+
|
44
48
|
# Base URL used for REST calls. Modify within method calls as needed.
|
45
49
|
@base_url = Azure::Armrest::RESOURCE
|
46
50
|
|
@@ -84,12 +88,9 @@ module Azure
|
|
84
88
|
list.collect { |rp| rp.resource_types.map(&:locations) }.flatten.uniq.sort
|
85
89
|
end
|
86
90
|
|
87
|
-
# Returns a list of
|
88
|
-
#
|
91
|
+
# Returns a list of subscriptions for the current tenant.
|
89
92
|
def list_subscriptions
|
90
|
-
|
91
|
-
response = rest_get(url)
|
92
|
-
JSON.parse(response.body)['value'].map { |hash| Azure::Armrest::Subscription.new(hash) }
|
93
|
+
Azure::Armrest::SubscriptionService.new(configuration).list
|
93
94
|
end
|
94
95
|
|
95
96
|
alias subscriptions list_subscriptions
|
@@ -100,15 +101,8 @@ module Azure
|
|
100
101
|
# specified.
|
101
102
|
#
|
102
103
|
def get_subscription(subscription_id = configuration.subscription_id)
|
103
|
-
|
104
|
-
|
105
|
-
@base_url,
|
106
|
-
'subscriptions',
|
107
|
-
subscription_id
|
108
|
-
)
|
109
|
-
|
110
|
-
response = rest_get(url)
|
111
|
-
Azure::Armrest::Subscription.new(response.body)
|
104
|
+
subs = Azure::Armrest::SubscriptionService.new(configuration)
|
105
|
+
subs.get(subscription_id)
|
112
106
|
end
|
113
107
|
|
114
108
|
alias subscription_info get_subscription
|
@@ -35,7 +35,7 @@ module Azure
|
|
35
35
|
attr_accessor :tenant_id
|
36
36
|
|
37
37
|
# The subscription ID used for each http request.
|
38
|
-
|
38
|
+
attr_reader :subscription_id
|
39
39
|
|
40
40
|
# The resource group used for http requests.
|
41
41
|
attr_accessor :resource_group
|
@@ -50,7 +50,7 @@ module Azure
|
|
50
50
|
attr_accessor :accept
|
51
51
|
|
52
52
|
# Proxy to be used for all http requests.
|
53
|
-
|
53
|
+
attr_reader :proxy
|
54
54
|
|
55
55
|
# SSL version to be used for all http requests.
|
56
56
|
attr_accessor :ssl_version
|
@@ -65,8 +65,8 @@ module Azure
|
|
65
65
|
attr_accessor :max_threads
|
66
66
|
|
67
67
|
# Yields a new Azure::Armrest::Configuration objects. Note that you must
|
68
|
-
# specify a client_id, client_key, tenant_id
|
69
|
-
# parameters are optional.
|
68
|
+
# specify a client_id, client_key, tenant_id. The subscription_id is optional
|
69
|
+
# but should be specified in most cases. All other parameters are optional.
|
70
70
|
#
|
71
71
|
# Example:
|
72
72
|
#
|
@@ -84,9 +84,8 @@ module Azure
|
|
84
84
|
# Although you can specify an :api_version, it is typically overridden
|
85
85
|
# by individual service classes.
|
86
86
|
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
# validate your subscription ID as well, use the validate_subscription! method.
|
87
|
+
# The constructor will also validate that the subscription ID is valid
|
88
|
+
# if present.
|
90
89
|
#
|
91
90
|
def initialize(args)
|
92
91
|
# Use defaults, and override with provided arguments
|
@@ -106,31 +105,46 @@ module Azure
|
|
106
105
|
user_token = options.delete(:token)
|
107
106
|
user_token_expiration = options.delete(:token_expiration)
|
108
107
|
|
109
|
-
|
108
|
+
# We need to ensure these are set before subscription_id=
|
109
|
+
@tenant_id = options.delete(:tenant_id)
|
110
|
+
@client_id = options.delete(:client_id)
|
111
|
+
@client_key = options.delete(:client_key)
|
110
112
|
|
111
|
-
unless client_id && client_key && tenant_id
|
112
|
-
raise ArgumentError, "client_id, client_key,
|
113
|
+
unless client_id && client_key && tenant_id
|
114
|
+
raise ArgumentError, "client_id, client_key, and tenant_id must all be specified"
|
113
115
|
end
|
114
116
|
|
115
|
-
#
|
116
|
-
|
117
|
-
|
118
|
-
validate_subscription
|
117
|
+
# Then set the remaining options automatically
|
118
|
+
options.each { |key, value| send("#{key}=", value) }
|
119
119
|
|
120
120
|
if user_token && user_token_expiration
|
121
121
|
set_token(user_token, user_token_expiration)
|
122
122
|
elsif user_token || user_token_expiration
|
123
123
|
raise ArgumentError, "token and token_expiration must be both specified"
|
124
124
|
end
|
125
|
-
|
126
|
-
@providers = fetch_providers
|
127
|
-
set_provider_api_versions
|
128
125
|
end
|
129
126
|
|
130
127
|
def hash
|
131
128
|
[tenant_id, client_id, client_key].join('_').hash
|
132
129
|
end
|
133
130
|
|
131
|
+
# Allow for strings or URI objects when assigning a proxy.
|
132
|
+
#
|
133
|
+
def proxy=(value)
|
134
|
+
@proxy = value ? value.to_s : value
|
135
|
+
end
|
136
|
+
|
137
|
+
# Set the subscription ID, and validate the value. This also sets
|
138
|
+
# provider information.
|
139
|
+
#
|
140
|
+
def subscription_id=(value)
|
141
|
+
@subscription_id = value
|
142
|
+
validate_subscription
|
143
|
+
@providers = fetch_providers
|
144
|
+
set_provider_api_versions
|
145
|
+
value
|
146
|
+
end
|
147
|
+
|
134
148
|
def eql?(other)
|
135
149
|
return true if equal?(other)
|
136
150
|
return false unless self.class == other.class
|
@@ -186,9 +200,16 @@ module Azure
|
|
186
200
|
RestClient.log = output
|
187
201
|
end
|
188
202
|
|
203
|
+
# Returns a list of subscriptions for the current configuration object.
|
204
|
+
#
|
205
|
+
def subscriptions
|
206
|
+
Azure::Armrest::SubscriptionService.new(self).list
|
207
|
+
end
|
208
|
+
|
189
209
|
private
|
190
210
|
|
191
|
-
# Validate the subscription ID for the given credentials.
|
211
|
+
# Validate the subscription ID for the given credentials. Returns the
|
212
|
+
# subscription ID if valid.
|
192
213
|
#
|
193
214
|
# If the subscription ID that was provided in the constructor cannot
|
194
215
|
# be found within the list of valid subscriptions, then an error is
|
@@ -198,36 +219,15 @@ module Azure
|
|
198
219
|
# then a warning will be issued, but no error will be raised.
|
199
220
|
#
|
200
221
|
def validate_subscription
|
201
|
-
|
202
|
-
|
203
|
-
options = {
|
204
|
-
:url => url,
|
205
|
-
:proxy => proxy,
|
206
|
-
:ssl_version => ssl_version,
|
207
|
-
:ssl_verify => ssl_verify,
|
208
|
-
:headers => {
|
209
|
-
:accept => accept,
|
210
|
-
:content_type => content_type,
|
211
|
-
:authorization => token
|
212
|
-
}
|
213
|
-
}
|
214
|
-
|
215
|
-
response = Azure::Armrest::ArmrestService.send(:rest_get, options)
|
216
|
-
json = JSON.parse(response.body)['value']
|
217
|
-
|
218
|
-
subscriptions = json.map { |hash| [hash['subscriptionId'], hash['state']] }
|
219
|
-
|
220
|
-
found = subscriptions.find { |array| array.first == subscription_id }
|
222
|
+
found = subscriptions.find { |sub| sub.subscription_id == subscription_id }
|
221
223
|
|
222
224
|
unless found
|
223
225
|
raise ArgumentError, "Subscription ID '#{subscription_id}' not found"
|
224
226
|
end
|
225
227
|
|
226
|
-
if found.
|
227
|
-
warn "Subscription '#{found.
|
228
|
+
if found.state.casecmp('enabled') != 0
|
229
|
+
warn "Subscription '#{found.subscription_id}' found but not enabled."
|
228
230
|
end
|
229
|
-
|
230
|
-
true
|
231
231
|
end
|
232
232
|
|
233
233
|
def ensure_token
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Azure
|
2
|
+
module Armrest
|
3
|
+
class SubscriptionService < ArmrestService
|
4
|
+
# This overrides the typical constructor for an ArmrestService subclass
|
5
|
+
# because it does not have a service name or a provider.
|
6
|
+
def initialize(configuration, options = {})
|
7
|
+
@armrest_configuration = configuration
|
8
|
+
@api_version = options[:api_version] || '2016-06-01'
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a list of Subscription objects for the current tenant, one for
|
12
|
+
# each subscription ID.
|
13
|
+
#
|
14
|
+
def list
|
15
|
+
url = subscriptions_url + "?api-version=#{api_version}"
|
16
|
+
response = rest_get(url)
|
17
|
+
Azure::Armrest::ArmrestCollection.create_from_response(response, Azure::Armrest::Subscription)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns a Subscription object for the given +subscription_id+.
|
21
|
+
#
|
22
|
+
def get(subscription_id)
|
23
|
+
url = File.join(subscriptions_url, subscription_id) + "?api-version=#{api_version}"
|
24
|
+
response = rest_get(url)
|
25
|
+
Azure::Armrest::Subscription.new(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def subscriptions_url
|
31
|
+
File.join(Azure::Armrest::RESOURCE, 'subscriptions')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azure-armrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-12-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: json
|
@@ -265,6 +265,7 @@ files:
|
|
265
265
|
- lib/azure/armrest/sql/sql_database_service.rb
|
266
266
|
- lib/azure/armrest/sql/sql_server_service.rb
|
267
267
|
- lib/azure/armrest/storage_account_service.rb
|
268
|
+
- lib/azure/armrest/subscription_service.rb
|
268
269
|
- lib/azure/armrest/template_deployment_service.rb
|
269
270
|
- lib/azure/armrest/version.rb
|
270
271
|
- lib/azure/armrest/virtual_machine_extension_service.rb
|
@@ -290,7 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
290
291
|
version: '0'
|
291
292
|
requirements: []
|
292
293
|
rubyforge_project:
|
293
|
-
rubygems_version: 2.6.
|
294
|
+
rubygems_version: 2.6.8
|
294
295
|
signing_key:
|
295
296
|
specification_version: 4
|
296
297
|
summary: An interface for ARM/JSON Azure REST API
|