azure-armrest 0.9.1 → 0.9.2

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
  SHA1:
3
- metadata.gz: '08bd3d2e3e8ede9dafb7b9851aae5db77bb0e770'
4
- data.tar.gz: 94e69ee9f9b4a9c843addd3e9965981ad97f8da7
3
+ metadata.gz: 2b445a2a57cca396bfb03a3f62393f4c0669f708
4
+ data.tar.gz: 9a4984a64e5db8057e7c018b8f9730134735dd6a
5
5
  SHA512:
6
- metadata.gz: 6af19fd0c290e2e21f690b4fc15b6d7549234a250ffed764daef8dafb41b6c35e8ab0444574b1a9ffebcef6500ada264dfad4d9cb402b40f038044c1d275cff8
7
- data.tar.gz: 1b86a6de9fd1845c36a32efae9424c709f7f05c1a69eaac728bd6950bdde68eedb35a2678883b792728a09bd77077f2c42a2ce1e5e09e8eb64b65c1ce71f0187
6
+ metadata.gz: aefd6f6a4936e5f93e6144f4dec4d841f6335dc65542c0ad00fdb881a3153ca9e2abd163b527633cc4a1eba09495b93917d97f6ecbbf23bd2f01a0c0a6373c0a
7
+ data.tar.gz: e7338c46f28895160763f8bc1df1b9c0118fa16830435c1fdd90f5d62bdb3bce01595a78e0aa292ea55f8a5887de8a0dfab7dd395ed3e2ba38d63b0f29372167
data/CHANGES CHANGED
@@ -1,3 +1,14 @@
1
+ = 0.9.2 - 31-Oct-2017
2
+ * Fixed a bug in the StorageAccountService#list_private_images method. It
3
+ now accepts an option to skip accessor definitions.
4
+ * Fixed a caller bug that caused tests to fail on Windows.
5
+ * Fixed a bug where an argument to a sleep call could be a string by mistake.
6
+ * Fixed issues with continuation results for list methods in the
7
+ StorageAccount model class.
8
+ * The json dependency restriction was loosened to 1.anything.
9
+ * The nokogiri dependency was removed. We now rely on Hash#from_xml courtesy
10
+ of activesupport, which we were already using.
11
+
1
12
  = 0.9.1 - 9-Oct-2017
2
13
  * Fixed an issue where hash properties that contain a '$' sign would fail
3
14
  when we attempted to convert them to model objects. They are now converted
@@ -17,12 +17,11 @@ different than the current azure gem, which uses the older (XML) interface
17
17
  behind the scenes.
18
18
  EOF
19
19
 
20
- spec.add_dependency 'json', '~> 2.0.1'
20
+ spec.add_dependency 'json', '~> 2'
21
21
  spec.add_dependency 'rest-client', '~> 2.0.0'
22
22
  spec.add_dependency 'memoist', '~> 0.15.0'
23
23
  spec.add_dependency 'azure-signature', '~> 0.2.3'
24
24
  spec.add_dependency 'activesupport', '>= 4.2.2'
25
- spec.add_dependency 'nokogiri', '>= 1.8.1', '~> 1.8'
26
25
  spec.add_dependency 'addressable', '~> 2.4.0'
27
26
  spec.add_dependency 'parallel', '~> 1.12.0'
28
27
 
@@ -216,7 +216,9 @@ module Azure
216
216
  if tries <= max_retries
217
217
  msg = "A rate limit or server side issue has occurred [#{err.http_code}]. Retry number #{tries}."
218
218
  Azure::Armrest::Configuration.log.try(:log, Logger::WARN, msg)
219
- sleep_time = err.response.headers[:retry_after] || 30
219
+ sleep_time = (err.response.headers[:retry_after] || 30).to_i
220
+ sleep_time = 5 if sleep_time < 5 # 5 second minimum
221
+ sleep_time = 120 if sleep_time > 120 # 2 minute maximum
220
222
  sleep(sleep_time)
221
223
  retry
222
224
  end
@@ -56,7 +56,9 @@ module Azure
56
56
  # #=> "123.123.123.123"
57
57
  #
