azure-storage 0.13.0.preview → 0.14.0.preview
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/azure/storage.rb +14 -13
- data/lib/azure/storage/autoload.rb +31 -31
- data/lib/azure/storage/blob/append.rb +43 -41
- data/lib/azure/storage/blob/blob.rb +150 -147
- data/lib/azure/storage/blob/blob_service.rb +186 -184
- data/lib/azure/storage/blob/block.rb +56 -56
- data/lib/azure/storage/blob/container.rb +93 -92
- data/lib/azure/storage/blob/page.rb +187 -104
- data/lib/azure/storage/blob/serialization.rb +32 -18
- data/lib/azure/storage/client.rb +18 -17
- data/lib/azure/storage/client_options.rb +192 -193
- data/lib/azure/storage/client_options_error.rb +5 -5
- data/lib/azure/storage/configurable.rb +39 -39
- data/lib/azure/storage/core.rb +6 -4
- data/lib/azure/storage/core/auth/shared_access_signature.rb +5 -3
- data/lib/azure/storage/core/auth/shared_access_signature_generator.rb +34 -33
- data/lib/azure/storage/core/auth/shared_access_signature_signer.rb +5 -5
- data/lib/azure/storage/core/auth/shared_key.rb +17 -15
- data/lib/azure/storage/core/autoload.rb +15 -13
- data/lib/azure/storage/core/error.rb +3 -1
- data/lib/azure/storage/core/filter/exponential_retry_filter.rb +13 -11
- data/lib/azure/storage/core/filter/linear_retry_filter.rb +10 -8
- data/lib/azure/storage/core/filter/retry_filter.rb +30 -29
- data/lib/azure/storage/core/http_client.rb +18 -16
- data/lib/azure/storage/core/sr.rb +50 -48
- data/lib/azure/storage/core/utility.rb +19 -17
- data/lib/azure/storage/default.rb +371 -361
- data/lib/azure/storage/file/directory.rb +36 -31
- data/lib/azure/storage/file/file.rb +103 -100
- data/lib/azure/storage/file/file_service.rb +42 -40
- data/lib/azure/storage/file/serialization.rb +9 -6
- data/lib/azure/storage/file/share.rb +48 -46
- data/lib/azure/storage/queue/message.rb +3 -1
- data/lib/azure/storage/queue/queue.rb +3 -2
- data/lib/azure/storage/queue/queue_service.rb +152 -151
- data/lib/azure/storage/queue/serialization.rb +7 -5
- data/lib/azure/storage/service/access_policy.rb +3 -1
- data/lib/azure/storage/service/cors.rb +4 -2
- data/lib/azure/storage/service/cors_rule.rb +3 -1
- data/lib/azure/storage/service/enumeration_results.rb +3 -1
- data/lib/azure/storage/service/logging.rb +5 -3
- data/lib/azure/storage/service/metrics.rb +5 -3
- data/lib/azure/storage/service/retention_policy.rb +3 -1
- data/lib/azure/storage/service/serialization.rb +31 -30
- data/lib/azure/storage/service/signed_identifier.rb +5 -4
- data/lib/azure/storage/service/storage_service.rb +33 -32
- data/lib/azure/storage/service/storage_service_properties.rb +6 -4
- data/lib/azure/storage/table/auth/shared_key.rb +9 -8
- data/lib/azure/storage/table/batch.rb +55 -55
- data/lib/azure/storage/table/batch_response.rb +17 -17
- data/lib/azure/storage/table/edmtype.rb +9 -7
- data/lib/azure/storage/table/entity.rb +4 -3
- data/lib/azure/storage/table/guid.rb +3 -1
- data/lib/azure/storage/table/query.rb +17 -19
- data/lib/azure/storage/table/serialization.rb +14 -12
- data/lib/azure/storage/table/table_service.rb +79 -80
- data/lib/azure/storage/version.rb +7 -5
- metadata +2 -2
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#-------------------------------------------------------------------------
|
2
4
|
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
3
5
|
#
|
@@ -21,23 +23,23 @@
|
|
21
23
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
24
|
# THE SOFTWARE.
|
23
25
|
#--------------------------------------------------------------------------
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
26
|
+
require "base64"
|
27
|
+
require "azure/storage/core/auth/shared_key"
|
28
|
+
require "azure/storage/blob/container"
|
29
|
+
require "azure/storage/blob/blob"
|
30
|
+
require "azure/storage/blob/block"
|
31
|
+
require "azure/storage/blob/page"
|
32
|
+
require "azure/storage/blob/append"
|
31
33
|
|
32
34
|
module Azure::Storage
|
33
35
|
include Service
|
34
|
-
|
36
|
+
|
35
37
|
module Blob
|
36
38
|
class BlobService < StorageService
|
37
39
|
include Azure::Storage::Core::Utility
|
38
40
|
include Azure::Storage::Blob
|
39
41
|
include Azure::Storage::Blob::Container
|
40
|
-
|
42
|
+
|
41
43
|
def initialize(options = {}, &block)
|
42
44
|
client_config = options[:client] || Azure::Storage
|
43
45
|
signer = options[:signer] || client_config.signer || Azure::Storage::Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
|
@@ -45,13 +47,13 @@ module Azure::Storage
|
|
45
47
|
@host = client.storage_blob_host
|
46
48
|
end
|
47
49
|
|
48
|
-
def call(method, uri, body=nil, headers={}, options={})
|
50
|
+
def call(method, uri, body = nil, headers = {}, options = {})
|
49
51
|
# Force the request.body to the content encoding of specified in the header
|
50
|
-
if headers && !body.nil? && (body.is_a? String) && ((body.encoding.to_s <=>
|
51
|
-
if headers[
|
52
|
-
Service::StorageService.with_header headers,
|
52
|
+
if headers && !body.nil? && (body.is_a? String) && ((body.encoding.to_s <=> "ASCII_8BIT") != 0)
|
53
|
+
if headers["x-ms-blob-content-type"].nil?
|
54
|
+
Service::StorageService.with_header headers, "x-ms-blob-content-type", "text/plain; charset=#{body.encoding}"
|
53
55
|
else
|
54
|
-
charset = parse_charset_from_content_type(headers[
|
56
|
+
charset = parse_charset_from_content_type(headers["x-ms-blob-content-type"])
|
55
57
|
body.force_encoding(charset) if charset
|
56
58
|
end
|
57
59
|
end
|
@@ -60,8 +62,8 @@ module Azure::Storage
|
|
60
62
|
|
61
63
|
# Force the response.body to the content charset of specified in the header.
|
62
64
|
# Content-Type is echo'd back for the blob and is used to store the encoding of the octet stream
|
63
|
-
if !response.nil? && !response.body.nil? && response.headers[
|
64
|
-
charset = parse_charset_from_content_type(response.headers[
|
65
|
+
if !response.nil? && !response.body.nil? && response.headers["Content-Type"]
|
66
|
+
charset = parse_charset_from_content_type(response.headers["Content-Type"])
|
65
67
|
response.body.force_encoding(charset) if charset && charset.length > 0
|
66
68
|
end
|
67
69
|
|
@@ -98,7 +100,7 @@ module Azure::Storage
|
|
98
100
|
#
|
99
101
|
# * +:timeout+ - Integer. A timeout in seconds.
|
100
102
|
#
|
101
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
103
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
102
104
|
# in the analytics logs when storage analytics logging is enabled.
|
103
105
|
#
|
104
106
|
# See: https://msdn.microsoft.com/en-us/library/azure/dd179352.aspx
|
@@ -114,14 +116,14 @@ module Azure::Storage
|
|
114
116
|
#
|
115
117
|
# Returns an Azure::Service::EnumerationResults
|
116
118
|
#
|
117
|
-
def list_containers(options={})
|
118
|
-
query = {
|
119
|
+
def list_containers(options = {})
|
120
|
+
query = {}
|
119
121
|
if options
|
120
|
-
StorageService.with_query query,
|
121
|
-
StorageService.with_query query,
|
122
|
-
StorageService.with_query query,
|
123
|
-
StorageService.with_query query,
|
124
|
-
StorageService.with_query query,
|
122
|
+
StorageService.with_query query, "prefix", options[:prefix]
|
123
|
+
StorageService.with_query query, "marker", options[:marker]
|
124
|
+
StorageService.with_query query, "maxresults", options[:max_results].to_s if options[:max_results]
|
125
|
+
StorageService.with_query query, "include", "metadata" if options[:metadata] == true
|
126
|
+
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
125
127
|
end
|
126
128
|
|
127
129
|
uri = containers_uri(query)
|
@@ -129,7 +131,7 @@ module Azure::Storage
|
|
129
131
|
|
130
132
|
Serialization.container_enumeration_results_from_xml(response.body)
|
131
133
|
end
|
132
|
-
|
134
|
+
|
133
135
|
# Protected: Establishes an exclusive write lock on a container or a blob. The lock duration can be 15 to 60 seconds, or can be infinite.
|
134
136
|
# To write to a locked container or blob, a client must provide a lease ID.
|
135
137
|
#
|
@@ -147,19 +149,19 @@ module Azure::Storage
|
|
147
149
|
# * +:proposed_lease_id+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
|
148
150
|
# if the proposed lease ID is not in the correct format. (optional)
|
149
151
|
# * +:timeout+ - Integer. A timeout in seconds.
|
150
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
152
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
151
153
|
# in the analytics logs when storage analytics logging is enabled.
|
152
154
|
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
|
153
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
155
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
154
156
|
# the Blob service returns status code 412 (Precondition Failed).
|
155
157
|
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
|
156
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
158
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
157
159
|
# the Blob service returns status code 412 (Precondition Failed).
|
158
160
|
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
|
159
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
161
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
160
162
|
# the Blob service returns status code 412 (Precondition Failed).
|
161
163
|
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
|
162
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
164
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
163
165
|
# the Blob service returns status code 412 (Precondition Failed).
|
164
166
|
#
|
165
167
|
# See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
|
@@ -168,28 +170,28 @@ module Azure::Storage
|
|
168
170
|
# to write, or to renew, change, or release the lease.
|
169
171
|
#
|
170
172
|
protected
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
if blob
|
176
|
-
uri = blob_uri(container, blob, query)
|
177
|
-
else
|
178
|
-
uri = container_uri(container, query)
|
179
|
-
end
|
173
|
+
def acquire_lease(container, blob, options = {})
|
174
|
+
query = { "comp" => "lease" }
|
175
|
+
Service::StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
180
176
|
|
181
|
-
|
182
|
-
|
177
|
+
if blob
|
178
|
+
uri = blob_uri(container, blob, query)
|
179
|
+
else
|
180
|
+
uri = container_uri(container, query)
|
181
|
+
end
|
183
182
|
|
184
|
-
|
185
|
-
|
186
|
-
Service::StorageService.with_header headers, 'x-ms-lease-duration', duration.to_s if duration
|
187
|
-
Service::StorageService.with_header headers, 'x-ms-proposed-lease-id', options[:proposed_lease_id]
|
188
|
-
add_blob_conditional_headers options, headers
|
183
|
+
duration = -1
|
184
|
+
duration = options[:duration] if options[:duration]
|
189
185
|
|
190
|
-
|
191
|
-
|
192
|
-
|
186
|
+
headers = Service::StorageService.common_headers
|
187
|
+
Service::StorageService.with_header headers, "x-ms-lease-action", "acquire"
|
188
|
+
Service::StorageService.with_header headers, "x-ms-lease-duration", duration.to_s if duration
|
189
|
+
Service::StorageService.with_header headers, "x-ms-proposed-lease-id", options[:proposed_lease_id]
|
190
|
+
add_blob_conditional_headers options, headers
|
191
|
+
|
192
|
+
response = call(:put, uri, nil, headers, options)
|
193
|
+
response.headers["x-ms-lease-id"]
|
194
|
+
end
|
193
195
|
|
194
196
|
# Protected: Renews the lease. The lease can be renewed if the lease ID specified on the request matches that
|
195
197
|
# associated with the blob. Note that the lease may be renewed even if it has expired as long as the container or blob
|
@@ -207,19 +209,19 @@ module Azure::Storage
|
|
207
209
|
#
|
208
210
|
# Accepted key/value pairs in options parameter are:
|
209
211
|
# * +:timeout+ - Integer. A timeout in seconds.
|
210
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
212
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
211
213
|
# in the analytics logs when storage analytics logging is enabled.
|
212
214
|
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
|
213
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
215
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
214
216
|
# the Blob service returns status code 412 (Precondition Failed).
|
215
217
|
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
|
216
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
218
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
217
219
|
# the Blob service returns status code 412 (Precondition Failed).
|
218
220
|
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
|
219
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
221
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
220
222
|
# the Blob service returns status code 412 (Precondition Failed).
|
221
223
|
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
|
222
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
224
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
223
225
|
# the Blob service returns status code 412 (Precondition Failed).
|
224
226
|
#
|
225
227
|
# See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
|
@@ -227,25 +229,25 @@ module Azure::Storage
|
|
227
229
|
# Returns the renewed lease id
|
228
230
|
#
|
229
231
|
protected
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
232
|
+
def renew_lease(container, blob, lease, options = {})
|
233
|
+
query = { "comp" => "lease" }
|
234
|
+
Service::StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
235
|
+
|
236
|
+
if blob
|
237
|
+
uri = blob_uri(container, blob, query)
|
238
|
+
else
|
239
|
+
uri = container_uri(container, query)
|
240
|
+
end
|
239
241
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
242
|
+
headers = Service::StorageService.common_headers
|
243
|
+
Service::StorageService.with_header headers, "x-ms-lease-action", "renew"
|
244
|
+
Service::StorageService.with_header headers, "x-ms-lease-id", lease
|
245
|
+
add_blob_conditional_headers options, headers
|
246
|
+
|
247
|
+
response = call(:put, uri, nil, headers, options)
|
248
|
+
response.headers["x-ms-lease-id"]
|
249
|
+
end
|
244
250
|
|
245
|
-
response = call(:put, uri, nil, headers, options)
|
246
|
-
response.headers['x-ms-lease-id']
|
247
|
-
end
|
248
|
-
|
249
251
|
# Protected: Change the ID of an existing lease.
|
250
252
|
#
|
251
253
|
# ==== Attributes
|
@@ -261,19 +263,19 @@ module Azure::Storage
|
|
261
263
|
#
|
262
264
|
# Accepted key/value pairs in options parameter are:
|
263
265
|
# * +:timeout+ - Integer. A timeout in seconds.
|
264
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
266
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
265
267
|
# in the analytics logs when storage analytics logging is enabled.
|
266
268
|
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to change the lease
|
267
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
269
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
268
270
|
# the Blob service returns status code 412 (Precondition Failed).
|
269
271
|
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to change the lease
|
270
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
272
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
271
273
|
# the Blob service returns status code 412 (Precondition Failed).
|
272
274
|
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
|
273
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
275
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
274
276
|
# the Blob service returns status code 412 (Precondition Failed).
|
275
277
|
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
|
276
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
278
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
277
279
|
# the Blob service returns status code 412 (Precondition Failed).
|
278
280
|
#
|
279
281
|
# See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
|
@@ -282,25 +284,25 @@ module Azure::Storage
|
|
282
284
|
# to write, or to renew, change, or release the lease.
|
283
285
|
#
|
284
286
|
protected
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
if blob
|
290
|
-
uri = blob_uri(container, blob, query)
|
291
|
-
else
|
292
|
-
uri = container_uri(container, query)
|
293
|
-
end
|
287
|
+
def change_lease(container, blob, lease, proposed_lease, options = {})
|
288
|
+
query = { "comp" => "lease" }
|
289
|
+
Service::StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
294
290
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
291
|
+
if blob
|
292
|
+
uri = blob_uri(container, blob, query)
|
293
|
+
else
|
294
|
+
uri = container_uri(container, query)
|
295
|
+
end
|
300
296
|
|
301
|
-
|
302
|
-
|
303
|
-
|
297
|
+
headers = Service::StorageService.common_headers
|
298
|
+
Service::StorageService.with_header headers, "x-ms-lease-action", "change"
|
299
|
+
Service::StorageService.with_header headers, "x-ms-lease-id", lease
|
300
|
+
Service::StorageService.with_header headers, "x-ms-proposed-lease-id", proposed_lease
|
301
|
+
add_blob_conditional_headers options, headers
|
302
|
+
|
303
|
+
response = call(:put, uri, nil, headers, options)
|
304
|
+
response.headers["x-ms-lease-id"]
|
305
|
+
end
|
304
306
|
|
305
307
|
# Protected: Releases the lease. The lease may be released if the lease ID specified on the request matches that
|
306
308
|
# associated with the container or blob. Releasing the lease allows another client to immediately acquire the lease for
|
@@ -317,19 +319,19 @@ module Azure::Storage
|
|
317
319
|
#
|
318
320
|
# Accepted key/value pairs in options parameter are:
|
319
321
|
# * +: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
|
322
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
321
323
|
# in the analytics logs when storage analytics logging is enabled.
|
322
324
|
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to release the lease
|
323
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
325
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
324
326
|
# the Blob service returns status code 412 (Precondition Failed).
|
325
327
|
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to release the lease
|
326
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
328
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
327
329
|
# the Blob service returns status code 412 (Precondition Failed).
|
328
330
|
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
|
329
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
331
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
330
332
|
# the Blob service returns status code 412 (Precondition Failed).
|
331
333
|
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
|
332
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
334
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
333
335
|
# the Blob service returns status code 412 (Precondition Failed).
|
334
336
|
#
|
335
337
|
# See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
|
@@ -337,24 +339,24 @@ module Azure::Storage
|
|
337
339
|
# Returns nil on success
|
338
340
|
#
|
339
341
|
protected
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
342
|
+
def release_lease(container, blob, lease, options = {})
|
343
|
+
query = { "comp" => "lease" }
|
344
|
+
Service::StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
345
|
+
|
346
|
+
if blob
|
347
|
+
uri = blob_uri(container, blob, query)
|
348
|
+
else
|
349
|
+
uri = container_uri(container, query)
|
350
|
+
end
|
349
351
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
352
|
+
headers = Service::StorageService.common_headers
|
353
|
+
Service::StorageService.with_header headers, "x-ms-lease-action", "release"
|
354
|
+
Service::StorageService.with_header headers, "x-ms-lease-id", lease
|
355
|
+
add_blob_conditional_headers options, headers
|
354
356
|
|
355
|
-
|
356
|
-
|
357
|
-
|
357
|
+
call(:put, uri, nil, headers, options)
|
358
|
+
nil
|
359
|
+
end
|
358
360
|
|
359
361
|
# Protected: Breaks the lease, if the container or blob has an active lease. Once a lease is broken, it cannot be renewed. Any
|
360
362
|
# authorized request can break the lease; the request is not required to specify a matching lease ID. When a
|
@@ -383,19 +385,19 @@ module Azure::Storage
|
|
383
385
|
# If this option is not used, a fixed-duration lease breaks after the remaining lease
|
384
386
|
# period elapses, and an infinite lease breaks immediately.
|
385
387
|
# * +:timeout+ - Integer. A timeout in seconds.
|
386
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
388
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
387
389
|
# in the analytics logs when storage analytics logging is enabled.
|
388
390
|
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
|
389
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
391
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
390
392
|
# the Blob service returns status code 412 (Precondition Failed).
|
391
393
|
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
|
392
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
394
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
393
395
|
# the Blob service returns status code 412 (Precondition Failed).
|
394
396
|
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
|
395
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
397
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
396
398
|
# the Blob service returns status code 412 (Precondition Failed).
|
397
399
|
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
|
398
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
400
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
399
401
|
# the Blob service returns status code 412 (Precondition Failed).
|
400
402
|
#
|
401
403
|
# See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
|
@@ -405,25 +407,25 @@ module Azure::Storage
|
|
405
407
|
# is immediate, 0 is returned.
|
406
408
|
#
|
407
409
|
protected
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
if blob
|
413
|
-
uri = blob_uri(container, blob, query)
|
414
|
-
else
|
415
|
-
uri = container_uri(container, query)
|
416
|
-
end
|
410
|
+
def break_lease(container, blob, options = {})
|
411
|
+
query = { "comp" => "lease" }
|
412
|
+
Service::StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
417
413
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
414
|
+
if blob
|
415
|
+
uri = blob_uri(container, blob, query)
|
416
|
+
else
|
417
|
+
uri = container_uri(container, query)
|
418
|
+
end
|
419
|
+
|
420
|
+
headers = Service::StorageService.common_headers
|
421
|
+
Service::StorageService.with_header headers, "x-ms-lease-action", "break"
|
422
|
+
Service::StorageService.with_header headers, "x-ms-lease-break-period", options[:break_period].to_s if options[:break_period]
|
423
|
+
add_blob_conditional_headers options, headers
|
424
|
+
|
425
|
+
response = call(:put, uri, nil, headers, options)
|
426
|
+
response.headers["x-ms-lease-time"].to_i
|
427
|
+
end
|
422
428
|
|
423
|
-
response = call(:put, uri, nil, headers, options)
|
424
|
-
response.headers['x-ms-lease-time'].to_i
|
425
|
-
end
|
426
|
-
|
427
429
|
# Protected: Generate the URI for the collection of containers.
|
428
430
|
#
|
429
431
|
# ==== Attributes
|
@@ -433,11 +435,11 @@ module Azure::Storage
|
|
433
435
|
# Returns a URI.
|
434
436
|
#
|
435
437
|
protected
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
438
|
+
def containers_uri(query = {})
|
439
|
+
query = { "comp" => "list" }.merge(query)
|
440
|
+
generate_uri("", query)
|
441
|
+
end
|
442
|
+
|
441
443
|
# Protected: Generate the URI for a specific container.
|
442
444
|
#
|
443
445
|
# ==== Attributes
|
@@ -448,12 +450,12 @@ module Azure::Storage
|
|
448
450
|
# Returns a URI.
|
449
451
|
#
|
450
452
|
protected
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
453
|
+
def container_uri(name, query = {})
|
454
|
+
return name if name.kind_of? ::URI
|
455
|
+
query = { "restype" => "container" }.merge(query)
|
456
|
+
generate_uri(name, query)
|
457
|
+
end
|
458
|
+
|
457
459
|
# Protected: Generate the URI for a specific Blob.
|
458
460
|
#
|
459
461
|
# ==== Attributes
|
@@ -465,51 +467,51 @@ module Azure::Storage
|
|
465
467
|
# Returns a URI.
|
466
468
|
#
|
467
469
|
protected
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
470
|
+
def blob_uri(container_name, blob_name, query = {})
|
471
|
+
if container_name.nil? || container_name.empty?
|
472
|
+
path = blob_name
|
473
|
+
else
|
474
|
+
path = ::File.join(container_name, blob_name)
|
475
|
+
end
|
476
|
+
generate_uri(path, query, true)
|
473
477
|
end
|
474
|
-
|
475
|
-
end
|
476
|
-
|
478
|
+
|
477
479
|
# Adds conditional header with required condition
|
478
480
|
#
|
479
481
|
# headers - A Hash of HTTP headers
|
480
482
|
# options - A Hash of condition name/value pairs
|
481
483
|
#
|
482
484
|
protected
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
485
|
+
def add_blob_conditional_headers(options, headers)
|
486
|
+
return unless options
|
487
|
+
|
488
|
+
# Common conditional headers for blobs: https://msdn.microsoft.com/en-us/library/azure/dd179371.aspx
|
489
|
+
Service::StorageService.with_header headers, "If-Modified-Since", options[:if_modified_since]
|
490
|
+
Service::StorageService.with_header headers, "If-Unmodified-Since", options[:if_unmodified_since]
|
491
|
+
Service::StorageService.with_header headers, "If-Match", options[:if_match]
|
492
|
+
Service::StorageService.with_header headers, "If-None-Match", options[:if_none_match]
|
493
|
+
|
494
|
+
# Conditional headers for copying blob
|
495
|
+
Service::StorageService.with_header headers, "If-Modified-Since", options[:dest_if_modified_since]
|
496
|
+
Service::StorageService.with_header headers, "If-Unmodified-Since", options[:dest_if_unmodified_since]
|
497
|
+
Service::StorageService.with_header headers, "If-Match", options[:dest_if_match]
|
498
|
+
Service::StorageService.with_header headers, "If-None-Match", options[:dest_if_none_match]
|
499
|
+
Service::StorageService.with_header headers, "x-ms-source-if-modified-since", options[:source_if_modified_since]
|
500
|
+
Service::StorageService.with_header headers, "x-ms-source-if-unmodified-since", options[:source_if_unmodified_since]
|
501
|
+
Service::StorageService.with_header headers, "x-ms-source-if-match", options[:source_if_match]
|
502
|
+
Service::StorageService.with_header headers, "x-ms-source-if-none-match", options[:source_if_none_match]
|
503
|
+
|
504
|
+
# Conditional headers for page blob
|
505
|
+
Service::StorageService.with_header headers, "x-ms-if-sequence-number-le", options[:if_sequence_number_le]
|
506
|
+
Service::StorageService.with_header headers, "x-ms-if-sequence-number-lt", options[:if_sequence_number_lt]
|
507
|
+
Service::StorageService.with_header headers, "x-ms-if-sequence-number-eq", options[:if_sequence_number_eq]
|
508
|
+
|
509
|
+
# Conditional headers for append blob
|
510
|
+
Service::StorageService.with_header headers, "x-ms-blob-condition-maxsize", options[:max_size]
|
511
|
+
Service::StorageService.with_header headers, "x-ms-blob-condition-appendpos", options[:append_position]
|
512
|
+
end
|
511
513
|
end
|
512
514
|
end
|
513
515
|
end
|
514
516
|
|
515
|
-
Azure::Storage::BlobService = Azure::Storage::Blob::BlobService
|
517
|
+
Azure::Storage::BlobService = Azure::Storage::Blob::BlobService
|