azure-storage-blob2 2.0.8 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/azure/storage/blob/append.rb +244 -0
- data/lib/azure/storage/blob/autoload.rb +47 -0
- data/lib/azure/storage/blob/blob.rb +932 -0
- data/lib/azure/storage/blob/blob_service.rb +720 -0
- data/lib/azure/storage/blob/block.rb +530 -0
- data/lib/azure/storage/blob/container.rb +634 -0
- data/lib/azure/storage/blob/default.rb +171 -0
- data/lib/azure/storage/blob/page.rb +566 -0
- data/lib/azure/storage/blob/serialization.rb +351 -0
- data/lib/azure/storage/blob/version.rb +49 -0
- metadata +12 -2
@@ -0,0 +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
|
+
# * :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
|