58
58
  def self.attr_from_hash(attrs = {})
59
- file, line, _ = caller.first.split(":")
59
+ location = caller_locations(1, 1).first
60
+ file, line = location.path, location.lineno
61
+
60
62
  attrs.each do |attr_name, keys|
61
63
  keys = Array(keys)
62
64
  first_key = keys.shift
@@ -1,6 +1,5 @@
1
1
  require 'azure-signature'
2
2
  require 'active_support/core_ext/hash/conversions'
3
- require 'nokogiri'
4
3
 
5
4
  module Azure
6
5
  module Armrest
@@ -194,27 +193,43 @@ module Azure
194
193
  # * marker
195
194
  # * maxresults
196
195
  # * timeout
196
+ # * all
197
+ #
198
+ # If the :all option is set to true, then this method will collect all
199
+ # records. Otherwise, it is capped at 5000 records by Azure, or whatever
200
+ # you set :maxresults to. If you set both the :all option and the :maxresults
201
+ # option, then all records will be collected in :maxresults batches.
197
202
  #
198
203
  def files(share, key = access_key, options = {})
199
204
  raise ArgumentError, "No access key specified" unless key
200
205
 
201
- query = {:restype => 'directory', :comp => 'list'}.merge(options).to_query
206
+ query = "comp=list&restype=directory"
207
+
208
+ skip_defs = options[:skip_accessors_definition]
209
+
210
+ options.each do |okey, ovalue|
211
+ unless okey == :skip_accessors_definition
212
+ query += "&#{okey}=#{[ovalue].flatten.join(',')}"
213
+ end
214
+ end
202
215
 
203
216
  response = file_response(key, query, 'get', nil, share)
204
217
 
205
- doc = Nokogiri::XML(response.body)
218
+ hash = Hash.from_xml(response.body)['EnumerationResults']['Entries']
206
219
  results = []
207
220
 
208
- doc.xpath('//EnumerationResults/Entries').each do |element|
209
- element.xpath('//Directory').each do |dir|
210
- results << ShareDirectory.new(Hash.from_xml(dir.to_s)['Directory'])
211
- end
212
- element.xpath('//File').each do |file|
213
- results << ShareFile.new(Hash.from_xml(file.to_s)['File'])
214
- end
221
+ if hash && hash['Directory']
222
+ Array.wrap(hash['Directory']).each { |dir| results << ShareDirectory.new(dir, skip_defs) }
223
+ end
224
+
225
+ if hash && hash['File']
226
+ Array.wrap(hash['File']).each { |file| results << ShareFile.new(file, skip_defs) }
215
227
  end
216
228
 
217
- results.concat(next_marker_results(doc, :files, key, options))
229
+ if options[:all] && hash['NextMarker']
230
+ options[:marker] = hash['NextMarker']
231
+ results.concat(files(share, key, options))
232
+ end
218
233
 
219
234
  results
220
235
  end
@@ -407,6 +422,7 @@ module Azure
407
422
  # * maxresults
408
423
  # * include
409
424
  # * timeout
425
+ # * all
410
426
  #
411
427
  # By default Azure uses a value of 5000 for :maxresults.
412
428
  #
@@ -414,6 +430,11 @@ module Azure
414
430
  # one element: metadata. More options may be added by Microsoft
415
431
  # at a later date.
416
432
  #
433
+ # If the :all option is set to true, then this method will collect all
434
+ # records. Otherwise, it is capped at 5000 records by Azure, or whatever
435
+ # you set :maxresults to. If you set both the :all option and the :maxresults
436
+ # option, then all records will be collected in :maxresults batches.
437
+ #
417
438
  # Example:
418
439
  #
419
440
  # sas = Azure::Armrest::StorageAccountService.new(conf)
@@ -424,10 +445,6 @@ module Azure
424
445
  # p acct.containers(key, :include => ['metadata'])
425
446
  # p acct.containers(key, :maxresults => 1)
426
447
  #
427
- # In cases where a NextMarker element is found in the original response,
428
- # another call will automatically be made with the marker value included
429
- # in the URL so that you don't have to perform such a step manually.
430
- #
431
448
  def containers(key = access_key, options = {})
