azure-storage-blob 1.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,931 +1,932 @@
1
- # frozen_string_literal: true
2
-
3
- #-------------------------------------------------------------------------
4
- # # Copyright (c) Microsoft and contributors. All rights reserved.
5
- #
6
- # The MIT License(MIT)
7
-
8
- # Permission is hereby granted, free of charge, to any person obtaining a copy
9
- # of this software and associated documentation files(the "Software"), to deal
10
- # in the Software without restriction, including without limitation the rights
11
- # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
- # copies of the Software, and to permit persons to whom the Software is
13
- # furnished to do so, subject to the following conditions :
14
-
15
- # The above copyright notice and this permission notice shall be included in
16
- # all copies or substantial portions of the Software.
17
-
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- # THE SOFTWARE.
25
- #--------------------------------------------------------------------------
26
-
27
- module Azure::Storage
28
- module Blob
29
- include Azure::Storage::Common::Service
30
-
31
- class Blob
32
- def initialize
33
- @properties = {}
34
- @metadata = {}
35
- yield self if block_given?
36
- end
37
-
38
- attr_accessor :name
39
- attr_accessor :snapshot
40
- attr_accessor :properties
41
- attr_accessor :metadata
42
- attr_accessor :encrypted
43
- end
44
-
45
- # Public: Reads or downloads a blob from the system, including its metadata and properties.
46
- #
47
- # ==== Attributes
48
- #
49
- # * +container+ - String. The container name.
50
- # * +blob+ - String. The blob name.
51
- # * +options+ - Hash. Optional parameters.
52
- #
53
- # ==== Options
54
- #
55
- # Accepted key/value pairs in options parameter are:
56
- # * +:start_range+ - Integer. Position of first byte of first page. (optional)
57
- # * +:end_range+ - Integer. Position of last byte of of last page. (optional)
58
- # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
59
- # retrieve information from. (optional)
60
- # * +:get_content_md5+ - Boolean. Return the MD5 hash for the range. This option only valid if
61
- # start_range and end_range are specified. (optional)
62
- # * +:timeout+ - Integer. A timeout in seconds.
63
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
64
- # in the analytics logs when storage analytics logging is enabled.
65
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
66
- # which location the request should be sent to.
67
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to get the blob
68
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
69
- # the Blob service returns status code 412 (Precondition Failed).
70
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to get the blob
71
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
72
- # the Blob service returns status code 412 (Precondition Failed).
73
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob
74
- # only if the blob's ETag value matches the value specified. If the values do not match,
75
- # the Blob service returns status code 412 (Precondition Failed).
76
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob
77
- # only if the blob's ETag value does not match the value specified. If the values are identical,
78
- # the Blob service returns status code 412 (Precondition Failed).
79
- # * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
80
- # following conditions are met:
81
- # - The blob's lease is currently active.
82
- # - The lease ID specified in the request matches that of the blob.
83
- # If this header is specified and both of these conditions are not met, the request will fail
84
- # and the Get Blob operation will fail with status code 412 (Precondition Failed).
85
- #
86
- # See http://msdn.microsoft.com/en-us/library/azure/dd179440.aspx
87
- #
88
- # Returns a blob and the blob body
89
- def get_blob(container, blob, options = {})
90
- query = {}
91
- StorageService.with_query query, "snapshot", options[:snapshot]
92
- StorageService.with_query query, "timeout", options[:timeout] if options[:timeout]
93
-
94
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
95
- uri = blob_uri(container, blob, query, options)
96
-
97
- headers = {}
98
- options[:start_range] = 0 if options[:end_range] && (not options[:start_range])
99
- if options[:start_range]
100
- StorageService.with_header headers, "x-ms-range", "bytes=#{options[:start_range]}-#{options[:end_range]}"
101
- StorageService.with_header headers, "x-ms-range-get-content-md5", "true" if options[:get_content_md5]
102
- end
103
- add_blob_conditional_headers options, headers
104
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
105
-
106
- response = call(:get, uri, nil, headers, options)
107
- result = Serialization.blob_from_headers(response.headers)
108
- result.name = blob unless result.name
109
-
110
- return result, response.body
111
- end
112
-
113
- # Public: Returns all properties and metadata on the blob.
114
- #
115
- # ==== Attributes
116
- #
117
- # * +container+ - String. The container name.
118
- # * +blob+ - String. The blob name.
119
- # * +options+ - Hash. Optional parameters.
120
- #
121
- # ==== Options
122
- #
123
- # Accepted key/value pairs in options parameter are:
124
- # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
125
- # retrieve information from.
126
- # * +:timeout+ - Integer. A timeout in seconds.
127
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
128
- # in the analytics logs when storage analytics logging is enabled.
129
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
130
- # which location the request should be sent to.
131
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to get the blob properties
132
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
133
- # the Blob service returns status code 412 (Precondition Failed).
134
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to get the blob properties
135
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
136
- # the Blob service returns status code 412 (Precondition Failed).
137
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob properties
138
- # only if the blob's ETag value matches the value specified. If the values do not match,
139
- # the Blob service returns status code 412 (Precondition Failed).
140
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob properties
141
- # only if the blob's ETag value does not match the value specified. If the values are identical,
142
- # the Blob service returns status code 412 (Precondition Failed).
143
- # * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
144
- # following conditions are met:
145
- #
146
- # - The blob's lease is currently active.
147
- # - The lease ID specified in the request matches that of the blob.
148
- #
149
- # If this header is specified and both of these conditions are not met, the request will fail
150
- # and the Get Blob Properties operation will fail with status code 412 (Precondition Failed).
151
- #
152
- # See http://msdn.microsoft.com/en-us/library/azure/dd179394.aspx
153
- #
154
- # Returns the blob properties with a Blob instance
155
- def get_blob_properties(container, blob, options = {})
156
- query = {}
157
- StorageService.with_query query, "snapshot", options[:snapshot]
158
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
159
-
160
- headers = {}
161
- unless options.empty?
162
- add_blob_conditional_headers options, headers
163
- end
164
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
165
-
166
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
167
- uri = blob_uri(container, blob, query, options)
168
-
169
- response = call(:head, uri, nil, headers, options)
170
-
171
- result = Serialization.blob_from_headers(response.headers)
172
-
173
- result.name = blob
174
- result.snapshot = options[:snapshot]
175
-
176
- result
177
- end
178
-
179
- # Public: Sets system properties defined for a blob.
180
- #
181
- # ==== Attributes
182
- #
183
- # * +container+ - String. The container name.
184
- # * +blob+ - String. The blob name.
185
- # * +options+ - Hash. Optional parameters.
186
- #
187
- # ==== Options
188
- #
189
- # Accepted key/value pairs in options parameter are:
190
- # * +:content_type+ - String. Content type for the blob. Will be saved with blob.
191
- # * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
192
- # * +:content_language+ - String. Content language for the blob. Will be saved with blob.
193
- # * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
194
- # * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
195
- # * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
196
- # and also can be used to attach additional metadata
197
- # * +:content_length+ - Integer. Resizes a page blob to the specified size. If the specified
198
- # value is less than the current size of the blob, then all pages above
199
- # the specified value are cleared. This property cannot be used to change
200
- # the size of a block blob. Setting this property for a block blob returns
201
- # status code 400 (Bad Request).
202
- # * +:sequence_number_action+ - Symbol. This property indicates how the service should modify the sequence
203
- # number for the blob. Required if :sequence_number is used. This property
204
- # applies to page blobs only.
205
- #
206
- # Specify one of the following options for this property:
207
- #
208
- # * +:max+ - Sets the sequence number to be the higher of the value included with
209
- # the request and the value currently stored for the blob.
210
- # * +:update+ - Sets the sequence number to the value included with the request.
211
- # * +:increment+ - Increments the value of the sequence number by 1. If specifying this
212
- # option, do not include the sequence_number option; doing so will return
213
- # status code 400 (Bad Request).
214
- #
215
- # * +:sequence_number+ - Integer. This property sets the blob's sequence number. The sequence number is a
216
- # user-controlled property that you can use to track requests and manage concurrency
217
- # issues. Required if the :sequence_number_action option is set to :max or :update.
218
- # This property applies to page blobs only.
219
- #
220
- # Use this together with the :sequence_number_action to update the blob's sequence
221
- # number, either to the specified value or to the higher of the values specified with
222
- # the request or currently stored with the blob.
223
- #
224
- # This header should not be specified if :sequence_number_action is set to :increment;
225
- # in this case the service automatically increments the sequence number by one.
226
- #
227
- # To set the sequence number to a value of your choosing, this property must be specified
228
- # together with :sequence_number_action
229
- # * +:timeout+ - Integer. A timeout in seconds.
230
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
231
- # in the analytics logs when storage analytics logging is enabled.
232
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
233
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
234
- # the Blob service returns status code 412 (Precondition Failed).
235
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
236
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
237
- # the Blob service returns status code 412 (Precondition Failed).
238
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
239
- # only if the blob's ETag value matches the value specified. If the values do not match,
240
- # the Blob service returns status code 412 (Precondition Failed).
241
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
242
- # only if the blob's ETag value does not match the value specified. If the values are identical,
243
- # the Blob service returns status code 412 (Precondition Failed).
244
- # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active
245
- # lease, specify the valid lease ID for this header.
246
- #
247
- # Remarks:
248
- #
249
- # The semantics for updating a blob's properties are as follows:
250
- #
251
- # * A page blob's sequence number is updated only if the request meets either of the following conditions:
252
- #
253
- # * The :sequence_number_action property is set to :max or :update, and a value for :sequence_number is also set.
254
- # * The :sequence_number_action property is set to :increment, indicating that the service should increment
255
- # the sequence number by one.
256
- #
257
- # * The size of the page blob is modified only if a value for :content_length is specified.
258
- #
259
- # * If :sequence_number and/or :content_length are the only properties specified, then the other properties of the blob
260
- # will NOT be modified.
261
- #
262
- # * If any one or more of the following properties are set, then all of these properties are set together. If a value is
263
- # not provided for a given property when at least one of the properties listed below is set, then that property will be
264
- # cleared for the blob.
265
- #
266
- # * :cache_control
267
- # * :content_type
268
- # * :content_md5
269
- # * :content_encoding
270
- # * :content_language
271
- #
272
- # See http://msdn.microsoft.com/en-us/library/azure/ee691966.aspx
273
- #
274
- # Returns nil on success.
275
- def set_blob_properties(container, blob, options = {})
276
- query = { "comp" => "properties" }
277
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
278
- uri = blob_uri(container, blob, query)
279
-
280
- headers = {}
281
-
282
- unless options.empty?
283
- StorageService.with_header headers, "x-ms-blob-content-type", options[:content_type]
284
- StorageService.with_header headers, "x-ms-blob-content-encoding", options[:content_encoding]
285
- StorageService.with_header headers, "x-ms-blob-content-language", options[:content_language]
286
- StorageService.with_header headers, "x-ms-blob-content-md5", options[:content_md5]
287
- StorageService.with_header headers, "x-ms-blob-cache-control", options[:cache_control]
288
- StorageService.with_header headers, "x-ms-blob-content-length", options[:content_length] if options[:content_length]
289
- StorageService.with_header headers, "x-ms-blob-content-disposition", options[:content_disposition]
290
-
291
- if options[:sequence_number_action]
292
- StorageService.with_header headers, "x-ms-sequence-number-action", options[:sequence_number_action]
293
-
294
- if options[:sequence_number_action].to_s != "increment" && options[:sequence_number]
295
- StorageService.with_header headers, "x-ms-blob-sequence-number", options[:sequence_number]
296
- end
297
- end
298
-
299
- add_blob_conditional_headers options, headers
300
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
301
- end
302
- call(:put, uri, nil, headers, options)
303
- nil
304
- end
305
-
306
- # Public: Returns metadata on the blob.
307
- #
308
- # ==== Attributes
309
- #
310
- # * +container+ - String. The container name.
311
- # * +blob+ - String. The blob name.
312
- # * +options+ - Hash. Optional parameters.
313
- #
314
- # ==== Options
315
- #
316
- # Accepted key/value pairs in options parameter are:
317
- # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
318
- # retrieve information from.
319
- # * +:timeout+ - Integer. A timeout in seconds.
320
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
321
- # in the analytics logs when storage analytics logging is enabled.
322
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
323
- # which location the request should be sent to.
324
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to get the blob metadata
325
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
326
- # the Blob service returns status code 412 (Precondition Failed).
327
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to get the blob metadata
328
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
329
- # the Blob service returns status code 412 (Precondition Failed).
330
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob metadata
331
- # only if the blob's ETag value matches the value specified. If the values do not match,
332
- # the Blob service returns status code 412 (Precondition Failed).
333
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob metadata
334
- # only if the blob's ETag value does not match the value specified. If the values are identical,
335
- # the Blob service returns status code 412 (Precondition Failed).
336
- # * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
337
- # following conditions are met:
338
- #
339
- # - The blob's lease is currently active.
340
- # - The lease ID specified in the request matches that of the blob.
341
- #
342
- # If this header is specified and both of these conditions are not met, the request will fail
343
- # and the Get Blob Metadata operation will fail with status code 412 (Precondition Failed).
344
- #
345
- # See http://msdn.microsoft.com/en-us/library/azure/dd179350.aspx
346
- #
347
- # Returns a Blob
348
- def get_blob_metadata(container, blob, options = {})
349
- query = { "comp" => "metadata" }
350
- StorageService.with_query query, "snapshot", options[:snapshot]
351
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
352
-
353
- headers = {}
354
- unless options.empty?
355
- add_blob_conditional_headers options, headers
356
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
357
- end
358
-
359
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
360
- uri = blob_uri(container, blob, query, options)
361
- response = call(:get, uri, nil, headers, options)
362
- result = Serialization.blob_from_headers(response.headers)
363
-
364
- result.name = blob
365
- result.snapshot = options[:snapshot]
366
-
367
- result
368
- end
369
-
370
- # Public: Sets metadata headers on the blob.
371
- #
372
- # ==== Attributes
373
- #
374
- # * +container+ - String. The container name.
375
- # * +blob+ - String. The blob name.
376
- # * +metadata+ - Hash. The custom metadata.
377
- # * +options+ - Hash. Optional parameters.
378
- #
379
- # ==== Options
380
- #
381
- # Accepted key/value pairs in options parameter are:
382
- # * +:timeout+ - Integer. A timeout in seconds.
383
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
384
- # in the analytics logs when storage analytics logging is enabled.
385
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to set the blob metadata
386
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
387
- # the Blob service returns status code 412 (Precondition Failed).
388
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to set the blob metadata
389
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
390
- # the Blob service returns status code 412 (Precondition Failed).
391
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob metadata
392
- # only if the blob's ETag value matches the value specified. If the values do not match,
393
- # the Blob service returns status code 412 (Precondition Failed).
394
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob metadata
395
- # only if the blob's ETag value does not match the value specified. If the values are identical,
396
- # the Blob service returns status code 412 (Precondition Failed).
397
- # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active
398
- # lease, specify the valid lease ID for this header.
399
- #
400
- # See http://msdn.microsoft.com/en-us/library/azure/dd179414.aspx
401
- #
402
- # Returns nil on success.
403
- def set_blob_metadata(container, blob, metadata, options = {})
404
- query = { "comp" => "metadata" }
405
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
406
-
407
- uri = blob_uri(container, blob, query)
408
-
409
- headers = {}
410
- StorageService.add_metadata_to_headers metadata, headers
411
- unless options.empty?
412
- add_blob_conditional_headers options, headers
413
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
414
- end
415
-
416
- call(:put, uri, nil, headers, options)
417
- nil
418
- end
419
-
420
- # Public: Establishes an exclusive write lock on a blob. The lock duration can be 15 to 60 seconds, or can be infinite.
421
- # To write to a locked blob, a client must provide a lease ID.
422
- #
423
- # ==== Attributes
424
- #
425
- # * +container+ - String. The container name.
426
- # * +blob+ - String. The blob name.
427
- # * +options+ - Hash. Optional parameters.
428
- #
429
- # ==== Options
430
- #
431
- # Accepted key/value pairs in options parameter are:
432
- # * +:duration+ - Integer. Default -1. Specifies the duration of the lease, in seconds, or negative one (-1)
433
- # for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. (optional)
434
- # * +:proposed_lease_id+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
435
- # if the proposed lease ID is not in the correct format. (optional)
436
- # * +:timeout+ - Integer. A timeout in seconds.
437
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
438
- # in the analytics logs when storage analytics logging is enabled.
439
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
440
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
441
- # the Blob service returns status code 412 (Precondition Failed).
442
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
443
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
444
- # the Blob service returns status code 412 (Precondition Failed).
445
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
446
- # only if the blob's ETag value matches the value specified. If the values do not match,
447
- # the Blob service returns status code 412 (Precondition Failed).
448
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
449
- # only if the blob's ETag value does not match the value specified. If the values are identical,
450
- # the Blob service returns status code 412 (Precondition Failed).
451
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
452
- # in cross-origin resource sharing headers on the response.
453
- #
454
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
455
- #
456
- # Returns a String of the new unique lease id. While the lease is active, you must include the lease ID with any request
457
- # to write to the blob, or to renew, change, or release the lease.
458
- #
459
- def acquire_blob_lease(container, blob, options = {})
460
- acquire_lease container, blob, options
461
- end
462
-
463
- # Public: Renews the lease. The lease can be renewed if the lease ID specified on the request matches that
464
- # associated with the blob. Note that the lease may be renewed even if it has expired as long as the blob
465
- # has not been modified or leased again since the expiration of that lease. When you renew a lease, the
466
- # lease duration clock resets.
467
- #
468
- # ==== Attributes
469
- #
470
- # * +container+ - String. The container name.
471
- # * +blob+ - String. The blob name.
472
- # * +lease+ - String. The lease id
473
- # * +options+ - Hash. Optional parameters.
474
- #
475
- # ==== Options
476
- #
477
- # Accepted key/value pairs in options parameter are:
478
- # * +:timeout+ - Integer. A timeout in seconds.
479
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
480
- # in the analytics logs when storage analytics logging is enabled.
481
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
482
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
483
- # the Blob service returns status code 412 (Precondition Failed).
484
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
485
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
486
- # the Blob service returns status code 412 (Precondition Failed).
487
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
488
- # only if the blob's ETag value matches the value specified. If the values do not match,
489
- # the Blob service returns status code 412 (Precondition Failed).
490
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
491
- # only if the blob's ETag value does not match the value specified. If the values are identical,
492
- # the Blob service returns status code 412 (Precondition Failed).
493
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
494
- # in cross-origin resource sharing headers on the response.
495
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
496
- #
497
- # Returns the renewed lease id
498
- def renew_blob_lease(container, blob, lease, options = {})
499
- renew_lease container, blob, lease, options
500
- end
501
-
502
- # Public: Change the lease ID.
503
- #
504
- # ==== Attributes
505
- #
506
- # * +container+ - String. The container name.
507
- # * +blob+ - String. The blob name.
508
- # * +lease+ - String. The existing lease id.
509
- # * +proposed_lease+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
510
- # if the proposed lease ID is not in the correct format. (optional).
511
- # * +options+ - Hash. Optional parameters.
512
- #
513
- # ==== Options
514
- #
515
- # Accepted key/value pairs in options parameter are:
516
- # * +:timeout+ - Integer. A timeout in seconds.
517
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
518
- # in the analytics logs when storage analytics logging is enabled.
519
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to change the lease
520
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
521
- # the Blob service returns status code 412 (Precondition Failed).
522
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to change the lease
523
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
524
- # the Blob service returns status code 412 (Precondition Failed).
525
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
526
- # only if the blob's ETag value matches the value specified. If the values do not match,
527
- # the Blob service returns status code 412 (Precondition Failed).
528
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
529
- # only if the blob's ETag value does not match the value specified. If the values are identical,
530
- # the Blob service returns status code 412 (Precondition Failed).
531
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
532
- # in cross-origin resource sharing headers on the response.
533
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
534
- #
535
- # Returns the changed lease id
536
- def change_blob_lease(container, blob, lease, proposed_lease, options = {})
537
- change_lease container, blob, lease, proposed_lease, options
538
- end
539
-
540
- # Public: Releases the lease. The lease may be released if the lease ID specified on the request matches that
541
- # associated with the blob. Releasing the lease allows another client to immediately acquire the lease for
542
- # the blob as soon as the release is complete.
543
- #
544
- # ==== Attributes
545
- #
546
- # * +container+ - String. The container name.
547
- # * +blob+ - String. The blob name.
548
- # * +lease+ - String. The lease id.
549
- # * +options+ - Hash. Optional parameters.
550
- #
551
- # ==== Options
552
- #
553
- # Accepted key/value pairs in options parameter are:
554
- # * +:timeout+ - Integer. A timeout in seconds.
555
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
556
- # in the analytics logs when storage analytics logging is enabled.
557
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to release the lease
558
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
559
- # the Blob service returns status code 412 (Precondition Failed).
560
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to release the lease
561
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
562
- # the Blob service returns status code 412 (Precondition Failed).
563
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
564
- # only if the blob's ETag value matches the value specified. If the values do not match,
565
- # the Blob service returns status code 412 (Precondition Failed).
566
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
567
- # only if the blob's ETag value does not match the value specified. If the values are identical,
568
- # the Blob service returns status code 412 (Precondition Failed).
569
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
570
- # in cross-origin resource sharing headers on the response.
571
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
572
- #
573
- # Returns nil on success
574
- def release_blob_lease(container, blob, lease, options = {})
575
- release_lease container, blob, lease, options
576
- end
577
-
578
- # Public: Breaks the lease, if the blob has an active lease. Once a lease is broken, it cannot be renewed. Any
579
- # authorized request can break the lease; the request is not required to specify a matching lease ID. When a
580
- # lease is broken, the lease break period is allowed to elapse, during which time no lease operation except
581
- # break and release can be performed on the blob. When a lease is successfully broken, the response indicates
582
- # the interval in seconds until a new lease can be acquired.
583
- #
584
- # A lease that has been broken can also be released, in which case another client may immediately acquire the
585
- # lease on the blob.
586
- #
587
- # ==== Attributes
588
- #
589
- # * +container+ - String. The container name.
590
- # * +blob+ - String. The blob name.
591
- # * +options+ - Hash. Optional parameters.
592
- #
593
- # ==== Options
594
- #
595
- # Accepted key/value pairs in options parameter are:
596
- # * +:break_period+ - Integer. The proposed duration of seconds that the lease should continue before it is
597
- # broken, between 0 and 60 seconds. This break period is only used if it is shorter than
598
- # the time remaining on the lease. If longer, the time remaining on the lease is used. A
599
- # new lease will not be available before the break period has expired, but the lease may
600
- # be held for longer than the break period.
601
- #
602
- # If this option is not used, a fixed-duration lease breaks after the remaining lease
603
- # period elapses, and an infinite lease breaks immediately.
604
- # * +:timeout+ - Integer. A timeout in seconds.
605
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
606
- # in the analytics logs when storage analytics logging is enabled.
607
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to break the lease
608
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
609
- # the Blob service returns status code 412 (Precondition Failed).
610
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to break the lease
611
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
612
- # the Blob service returns status code 412 (Precondition Failed).
613
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
614
- # only if the blob's ETag value matches the value specified. If the values do not match,
615
- # the Blob service returns status code 412 (Precondition Failed).
616
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
617
- # only if the blob's ETag value does not match the value specified. If the values are identical,
618
- # the Blob service returns status code 412 (Precondition Failed).
619
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
620
- # in cross-origin resource sharing headers on the response.
621
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
622
- #
623
- # Returns an Integer of the remaining lease time. This value is the approximate time remaining in the lease
624
- # period, in seconds. This header is returned only for a successful request to break the lease. If the break
625
- # is immediate, 0 is returned.
626
- def break_blob_lease(container, blob, options = {})
627
- break_lease container, blob, options
628
- end
629
-
630
- # Public: Creates a snapshot of a blob.
631
- #
632
- # ==== Attributes
633
- #
634
- # * +container+ - String. The container name.
635
- # * +blob+ - String. The blob name.
636
- # * +options+ - Hash. Optional parameters.
637
- #
638
- # ==== Options
639
- #
640
- # Accepted key/value pairs in options parameter are:
641
- # * +:metadata+ - Hash. Custom metadata values to store with the blob snapshot.
642
- # * +:timeout+ - Integer. A timeout in seconds.
643
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
644
- # in the analytics logs when storage analytics logging is enabled.
645
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create the blob snapshot
646
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
647
- # the Blob service returns status code 412 (Precondition Failed).
648
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create the blob snapshot
649
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
650
- # the Blob service returns status code 412 (Precondition Failed).
651
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create the blob snapshot
652
- # only if the blob's ETag value matches the value specified. If the values do not match,
653
- # the Blob service returns status code 412 (Precondition Failed).
654
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create the blob snapshot
655
- # only if the blob's ETag value does not match the value specified. If the values are identical,
656
- # the Blob service returns status code 412 (Precondition Failed).
657
- # * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
658
- # following conditions are met:
659
- # - The blob's lease is currently active.
660
- # - The lease ID specified in the request matches that of the blob.
661
- # If this header is specified and both of these conditions are not met, the request will fail
662
- # and the Snapshot Blob operation will fail with status code 412 (Precondition Failed).
663
- #
664
- # See http://msdn.microsoft.com/en-us/library/azure/ee691971.aspx
665
- #
666
- # Returns the snapshot DateTime value
667
- def create_blob_snapshot(container, blob, options = {})
668
- query = { "comp" => "snapshot" }
669
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
670
-
671
- uri = blob_uri(container, blob, query)
672
-
673
- headers = {}
674
- unless options.empty?
675
- StorageService.add_metadata_to_headers(options[:metadata], headers)
676
- add_blob_conditional_headers(options, headers)
677
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
678
- end
679
-
680
- response = call(:put, uri, nil, headers, options)
681
-
682
- response.headers["x-ms-snapshot"]
683
- end
684
-
685
- # Public: Copies a source blob or file to a destination blob.
686
- #
687
- # ==== Attributes
688
- #
689
- # * +destination_container+ - String. The destination container name to copy to.
690
- # * +destination_blob+ - String. The destination blob name to copy to.
691
- # * +source_uri+ - String. The source blob or file URI to copy from.
692
- # * +options+ - Hash. Optional parameters.
693
- #
694
- # ==== Options
695
- #
696
- # Accepted key/value pairs in options parameter are:
697
- # * +:source_snapshot+ - String. A snapshot id for the source blob
698
- # * +:metadata+ - Hash. Custom metadata values to store with the copy. If this parameter is not
699
- # specified, the operation will copy the source blob metadata to the destination
700
- # blob. If this parameter is specified, the destination blob is created with the
701
- # specified metadata, and metadata is not copied from the source blob.
702
- # * +:source_if_modified_since+ - String. A DateTime value. Specify this option to write the page only if the source blob
703
- # has been modified since the specified date/time. If the blob has not been
704
- # modified, the Blob service returns status code 412 (Precondition Failed).
705
- # * +:source_if_unmodified_since+ - String. A DateTime value. Specify this option to write the page only if the source blob
706
- # has not been modified since the specified date/time. If the blob has been
707
- # modified, the Blob service returns status code 412 (Precondition Failed).
708
- # * +:source_if_match+ - String. An ETag value. Specify an ETag value to write the page only if the source blob's
709
- # ETag value matches the value specified. If the values do not match, the Blob
710
- # service returns status code 412 (Precondition Failed).
711
- # * +:source_if_none_match+ - String. An ETag value. Specify an ETag value to write the page only if the source blob's
712
- # ETag value does not match the value specified. If the values are identical, the
713
- # Blob service returns status code 412 (Precondition Failed).
714
- # * +:dest_if_modified_since+ - String. A DateTime value. Specify this option to write the page only if the destination
715
- # blob has been modified since the specified date/time. If the blob has not been
716
- # modified, the Blob service returns status code 412 (Precondition Failed).
717
- # * +:dest_if_unmodified_since+ - String. A DateTime value. Specify this option to write the page only if the destination
718
- # blob has not been modified since the specified date/time. If the blob has been
719
- # modified, the Blob service returns status code 412 (Precondition Failed).
720
- # * +:dest_if_match+ - String. An ETag value. Specify an ETag value to write the page only if the destination
721
- # blob's ETag value matches the value specified. If the values do not match, the
722
- # Blob service returns status code 412 (Precondition Failed).
723
- # * +:dest_if_none_match+ - String. An ETag value. Specify an ETag value to write the page only if the destination
724
- # blob's ETag value does not match the value specified. If the values are
725
- # identical, the Blob service returns status code 412 (Precondition Failed).
726
- # * +:timeout+ - Integer. A timeout in seconds.
727
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
728
- # in the analytics logs when storage analytics logging is enabled.
729
- # * +:lease_id+ - String. Required if the destination blob has an active lease. The lease ID specified for
730
- # this header must match the lease ID of the destination blob. If the request does not include
731
- # the lease ID or it is not valid, the operation fails with status code 412 (Precondition Failed).
732
- # If this header is specified and the destination blob does not currently have an active lease,
733
- # the operation will also fail with status code 412 (Precondition Failed).
734
- # In version 2012-02-12 and newer, this value must specify an active, infinite lease for a
735
- # leased blob. A finite-duration lease ID fails with 412 (Precondition Failed).
736
- #
737
- # See http://msdn.microsoft.com/en-us/library/azure/dd894037.aspx
738
- #
739
- # Returns a tuple of (copy_id, copy_status).
740
- #
741
- # * +copy_id+ - String identifier for this copy operation. Use with get_blob or get_blob_properties to check
742
- # the status of this copy operation, or pass to abort_copy_blob to abort a pending copy.
743
- # * +copy_status+ - String. The state of the copy operation, with these values:
744
- # "success" - The copy completed successfully.
745
- # "pending" - The copy is in progress.
746
- #
747
- def copy_blob_from_uri(destination_container, destination_blob, source_uri, options = {})
748
- query = {}
749
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
750
-
751
- uri = blob_uri(destination_container, destination_blob, query)
752
- headers = {}
753
- StorageService.with_header headers, "x-ms-copy-source", source_uri
754
-
755
- unless options.empty?
756
- add_blob_conditional_headers options, headers
757
- StorageService.add_metadata_to_headers options[:metadata], headers
758
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
759
- end
760
-
761
- response = call(:put, uri, nil, headers, options)
762
- return response.headers["x-ms-copy-id"], response.headers["x-ms-copy-status"]
763
- end
764
-
765
- # Public: Copies a source blob to a destination blob within the same storage account.
766
- #
767
- # ==== Attributes
768
- #
769
- # * +destination_container+ - String. The destination container name to copy to.
770
- # * +destination_blob+ - String. The destination blob name to copy to.
771
- # * +source_container+ - String. The source container name to copy from.
772
- # * +source_blob+ - String. The source blob name to copy from.
773
- # * +options+ - Hash. Optional parameters.
774
- #
775
- # ==== Options
776
- #
777
- # Accepted key/value pairs in options parameter are:
778
- # * +:source_snapshot+ - String. A snapshot id for the source blob
779
- # * +:metadata+ - Hash. Custom metadata values to store with the copy. If this parameter is not
780
- # specified, the operation will copy the source blob metadata to the destination
781
- # blob. If this parameter is specified, the destination blob is created with the
782
- # specified metadata, and metadata is not copied from the source blob.
783
- # * +:source_if_modified_since+ - String. A DateTime value. Specify this option to write the page only if the source blob
784
- # has been modified since the specified date/time. If the blob has not been
785
- # modified, the Blob service returns status code 412 (Precondition Failed).
786
- # * +:source_if_unmodified_since+ - String. A DateTime value. Specify this option to write the page only if the source blob
787
- # has not been modified since the specified date/time. If the blob has been
788
- # modified, the Blob service returns status code 412 (Precondition Failed).
789
- # * +:source_if_match+ - String. An ETag value. Specify an ETag value to write the page only if the source blob's
790
- # ETag value matches the value specified. If the values do not match, the Blob
791
- # service returns status code 412 (Precondition Failed).
792
- # * +:source_if_none_match+ - String. An ETag value. Specify an ETag value to write the page only if the source blob's
793
- # ETag value does not match the value specified. If the values are identical, the
794
- # Blob service returns status code 412 (Precondition Failed).
795
- # * +:dest_if_modified_since+ - String. A DateTime value. Specify this option to write the page only if the destination
796
- # blob has been modified since the specified date/time. If the blob has not been
797
- # modified, the Blob service returns status code 412 (Precondition Failed).
798
- # * +:dest_if_unmodified_since+ - String. A DateTime value. Specify this option to write the page only if the destination
799
- # blob has not been modified since the specified date/time. If the blob has been
800
- # modified, the Blob service returns status code 412 (Precondition Failed).
801
- # * +:dest_if_match+ - String. An ETag value. Specify an ETag value to write the page only if the destination
802
- # blob's ETag value matches the value specified. If the values do not match, the
803
- # Blob service returns status code 412 (Precondition Failed).
804
- # * +:dest_if_none_match+ - String. An ETag value. Specify an ETag value to write the page only if the destination
805
- # blob's ETag value does not match the value specified. If the values are
806
- # identical, the Blob service returns status code 412 (Precondition Failed).
807
- # * +:timeout+ - Integer. A timeout in seconds.
808
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
809
- # in the analytics logs when storage analytics logging is enabled.
810
- # * +:lease_id+ - String. Required if the destination blob has an active lease. The lease ID specified for
811
- # this header must match the lease ID of the destination blob. If the request does not include
812
- # the lease ID or it is not valid, the operation fails with status code 412 (Precondition Failed).
813
- # If this header is specified and the destination blob does not currently have an active lease,
814
- # the operation will also fail with status code 412 (Precondition Failed).
815
- # In version 2012-02-12 and newer, this value must specify an active, infinite lease for a
816
- # leased blob. A finite-duration lease ID fails with 412 (Precondition Failed).
817
- #
818
- # See http://msdn.microsoft.com/en-us/library/azure/dd894037.aspx
819
- #
820
- # Returns a tuple of (copy_id, copy_status).
821
- #
822
- # * +copy_id+ - String identifier for this copy operation. Use with get_blob or get_blob_properties to check
823
- # the status of this copy operation, or pass to abort_copy_blob to abort a pending copy.
824
- # * +copy_status+ - String. The state of the copy operation, with these values:
825
- # "success" - The copy completed successfully.
826
- # "pending" - The copy is in progress.
827
- #
828
- def copy_blob(destination_container, destination_blob, source_container, source_blob, options = {})
829
- source_blob_uri = blob_uri(source_container, source_blob, options[:source_snapshot] ? { "snapshot" => options[:source_snapshot] } : {}).to_s
830
-
831
- return copy_blob_from_uri(destination_container, destination_blob, source_blob_uri, options)
832
- end
833
-
834
- # Public: Aborts a pending Copy Blob operation and leaves a destination blob with zero length and full metadata.
835
- #
836
- # ==== Attributes
837
- #
838
- # * +container+ - String. The destination container name.
839
- # * +blob+ - String. The destination blob name.
840
- # * +copy_id+ - String. The copy identifier returned in the copy blob operation.
841
- # * +options+ - Hash. Optional parameters.
842
- #
843
- # ==== Options
844
- #
845
- # Accepted key/value pairs in options parameter are:
846
- # * +:lease_id+ - String. The lease id if the destination blob has an active infinite lease
847
- # * +:timeout+ - Integer. A timeout in seconds.
848
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
849
- # in the analytics logs when storage analytics logging is enabled.
850
- #
851
- # See https://msdn.microsoft.com/en-us/library/azure/jj159098.aspx
852
- #
853
- # Returns nil on success
854
- def abort_copy_blob(container, blob, copy_id, options = {})
855
- query = { "comp" => "copy" }
856
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
857
- StorageService.with_query query, "copyid", copy_id
858
-
859
- uri = blob_uri(container, blob, query);
860
- headers = {}
861
- StorageService.with_header headers, "x-ms-copy-action", "abort";
862
-
863
- unless options.empty?
864
- StorageService.with_header headers, "x-ms-lease-id", options[:lease_id]
865
- end
866
-
867
- call(:put, uri, nil, headers, options)
868
- nil
869
- end
870
-
871
- # Public: Deletes a blob or blob snapshot.
872
- #
873
- # ==== Attributes
874
- #
875
- # * +container+ - String. The container name.
876
- # * +blob+ - String. The blob name.
877
- # * +options+ - Hash. Optional parameters.
878
- #
879
- # ==== Options
880
- #
881
- # Accepted key/value pairs in options parameter are:
882
- # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
883
- # retrieve information from. (optional)
884
- # * +:delete_snapshots+ - Symbol. Used to specify the scope of the delete operation for snapshots.
885
- # This parameter is ignored if a blob does not have snapshots, or if a
886
- # snapshot is specified in the snapshot parameter. (optional)
887
- #
888
- # Possible values include:
889
- # * +:only+ - Deletes only the snapshots for the blob, but leaves the blob
890
- # * +:include+ - Deletes the blob and all of the snapshots for the blob
891
- # * +:timeout+ - Integer. A timeout in seconds.
892
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
893
- # in the analytics logs when storage analytics logging is enabled.
894
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create the blob snapshot
895
- # only if the blob has been modified since the specified date/time. If the blob has not been modified,
896
- # the Blob service returns status code 412 (Precondition Failed).
897
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create the blob snapshot
898
- # only if the blob has not been modified since the specified date/time. If the blob has been modified,
899
- # the Blob service returns status code 412 (Precondition Failed).
900
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create the blob snapshot
901
- # only if the blob's ETag value matches the value specified. If the values do not match,
902
- # the Blob service returns status code 412 (Precondition Failed).
903
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create the blob snapshot
904
- # only if the blob's ETag value does not match the value specified. If the values are identical,
905
- # the Blob service returns status code 412 (Precondition Failed).
906
- # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an
907
- # active lease, specify the valid lease ID for this header. If a valid lease ID is not specified
908
- # on the request, the operation will fail with status code 403 (Forbidden).
909
- #
910
- # See http://msdn.microsoft.com/en-us/library/azure/dd179440.aspx
911
- #
912
- # Returns nil on success
913
- def delete_blob(container, blob, options = {})
914
- query = {}
915
- StorageService.with_query query, "snapshot", options[:snapshot]
916
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
917
-
918
- uri = blob_uri(container, blob, query)
919
-
920
- options[:delete_snapshots] = :include unless options[:delete_snapshots]
921
-
922
- headers = {}
923
- StorageService.with_header headers, "x-ms-delete-snapshots", options[:delete_snapshots].to_s if options[:delete_snapshots] && options[:snapshot] == nil
924
- add_blob_conditional_headers options, headers
925
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
926
-
927
- call(:delete, uri, nil, headers, options)
928
- nil
929
- end
930
- end
931
- end
1
+ # frozen_string_literal: true
2
+
3
+ #-------------------------------------------------------------------------
4
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
5
+ #
6
+ # The MIT License(MIT)
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files(the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions :
14
+
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #--------------------------------------------------------------------------
26
+
27
+ module Azure::Storage
28
+ module Blob
29
+ include Azure::Storage::Common::Service
30
+
31
+ class Blob
32
+ def initialize
33
+ @properties = {}
34
+ @metadata = {}
35
+ yield self if block_given?
36
+ end
37
+
38
+ attr_accessor :name
39
+ attr_accessor :snapshot
40
+ attr_accessor :properties
41
+ attr_accessor :metadata
42
+ attr_accessor :encrypted
43
+ end
44
+
45
+ # Public: Reads or downloads a blob from the system, including its metadata and properties.
46
+ #
47
+ # ==== Attributes
48
+ #
49
+ # * +container+ - String. The container name.
50
+ # * +blob+ - String. The blob name.
51
+ # * +options+ - Hash. Optional parameters.
52
+ #
53
+ # ==== Options
54
+ #
55
+ # Accepted key/value pairs in options parameter are:
56
+ # * +:start_range+ - Integer. Position of first byte of first page. (optional)
57
+ # * +:end_range+ - Integer. Position of last byte of of last page. (optional)
58
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
59
+ # retrieve information from. (optional)
60
+ # * +:get_content_md5+ - Boolean. Return the MD5 hash for the range. This option only valid if
61
+ # start_range and end_range are specified. (optional)
62
+ # * +:timeout+ - Integer. A timeout in seconds.
63
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
64
+ # in the analytics logs when storage analytics logging is enabled.
65
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
66
+ # which location the request should be sent to.
67
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to get the blob
68
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
69
+ # the Blob service returns status code 412 (Precondition Failed).
70
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to get the blob
71
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
72
+ # the Blob service returns status code 412 (Precondition Failed).
73
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob
74
+ # only if the blob's ETag value matches the value specified. If the values do not match,
75
+ # the Blob service returns status code 412 (Precondition Failed).
76
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob
77
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
78
+ # the Blob service returns status code 412 (Precondition Failed).
79
+ # * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
80
+ # following conditions are met:
81
+ # - The blob's lease is currently active.
82
+ # - The lease ID specified in the request matches that of the blob.
83
+ # If this header is specified and both of these conditions are not met, the request will fail
84
+ # and the Get Blob operation will fail with status code 412 (Precondition Failed).
85
+ #
86
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179440.aspx
87
+ #
88
+ # Returns a blob and the blob body
89
+ def get_blob(container, blob, options = {})
90
+ query = {}
91
+ StorageService.with_query query, "snapshot", options[:snapshot]
92
+ StorageService.with_query query, "timeout", options[:timeout] if options[:timeout]
93
+
94
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
95
+ uri = blob_uri(container, blob, query, options)
96
+
97
+ headers = {}
98
+ options[:start_range] = 0 if options[:end_range] && (not options[:start_range])
99
+ if options[:start_range]
100
+ StorageService.with_header headers, "x-ms-range", "bytes=#{options[:start_range]}-#{options[:end_range]}"
101
+ StorageService.with_header headers, "x-ms-range-get-content-md5", "true" if options[:get_content_md5]
102
+ end
103
+ add_blob_conditional_headers options, headers
104
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
105
+
106
+ response = call(:get, uri, nil, headers, options)
107
+ result = Serialization.blob_from_headers(response.headers)
108
+ result.name = blob unless result.name
109
+
110
+ return result, response.body
111
+ end
112
+
113
+ # Public: Returns all properties and metadata on the blob.
114
+ #
115
+ # ==== Attributes
116
+ #
117
+ # * +container+ - String. The container name.
118
+ # * +blob+ - String. The blob name.
119
+ # * +options+ - Hash. Optional parameters.
120
+ #
121
+ # ==== Options
122
+ #
123
+ # Accepted key/value pairs in options parameter are:
124
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
125
+ # retrieve information from.
126
+ # * +:timeout+ - Integer. A timeout in seconds.
127
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
128
+ # in the analytics logs when storage analytics logging is enabled.
129
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
130
+ # which location the request should be sent to.
131
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to get the blob properties
132
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
133
+ # the Blob service returns status code 412 (Precondition Failed).
134
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to get the blob properties
135
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
136
+ # the Blob service returns status code 412 (Precondition Failed).
137
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob properties
138
+ # only if the blob's ETag value matches the value specified. If the values do not match,
139
+ # the Blob service returns status code 412 (Precondition Failed).
140
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob properties
141
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
142
+ # the Blob service returns status code 412 (Precondition Failed).
143
+ # * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
144
+ # following conditions are met:
145
+ #
146
+ # - The blob's lease is currently active.
147
+ # - The lease ID specified in the request matches that of the blob.
148
+ #
149
+ # If this header is specified and both of these conditions are not met, the request will fail
150
+ # and the Get Blob Properties operation will fail with status code 412 (Precondition Failed).
151
+ #
152
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179394.aspx
153
+ #
154
+ # Returns the blob properties with a Blob instance
155
+ def get_blob_properties(container, blob, options = {})
156
+ query = {}
157
+ StorageService.with_query query, "snapshot", options[:snapshot]
158
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
159
+
160
+ headers = {}
161
+ unless options.empty?
162
+ add_blob_conditional_headers options, headers
163
+ end
164
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
165
+
166
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
167
+ uri = blob_uri(container, blob, query, options)
168
+
169
+ response = call(:head, uri, nil, headers, options)
170
+
171
+ result = Serialization.blob_from_headers(response.headers)
172
+
173
+ result.name = blob
174
+ result.snapshot = options[:snapshot]
175
+
176
+ result
177
+ end
178
+
179
+ # Public: Sets system properties defined for a blob.
180
+ #
181
+ # ==== Attributes
182
+ #
183
+ # * +container+ - String. The container name.
184
+ # * +blob+ - String. The blob name.
185
+ # * +options+ - Hash. Optional parameters.
186
+ #
187
+ # ==== Options
188
+ #
189
+ # Accepted key/value pairs in options parameter are:
190
+ # * +:content_type+ - String. Content type for the blob. Will be saved with blob.
191
+ # * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
192
+ # * +:content_language+ - String. Content language for the blob. Will be saved with blob.
193
+ # * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
194
+ # * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
195
+ # * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
196
+ # and also can be used to attach additional metadata
197
+ # * +:content_length+ - Integer. Resizes a page blob to the specified size. If the specified
198
+ # value is less than the current size of the blob, then all pages above
199
+ # the specified value are cleared. This property cannot be used to change
200
+ # the size of a block blob. Setting this property for a block blob returns
201
+ # status code 400 (Bad Request).
202
+ # * +:sequence_number_action+ - Symbol. This property indicates how the service should modify the sequence
203
+ # number for the blob. Required if :sequence_number is used. This property
204
+ # applies to page blobs only.
205
+ #
206
+ # Specify one of the following options for this property:
207
+ #
208
+ # * +:max+ - Sets the sequence number to be the higher of the value included with
209
+ # the request and the value currently stored for the blob.
210
+ # * +:update+ - Sets the sequence number to the value included with the request.
211
+ # * +:increment+ - Increments the value of the sequence number by 1. If specifying this
212
+ # option, do not include the sequence_number option; doing so will return
213
+ # status code 400 (Bad Request).
214
+ #
215
+ # * +:sequence_number+ - Integer. This property sets the blob's sequence number. The sequence number is a
216
+ # user-controlled property that you can use to track requests and manage concurrency
217
+ # issues. Required if the :sequence_number_action option is set to :max or :update.
218
+ # This property applies to page blobs only.
219
+ #
220
+ # Use this together with the :sequence_number_action to update the blob's sequence
221
+ # number, either to the specified value or to the higher of the values specified with
222
+ # the request or currently stored with the blob.
223
+ #
224
+ # This header should not be specified if :sequence_number_action is set to :increment;
225
+ # in this case the service automatically increments the sequence number by one.
226
+ #
227
+ # To set the sequence number to a value of your choosing, this property must be specified
228
+ # together with :sequence_number_action
229
+ # * +:timeout+ - Integer. A timeout in seconds.
230
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
231
+ # in the analytics logs when storage analytics logging is enabled.
232
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
233
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
234
+ # the Blob service returns status code 412 (Precondition Failed).
235
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
236
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
237
+ # the Blob service returns status code 412 (Precondition Failed).
238
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
239
+ # only if the blob's ETag value matches the value specified. If the values do not match,
240
+ # the Blob service returns status code 412 (Precondition Failed).
241
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
242
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
243
+ # the Blob service returns status code 412 (Precondition Failed).
244
+ # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active
245
+ # lease, specify the valid lease ID for this header.
246
+ #
247
+ # Remarks:
248
+ #
249
+ # The semantics for updating a blob's properties are as follows:
250
+ #
251
+ # * A page blob's sequence number is updated only if the request meets either of the following conditions:
252
+ #
253
+ # * The :sequence_number_action property is set to :max or :update, and a value for :sequence_number is also set.
254
+ # * The :sequence_number_action property is set to :increment, indicating that the service should increment
255
+ # the sequence number by one.
256
+ #
257
+ # * The size of the page blob is modified only if a value for :content_length is specified.
258
+ #
259
+ # * If :sequence_number and/or :content_length are the only properties specified, then the other properties of the blob
260
+ # will NOT be modified.
261
+ #
262
+ # * If any one or more of the following properties are set, then all of these properties are set together. If a value is
263
+ # not provided for a given property when at least one of the properties listed below is set, then that property will be
264
+ # cleared for the blob.
265
+ #
266
+ # * :cache_control
267
+ # * :content_type
268
+ # * :content_md5
269
+ # * :content_encoding
270
+ # * :content_language
271
+ # * :content_disposition
272
+ #
273
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691966.aspx
274
+ #
275
+ # Returns nil on success.
276
+ def set_blob_properties(container, blob, options = {})
277
+ query = { "comp" => "properties" }
278
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
279
+ uri = blob_uri(container, blob, query)
280
+
281
+ headers = {}
282
+
283
+ unless options.empty?
284
+ StorageService.with_header headers, "x-ms-blob-content-type", options[:content_type]
285
+ StorageService.with_header headers, "x-ms-blob-content-encoding", options[:content_encoding]
286
+ StorageService.with_header headers, "x-ms-blob-content-language", options[:content_language]
287
+ StorageService.with_header headers, "x-ms-blob-content-md5", options[:content_md5]
288
+ StorageService.with_header headers, "x-ms-blob-cache-control", options[:cache_control]
289
+ StorageService.with_header headers, "x-ms-blob-content-length", options[:content_length] if options[:content_length]
290
+ StorageService.with_header headers, "x-ms-blob-content-disposition", options[:content_disposition]
291
+
292
+ if options[:sequence_number_action]
293
+ StorageService.with_header headers, "x-ms-sequence-number-action", options[:sequence_number_action]
294
+
295
+ if options[:sequence_number_action].to_s != "increment" && options[:sequence_number]
296
+ StorageService.with_header headers, "x-ms-blob-sequence-number", options[:sequence_number]
297
+ end
298
+ end
299
+
300
+ add_blob_conditional_headers options, headers
301
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
302
+ end
303
+ call(:put, uri, nil, headers, options)
304
+ nil
305
+ end
306
+
307
+ # Public: Returns metadata on the blob.
308
+ #
309
+ # ==== Attributes
310
+ #
311
+ # * +container+ - String. The container name.
312
+ # * +blob+ - String. The blob name.
313
+ # * +options+ - Hash. Optional parameters.
314
+ #
315
+ # ==== Options
316
+ #
317
+ # Accepted key/value pairs in options parameter are:
318
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
319
+ # retrieve information from.
320
+ # * +:timeout+ - Integer. A timeout in seconds.
321
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
322
+ # in the analytics logs when storage analytics logging is enabled.
323
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
324
+ # which location the request should be sent to.
325
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to get the blob metadata
326
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
327
+ # the Blob service returns status code 412 (Precondition Failed).
328
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to get the blob metadata
329
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
330
+ # the Blob service returns status code 412 (Precondition Failed).
331
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob metadata
332
+ # only if the blob's ETag value matches the value specified. If the values do not match,
333
+ # the Blob service returns status code 412 (Precondition Failed).
334
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to get the blob metadata
335
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
336
+ # the Blob service returns status code 412 (Precondition Failed).
337
+ # * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
338
+ # following conditions are met:
339
+ #
340
+ # - The blob's lease is currently active.
341
+ # - The lease ID specified in the request matches that of the blob.
342
+ #
343
+ # If this header is specified and both of these conditions are not met, the request will fail
344
+ # and the Get Blob Metadata operation will fail with status code 412 (Precondition Failed).
345
+ #
346
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179350.aspx
347
+ #
348
+ # Returns a Blob
349
+ def get_blob_metadata(container, blob, options = {})
350
+ query = { "comp" => "metadata" }
351
+ StorageService.with_query query, "snapshot", options[:snapshot]
352
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
353
+
354
+ headers = {}
355
+ unless options.empty?
356
+ add_blob_conditional_headers options, headers
357
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
358
+ end
359
+
360
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
361
+ uri = blob_uri(container, blob, query, options)
362
+ response = call(:get, uri, nil, headers, options)
363
+ result = Serialization.blob_from_headers(response.headers)
364
+
365
+ result.name = blob
366
+ result.snapshot = options[:snapshot]
367
+
368
+ result
369
+ end
370
+
371
+ # Public: Sets metadata headers on the blob.
372
+ #
373
+ # ==== Attributes
374
+ #
375
+ # * +container+ - String. The container name.
376
+ # * +blob+ - String. The blob name.
377
+ # * +metadata+ - Hash. The custom metadata.
378
+ # * +options+ - Hash. Optional parameters.
379
+ #
380
+ # ==== Options
381
+ #
382
+ # Accepted key/value pairs in options parameter are:
383
+ # * +:timeout+ - Integer. A timeout in seconds.
384
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
385
+ # in the analytics logs when storage analytics logging is enabled.
386
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to set the blob metadata
387
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
388
+ # the Blob service returns status code 412 (Precondition Failed).
389
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to set the blob metadata
390
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
391
+ # the Blob service returns status code 412 (Precondition Failed).
392
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob metadata
393
+ # only if the blob's ETag value matches the value specified. If the values do not match,
394
+ # the Blob service returns status code 412 (Precondition Failed).
395
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob metadata
396
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
397
+ # the Blob service returns status code 412 (Precondition Failed).
398
+ # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active
399
+ # lease, specify the valid lease ID for this header.
400
+ #
401
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179414.aspx
402
+ #
403
+ # Returns nil on success.
404
+ def set_blob_metadata(container, blob, metadata, options = {})
405
+ query = { "comp" => "metadata" }
406
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
407
+
408
+ uri = blob_uri(container, blob, query)
409
+
410
+ headers = {}
411
+ StorageService.add_metadata_to_headers metadata, headers
412
+ unless options.empty?
413
+ add_blob_conditional_headers options, headers
414
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
415
+ end
416
+
417
+ call(:put, uri, nil, headers, options)
418
+ nil
419
+ end
420
+
421
+ # Public: Establishes an exclusive write lock on a blob. The lock duration can be 15 to 60 seconds, or can be infinite.
422
+ # To write to a locked blob, a client must provide a lease ID.
423
+ #
424
+ # ==== Attributes
425
+ #
426
+ # * +container+ - String. The container name.
427
+ # * +blob+ - String. The blob name.
428
+ # * +options+ - Hash. Optional parameters.
429
+ #
430
+ # ==== Options
431
+ #
432
+ # Accepted key/value pairs in options parameter are:
433
+ # * +:duration+ - Integer. Default -1. Specifies the duration of the lease, in seconds, or negative one (-1)
434
+ # for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. (optional)
435
+ # * +:proposed_lease_id+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
436
+ # if the proposed lease ID is not in the correct format. (optional)
437
+ # * +:timeout+ - Integer. A timeout in seconds.
438
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
439
+ # in the analytics logs when storage analytics logging is enabled.
440
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
441
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
442
+ # the Blob service returns status code 412 (Precondition Failed).
443
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
444
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
445
+ # the Blob service returns status code 412 (Precondition Failed).
446
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
447
+ # only if the blob's ETag value matches the value specified. If the values do not match,
448
+ # the Blob service returns status code 412 (Precondition Failed).
449
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
450
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
451
+ # the Blob service returns status code 412 (Precondition Failed).
452
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
453
+ # in cross-origin resource sharing headers on the response.
454
+ #
455
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
456
+ #
457
+ # Returns a String of the new unique lease id. While the lease is active, you must include the lease ID with any request
458
+ # to write to the blob, or to renew, change, or release the lease.
459
+ #
460
+ def acquire_blob_lease(container, blob, options = {})
461
+ acquire_lease container, blob, options
462
+ end
463
+
464
+ # Public: Renews the lease. The lease can be renewed if the lease ID specified on the request matches that
465
+ # associated with the blob. Note that the lease may be renewed even if it has expired as long as the blob
466
+ # has not been modified or leased again since the expiration of that lease. When you renew a lease, the
467
+ # lease duration clock resets.
468
+ #
469
+ # ==== Attributes
470
+ #
471
+ # * +container+ - String. The container name.
472
+ # * +blob+ - String. The blob name.
473
+ # * +lease+ - String. The lease id
474
+ # * +options+ - Hash. Optional parameters.
475
+ #
476
+ # ==== Options
477
+ #
478
+ # Accepted key/value pairs in options parameter are:
479
+ # * +:timeout+ - Integer. A timeout in seconds.
480
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
481
+ # in the analytics logs when storage analytics logging is enabled.
482
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
483
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
484
+ # the Blob service returns status code 412 (Precondition Failed).
485
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
486
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
487
+ # the Blob service returns status code 412 (Precondition Failed).
488
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
489
+ # only if the blob's ETag value matches the value specified. If the values do not match,
490
+ # the Blob service returns status code 412 (Precondition Failed).
491
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
492
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
493
+ # the Blob service returns status code 412 (Precondition Failed).
494
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
495
+ # in cross-origin resource sharing headers on the response.
496
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
497
+ #
498
+ # Returns the renewed lease id
499
+ def renew_blob_lease(container, blob, lease, options = {})
500
+ renew_lease container, blob, lease, options
501
+ end
502
+
503
+ # Public: Change the lease ID.
504
+ #
505
+ # ==== Attributes
506
+ #
507
+ # * +container+ - String. The container name.
508
+ # * +blob+ - String. The blob name.
509
+ # * +lease+ - String. The existing lease id.
510
+ # * +proposed_lease+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
511
+ # if the proposed lease ID is not in the correct format. (optional).
512
+ # * +options+ - Hash. Optional parameters.
513
+ #
514
+ # ==== Options
515
+ #
516
+ # Accepted key/value pairs in options parameter are:
517
+ # * +:timeout+ - Integer. A timeout in seconds.
518
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
519
+ # in the analytics logs when storage analytics logging is enabled.
520
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to change the lease
521
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
522
+ # the Blob service returns status code 412 (Precondition Failed).
523
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to change the lease
524
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
525
+ # the Blob service returns status code 412 (Precondition Failed).
526
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
527
+ # only if the blob's ETag value matches the value specified. If the values do not match,
528
+ # the Blob service returns status code 412 (Precondition Failed).
529
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
530
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
531
+ # the Blob service returns status code 412 (Precondition Failed).
532
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
533
+ # in cross-origin resource sharing headers on the response.
534
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
535
+ #
536
+ # Returns the changed lease id
537
+ def change_blob_lease(container, blob, lease, proposed_lease, options = {})
538
+ change_lease container, blob, lease, proposed_lease, options
539
+ end
540
+
541
+ # Public: Releases the lease. The lease may be released if the lease ID specified on the request matches that
542
+ # associated with the blob. Releasing the lease allows another client to immediately acquire the lease for
543
+ # the blob as soon as the release is complete.
544
+ #
545
+ # ==== Attributes
546
+ #
547
+ # * +container+ - String. The container name.
548
+ # * +blob+ - String. The blob name.
549
+ # * +lease+ - String. The lease id.
550
+ # * +options+ - Hash. Optional parameters.
551
+ #
552
+ # ==== Options
553
+ #
554
+ # Accepted key/value pairs in options parameter are:
555
+ # * +:timeout+ - Integer. A timeout in seconds.
556
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
557
+ # in the analytics logs when storage analytics logging is enabled.
558
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to release the lease
559
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
560
+ # the Blob service returns status code 412 (Precondition Failed).
561
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to release the lease
562
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
563
+ # the Blob service returns status code 412 (Precondition Failed).
564
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
565
+ # only if the blob's ETag value matches the value specified. If the values do not match,
566
+ # the Blob service returns status code 412 (Precondition Failed).
567
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
568
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
569
+ # the Blob service returns status code 412 (Precondition Failed).
570
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
571
+ # in cross-origin resource sharing headers on the response.
572
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
573
+ #
574
+ # Returns nil on success
575
+ def release_blob_lease(container, blob, lease, options = {})
576
+ release_lease container, blob, lease, options
577
+ end
578
+
579
+ # Public: Breaks the lease, if the blob has an active lease. Once a lease is broken, it cannot be renewed. Any
580
+ # authorized request can break the lease; the request is not required to specify a matching lease ID. When a
581
+ # lease is broken, the lease break period is allowed to elapse, during which time no lease operation except
582
+ # break and release can be performed on the blob. When a lease is successfully broken, the response indicates
583
+ # the interval in seconds until a new lease can be acquired.
584
+ #
585
+ # A lease that has been broken can also be released, in which case another client may immediately acquire the
586
+ # lease on the blob.
587
+ #
588
+ # ==== Attributes
589
+ #
590
+ # * +container+ - String. The container name.
591
+ # * +blob+ - String. The blob name.
592
+ # * +options+ - Hash. Optional parameters.
593
+ #
594
+ # ==== Options
595
+ #
596
+ # Accepted key/value pairs in options parameter are:
597
+ # * +:break_period+ - Integer. The proposed duration of seconds that the lease should continue before it is
598
+ # broken, between 0 and 60 seconds. This break period is only used if it is shorter than
599
+ # the time remaining on the lease. If longer, the time remaining on the lease is used. A
600
+ # new lease will not be available before the break period has expired, but the lease may
601
+ # be held for longer than the break period.
602
+ #
603
+ # If this option is not used, a fixed-duration lease breaks after the remaining lease
604
+ # period elapses, and an infinite lease breaks immediately.
605
+ # * +:timeout+ - Integer. A timeout in seconds.
606
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
607
+ # in the analytics logs when storage analytics logging is enabled.
608
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to break the lease
609
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
610
+ # the Blob service returns status code 412 (Precondition Failed).
611
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to break the lease
612
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
613
+ # the Blob service returns status code 412 (Precondition Failed).
614
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
615
+ # only if the blob's ETag value matches the value specified. If the values do not match,
616
+ # the Blob service returns status code 412 (Precondition Failed).
617
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
618
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
619
+ # the Blob service returns status code 412 (Precondition Failed).
620
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
621
+ # in cross-origin resource sharing headers on the response.
622
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
623
+ #
624
+ # Returns an Integer of the remaining lease time. This value is the approximate time remaining in the lease
625
+ # period, in seconds. This header is returned only for a successful request to break the lease. If the break
626
+ # is immediate, 0 is returned.
627
+ def break_blob_lease(container, blob, options = {})
628
+ break_lease container, blob, options
629
+ end
630
+
631
+ # Public: Creates a snapshot of a blob.
632
+ #
633
+ # ==== Attributes
634
+ #
635
+ # * +container+ - String. The container name.
636
+ # * +blob+ - String. The blob name.
637
+ # * +options+ - Hash. Optional parameters.
638
+ #
639
+ # ==== Options
640
+ #
641
+ # Accepted key/value pairs in options parameter are:
642
+ # * +:metadata+ - Hash. Custom metadata values to store with the blob snapshot.
643
+ # * +:timeout+ - Integer. A timeout in seconds.
644
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
645
+ # in the analytics logs when storage analytics logging is enabled.
646
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create the blob snapshot
647
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
648
+ # the Blob service returns status code 412 (Precondition Failed).
649
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create the blob snapshot
650
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
651
+ # the Blob service returns status code 412 (Precondition Failed).
652
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create the blob snapshot
653
+ # only if the blob's ETag value matches the value specified. If the values do not match,
654
+ # the Blob service returns status code 412 (Precondition Failed).
655
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create the blob snapshot
656
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
657
+ # the Blob service returns status code 412 (Precondition Failed).
658
+ # * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
659
+ # following conditions are met:
660
+ # - The blob's lease is currently active.
661
+ # - The lease ID specified in the request matches that of the blob.
662
+ # If this header is specified and both of these conditions are not met, the request will fail
663
+ # and the Snapshot Blob operation will fail with status code 412 (Precondition Failed).
664
+ #
665
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691971.aspx
666
+ #
667
+ # Returns the snapshot DateTime value
668
+ def create_blob_snapshot(container, blob, options = {})
669
+ query = { "comp" => "snapshot" }
670
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
671
+
672
+ uri = blob_uri(container, blob, query)
673
+
674
+ headers = {}
675
+ unless options.empty?
676
+ StorageService.add_metadata_to_headers(options[:metadata], headers)
677
+ add_blob_conditional_headers(options, headers)
678
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
679
+ end
680
+
681
+ response = call(:put, uri, nil, headers, options)
682
+
683
+ response.headers["x-ms-snapshot"]
684
+ end
685
+
686
+ # Public: Copies a source blob or file to a destination blob.
687
+ #
688
+ # ==== Attributes
689
+ #
690
+ # * +destination_container+ - String. The destination container name to copy to.
691
+ # * +destination_blob+ - String. The destination blob name to copy to.
692
+ # * +source_uri+ - String. The source blob or file URI to copy from.
693
+ # * +options+ - Hash. Optional parameters.
694
+ #
695
+ # ==== Options
696
+ #
697
+ # Accepted key/value pairs in options parameter are:
698
+ # * +:source_snapshot+ - String. A snapshot id for the source blob
699
+ # * +:metadata+ - Hash. Custom metadata values to store with the copy. If this parameter is not
700
+ # specified, the operation will copy the source blob metadata to the destination
701
+ # blob. If this parameter is specified, the destination blob is created with the
702
+ # specified metadata, and metadata is not copied from the source blob.
703
+ # * +:source_if_modified_since+ - String. A DateTime value. Specify this option to write the page only if the source blob
704
+ # has been modified since the specified date/time. If the blob has not been
705
+ # modified, the Blob service returns status code 412 (Precondition Failed).
706
+ # * +:source_if_unmodified_since+ - String. A DateTime value. Specify this option to write the page only if the source blob
707
+ # has not been modified since the specified date/time. If the blob has been
708
+ # modified, the Blob service returns status code 412 (Precondition Failed).
709
+ # * +:source_if_match+ - String. An ETag value. Specify an ETag value to write the page only if the source blob's
710
+ # ETag value matches the value specified. If the values do not match, the Blob
711
+ # service returns status code 412 (Precondition Failed).
712
+ # * +:source_if_none_match+ - String. An ETag value. Specify an ETag value to write the page only if the source blob's
713
+ # ETag value does not match the value specified. If the values are identical, the
714
+ # Blob service returns status code 412 (Precondition Failed).
715
+ # * +:dest_if_modified_since+ - String. A DateTime value. Specify this option to write the page only if the destination
716
+ # blob has been modified since the specified date/time. If the blob has not been
717
+ # modified, the Blob service returns status code 412 (Precondition Failed).
718
+ # * +:dest_if_unmodified_since+ - String. A DateTime value. Specify this option to write the page only if the destination
719
+ # blob has not been modified since the specified date/time. If the blob has been
720
+ # modified, the Blob service returns status code 412 (Precondition Failed).
721
+ # * +:dest_if_match+ - String. An ETag value. Specify an ETag value to write the page only if the destination
722
+ # blob's ETag value matches the value specified. If the values do not match, the
723
+ # Blob service returns status code 412 (Precondition Failed).
724
+ # * +:dest_if_none_match+ - String. An ETag value. Specify an ETag value to write the page only if the destination
725
+ # blob's ETag value does not match the value specified. If the values are
726
+ # identical, the Blob service returns status code 412 (Precondition Failed).
727
+ # * +:timeout+ - Integer. A timeout in seconds.
728
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
729
+ # in the analytics logs when storage analytics logging is enabled.
730
+ # * +:lease_id+ - String. Required if the destination blob has an active lease. The lease ID specified for
731
+ # this header must match the lease ID of the destination blob. If the request does not include
732
+ # the lease ID or it is not valid, the operation fails with status code 412 (Precondition Failed).
733
+ # If this header is specified and the destination blob does not currently have an active lease,
734
+ # the operation will also fail with status code 412 (Precondition Failed).
735
+ # In version 2012-02-12 and newer, this value must specify an active, infinite lease for a
736
+ # leased blob. A finite-duration lease ID fails with 412 (Precondition Failed).
737
+ #
738
+ # See http://msdn.microsoft.com/en-us/library/azure/dd894037.aspx
739
+ #
740
+ # Returns a tuple of (copy_id, copy_status).
741
+ #
742
+ # * +copy_id+ - String identifier for this copy operation. Use with get_blob or get_blob_properties to check
743
+ # the status of this copy operation, or pass to abort_copy_blob to abort a pending copy.
744
+ # * +copy_status+ - String. The state of the copy operation, with these values:
745
+ # "success" - The copy completed successfully.
746
+ # "pending" - The copy is in progress.
747
+ #
748
+ def copy_blob_from_uri(destination_container, destination_blob, source_uri, options = {})
749
+ query = {}
750
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
751
+
752
+ uri = blob_uri(destination_container, destination_blob, query)
753
+ headers = {}
754
+ StorageService.with_header headers, "x-ms-copy-source", source_uri
755
+
756
+ unless options.empty?
757
+ add_blob_conditional_headers options, headers
758
+ StorageService.add_metadata_to_headers options[:metadata], headers
759
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
760
+ end
761
+
762
+ response = call(:put, uri, nil, headers, options)
763
+ return response.headers["x-ms-copy-id"], response.headers["x-ms-copy-status"]
764
+ end
765
+
766
+ # Public: Copies a source blob to a destination blob within the same storage account.
767
+ #
768
+ # ==== Attributes
769
+ #
770
+ # * +destination_container+ - String. The destination container name to copy to.
771
+ # * +destination_blob+ - String. The destination blob name to copy to.
772
+ # * +source_container+ - String. The source container name to copy from.
773
+ # * +source_blob+ - String. The source blob name to copy from.
774
+ # * +options+ - Hash. Optional parameters.
775
+ #
776
+ # ==== Options
777
+ #
778
+ # Accepted key/value pairs in options parameter are:
779
+ # * +:source_snapshot+ - String. A snapshot id for the source blob
780
+ # * +:metadata+ - Hash. Custom metadata values to store with the copy. If this parameter is not
781
+ # specified, the operation will copy the source blob metadata to the destination
782
+ # blob. If this parameter is specified, the destination blob is created with the
783
+ # specified metadata, and metadata is not copied from the source blob.
784
+ # * +:source_if_modified_since+ - String. A DateTime value. Specify this option to write the page only if the source blob
785
+ # has been modified since the specified date/time. If the blob has not been
786
+ # modified, the Blob service returns status code 412 (Precondition Failed).
787
+ # * +:source_if_unmodified_since+ - String. A DateTime value. Specify this option to write the page only if the source blob
788
+ # has not been modified since the specified date/time. If the blob has been
789
+ # modified, the Blob service returns status code 412 (Precondition Failed).
790
+ # * +:source_if_match+ - String. An ETag value. Specify an ETag value to write the page only if the source blob's
791
+ # ETag value matches the value specified. If the values do not match, the Blob
792
+ # service returns status code 412 (Precondition Failed).
793
+ # * +:source_if_none_match+ - String. An ETag value. Specify an ETag value to write the page only if the source blob's
794
+ # ETag value does not match the value specified. If the values are identical, the
795
+ # Blob service returns status code 412 (Precondition Failed).
796
+ # * +:dest_if_modified_since+ - String. A DateTime value. Specify this option to write the page only if the destination
797
+ # blob has been modified since the specified date/time. If the blob has not been
798
+ # modified, the Blob service returns status code 412 (Precondition Failed).
799
+ # * +:dest_if_unmodified_since+ - String. A DateTime value. Specify this option to write the page only if the destination
800
+ # blob has not been modified since the specified date/time. If the blob has been
801
+ # modified, the Blob service returns status code 412 (Precondition Failed).
802
+ # * +:dest_if_match+ - String. An ETag value. Specify an ETag value to write the page only if the destination
803
+ # blob's ETag value matches the value specified. If the values do not match, the
804
+ # Blob service returns status code 412 (Precondition Failed).
805
+ # * +:dest_if_none_match+ - String. An ETag value. Specify an ETag value to write the page only if the destination
806
+ # blob's ETag value does not match the value specified. If the values are
807
+ # identical, the Blob service returns status code 412 (Precondition Failed).
808
+ # * +:timeout+ - Integer. A timeout in seconds.
809
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
810
+ # in the analytics logs when storage analytics logging is enabled.
811
+ # * +:lease_id+ - String. Required if the destination blob has an active lease. The lease ID specified for
812
+ # this header must match the lease ID of the destination blob. If the request does not include
813
+ # the lease ID or it is not valid, the operation fails with status code 412 (Precondition Failed).
814
+ # If this header is specified and the destination blob does not currently have an active lease,
815
+ # the operation will also fail with status code 412 (Precondition Failed).
816
+ # In version 2012-02-12 and newer, this value must specify an active, infinite lease for a
817
+ # leased blob. A finite-duration lease ID fails with 412 (Precondition Failed).
818
+ #
819
+ # See http://msdn.microsoft.com/en-us/library/azure/dd894037.aspx
820
+ #
821
+ # Returns a tuple of (copy_id, copy_status).
822
+ #
823
+ # * +copy_id+ - String identifier for this copy operation. Use with get_blob or get_blob_properties to check
824
+ # the status of this copy operation, or pass to abort_copy_blob to abort a pending copy.
825
+ # * +copy_status+ - String. The state of the copy operation, with these values:
826
+ # "success" - The copy completed successfully.
827
+ # "pending" - The copy is in progress.
828
+ #
829
+ def copy_blob(destination_container, destination_blob, source_container, source_blob, options = {})
830
+ source_blob_uri = blob_uri(source_container, source_blob, options[:source_snapshot] ? { "snapshot" => options[:source_snapshot] } : {}).to_s
831
+
832
+ return copy_blob_from_uri(destination_container, destination_blob, source_blob_uri, options)
833
+ end
834
+
835
+ # Public: Aborts a pending Copy Blob operation and leaves a destination blob with zero length and full metadata.
836
+ #
837
+ # ==== Attributes
838
+ #
839
+ # * +container+ - String. The destination container name.
840
+ # * +blob+ - String. The destination blob name.
841
+ # * +copy_id+ - String. The copy identifier returned in the copy blob operation.
842
+ # * +options+ - Hash. Optional parameters.
843
+ #
844
+ # ==== Options
845
+ #
846
+ # Accepted key/value pairs in options parameter are:
847
+ # * +:lease_id+ - String. The lease id if the destination blob has an active infinite lease
848
+ # * +:timeout+ - Integer. A timeout in seconds.
849
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
850
+ # in the analytics logs when storage analytics logging is enabled.
851
+ #
852
+ # See https://msdn.microsoft.com/en-us/library/azure/jj159098.aspx
853
+ #
854
+ # Returns nil on success
855
+ def abort_copy_blob(container, blob, copy_id, options = {})
856
+ query = { "comp" => "copy" }
857
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
858
+ StorageService.with_query query, "copyid", copy_id
859
+
860
+ uri = blob_uri(container, blob, query);
861
+ headers = {}
862
+ StorageService.with_header headers, "x-ms-copy-action", "abort";
863
+
864
+ unless options.empty?
865
+ StorageService.with_header headers, "x-ms-lease-id", options[:lease_id]
866
+ end
867
+
868
+ call(:put, uri, nil, headers, options)
869
+ nil
870
+ end
871
+
872
+ # Public: Deletes a blob or blob snapshot.
873
+ #
874
+ # ==== Attributes
875
+ #
876
+ # * +container+ - String. The container name.
877
+ # * +blob+ - String. The blob name.
878
+ # * +options+ - Hash. Optional parameters.
879
+ #
880
+ # ==== Options
881
+ #
882
+ # Accepted key/value pairs in options parameter are:
883
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
884
+ # retrieve information from. (optional)
885
+ # * +:delete_snapshots+ - Symbol. Used to specify the scope of the delete operation for snapshots.
886
+ # This parameter is ignored if a blob does not have snapshots, or if a
887
+ # snapshot is specified in the snapshot parameter. (optional)
888
+ #
889
+ # Possible values include:
890
+ # * +:only+ - Deletes only the snapshots for the blob, but leaves the blob
891
+ # * +:include+ - Deletes the blob and all of the snapshots for the blob
892
+ # * +:timeout+ - Integer. A timeout in seconds.
893
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
894
+ # in the analytics logs when storage analytics logging is enabled.
895
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create the blob snapshot
896
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
897
+ # the Blob service returns status code 412 (Precondition Failed).
898
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create the blob snapshot
899
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
900
+ # the Blob service returns status code 412 (Precondition Failed).
901
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create the blob snapshot
902
+ # only if the blob's ETag value matches the value specified. If the values do not match,
903
+ # the Blob service returns status code 412 (Precondition Failed).
904
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create the blob snapshot
905
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
906
+ # the Blob service returns status code 412 (Precondition Failed).
907
+ # * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an
908
+ # active lease, specify the valid lease ID for this header. If a valid lease ID is not specified
909
+ # on the request, the operation will fail with status code 403 (Forbidden).
910
+ #
911
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179440.aspx
912
+ #
913
+ # Returns nil on success
914
+ def delete_blob(container, blob, options = {})
915
+ query = {}
916
+ StorageService.with_query query, "snapshot", options[:snapshot]
917
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
918
+
919
+ uri = blob_uri(container, blob, query)
920
+
921
+ options[:delete_snapshots] = :include unless options[:delete_snapshots]
922
+
923
+ headers = {}
924
+ StorageService.with_header headers, "x-ms-delete-snapshots", options[:delete_snapshots].to_s if options[:delete_snapshots] && options[:snapshot] == nil
925
+ add_blob_conditional_headers options, headers
926
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
927
+
928
+ call(:delete, uri, nil, headers, options)
929
+ nil
930
+ end
931
+ end
932
+ end