azure-armrest 0.2.5 → 0.2.6
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 +11 -0
- data/lib/azure/armrest/armrest_service.rb +30 -5
- data/lib/azure/armrest/model/base_model.rb +7 -0
- data/lib/azure/armrest/storage_account_service.rb +86 -13
- data/lib/azure/armrest/template_deployment_service.rb +0 -2
- data/lib/azure/armrest/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bc812c499cfa7408aec0074256c17473d845988
|
4
|
+
data.tar.gz: d54a716667c8d7c50f28275d6652cf3c61998305
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc3934aab613328f0c07f3dfa0851b4e8c4ba2b86f10cc282171557dce558d4f9931359e7eb9214b07c8fc414885b985afea68249e004b660aeab133dfc3325b
|
7
|
+
data.tar.gz: eb767973f551518150186ed4ba42e38f4e6a752ed80f69319c0060e61a28f5e3834c029e1b93b5ee0bda7bd2f09db3d1f4c0ac6c5dbfd3842d76f1f976def50a
|
data/CHANGES
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
= 0.2.6 - 9-May-2016
|
2
|
+
* If no subscription is provided, the internal method for fetching a default
|
3
|
+
subscription ID will now skip over tenant/subscription mismatches.
|
4
|
+
* Removed the hard-coded api-version string for both TemplateDeploymentService
|
5
|
+
and StorageAccountService.
|
6
|
+
* Because there was an underlying REST API change for storage account keys for
|
7
|
+
api-version strings set at 2016-01-01 or later, the list_account_key_objects
|
8
|
+
and regenerate_account_key_objects methods were added. These return model
|
9
|
+
objects instead of plain hashes. The list_account_keys and regenerate_account_keys
|
10
|
+
methods still behave as before.
|
11
|
+
|
1
12
|
= 0.2.5 - 11-Apr-2016
|
2
13
|
* Fixed a bug in the custom exception handler where the error code and
|
3
14
|
message were not set properly.
|
@@ -171,25 +171,49 @@ module Azure
|
|
171
171
|
|
172
172
|
url = File.join(Azure::Armrest::RESOURCE, "subscriptions?api-version=#{config.api_version}")
|
173
173
|
|
174
|
-
|
174
|
+
options = {
|
175
175
|
:url => url,
|
176
176
|
:proxy => config.proxy,
|
177
177
|
:ssl_version => config.ssl_version,
|
178
178
|
:ssl_verify => config.ssl_verify,
|
179
|
-
:headers
|
179
|
+
:headers => {
|
180
180
|
:content_type => config.content_type,
|
181
181
|
:authorization => config.token
|
182
182
|
}
|
183
|
-
|
183
|
+
}
|
184
184
|
|
185
|
-
|
185
|
+
response = rest_get(options)
|
186
|
+
array = JSON.parse(response)['value']
|
186
187
|
|
187
188
|
if array.nil? || array.empty?
|
188
189
|
raise ArgumentError, "No associated subscription found"
|
189
190
|
end
|
190
191
|
|
192
|
+
results = []
|
193
|
+
|
194
|
+
# Skip over any invalid subscriptions
|
195
|
+
array.each do |sub_hash|
|
196
|
+
sub_id = sub_hash['subscriptionId']
|
197
|
+
|
198
|
+
# Use tagNames as a test URL
|
199
|
+
test_url = File.join(
|
200
|
+
Azure::Armrest::RESOURCE, 'subscriptions', sub_id,
|
201
|
+
"tagNames?api-version=#{config.api_version}"
|
202
|
+
)
|
203
|
+
|
204
|
+
begin
|
205
|
+
options[:url] = test_url
|
206
|
+
rest_get(options)
|
207
|
+
rescue Azure::Armrest::UnauthorizedException, Azure::Armrest::BadRequestException
|
208
|
+
next
|
209
|
+
else
|
210
|
+
results << sub_hash
|
211
|
+
break if sub_hash['state'] == 'Enabled'
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
191
215
|
# Look for the first enabled subscription, otherwise just take the first subscription found.
|
192
|
-
hash =
|
216
|
+
hash = results.find { |h| h['state'] == 'Enabled' } || results.first
|
193
217
|
|
194
218
|
id = hash.fetch('subscriptionId')
|
195
219
|
|
@@ -412,6 +436,7 @@ module Azure
|
|
412
436
|
|
413
437
|
raise exception_type.new(code, message, e)
|
414
438
|
end
|
439
|
+
|
415
440
|
private_class_method :raise_api_exception
|
416
441
|
|
417
442
|
private
|
@@ -173,7 +173,14 @@ module Azure
|
|
173
173
|
class ResourceGroup < BaseModel; end
|
174
174
|
class ResourceProvider < BaseModel; end
|
175
175
|
class Sku < BaseModel; end
|
176
|
+
|
176
177
|
class StorageAccount < BaseModel; end
|
178
|
+
class StorageAccountKey < StorageAccount
|
179
|
+
def key1; key_name == 'key1' ? value : nil; end
|
180
|
+
def key2; key_name == 'key2' ? value : nil; end
|
181
|
+
def key; key1 || key2; end
|
182
|
+
end
|
183
|
+
|
177
184
|
class Subscription < BaseModel; end
|
178
185
|
class Tag < BaseModel; end
|
179
186
|
class TemplateDeployment < BaseModel
|
@@ -16,7 +16,6 @@ module Azure
|
|
16
16
|
# Creates and returns a new StorageAccountService (SAS) instance.
|
17
17
|
#
|
18
18
|
def initialize(configuration, options = {})
|
19
|
-
options = {'api_version' => '2015-05-01-preview'}.merge(options) # Must hard code for now
|
20
19
|
super(configuration, 'storageAccounts', 'Microsoft.Storage', options)
|
21
20
|
end
|
22
21
|
|
@@ -108,33 +107,85 @@ module Azure
|
|
108
107
|
acct
|
109
108
|
end
|
110
109
|
|
111
|
-
# Returns the primary and secondary access keys for the given
|
112
|
-
#
|
110
|
+
# Returns the primary and secondary access keys for the given storage
|
111
|
+
# account. This method will return a hash with 'key1' and 'key2' as its
|
112
|
+
# keys.
|
113
|
+
#
|
114
|
+
# If you want a list of StorageAccountKey objects, then use the
|
115
|
+
# list_account_key_objects method instead.
|
113
116
|
#
|
114
117
|
def list_account_keys(account_name, group = configuration.resource_group)
|
115
118
|
validate_resource_group(group)
|
116
119
|
|
117
120
|
url = build_url(group, account_name, 'listKeys')
|
118
121
|
response = rest_post(url)
|
119
|
-
JSON.parse(response)
|
122
|
+
hash = JSON.parse(response.body)
|
123
|
+
|
124
|
+
parse_account_keys_from_hash(hash)
|
125
|
+
end
|
126
|
+
|
127
|
+
alias list_storage_account_keys list_account_keys
|
128
|
+
|
129
|
+
# Returns a list of StorageAccountKey objects consisting of information
|
130
|
+
# the primary and secondary keys. This method requires an api-version
|
131
|
+
# string of 2016-01-01 or later, or an error is raised.
|
132
|
+
#
|
133
|
+
# If you want a plain hash, use the list_account_keys method instead.
|
134
|
+
#
|
135
|
+
def list_account_key_objects(account_name, group = configuration.resource_group)
|
136
|
+
validate_resource_group(group)
|
137
|
+
|
138
|
+
unless recent_api_version?
|
139
|
+
raise ArgumentError, "unsupported api-version string '#{api_version}'"
|
140
|
+
end
|
141
|
+
|
142
|
+
url = build_url(group, account_name, 'listKeys')
|
143
|
+
response = rest_post(url)
|
144
|
+
JSON.parse(response.body)['keys'].map { |hash| StorageAccountKey.new(hash) }
|
145
|
+
end
|
146
|
+
|
147
|
+
alias list_storage_account_key_objects list_account_key_objects
|
148
|
+
|
149
|
+
# Regenerates the primary or secondary access keys for the given storage
|
150
|
+
# account. The +key_name+ may be either 'key1' or 'key2'. If no key name
|
151
|
+
# is provided, then it defaults to 'key1'.
|
152
|
+
#
|
153
|
+
def regenerate_account_keys(account_name, group = configuration.resource_group, key_name = 'key1')
|
154
|
+
validate_resource_group(group)
|
155
|
+
|
156
|
+
options = {'keyName' => key_name}
|
157
|
+
|
158
|
+
url = build_url(group, account_name, 'regenerateKey')
|
159
|
+
response = rest_post(url, options.to_json)
|
160
|
+
hash = JSON.parse(response.body)
|
161
|
+
|
162
|
+
parse_account_keys_from_hash(hash)
|
120
163
|
end
|
121
164
|
|
122
|
-
|
123
|
-
|
165
|
+
alias regenerate_storage_account_keys regenerate_account_keys
|
166
|
+
|
167
|
+
# Same as regenerate_account_keys, but returns an array of
|
168
|
+
# StorageAccountKey objects instead.
|
124
169
|
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
# "keyName": "key1|key2"
|
128
|
-
# }
|
170
|
+
# This method requires an api-version string of 2016-01-01 or later
|
171
|
+
# or an ArgumentError is raised.
|
129
172
|
#
|
130
|
-
def
|
173
|
+
def regenerate_account_key_objects(account_name, group = configuration.resource_group, key_name = 'key1')
|
131
174
|
validate_resource_group(group)
|
132
175
|
|
176
|
+
unless recent_api_version?
|
177
|
+
raise ArgumentError, "unsupported api-version string '#{api_version}'"
|
178
|
+
end
|
179
|
+
|
180
|
+
options = {'keyName' => key_name}
|
181
|
+
|
133
182
|
url = build_url(group, account_name, 'regenerateKey')
|
134
183
|
response = rest_post(url, options.to_json)
|
135
|
-
JSON.parse(response)
|
184
|
+
JSON.parse(response.body)['keys'].map { |hash| StorageAccountKey.new(hash) }
|
136
185
|
end
|
137
186
|
|
187
|
+
alias regenerate_storage_account_key_objects regenerate_account_key_objects
|
188
|
+
|
138
189
|
# Returns a list of images that are available for provisioning for all
|
139
190
|
# storage accounts in the provided resource group. The custom keys
|
140
191
|
# :uri and :operating_system have been added for convenience.
|
@@ -146,7 +197,11 @@ module Azure
|
|
146
197
|
|
147
198
|
list(group).each do |lstorage_account|
|
148
199
|
threads << Thread.new(lstorage_account) do |storage_account|
|
149
|
-
|
200
|
+
if recent_api_version?
|
201
|
+
key = list_account_key_objects(storage_account.name, group).first.key
|
202
|
+
else
|
203
|
+
key = list_account_keys(storage_account.name, group).fetch('key1')
|
204
|
+
end
|
150
205
|
|
151
206
|
storage_account.all_blobs(key).each do |blob|
|
152
207
|
next unless File.extname(blob.name).downcase == '.vhd'
|
@@ -212,6 +267,24 @@ module Azure
|
|
212
267
|
|
213
268
|
private
|
214
269
|
|
270
|
+
# Check to see if the api-version string is 2016-01-01 or later.
|
271
|
+
def recent_api_version?
|
272
|
+
Time.parse(api_version).utc >= Time.parse('2016-01-01').utc
|
273
|
+
end
|
274
|
+
|
275
|
+
# As of api-version 2016-01-01, the format returned for listing and
|
276
|
+
# regenerating hash keys has changed.
|
277
|
+
#
|
278
|
+
def parse_account_keys_from_hash(hash)
|
279
|
+
if recent_api_version?
|
280
|
+
key1 = hash['keys'].find { |h| h['keyName'] == 'key1' }['value']
|
281
|
+
key2 = hash['keys'].find { |h| h['keyName'] == 'key2' }['value']
|
282
|
+
hash = {'key1' => key1, 'key2' => key2}
|
283
|
+
end
|
284
|
+
|
285
|
+
hash
|
286
|
+
end
|
287
|
+
|
215
288
|
def validate_account_type(account_type)
|
216
289
|
unless VALID_ACCOUNT_TYPES.include?(account_type)
|
217
290
|
raise ArgumentError, "invalid account type '#{account_type}'"
|
@@ -4,8 +4,6 @@ module Azure
|
|
4
4
|
class TemplateDeploymentService < ResourceGroupBasedService
|
5
5
|
|
6
6
|
def initialize(configuration, options = {})
|
7
|
-
# Has to be hard coded for now
|
8
|
-
options = {'api_version' => '2014-04-01-preview'}.merge(options)
|
9
7
|
super(configuration, 'deployments', 'Microsoft.Resources', options)
|
10
8
|
end
|
11
9
|
|
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.2.
|
4
|
+
version: 0.2.6
|
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-05-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: json
|
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
241
|
version: '0'
|
242
242
|
requirements: []
|
243
243
|
rubyforge_project:
|
244
|
-
rubygems_version: 2.
|
244
|
+
rubygems_version: 2.6.4
|
245
245
|
signing_key:
|
246
246
|
specification_version: 4
|
247
247
|
summary: An interface for ARM/JSON Azure REST API
|