432
449
  raise ArgumentError, "No access key specified" unless key
433
450
 
@@ -442,13 +459,19 @@ module Azure
442
459
 
443
460
  response = blob_response(key, query)
444
461
 
445
- doc = Nokogiri::XML(response.body)
462
+ hash = Hash.from_xml(response.body)['EnumerationResults']['Containers']
463
+ results = []
464
+
465
+ if hash && hash['Container']
466
+ Array.wrap(hash['Container']).each { |c| results << Container.new(c, skip_defs) }
467
+ end
446
468
 
447
- results = doc.xpath('//Containers/Container').collect do |element|
448
- Container.new(Hash.from_xml(element.to_s)['Container'], skip_defs)
469
+ if options[:all] && hash['NextMarker']
470
+ options[:marker] = hash['NextMarker']
471
+ results.concat(containers(key, options))
449
472
  end
450
473
 
451
- results.concat(next_marker_results(doc, :containers, key, options))
474
+ results
452
475
  end
453
476
 
454
477
  # Returns the properties for the given container +name+ using account +key+.
@@ -555,6 +578,11 @@ module Azure
555
578
  # one or more of the following values: snapshots, metadata, copy or
556
579
  # uncommittedblobs.
557
580
  #
581
+ # If the :all option is set to true, then this method will collect all
582
+ # records. Otherwise, it is capped at 5000 records by Azure, or whatever
583
+ # you set :maxresults to. If you set both the :all option and the :maxresults
584
+ # option, then all records will be collected in :maxresults batches.
585
+ #
558
586
  # Example:
559
587
  #
560
588
  # sas = Azure::Armrest::StorageAccountService.new(conf)
@@ -565,10 +593,6 @@ module Azure
565
593
  # p acct.blobs('vhds', key, :timeout => 30)
566
594
  # p acct.blobs('vhds', key, :include => ['snapshots', 'metadata'])
567
595
  #
568
- # In cases where a NextMarker element is found in the original response,
569
- # another call will automatically be made with the marker value included
570
- # in the URL so that you don't have to perform such a step manually.
571
- #
572
596
  def blobs(container, key = access_key, options = {})
573
597
  raise ArgumentError, "No access key specified" unless key
574
598
 
@@ -583,14 +607,23 @@ module Azure
583
607
 
584
608
  response = blob_response(key, query, container)
585
609
 
586
- doc = Nokogiri::XML(response.body)
610
+ hash = Hash.from_xml(response.body)['EnumerationResults']['Blobs']
611
+ results = []
612
+
613
+ if hash && hash['Blob']
614
+ Array.wrap(hash['Blob']).each do |h|
615
+ h[:container] = container
616
+ object = h.key?('Snapshot') ? BlobSnapshot.new(h, skip_defs) : Blob.new(h, skip_defs)
617
+ results << object
618
+ end
619
+ end
587
620
 
588
- results = doc.xpath('//Blobs/Blob').collect do |node|
589
- hash = Hash.from_xml(node.to_s)['Blob'].merge(:container => container)
590
- hash.key?('Snapshot') ? BlobSnapshot.new(hash, skip_defs) : Blob.new(hash, skip_defs)
621
+ if options[:all] && hash['NextMarker']
622
+ options[:marker] = hash['NextMarker']
623
+ results.concat(blobs(container, key, options))
591
624
  end
592
625
 
593
- results.concat(next_marker_results(doc, :blobs, container, key, options))
626
+ results
594
627
  end
595
628
 
596
629
  # Returns an array of all blobs for all containers. The +options+ hash
@@ -625,10 +658,9 @@ module Azure
625
658
  raise ArgumentError, "No access key specified" unless key
626
659
 
627
660
  response = blob_response(key, "restype=service&comp=properties")
628
- toplevel = 'StorageServiceProperties'
661
+ hash = Hash.from_xml(response.body)['StorageServiceProperties']
629
662
 
630
- doc = Nokogiri::XML(response.body).xpath("//#{toplevel}")
631
- BlobServiceProperty.new(Hash.from_xml(doc.to_s)[toplevel])
663
+ BlobServiceProperty.new(hash)
632
664
  end
