azure 0.7.0.pre → 0.7.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env_sample +3 -1
- data/.gitignore +15 -0
- data/LICENSE.txt +1 -1
- data/README.md +322 -248
- data/Rakefile +3 -1
- data/azure.gemspec +18 -14
- data/lib/azure.rb +124 -38
- data/lib/azure/base_management/base_management_service.rb +57 -69
- data/lib/azure/base_management/location.rb +1 -1
- data/lib/azure/base_management/management_http_request.rb +55 -58
- data/lib/azure/base_management/serialization.rb +5 -0
- data/lib/azure/base_management/sql_management_http_request.rb +10 -20
- data/lib/azure/blob/auth/shared_access_signature.rb +82 -76
- data/lib/azure/blob/blob_service.rb +196 -171
- data/lib/azure/client.rb +31 -0
- data/lib/azure/client_services.rb +98 -0
- data/lib/azure/cloud_service_management/cloud_service_management_service.rb +8 -10
- data/lib/azure/configurable.rb +290 -0
- data/lib/azure/core/auth/authorizer.rb +1 -1
- data/lib/azure/core/auth/shared_key.rb +48 -40
- data/lib/azure/core/auth/shared_key_lite.rb +9 -9
- data/lib/azure/core/auth/signer.rb +15 -12
- data/lib/azure/core/error.rb +2 -3
- data/lib/azure/core/filtered_service.rb +4 -3
- data/lib/azure/core/http/http_error.rb +10 -12
- data/lib/azure/core/http/http_request.rb +82 -69
- data/lib/azure/core/http/http_response.rb +12 -56
- data/lib/azure/core/http/signer_filter.rb +3 -4
- data/lib/azure/core/service.rb +8 -25
- data/lib/azure/core/signed_service.rb +7 -5
- data/lib/azure/core/utility.rb +45 -6
- data/lib/azure/default.rb +126 -0
- data/lib/azure/http_client.rb +85 -0
- data/lib/azure/queue/queue.rb +0 -1
- data/lib/azure/queue/queue_service.rb +6 -4
- data/lib/azure/queue/serialization.rb +0 -1
- data/lib/azure/service/storage_service.rb +9 -6
- data/lib/azure/service_bus/auth/shared_access_signer.rb +44 -0
- data/lib/azure/service_bus/auth/wrap_service.rb +5 -4
- data/lib/azure/service_bus/auth/wrap_signer.rb +14 -6
- data/lib/azure/service_bus/service_bus_service.rb +34 -30
- data/lib/azure/sql_database_management/errors.rb +11 -0
- data/lib/azure/sql_database_management/firewall_rule.rb +30 -0
- data/lib/azure/sql_database_management/serialization.rb +40 -53
- data/lib/azure/sql_database_management/sql_database_management_service.rb +141 -130
- data/lib/azure/sql_database_management/{sql_database.rb → sql_server.rb} +4 -3
- data/lib/azure/storage_management/storage_management_service.rb +9 -10
- data/lib/azure/table/auth/shared_key.rb +17 -50
- data/lib/azure/table/auth/shared_key_lite.rb +3 -3
- data/lib/azure/table/serialization.rb +24 -24
- data/lib/azure/table/table_service.rb +21 -18
- data/lib/azure/version.rb +1 -1
- data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +6 -12
- data/lib/azure/virtual_machine_management/serialization.rb +4 -1
- data/lib/azure/virtual_machine_management/virtual_machine.rb +1 -0
- data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +29 -37
- data/lib/azure/virtual_network_management/virtual_network_management_service.rb +5 -6
- data/test/fixtures/list_locations.xml +150 -0
- data/test/fixtures/list_sql_database.xml +6 -18
- data/test/fixtures/list_sql_server_firewall.xml +18 -18
- data/test/fixtures/management_certificate.pfx +0 -0
- data/test/fixtures/virtual_machine.xml +1 -0
- data/test/integration/affinity_group/Create_Affinity_test.rb +1 -1
- data/test/integration/affinity_group/Update_Affinity_test.rb +4 -0
- data/test/integration/blob/blob_gb18030_test.rb +29 -29
- data/test/integration/blob/blob_pages_test.rb +16 -16
- data/test/integration/blob/container/create_container_test.rb +6 -6
- data/test/integration/blob/container/root_container_test.rb +2 -1
- data/test/integration/database/create_sql_server_firewall_test.rb +26 -31
- data/test/integration/database/create_sql_server_test.rb +6 -6
- data/test/integration/database/delete_sql_server_firewall_test.rb +18 -24
- data/test/integration/database/delete_sql_server_test.rb +9 -22
- data/test/integration/database/list_sql_server_firewall_test.rb +7 -8
- data/test/integration/database/list_sql_servers_test.rb +4 -4
- data/test/integration/database/reset_password_sql_server_test.rb +9 -11
- data/test/integration/location/RoleSize_List_test.rb +35 -0
- data/test/integration/queue/list_queues_test.rb +0 -1
- data/test/integration/service_bus/queues_scenario_test.rb +11 -11
- data/test/integration/service_bus/queues_test.rb +2 -2
- data/test/integration/service_bus/subscriptions_test.rb +25 -25
- data/test/integration/service_bus/topics_scenario_test.rb +6 -6
- data/test/integration/service_bus/topics_test.rb +15 -15
- data/test/integration/table/query_entities_test.rb +1 -0
- data/test/integration/table/table_acl_test.rb +9 -9
- data/test/integration/test_helper.rb +11 -9
- data/test/integration/vm/VM_Create_test.rb +23 -20
- data/test/integration/vnet/Virtual_Network_list_test.rb +1 -1
- data/test/test_helper.rb +5 -0
- data/test/unit/affinity_group/affinity_group_test.rb +4 -4
- data/test/unit/base_management/base_management_service_test.rb +19 -0
- data/test/unit/base_management/location_test.rb +6 -6
- data/test/unit/base_management/role_size_test.rb +50 -0
- data/test/unit/blob/auth/shared_access_signature_test.rb +19 -19
- data/test/unit/blob/blob_service_test.rb +583 -582
- data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +2 -2
- data/test/unit/config/azure_test.rb +112 -0
- data/test/unit/config/client_test.rb +37 -0
- data/test/unit/core/auth/shared_key_lite_test.rb +15 -15
- data/test/unit/core/auth/shared_key_test.rb +26 -26
- data/test/unit/core/http/http_error_test.rb +13 -14
- data/test/unit/core/http/http_request_test.rb +78 -53
- data/test/unit/core/http/http_response_test.rb +2 -27
- data/test/unit/core/http/retry_policy_test.rb +3 -3
- data/test/unit/core/utility_test.rb +122 -0
- data/test/unit/database/serialization_test.rb +17 -20
- data/test/unit/database/sql_database_server_service_test.rb +97 -40
- data/test/unit/http_client_test.rb +74 -0
- data/test/unit/service/storage_service_test.rb +105 -101
- data/test/unit/storage_management/storage_management_service_test.rb +28 -28
- data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +4 -4
- data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +37 -20
- data/test/unit/vnet/virtual_network_management_service_test.rb +1 -1
- metadata +91 -20
- data/lib/azure/core.rb +0 -41
- data/lib/azure/core/configuration.rb +0 -218
@@ -21,9 +21,12 @@ module Azure
|
|
21
21
|
module Blob
|
22
22
|
class BlobService < Service::StorageService
|
23
23
|
|
24
|
-
def initialize
|
25
|
-
|
26
|
-
|
24
|
+
def initialize(options = {})
|
25
|
+
client_config = options[:client] || Azure
|
26
|
+
signer = options[:signer] || Azure::Core::Auth::SharedKey.new(client_config.storage_account_name,
|
27
|
+
client_config.storage_access_key)
|
28
|
+
super(signer, client_config.storage_account_name, options)
|
29
|
+
@host = client.storage_blob_host
|
27
30
|
end
|
28
31
|
|
29
32
|
# Public: Get a list of Containers from the server
|
@@ -71,11 +74,11 @@ module Azure
|
|
71
74
|
def list_containers(options={})
|
72
75
|
query = { }
|
73
76
|
if options
|
74
|
-
query[
|
75
|
-
query[
|
76
|
-
query[
|
77
|
-
query[
|
78
|
-
query[
|
77
|
+
query['prefix'] = options[:prefix] if options[:prefix]
|
78
|
+
query['marker'] = options[:marker] if options[:marker]
|
79
|
+
query['maxresults'] = options[:max_results].to_s if options[:max_results]
|
80
|
+
query['include'] = 'metadata' if options[:metadata] == true
|
81
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
79
82
|
end
|
80
83
|
|
81
84
|
uri = containers_uri(query)
|
@@ -103,7 +106,7 @@ module Azure
|
|
103
106
|
# Returns a Container
|
104
107
|
def create_container(name, options={})
|
105
108
|
query = { }
|
106
|
-
query[
|
109
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
107
110
|
|
108
111
|
uri = container_uri(name, query)
|
109
112
|
|
@@ -111,7 +114,7 @@ module Azure
|
|
111
114
|
|
112
115
|
add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
|
113
116
|
|
114
|
-
headers[
|
117
|
+
headers['x-ms-blob-public-access'] = options[:public_access_level].to_s if options[:public_access_level]
|
115
118
|
|
116
119
|
response = call(:put, uri, nil, headers)
|
117
120
|
|
@@ -138,7 +141,7 @@ module Azure
|
|
138
141
|
# Returns nil on success
|
139
142
|
def delete_container(name, options={})
|
140
143
|
query = { }
|
141
|
-
query[
|
144
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
142
145
|
|
143
146
|
call(:delete, container_uri(name, query))
|
144
147
|
nil
|
@@ -161,7 +164,7 @@ module Azure
|
|
161
164
|
# Returns a Container
|
162
165
|
def get_container_properties(name, options={})
|
163
166
|
query = { }
|
164
|
-
query[
|
167
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
165
168
|
|
166
169
|
response = call(:get, container_uri(name, query))
|
167
170
|
|
@@ -186,8 +189,8 @@ module Azure
|
|
186
189
|
#
|
187
190
|
# Returns a Container
|
188
191
|
def get_container_metadata(name, options={})
|
189
|
-
query = {
|
190
|
-
query[
|
192
|
+
query = { 'comp' => 'metadata'}
|
193
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
191
194
|
|
192
195
|
response = call(:get, container_uri(name, query))
|
193
196
|
|
@@ -216,8 +219,8 @@ module Azure
|
|
216
219
|
# signed_identifiers - A list of Azure::Entity::SignedIdentifier instances
|
217
220
|
#
|
218
221
|
def get_container_acl(name, options={})
|
219
|
-
query = {
|
220
|
-
query[
|
222
|
+
query = { 'comp' => 'acl'}
|
223
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
221
224
|
response = call(:get, container_uri(name, query))
|
222
225
|
|
223
226
|
container = Serialization.container_from_headers(response.headers)
|
@@ -250,12 +253,12 @@ module Azure
|
|
250
253
|
# * +signed_identifiers+ - A list of Azure::Entity::SignedIdentifier instances
|
251
254
|
#
|
252
255
|
def set_container_acl(name, public_access_level, options={})
|
253
|
-
query = {
|
254
|
-
query[
|
256
|
+
query = { 'comp' => 'acl'}
|
257
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
255
258
|
uri =container_uri(name, query)
|
256
259
|
|
257
260
|
headers = service_properties_headers
|
258
|
-
headers[
|
261
|
+
headers['x-ms-blob-public-access'] = public_access_level if public_access_level && public_access_level.to_s.length > 0
|
259
262
|
|
260
263
|
signed_identifiers = nil
|
261
264
|
signed_identifiers = options[:signed_identifiers] if options[:signed_identifiers]
|
@@ -290,8 +293,8 @@ module Azure
|
|
290
293
|
#
|
291
294
|
# Returns nil on success
|
292
295
|
def set_container_metadata(name, metadata, options={})
|
293
|
-
query = {
|
294
|
-
query[
|
296
|
+
query = { 'comp' => 'metadata'}
|
297
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
295
298
|
|
296
299
|
headers = service_properties_headers
|
297
300
|
add_metadata_to_headers(metadata, headers) if metadata
|
@@ -354,20 +357,20 @@ module Azure
|
|
354
357
|
#
|
355
358
|
# Returns an Azure::Service::EnumerationResults
|
356
359
|
def list_blobs(name, options={})
|
357
|
-
query = {
|
358
|
-
query[
|
359
|
-
query[
|
360
|
-
query[
|
361
|
-
query[
|
362
|
-
query[
|
360
|
+
query = { 'comp' => 'list'}
|
361
|
+
query['prefix'] = options[:prefix].gsub(/\\/, '/') if options[:prefix]
|
362
|
+
query['delimiter'] = options[:delimiter] if options[:delimiter]
|
363
|
+
query['marker'] = options[:marker] if options[:marker]
|
364
|
+
query['maxresults'] = options[:max_results].to_s if options[:max_results]
|
365
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
363
366
|
|
364
367
|
included_datasets = []
|
365
|
-
included_datasets.push(
|
366
|
-
included_datasets.push(
|
367
|
-
included_datasets.push(
|
368
|
-
included_datasets.push(
|
368
|
+
included_datasets.push('metadata') if options[:metadata] == true
|
369
|
+
included_datasets.push('snapshots') if options[:snapshots] == true
|
370
|
+
included_datasets.push('uncommittedblobs') if options[:uncommittedblobs] == true
|
371
|
+
included_datasets.push('copy') if options[:copy] == true
|
369
372
|
|
370
|
-
query[
|
373
|
+
query['include'] = included_datasets.join ',' if included_datasets.length > 0
|
371
374
|
|
372
375
|
uri = container_uri(name, query)
|
373
376
|
response = call(:get, uri)
|
@@ -407,34 +410,34 @@ module Azure
|
|
407
410
|
# Returns a Blob
|
408
411
|
def create_page_blob(container, blob, length, options={})
|
409
412
|
query = { }
|
410
|
-
query[
|
413
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
411
414
|
|
412
415
|
uri = blob_uri(container, blob, query)
|
413
416
|
|
414
417
|
headers = service_properties_headers
|
415
418
|
|
416
419
|
# set x-ms-blob-type to PageBlob
|
417
|
-
headers[
|
420
|
+
headers['x-ms-blob-type'] = 'PageBlob'
|
418
421
|
|
419
422
|
# ensure content-length is 0 and x-ms-blob-content-length is the blob length
|
420
|
-
headers[
|
421
|
-
headers[
|
423
|
+
headers['Content-Length'] = 0.to_s
|
424
|
+
headers['x-ms-blob-content-length'] = length.to_s
|
422
425
|
|
423
426
|
# set x-ms-sequence-number from options (or default to 0)
|
424
|
-
headers[
|
427
|
+
headers['x-ms-sequence-number'] = (options[:sequence_number] || 0).to_s
|
425
428
|
|
426
429
|
# set the rest of the optional headers
|
427
|
-
headers[
|
428
|
-
headers[
|
429
|
-
headers[
|
430
|
-
headers[
|
431
|
-
headers[
|
432
|
-
|
433
|
-
headers[
|
434
|
-
headers[
|
435
|
-
headers[
|
436
|
-
headers[
|
437
|
-
headers[
|
430
|
+
headers['Content-Type'] = options[:content_type] if options[:content_type]
|
431
|
+
headers['Content-Encoding'] = options[:content_encoding] if options[:content_encoding]
|
432
|
+
headers['Content-Language'] = options[:content_language] if options[:content_language]
|
433
|
+
headers['Content-MD5'] = options[:content_md5] if options[:content_md5]
|
434
|
+
headers['Cache-Control'] = options[:cache_control] if options[:cache_control]
|
435
|
+
|
436
|
+
headers['x-ms-blob-content-type'] = options[:blob_content_type] if options[:blob_content_type]
|
437
|
+
headers['x-ms-blob-content-encoding'] = options[:blob_content_encoding] if options[:blob_content_encoding]
|
438
|
+
headers['x-ms-blob-content-language'] = options[:blob_content_language] if options[:blob_content_language]
|
439
|
+
headers['x-ms-blob-content-md5'] = options[:blob_content_md5] if options[:blob_content_md5]
|
440
|
+
headers['x-ms-blob-cache-control'] = options[:blob_cache_control] if options[:blob_cache_control]
|
438
441
|
|
439
442
|
add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
|
440
443
|
|
@@ -474,26 +477,26 @@ module Azure
|
|
474
477
|
#
|
475
478
|
# Returns Blob
|
476
479
|
def create_blob_pages(container, blob, start_range, end_range, content, options={})
|
477
|
-
query = {
|
478
|
-
query[
|
480
|
+
query = { 'comp' => 'page'}
|
481
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
479
482
|
|
480
483
|
uri = blob_uri(container, blob, query)
|
481
484
|
headers = service_properties_headers
|
482
|
-
headers[
|
483
|
-
headers[
|
485
|
+
headers['x-ms-range'] = "bytes=#{start_range}-#{end_range}"
|
486
|
+
headers['x-ms-page-write'] = 'update'
|
484
487
|
|
485
488
|
# clear default content type
|
486
|
-
headers[
|
489
|
+
headers['Content-Type'] = ''
|
487
490
|
|
488
491
|
# set optional headers
|
489
492
|
unless options.empty?
|
490
|
-
headers[
|
491
|
-
headers[
|
492
|
-
headers[
|
493
|
-
headers[
|
494
|
-
headers[
|
495
|
-
headers[
|
496
|
-
headers[
|
493
|
+
headers['x-ms-if-sequence-number-le'] = options[:if_sequence_number_le] if options[:if_sequence_number_le]
|
494
|
+
headers['x-ms-if-sequence-number-lt'] = options[:if_sequence_number_lt] if options[:if_sequence_number_lt]
|
495
|
+
headers['x-ms-if-sequence-number-eq'] = options[:if_sequence_number_eq] if options[:if_sequence_number_eq]
|
496
|
+
headers['If-Modified-Since'] = options[:if_modified_since] if options[:if_modified_since]
|
497
|
+
headers['If-Unmodified-Since'] = options[:if_unmodified_since] if options[:if_unmodified_since]
|
498
|
+
headers['If-Match'] = options[:if_match] if options[:if_match]
|
499
|
+
headers['If-None-Match'] = options[:if_none_match] if options[:if_none_match]
|
497
500
|
end
|
498
501
|
|
499
502
|
response = call(:put, uri, content, headers)
|
@@ -523,17 +526,17 @@ module Azure
|
|
523
526
|
#
|
524
527
|
# Returns Blob
|
525
528
|
def clear_blob_pages(container, blob, start_range, end_range, options={})
|
526
|
-
query = {
|
527
|
-
query[
|
529
|
+
query = { 'comp' => 'page'}
|
530
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
528
531
|
|
529
532
|
uri = blob_uri(container, blob, query)
|
530
533
|
|
531
534
|
headers = service_properties_headers
|
532
|
-
headers[
|
533
|
-
headers[
|
535
|
+
headers['x-ms-range'] = "bytes=#{start_range}-#{end_range}"
|
536
|
+
headers['x-ms-page-write'] = 'clear'
|
534
537
|
|
535
538
|
# clear default content type
|
536
|
-
headers[
|
539
|
+
headers['Content-Type'] = ''
|
537
540
|
|
538
541
|
response = call(:put, uri, nil, headers)
|
539
542
|
|
@@ -581,28 +584,28 @@ module Azure
|
|
581
584
|
# Returns a Blob
|
582
585
|
def create_block_blob(container, blob, content, options={})
|
583
586
|
query = { }
|
584
|
-
query[
|
587
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
585
588
|
|
586
589
|
uri = blob_uri(container, blob, query)
|
587
590
|
|
588
591
|
headers = service_properties_headers
|
589
592
|
|
590
593
|
# set x-ms-blob-type to BlockBlob
|
591
|
-
headers[
|
594
|
+
headers['x-ms-blob-type'] = 'BlockBlob'
|
592
595
|
|
593
596
|
# set the rest of the optional headers
|
594
|
-
headers[
|
595
|
-
headers[
|
596
|
-
headers[
|
597
|
-
headers[
|
598
|
-
headers[
|
599
|
-
|
600
|
-
headers[
|
601
|
-
headers[
|
602
|
-
headers[
|
603
|
-
headers[
|
604
|
-
headers[
|
605
|
-
headers[
|
597
|
+
headers['Content-Type'] = options[:content_type] || 'application/octet-stream'
|
598
|
+
headers['Content-Encoding'] = options[:content_encoding] if options[:content_encoding]
|
599
|
+
headers['Content-Language'] = options[:content_language] if options[:content_language]
|
600
|
+
headers['Content-MD5'] = options[:content_md5] if options[:content_md5]
|
601
|
+
headers['Cache-Control'] = options[:cache_control] if options[:cache_control]
|
602
|
+
|
603
|
+
headers['x-ms-blob-content-type'] = options[:blob_content_type] if options[:blob_content_type]
|
604
|
+
headers['x-ms-blob-content-encoding'] = options[:blob_content_encoding] if options[:blob_content_encoding]
|
605
|
+
headers['x-ms-blob-content-language'] = options[:blob_content_language] if options[:blob_content_language]
|
606
|
+
headers['x-ms-blob-content-md5'] = options[:blob_content_md5] if options[:blob_content_md5]
|
607
|
+
headers['x-ms-blob-cache-control'] = options[:blob_cache_control] if options[:blob_cache_control]
|
608
|
+
headers['x-ms-blob-content-disposition'] = options[:blob_content_disposition] if options[:blob_content_disposition]
|
606
609
|
|
607
610
|
add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
|
608
611
|
|
@@ -635,18 +638,18 @@ module Azure
|
|
635
638
|
#
|
636
639
|
# Returns the MD5 of the uploaded block (as calculated by the server)
|
637
640
|
def create_blob_block(container, blob, block_id, content, options={})
|
638
|
-
query = {
|
639
|
-
query[
|
640
|
-
query[
|
641
|
+
query = { 'comp' => 'block'}
|
642
|
+
query['blockid'] = Base64.strict_encode64(block_id)
|
643
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
641
644
|
|
642
645
|
uri = blob_uri(container, blob, query)
|
643
646
|
|
644
647
|
headers = service_properties_headers
|
645
|
-
headers[
|
648
|
+
headers['Content-MD5'] = options[:content_md5] if options[:content_md5]
|
646
649
|
|
647
650
|
response = call(:put, uri, content, headers)
|
648
651
|
|
649
|
-
response.headers[
|
652
|
+
response.headers['Content-MD5']
|
650
653
|
end
|
651
654
|
|
652
655
|
# Public: Commits existing blob blocks to a blob.
|
@@ -688,20 +691,20 @@ module Azure
|
|
688
691
|
#
|
689
692
|
# Returns nil on success
|
690
693
|
def commit_blob_blocks(container, blob, block_list, options={})
|
691
|
-
query = {
|
692
|
-
query[
|
694
|
+
query = { 'comp' => 'blocklist'}
|
695
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
693
696
|
|
694
697
|
uri = blob_uri(container, blob, query)
|
695
698
|
|
696
699
|
headers = service_properties_headers
|
697
700
|
unless options.empty?
|
698
|
-
headers[
|
699
|
-
headers[
|
700
|
-
headers[
|
701
|
-
headers[
|
702
|
-
headers[
|
703
|
-
headers[
|
704
|
-
headers[
|
701
|
+
headers['Content-MD5'] = options[:content_md5] if options[:content_md5]
|
702
|
+
headers['x-ms-blob-content-type'] = options[:blob_content_type] if options[:blob_content_type]
|
703
|
+
headers['x-ms-blob-content-encoding'] = options[:blob_content_encoding] if options[:blob_content_encoding]
|
704
|
+
headers['x-ms-blob-content-language'] = options[:blob_content_language] if options[:blob_content_language]
|
705
|
+
headers['x-ms-blob-content-md5'] = options[:blob_content_md5] if options[:blob_content_md5]
|
706
|
+
headers['x-ms-blob-cache-control'] = options[:blob_cache_control] if options[:blob_cache_control]
|
707
|
+
headers['x-ms-blob-content-disposition'] = options[:blob_content_disposition] if options[:blob_content_disposition]
|
705
708
|
|
706
709
|
add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
|
707
710
|
end
|
@@ -742,10 +745,10 @@ module Azure
|
|
742
745
|
|
743
746
|
options[:blocklist_type] = options[:blocklist_type] || :all
|
744
747
|
|
745
|
-
query = {
|
746
|
-
query[
|
747
|
-
query[
|
748
|
-
query[
|
748
|
+
query = { 'comp' => 'blocklist'}
|
749
|
+
query['snapshot'] = options[:snapshot] if options[:snapshot]
|
750
|
+
query['blocklisttype'] = options[:blocklist_type].to_s if options[:blocklist_type]
|
751
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
749
752
|
|
750
753
|
uri = blob_uri(container, blob, query)
|
751
754
|
|
@@ -774,8 +777,8 @@ module Azure
|
|
774
777
|
# Returns a Blob
|
775
778
|
def get_blob_properties(container, blob, options={})
|
776
779
|
query = { }
|
777
|
-
query[
|
778
|
-
query[
|
780
|
+
query['snapshot'] = options[:snapshot] if options[:snapshot]
|
781
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
779
782
|
|
780
783
|
uri = blob_uri(container, blob, query)
|
781
784
|
|
@@ -808,9 +811,9 @@ module Azure
|
|
808
811
|
#
|
809
812
|
# Returns a Blob
|
810
813
|
def get_blob_metadata(container, blob, options={})
|
811
|
-
query = {
|
812
|
-
query[
|
813
|
-
query[
|
814
|
+
query = {'comp' => 'metadata'}
|
815
|
+
query['snapshot'] = options[:snapshot] if options[:snapshot]
|
816
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
814
817
|
|
815
818
|
uri = blob_uri(container, blob, query)
|
816
819
|
|
@@ -849,16 +852,16 @@ module Azure
|
|
849
852
|
# eg. [ [0, 511], [512, 1024], ... ]
|
850
853
|
#
|
851
854
|
def list_page_blob_ranges(container, blob, options={})
|
852
|
-
query = {
|
853
|
-
query.update({
|
854
|
-
query[
|
855
|
+
query = {'comp' => 'pagelist'}
|
856
|
+
query.update({'snapshot' => options[:snapshot]}) if options[:snapshot]
|
857
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
855
858
|
|
856
859
|
uri = blob_uri(container, blob, query)
|
857
860
|
|
858
861
|
options[:start_range] = 0 if options[:end_range] and not options[:start_range]
|
859
862
|
|
860
863
|
headers = service_properties_headers
|
861
|
-
headers = {
|
864
|
+
headers = { 'x-ms-range' => "bytes=#{options[:start_range]}-#{options[:end_range]}" } if options[:start_range]
|
862
865
|
|
863
866
|
response = call(:get, uri, nil, headers)
|
864
867
|
|
@@ -944,22 +947,22 @@ module Azure
|
|
944
947
|
#
|
945
948
|
# Returns nil on success.
|
946
949
|
def set_blob_properties(container, blob, options={})
|
947
|
-
query = {
|
948
|
-
query[
|
950
|
+
query = { 'comp' => 'properties'}
|
951
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
949
952
|
uri = blob_uri(container, blob, query)
|
950
953
|
|
951
954
|
headers = service_properties_headers
|
952
955
|
|
953
956
|
unless options.empty?
|
954
|
-
headers[
|
955
|
-
headers[
|
956
|
-
headers[
|
957
|
-
headers[
|
958
|
-
headers[
|
959
|
-
headers[
|
960
|
-
headers[
|
961
|
-
headers[
|
962
|
-
headers[
|
957
|
+
headers['x-ms-blob-content-type'] = options[:blob_content_type] if options[:blob_content_type]
|
958
|
+
headers['x-ms-blob-content-encoding'] = options[:blob_content_encoding] if options[:blob_content_encoding]
|
959
|
+
headers['x-ms-blob-content-language'] = options[:blob_content_language] if options[:blob_content_language]
|
960
|
+
headers['x-ms-blob-content-md5'] = options[:blob_content_md5] if options[:blob_content_md5]
|
961
|
+
headers['x-ms-blob-cache-control'] = options[:blob_cache_control] if options[:blob_cache_control]
|
962
|
+
headers['x-ms-blob-content-length'] = options[:blob_content_length].to_s if options[:blob_content_length]
|
963
|
+
headers['x-ms-blob-sequence-number-action'] = options[:sequence_number_action].to_s if options[:sequence_number_action]
|
964
|
+
headers['x-ms-blob-sequence-number'] = options[:sequence_number].to_s if options[:sequence_number]
|
965
|
+
headers['x-ms-blob-content-disposition'] = options[:blob_content_disposition] if options[:blob_content_disposition]
|
963
966
|
end
|
964
967
|
|
965
968
|
call(:put, uri, nil, headers)
|
@@ -984,8 +987,8 @@ module Azure
|
|
984
987
|
#
|
985
988
|
# Returns nil on success.
|
986
989
|
def set_blob_metadata(container, blob, metadata, options={})
|
987
|
-
query = {
|
988
|
-
query[
|
990
|
+
query = { 'comp' => 'metadata'}
|
991
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
989
992
|
uri = blob_uri(container, blob, query)
|
990
993
|
|
991
994
|
headers = service_properties_headers
|
@@ -1020,20 +1023,20 @@ module Azure
|
|
1020
1023
|
# Returns a blob and the blob body
|
1021
1024
|
def get_blob(container, blob, options={})
|
1022
1025
|
query = { }
|
1023
|
-
query[
|
1024
|
-
query[
|
1026
|
+
query['snapshot'] = options[:snapshot] if options[:snapshot]
|
1027
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
1025
1028
|
uri = blob_uri(container, blob, query)
|
1026
1029
|
|
1027
1030
|
headers = service_properties_headers
|
1028
1031
|
options[:start_range] = 0 if options[:end_range] and not options[:start_range]
|
1029
1032
|
if options[:start_range]
|
1030
|
-
headers[
|
1031
|
-
headers[
|
1033
|
+
headers['x-ms-range'] = "bytes=#{options[:start_range]}-#{options[:end_range]}"
|
1034
|
+
headers['x-ms-range-get-content-md5'] = true if options[:get_content_md5]
|
1032
1035
|
end
|
1033
1036
|
|
1034
1037
|
response = call(:get, uri, nil, headers)
|
1035
1038
|
result = Serialization.blob_from_headers(response.headers)
|
1036
|
-
result.name = blob
|
1039
|
+
result.name = blob unless result.name
|
1037
1040
|
return result, response.body
|
1038
1041
|
end
|
1039
1042
|
|
@@ -1064,15 +1067,15 @@ module Azure
|
|
1064
1067
|
# Returns nil on success
|
1065
1068
|
def delete_blob(container, blob, options={})
|
1066
1069
|
query = { }
|
1067
|
-
query[
|
1068
|
-
query[
|
1070
|
+
query['snapshot'] = options[:snapshot] if options[:snapshot]
|
1071
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
1069
1072
|
|
1070
1073
|
uri = blob_uri(container, blob, query)
|
1071
1074
|
|
1072
|
-
options[:delete_snapshots] = :include
|
1075
|
+
options[:delete_snapshots] = :include unless options[:delete_snapshots]
|
1073
1076
|
|
1074
1077
|
headers = service_properties_headers
|
1075
|
-
headers[
|
1078
|
+
headers['x-ms-delete-snapshots'] = options[:delete_snapshots].to_s if options[:delete_snapshots] && options[:snapshot] == nil
|
1076
1079
|
|
1077
1080
|
call(:delete, uri, nil, headers)
|
1078
1081
|
nil
|
@@ -1108,8 +1111,8 @@ module Azure
|
|
1108
1111
|
#
|
1109
1112
|
# Returns the snapshot DateTime value
|
1110
1113
|
def create_blob_snapshot(container, blob, options={})
|
1111
|
-
query = {
|
1112
|
-
query[
|
1114
|
+
query = { 'comp' => 'snapshot'}
|
1115
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
1113
1116
|
|
1114
1117
|
uri = blob_uri(container, blob, query)
|
1115
1118
|
|
@@ -1117,15 +1120,15 @@ module Azure
|
|
1117
1120
|
unless options.empty?
|
1118
1121
|
add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
|
1119
1122
|
|
1120
|
-
headers[
|
1121
|
-
headers[
|
1122
|
-
headers[
|
1123
|
-
headers[
|
1123
|
+
headers['If-Modified-Since'] = options[:if_modified_since] if options[:if_modified_since]
|
1124
|
+
headers['If-Unmodified-Since'] = options[:if_unmodified_since] if options[:if_unmodified_since]
|
1125
|
+
headers['If-Match'] = options[:if_match] if options[:if_match]
|
1126
|
+
headers['If-None-Match'] = options[:if_none_match] if options[:if_none_match]
|
1124
1127
|
end
|
1125
1128
|
|
1126
1129
|
response = call(:put, uri, nil, headers)
|
1127
1130
|
|
1128
|
-
response.headers[
|
1131
|
+
response.headers['x-ms-snapshot']
|
1129
1132
|
end
|
1130
1133
|
|
1131
1134
|
# Public: Copies a source blob to a destination blob within the same storage account.
|
@@ -1184,27 +1187,27 @@ module Azure
|
|
1184
1187
|
#
|
1185
1188
|
def copy_blob(destination_container, destination_blob, source_container, source_blob, options={})
|
1186
1189
|
query = { }
|
1187
|
-
query[
|
1190
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
1188
1191
|
|
1189
1192
|
uri = blob_uri(destination_container, destination_blob, query)
|
1190
1193
|
headers = service_properties_headers
|
1191
|
-
headers[
|
1194
|
+
headers['x-ms-copy-source'] = blob_uri(source_container, source_blob, options[:source_snapshot] ? { 'snapshot' => options[:source_snapshot] } : {}).to_s
|
1192
1195
|
|
1193
1196
|
unless options.empty?
|
1194
|
-
headers[
|
1195
|
-
headers[
|
1196
|
-
headers[
|
1197
|
-
headers[
|
1198
|
-
headers[
|
1199
|
-
headers[
|
1200
|
-
headers[
|
1201
|
-
headers[
|
1197
|
+
headers['If-Modified-Since'] = options[:dest_if_modified_since] if options[:dest_if_modified_since]
|
1198
|
+
headers['If-Unmodified-Since'] = options[:dest_if_unmodified_since] if options[:dest_if_unmodified_since]
|
1199
|
+
headers['If-Match'] = options[:dest_if_match] if options[:dest_if_match]
|
1200
|
+
headers['If-None-Match'] = options[:dest_if_none_match] if options[:dest_if_none_match]
|
1201
|
+
headers['x-ms-source-if-modified-since'] = options[:source_if_modified_since] if options[:source_if_modified_since]
|
1202
|
+
headers['x-ms-source-if-unmodified-since'] = options[:source_if_unmodified_since] if options[:source_if_unmodified_since]
|
1203
|
+
headers['x-ms-source-if-match'] = options[:source_if_match] if options[:source_if_match]
|
1204
|
+
headers['x-ms-source-if-none-match'] = options[:source_if_none_match] if options[:source_if_none_match]
|
1202
1205
|
|
1203
1206
|
add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
|
1204
1207
|
end
|
1205
1208
|
|
1206
1209
|
response = call(:put, uri, nil, headers)
|
1207
|
-
return response.headers[
|
1210
|
+
return response.headers['x-ms-copy-id'], response.headers['x-ms-copy-status']
|
1208
1211
|
end
|
1209
1212
|
|
1210
1213
|
# Public: Establishes an exclusive one-minute write lock on a blob. To write to a locked
|
@@ -1232,8 +1235,8 @@ module Azure
|
|
1232
1235
|
# for the active lease.
|
1233
1236
|
#
|
1234
1237
|
def acquire_lease(container, blob, options={})
|
1235
|
-
query = {
|
1236
|
-
query[
|
1238
|
+
query = { 'comp' => 'lease'}
|
1239
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
1237
1240
|
|
1238
1241
|
uri = blob_uri(container, blob, query)
|
1239
1242
|
|
@@ -1241,12 +1244,12 @@ module Azure
|
|
1241
1244
|
duration = options[:duration] if options[:duration]
|
1242
1245
|
|
1243
1246
|
headers = service_properties_headers
|
1244
|
-
headers[
|
1245
|
-
headers[
|
1246
|
-
headers[
|
1247
|
+
headers['x-ms-lease-action'] = 'acquire'
|
1248
|
+
headers['x-ms-lease-duration'] = duration.to_s if duration
|
1249
|
+
headers['x-ms-proposed-lease-id'] = options[:proposed_lease_id] if options[:proposed_lease_id]
|
1247
1250
|
|
1248
1251
|
response = call(:put, uri, nil, headers)
|
1249
|
-
response.headers[
|
1252
|
+
response.headers['x-ms-lease-id']
|
1250
1253
|
end
|
1251
1254
|
|
1252
1255
|
# Public: Renews the lease. The lease can be renewed if the lease ID specified on the request matches that
|
@@ -1270,17 +1273,17 @@ module Azure
|
|
1270
1273
|
#
|
1271
1274
|
# Returns the renewed lease id
|
1272
1275
|
def renew_lease(container, blob, lease, options={})
|
1273
|
-
query = {
|
1274
|
-
query[
|
1276
|
+
query = { 'comp' => 'lease'}
|
1277
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
1275
1278
|
|
1276
1279
|
uri = blob_uri(container, blob, query)
|
1277
1280
|
|
1278
1281
|
headers = service_properties_headers
|
1279
|
-
headers[
|
1280
|
-
headers[
|
1282
|
+
headers['x-ms-lease-action'] = 'renew'
|
1283
|
+
headers['x-ms-lease-id'] = lease
|
1281
1284
|
|
1282
1285
|
response = call(:put, uri, nil, headers)
|
1283
|
-
response.headers[
|
1286
|
+
response.headers['x-ms-lease-id']
|
1284
1287
|
end
|
1285
1288
|
|
1286
1289
|
# Public: Releases the lease. The lease may be released if the lease ID specified on the request matches that
|
@@ -1303,14 +1306,14 @@ module Azure
|
|
1303
1306
|
#
|
1304
1307
|
# Returns nil on success
|
1305
1308
|
def release_lease(container, blob, lease, options={})
|
1306
|
-
query = {
|
1307
|
-
query[
|
1309
|
+
query = { 'comp' => 'lease'}
|
1310
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
1308
1311
|
|
1309
1312
|
uri = blob_uri(container, blob, query)
|
1310
1313
|
|
1311
1314
|
headers = service_properties_headers
|
1312
|
-
headers[
|
1313
|
-
headers[
|
1315
|
+
headers['x-ms-lease-action'] = 'release'
|
1316
|
+
headers['x-ms-lease-id'] = lease
|
1314
1317
|
|
1315
1318
|
call(:put, uri, nil, headers)
|
1316
1319
|
nil
|
@@ -1350,17 +1353,39 @@ module Azure
|
|
1350
1353
|
# period, in seconds. This header is returned only for a successful request to break the lease. If the break
|
1351
1354
|
# is immediate, 0 is returned.
|
1352
1355
|
def break_lease(container, blob, options={})
|
1353
|
-
query = {
|
1354
|
-
query[
|
1356
|
+
query = { 'comp' => 'lease'}
|
1357
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
1355
1358
|
|
1356
1359
|
uri = blob_uri(container, blob, query)
|
1357
1360
|
|
1358
1361
|
headers = service_properties_headers
|
1359
|
-
headers[
|
1360
|
-
headers[
|
1362
|
+
headers['x-ms-lease-action'] = 'break'
|
1363
|
+
headers['x-ms-lease-break-period'] = options[:break_period].to_s if options[:break_period]
|
1361
1364
|
|
1362
1365
|
response = call(:put, uri, nil, headers)
|
1363
|
-
response.headers[
|
1366
|
+
response.headers['x-ms-lease-time'].to_i
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
def call(method, uri, body=nil, headers=nil)
|
1370
|
+
# Force the request.body to the content encoding of specified in the header
|
1371
|
+
# (content encoding probably shouldn't be used this way)
|
1372
|
+
if headers && !body.nil?
|
1373
|
+
if headers['Content-Encoding'].nil?
|
1374
|
+
headers['Content-Encoding'] = body.encoding.to_s
|
1375
|
+
else
|
1376
|
+
body.force_encoding(headers['Content-Encoding'])
|
1377
|
+
end
|
1378
|
+
end
|
1379
|
+
|
1380
|
+
response = super
|
1381
|
+
|
1382
|
+
# Force the response.body to the content encoding of specified in the header.
|
1383
|
+
# content-encoding is echo'd back for the blob and is used to store the encoding of the octet stream
|
1384
|
+
if !response.nil? && !response.body.nil? && response.headers['content-encoding']
|
1385
|
+
response.body.force_encoding(response.headers['content-encoding'])
|
1386
|
+
end
|
1387
|
+
|
1388
|
+
response
|
1364
1389
|
end
|
1365
1390
|
|
1366
1391
|
# Protected: Generate the URI for the collection of containers.
|
@@ -1373,8 +1398,8 @@ module Azure
|
|
1373
1398
|
# Returns a URI.
|
1374
1399
|
protected
|
1375
1400
|
def containers_uri(query={})
|
1376
|
-
query = {
|
1377
|
-
generate_uri(
|
1401
|
+
query = { 'comp' => 'list'}.merge(query)
|
1402
|
+
generate_uri('/', query)
|
1378
1403
|
end
|
1379
1404
|
|
1380
1405
|
# Protected: Generate the URI for a specific container.
|
@@ -1386,10 +1411,9 @@ module Azure
|
|
1386
1411
|
# * +host+ - The host of the API.
|
1387
1412
|
#
|
1388
1413
|
# Returns a URI.
|
1389
|
-
protected
|
1390
1414
|
def container_uri(name, query={})
|
1391
1415
|
return name if name.kind_of? ::URI
|
1392
|
-
query = {
|
1416
|
+
query = { 'restype' => 'container'}.merge(query)
|
1393
1417
|
generate_uri(name, query)
|
1394
1418
|
end
|
1395
1419
|
|
@@ -1403,7 +1427,6 @@ module Azure
|
|
1403
1427
|
# * +host+ - The host of the API.
|
1404
1428
|
#
|
1405
1429
|
# Returns a URI.
|
1406
|
-
protected
|
1407
1430
|
def blob_uri(container_name, blob_name, query={})
|
1408
1431
|
if container_name.nil? || container_name.empty?
|
1409
1432
|
path = blob_name
|
@@ -1425,3 +1448,5 @@ module Azure
|
|
1425
1448
|
end
|
1426
1449
|
end
|
1427
1450
|
end
|
1451
|
+
|
1452
|
+
Azure::BlobService = Azure::Blob::BlobService
|