633
665
 
634
666
  # Return metadata for the given +blob+ within +container+. You may
@@ -653,10 +685,9 @@ module Azure
653
685
  raise ArgumentError, "No access key specified" unless key
654
686
 
655
687
  response = blob_response(key, "restype=service&comp=stats")
656
- toplevel = 'StorageServiceStats'
657
688
 
658
- doc = Nokogiri::XML(response.body).xpath("//#{toplevel}")
659
- BlobServiceStat.new(Hash.from_xml(doc.to_s)[toplevel])
689
+ hash = Hash.from_xml(response.body)['StorageServiceStats']
690
+ BlobServiceStat.new(hash)
660
691
  end
661
692
 
662
693
  # Copy the blob from the source container/blob to the destination container/blob.
@@ -1045,21 +1076,6 @@ module Azure
1045
1076
 
1046
1077
  headers
1047
1078
  end
1048
-
1049
- # Generic method to handle NextMarker token. The +doc+ should be an
1050
- # XML object that responds to .xpath, followed by a method name,
1051
- # followed by any arguments to pass to that method.
1052
- #
1053
- def next_marker_results(doc, method_name, *args)
1054
- xmarker = doc.xpath('//NextMarker').first # There is only one
1055
- if xmarker.children.empty?
1056
- return []
1057
- else
1058
- args = args.dup # Avoid modifying original argument
1059
- args.last[:marker] = xmarker.children.first.to_s
1060
- return send(method_name, *args)
1061
- end
1062
- end
1063
1079
  end
1064
1080
  end
1065
1081
  end
@@ -72,14 +72,14 @@ module Azure
72
72
  # Returns an ArmrestCollection, with the response headers set
73
73
  # for the operation as a whole.
74
74
  #
75
- def list(rgroup = configuration.resource_group)
75
+ def list(rgroup = configuration.resource_group, skip_accessors_definition = false)
76
76
  validate_resource_group(rgroup)
77
77
 
78
78
  url = build_url(rgroup)
79
79
  url = yield(url) || url if block_given?
80
80
  response = rest_get(url)
81
81
 
82
- get_all_results(response)
82
+ get_all_results(response, skip_accessors_definition)
83
83
  end
84
84
 
85
85
  # Use a single call to get all resources for the service. You may
@@ -18,7 +18,7 @@ module Azure
18
18
 
19
19
  # Same as other resource based list methods, but also sets the proxy on each model object.
20
20
  #
21
- def list(resource_group = configuration.resource_group)
21
+ def list(resource_group = configuration.resource_group, skip_accessors_definition = false)
22
22
  super.each { |model| model.configuration = configuration }
23
23
  end
24
24
 
@@ -1,6 +1,6 @@
1
1
  module Azure
2
2
  module Armrest
3
3
  # The version of the azure-armrest library.
4
- VERSION = '0.9.1'.freeze
4
+ VERSION = '0.9.2'.freeze
5
5
  end
6
6
  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.9.1
4
+ version: 0.9.2
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: 2017-10-09 00:00:00.000000000 Z
14
+ date: 2017-10-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - "~>"
21
21
  - !ruby/object:Gem::Version
22
- version: 2.0.1
22
+ version: '2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 2.0.1
29
+ version: '2'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rest-client
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -83,26 +83,6 @@ dependencies:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
85
  version: 4.2.2
86
- - !ruby/object:Gem::Dependency
87
- name: nokogiri
88
- requirement: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 1.8.1
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '1.8'
96
- type: :runtime
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: 1.8.1
103
- - - "~>"
104
- - !ruby/object:Gem::Version
105
- version: '1.8'
106
86
  - !ruby/object:Gem::Dependency
107
87
  name: addressable
108
88
  requirement: !ruby/object:Gem::Requirement
@@ -308,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
288
  version: '0'
309
289
  requirements: []
310
290
  rubyforge_project:
311
- rubygems_version: 2.6.12
291
+ rubygems_version: 2.6.14
312
292
  signing_key:
313
293
  specification_version: 4
314
294
  summary: An interface for ARM/JSON Azure REST API