azure-storage-blob 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,634 +1,634 @@
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::Blob
28
- module Container
29
- include Azure::Storage::Common::Service
30
-
31
- class Container
32
- def initialize
33
- @properties = {}
34
- @metadata = {}
35
- yield self if block_given?
36
- end
37
-
38
- attr_accessor :name
39
- attr_accessor :properties
40
- attr_accessor :metadata
41
- attr_accessor :public_access_level
42
- end
43
-
44
- # Public: Create a new container
45
- #
46
- # ==== Attributes
47
- #
48
- # * +name+ - String. The name of the container.
49
- # * +options+ - Hash. Optional parameters.
50
- #
51
- # ==== Options
52
- #
53
- # Accepted key/value pairs in options parameter are:
54
- # * +:metadata+ - Hash. User defined metadata for the container (optional).
55
- # * +:public_access_level+ - String. One of "container" or "blob" (optional).
56
- # * +:timeout+ - Integer. A timeout in seconds.
57
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
58
- # in the analytics logs when storage analytics logging is enabled.
59
- #
60
- # See http://msdn.microsoft.com/en-us/library/azure/dd179468.aspx
61
- #
62
- # Returns a Container
63
- def create_container(name, options = {})
64
- # Query
65
- query = {}
66
- query["timeout"] = options[:timeout].to_s if options[:timeout]
67
-
68
- # Scheme + path
69
- uri = container_uri(name, query)
70
-
71
- # Headers
72
- headers = {}
73
- StorageService.add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
74
- headers["x-ms-blob-public-access"] = options[:public_access_level].to_s if options[:public_access_level]
75
-
76
- # Call
77
- response = call(:put, uri, nil, headers, options)
78
-
79
- # result
80
- container = Serialization.container_from_headers(response.headers)
81
- container.name = name
82
- container.metadata = options[:metadata]
83
- container
84
- end
85
-
86
- # Public: Returns all properties and metadata on the container.
87
- #
88
- # ==== Attributes
89
- #
90
- # * +name+ - String. The name of the container
91
- # * +options+ - Hash. Optional parameters.
92
- #
93
- # ==== Options
94
- #
95
- # Accepted key/value pairs in options parameter are:
96
- # * +:timeout+ - Integer. A timeout in seconds.
97
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
98
- # in the analytics logs when storage analytics logging is enabled.
99
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
100
- # which location the request should be sent to.
101
- # * +:lease_id+ - String. If specified, Get Container Properties only succeeds if the container’s lease is
102
- # active and matches this ID. If there is no active lease or the ID does not match, 412
103
- # (Precondition Failed) is returned.
104
- #
105
- # See http://msdn.microsoft.com/en-us/library/azure/dd179370.aspx
106
- #
107
- # Returns a Container
108
- def get_container_properties(name, options = {})
109
- # Query
110
- query = {}
111
- query["timeout"] = options[:timeout].to_s if options[:timeout]
112
-
113
- headers = options[:lease_id] ? { "x-ms-lease-id" => options[:lease_id] } : {}
114
-
115
- # Call
116
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
117
- response = call(:get, container_uri(name, query, options), nil, headers, options)
118
-
119
- # result
120
- container = Serialization.container_from_headers(response.headers)
121
- container.name = name
122
- container
123
- end
124
-
125
- # Public: Returns only user-defined metadata for the specified container.
126
- #
127
- # ==== Attributes
128
- #
129
- # * +name+ - String. The name of the container
130
- # * +options+ - Hash. Optional parameters.
131
- #
132
- # ==== Options
133
- #
134
- # Accepted key/value pairs in options parameter are:
135
- # * +:timeout+ - Integer. A timeout in seconds.
136
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
137
- # in the analytics logs when storage analytics logging is enabled.
138
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
139
- # which location the request should be sent to.
140
- # * +:lease_id+ - String. If specified, Get Container Metadata only succeeds if the container’s lease is
141
- # active and matches this ID. If there is no active lease or the ID does not match, 412
142
- # (Precondition Failed) is returned.
143
- #
144
- # See http://msdn.microsoft.com/en-us/library/azure/ee691976.aspx
145
- #
146
- # Returns a Container
147
- def get_container_metadata(name, options = {})
148
- # Query
149
- query = { "comp" => "metadata" }
150
- query["timeout"] = options[:timeout].to_s if options[:timeout]
151
-
152
- headers = options[:lease_id] ? { "x-ms-lease-id" => options[:lease_id] } : {}
153
-
154
- # Call
155
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
156
- response = call(:get, container_uri(name, query, options), nil, headers, options)
157
-
158
- # result
159
- container = Serialization.container_from_headers(response.headers)
160
- container.name = name
161
- container
162
- end
163
-
164
- # Public: Sets custom metadata for the container.
165
- #
166
- # ==== Attributes
167
- #
168
- # * +name+ - String. The name of the container
169
- # * +metadata+ - Hash. A Hash of the metadata values
170
- # * +options+ - Hash. Optional parameters.
171
- #
172
- # ==== Options
173
- #
174
- # Accepted key/value pairs in options parameter are:
175
- # * +:timeout+ - Integer. A timeout in seconds.
176
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
177
- # in the analytics logs when storage analytics logging is enabled.
178
- # * +:lease_id+ - String. If specified, Set Container Metadata only succeeds if the container’s lease is
179
- # active and matches this ID. If there is no active lease or the ID does not match, 412
180
- # (Precondition Failed) is returned.
181
- #
182
- # See http://msdn.microsoft.com/en-us/library/azure/dd179362.aspx
183
- #
184
- # Returns nil on success
185
- def set_container_metadata(name, metadata, options = {})
186
- # Query
187
- query = { "comp" => "metadata" }
188
- query["timeout"] = options[:timeout].to_s if options[:timeout]
189
-
190
- # Headers
191
- headers = {}
192
- StorageService.add_metadata_to_headers(metadata, headers) if metadata
193
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
194
-
195
- # Call
196
- call(:put, container_uri(name, query), nil, headers, options)
197
-
198
- # Result
199
- nil
200
- end
201
-
202
- # Public: Gets the access control list (ACL) and any container-level access policies
203
- # for the container.
204
- #
205
- # ==== Attributes
206
- #
207
- # * +name+ - String. The name of the container
208
- # * +options+ - Hash. Optional parameters.
209
- #
210
- # ==== Options
211
- #
212
- # Accepted key/value pairs in options parameter are:
213
- # * +:timeout+ - Integer. A timeout in seconds.
214
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
215
- # in the analytics logs when storage analytics logging is enabled.
216
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
217
- # which location the request should be sent to.
218
- # * +:lease_id+ - String. If specified, Get Container ACL only succeeds if the container’s lease is
219
- # active and matches this ID. If there is no active lease or the ID does not match, 412
220
- # (Precondition Failed) is returned.
221
- #
222
- # See http://msdn.microsoft.com/en-us/library/azure/dd179469.aspx
223
- #
224
- # Returns a tuple of (container, signed_identifiers)
225
- # container - A Azure::Storage::Entity::Blob::Container instance
226
- # signed_identifiers - A list of Azure::Storage::Entity::SignedIdentifier instances
227
- #
228
- def get_container_acl(name, options = {})
229
- # Query
230
- query = { "comp" => "acl" }
231
- query["timeout"] = options[:timeout].to_s if options[:timeout]
232
-
233
- headers = options[:lease_id] ? { "x-ms-lease-id" => options[:lease_id] } : {}
234
-
235
- # Call
236
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
237
- response = call(:get, container_uri(name, query, options), nil, headers, options)
238
-
239
- # Result
240
- container = Serialization.container_from_headers(response.headers)
241
- container.name = name
242
-
243
- signed_identifiers = nil
244
- signed_identifiers = Serialization.signed_identifiers_from_xml(response.body) if response.body != nil && response.body.length > 0
245
-
246
- return container, signed_identifiers
247
- end
248
-
249
- # Public: Sets the ACL and any container-level access policies for the container.
250
- #
251
- # ==== Attributes
252
- #
253
- # * +name+ - String. The name of the container
254
- # * +public_access_level+ - String. The container public access level
255
- # * +options+ - Hash. Optional parameters.
256
- #
257
- # ==== Options
258
- #
259
- # Accepted key/value pairs in options parameter are:
260
- # * +:signed_identifiers+ - Array. A list of Azure::Storage::Entity::SignedIdentifier instances (optional)
261
- # * +:timeout+ - Integer. A timeout in seconds.
262
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
263
- # in the analytics logs when storage analytics logging is enabled.
264
- # * +:lease_id+ - String. If specified, Set Container ACL only succeeds if the container’s lease is
265
- # active and matches this ID. If there is no active lease or the ID does not match, 412
266
- # (Precondition Failed) is returned.
267
- #
268
- # See http://msdn.microsoft.com/en-us/library/azure/dd179391.aspx
269
- #
270
- # Returns a tuple of (container, signed_identifiers)
271
- # * +container+ - A Azure::Storage::Entity::Blob::Container instance
272
- # * +signed_identifiers+ - A list of Azure::Storage::Entity::SignedIdentifier instances
273
- #
274
- def set_container_acl(name, public_access_level, options = {})
275
- # Query
276
- query = { "comp" => "acl" }
277
- query["timeout"] = options[:timeout].to_s if options[:timeout]
278
-
279
- # Scheme + path
280
- uri = container_uri(name, query)
281
-
282
- # Headers + body
283
- headers = {}
284
- headers["x-ms-blob-public-access"] = public_access_level if public_access_level && public_access_level.to_s.length > 0
285
- headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
286
-
287
- signed_identifiers = nil
288
- signed_identifiers = options[:signed_identifiers] if options[:signed_identifiers]
289
-
290
- body = nil
291
- body = Serialization.signed_identifiers_to_xml(signed_identifiers) if signed_identifiers
292
-
293
- # Call
294
- response = call(:put, uri, body, headers, options)
295
-
296
- # Result
297
- container = Serialization.container_from_headers(response.headers)
298
- container.name = name
299
- container.public_access_level = public_access_level
300
-
301
- return container, signed_identifiers || []
302
- end
303
-
304
- # Public: Deletes a container.
305
- #
306
- # ==== Attributes
307
- #
308
- # * +name+ - String. The name of the container.
309
- # * +options+ - Hash. Optional parameters.
310
- #
311
- # ==== Options
312
- #
313
- # Accepted key/value pairs in options parameter are:
314
- # * +:timeout+ - Integer. A timeout in seconds.
315
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
316
- # in the analytics logs when storage analytics logging is enabled.
317
- # * +:lease_id+ - String. Required for version 2012-02-12 and newer if the container has an active lease. To call
318
- # Delete Container on a container that has an active lease, specify the lease ID in this header.
319
- # If this header is not specified when there is an active lease, Delete Container will return 409
320
- # (Conflict). If you specify the wrong lease ID, or a lease ID on a container that does not have
321
- # an active lease, Delete Container will return 412 (Precondition failed).
322
- #
323
- # See http://msdn.microsoft.com/en-us/library/azure/dd179408.aspx
324
- #
325
- # Returns nil on success
326
- def delete_container(name, options = {})
327
- # Query
328
- query = {}
329
- query["timeout"] = options[:timeout].to_s if options[:timeout]
330
-
331
- headers = options[:lease_id] ? { "x-ms-lease-id" => options[:lease_id] } : {}
332
-
333
- # Call
334
- call(:delete, container_uri(name, query), nil, headers, options)
335
-
336
- # result
337
- nil
338
- end
339
-
340
- # Public: Establishes an exclusive write lock on a container. The lock duration can be 15 to 60 seconds, or can be infinite.
341
- # To write to a locked container, a client must provide a lease ID.
342
- #
343
- # ==== Attributes
344
- #
345
- # * +container+ - String. The container name.
346
- # * +options+ - Hash. Optional parameters.
347
- #
348
- # ==== Options
349
- #
350
- # Accepted key/value pairs in options parameter are:
351
- # * +:duration+ - Integer. Default -1. Specifies the duration of the lease, in seconds, or negative one (-1)
352
- # for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. (optional)
353
- # * +:proposed_lease_id+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
354
- # if the proposed lease ID is not in the correct format. (optional)
355
- # * +:timeout+ - Integer. A timeout in seconds.
356
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
357
- # in the analytics logs when storage analytics logging is enabled.
358
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
359
- # only if the container has been modified since the specified date/time. If the container has not been modified,
360
- # the Blob service returns status code 412 (Precondition Failed).
361
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
362
- # only if the container has not been modified since the specified date/time. If the container has been modified,
363
- # the Blob service returns status code 412 (Precondition Failed).
364
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
365
- # only if the container's ETag value matches the value specified. If the values do not match,
366
- # the Blob service returns status code 412 (Precondition Failed).
367
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
368
- # only if the container's ETag value does not match the value specified. If the values are identical,
369
- # the Blob service returns status code 412 (Precondition Failed).
370
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
371
- # in cross-origin resource sharing headers on the response.
372
- #
373
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
374
- #
375
- # Returns a String of the new unique lease id. While the lease is active, you must include the lease ID with any request
376
- # to write, or to renew, change, or release the lease.
377
- #
378
- def acquire_container_lease(container, options = {})
379
- acquire_lease container, nil, options
380
- end
381
-
382
- # Public: Renews the lease. The lease can be renewed if the lease ID specified on the request matches that
383
- # associated with the container. Note that the lease may be renewed even if it has expired as long as the container
384
- # has not been modified or leased again since the expiration of that lease. When you renew a lease, the
385
- # lease duration clock resets.
386
- #
387
- # ==== Attributes
388
- #
389
- # * +container+ - String. The container name.
390
- # * +lease+ - String. The lease id
391
- # * +options+ - Hash. Optional parameters.
392
- #
393
- # ==== Options
394
- #
395
- # Accepted key/value pairs in options parameter are:
396
- # * +:timeout+ - Integer. A timeout in seconds.
397
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
398
- # in the analytics logs when storage analytics logging is enabled.
399
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
400
- # only if the container has been modified since the specified date/time. If the container has not been modified,
401
- # the Blob service returns status code 412 (Precondition Failed).
402
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
403
- # only if the container has not been modified since the specified date/time. If the container has been modified,
404
- # the Blob service returns status code 412 (Precondition Failed).
405
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
406
- # only if the container's ETag value matches the value specified. If the values do not match,
407
- # the Blob service returns status code 412 (Precondition Failed).
408
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
409
- # only if the container's ETag value does not match the value specified. If the values are identical,
410
- # the Blob service returns status code 412 (Precondition Failed).
411
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
412
- # in cross-origin resource sharing headers on the response.
413
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
414
- #
415
- # Returns the renewed lease id
416
- def renew_container_lease(container, lease, options = {})
417
- renew_lease container, nil, lease, options
418
- end
419
-
420
- # Public: Change the lease ID.
421
- #
422
- # ==== Attributes
423
- #
424
- # * +container+ - String. The container name.
425
- # * +lease+ - String. The existing lease id.
426
- # * +proposed_lease+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
427
- # if the proposed lease ID is not in the correct format. (optional).
428
- # * +options+ - Hash. Optional parameters.
429
- #
430
- # ==== Options
431
- #
432
- # Accepted key/value pairs in options parameter are:
433
- # * +:timeout+ - Integer. A timeout in seconds.
434
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
435
- # in the analytics logs when storage analytics logging is enabled.
436
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to change the lease
437
- # only if the container has been modified since the specified date/time. If the container has not been modified,
438
- # the Blob service returns status code 412 (Precondition Failed).
439
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to change the lease
440
- # only if the container has not been modified since the specified date/time. If the container has been modified,
441
- # the Blob service returns status code 412 (Precondition Failed).
442
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
443
- # only if the container's ETag value matches the value specified. If the values do not match,
444
- # the Blob service returns status code 412 (Precondition Failed).
445
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
446
- # only if the container's ETag value does not match the value specified. If the values are identical,
447
- # the Blob service returns status code 412 (Precondition Failed).
448
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
449
- # in cross-origin resource sharing headers on the response.
450
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
451
- #
452
- # Returns the changed lease id
453
- def change_container_lease(container, lease, proposed_lease, options = {})
454
- change_lease container, nil, lease, proposed_lease, options
455
- end
456
-
457
- # Public: Releases the lease. The lease may be released if the lease ID specified on the request matches that
458
- # associated with the container. Releasing the lease allows another client to immediately acquire the lease for
459
- # the container as soon as the release is complete.
460
- #
461
- # ==== Attributes
462
- #
463
- # * +container+ - String. The container name.
464
- # * +lease+ - String. The lease id.
465
- # * +options+ - Hash. Optional parameters.
466
- #
467
- # ==== Options
468
- #
469
- # Accepted key/value pairs in options parameter are:
470
- # * +:timeout+ - Integer. A timeout in seconds.
471
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
472
- # in the analytics logs when storage analytics logging is enabled.
473
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to release the lease
474
- # only if the container has been modified since the specified date/time. If the container has not been modified,
475
- # the Blob service returns status code 412 (Precondition Failed).
476
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to release the lease
477
- # only if the container has not been modified since the specified date/time. If the container has been modified,
478
- # the Blob service returns status code 412 (Precondition Failed).
479
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
480
- # only if the container's ETag value matches the value specified. If the values do not match,
481
- # the Blob service returns status code 412 (Precondition Failed).
482
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
483
- # only if the container's ETag value does not match the value specified. If the values are identical,
484
- # the Blob service returns status code 412 (Precondition Failed).
485
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
486
- # in cross-origin resource sharing headers on the response.
487
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
488
- #
489
- # Returns nil on success
490
- def release_container_lease(container, lease, options = {})
491
- release_lease container, nil, lease, options
492
- end
493
-
494
- # Public: Breaks the lease, if the container has an active lease. Once a lease is broken, it cannot be renewed. Any
495
- # authorized request can break the lease; the request is not required to specify a matching lease ID. When a
496
- # lease is broken, the lease break period is allowed to elapse, during which time no lease operation except
497
- # break and release can be performed on the container. When a lease is successfully broken, the response indicates
498
- # the interval in seconds until a new lease can be acquired.
499
- #
500
- # A lease that has been broken can also be released, in which case another client may immediately acquire the
501
- # lease on the container.
502
- #
503
- # ==== Attributes
504
- #
505
- # * +container+ - String. The container name.
506
- # * +options+ - Hash. Optional parameters.
507
- #
508
- # ==== Options
509
- #
510
- # Accepted key/value pairs in options parameter are:
511
- # * +:break_period+ - Integer. The proposed duration of seconds that the lease should continue before it is
512
- # broken, between 0 and 60 seconds. This break period is only used if it is shorter than
513
- # the time remaining on the lease. If longer, the time remaining on the lease is used. A
514
- # new lease will not be available before the break period has expired, but the lease may
515
- # be held for longer than the break period.
516
- #
517
- # If this option is not used, a fixed-duration lease breaks after the remaining lease
518
- # period elapses, and an infinite lease breaks immediately.
519
- # * +:timeout+ - Integer. A timeout in seconds.
520
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
521
- # in the analytics logs when storage analytics logging is enabled.
522
- # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to break the lease
523
- # only if the container has been modified since the specified date/time. If the container has not been modified,
524
- # the Blob service returns status code 412 (Precondition Failed).
525
- # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to break the lease
526
- # only if the container has not been modified since the specified date/time. If the container has been modified,
527
- # the Blob service returns status code 412 (Precondition Failed).
528
- # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
529
- # only if the container's ETag value matches the value specified. If the values do not match,
530
- # the Blob service returns status code 412 (Precondition Failed).
531
- # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
532
- # only if the container's ETag value does not match the value specified. If the values are identical,
533
- # the Blob service returns status code 412 (Precondition Failed).
534
- # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
535
- # in cross-origin resource sharing headers on the response.
536
- # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
537
- #
538
- # Returns an Integer of the remaining lease time. This value is the approximate time remaining in the lease
539
- # period, in seconds. This header is returned only for a successful request to break the lease. If the break
540
- # is immediate, 0 is returned.
541
- def break_container_lease(container, options = {})
542
- break_lease container, nil, options
543
- end
544
-
545
- # Public: Get a list of Blobs from the server
546
- #
547
- # ==== Attributes
548
- #
549
- # * +name+ - String. The name of the container to list blobs for.
550
- # * +options+ - Hash. Optional parameters.
551
- #
552
- # ==== Options
553
- #
554
- # Accepted key/value pairs in options parameter are:
555
- # * +:prefix+ - String. Filters the results to return only blobs
556
- # whose name begins with the specified prefix. (optional)
557
- # * +:delimiter+ - String. When the request includes this parameter, the operation
558
- # returns a BlobPrefix element in the response body that acts as a
559
- # placeholder for all blobs whose names begin with the same substring
560
- # up to the appearance of the delimiter character. The delimiter may
561
- # be a single character or a string.
562
- # * +:marker+ - String. An identifier that specifies the portion of the
563
- # list to be returned. This value comes from the property
564
- # Azure::Storage::Common::EnumerationResults.continuation_token when
565
- # there are more blobs available than were returned. The
566
- # marker value may then be used here to request the next set
567
- # of list items. (optional)
568
- # * +:max_results+ - Integer. Specifies the maximum number of blobs to return.
569
- # If max_results is not specified, or is a value greater than
570
- # 5,000, the server will return up to 5,000 items. If it is set
571
- # to a value less than or equal to zero, the server will return
572
- # status code 400 (Bad Request). (optional)
573
- # * +:metadata+ - Boolean. Specifies whether or not to return the blob metadata.
574
- # (optional, Default=false)
575
- # * +:snapshots+ - Boolean. Specifies that snapshots should be included in the
576
- # enumeration. Snapshots are listed from oldest to newest in the
577
- # response. (optional, Default=false)
578
- # * +:uncomittedblobs+ - Boolean. Specifies that blobs for which blocks have been uploaded,
579
- # but which have not been committed using put_block_list, be included
580
- # in the response. (optional, Default=false)
581
- # * +:copy+ - Boolean. Specifies that metadata related to any current or previous
582
- # copy_blob operation should be included in the response.
583
- # (optional, Default=false)
584
- # * +:timeout+ - Integer. A timeout in seconds.
585
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
586
- # in the analytics logs when storage analytics logging is enabled.
587
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
588
- # which location the request should be sent to.
589
- #
590
- # NOTE: Metadata requested with the :metadata parameter must have been stored in
591
- # accordance with the naming restrictions imposed by the 2009-09-19 version of the Blob
592
- # service. Beginning with that version, all metadata names must adhere to the naming
593
- # conventions for C# identifiers.
594
- #
595
- # See: http://msdn.microsoft.com/en-us/library/azure/dd135734.aspx
596
- #
597
- # Any metadata with invalid names which were previously stored, will be returned with the
598
- # key "x-ms-invalid-name" in the metadata hash. This may contain multiple values and be an
599
- # Array (vs a String if it only contains a single value).
600
- #
601
- # Returns an Azure::Storage::Common::EnumerationResults
602
- def list_blobs(name, options = {})
603
- # Query
604
- query = { "comp" => "list" }
605
- query["prefix"] = options[:prefix].gsub(/\\/, "/") if options[:prefix]
606
- query["delimiter"] = options[:delimiter] if options[:delimiter]
607
- query["marker"] = options[:marker] if options[:marker]
608
- query["maxresults"] = options[:max_results].to_s if options[:max_results]
609
- query["timeout"] = options[:timeout].to_s if options[:timeout]
610
-
611
- included_datasets = []
612
- included_datasets.push("metadata") if options[:metadata] == true
613
- included_datasets.push("snapshots") if options[:snapshots] == true
614
- included_datasets.push("uncommittedblobs") if options[:uncommittedblobs] == true
615
- included_datasets.push("copy") if options[:copy] == true
616
-
617
- query["include"] = included_datasets.join "," if included_datasets.length > 0
618
-
619
- # Scheme + path
620
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
621
- uri = container_uri(name, query, options)
622
-
623
- # Call
624
- response = call(:get, uri, nil, {}, options)
625
-
626
- # Result
627
- if response.success?
628
- Serialization.blob_enumeration_results_from_xml(response.body)
629
- else
630
- response.exception
631
- end
632
- end
633
- end
634
- end
1
+ # frozen_string_literal: true
2
+
3
+ #-------------------------------------------------------------------------
4
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
5
+ #
6
+ # The MIT License(MIT)
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files(the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions :
14
+
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #--------------------------------------------------------------------------
26
+
27
+ module Azure::Storage::Blob
28
+ module Container
29
+ include Azure::Storage::Common::Service
30
+
31
+ class Container
32
+ def initialize
33
+ @properties = {}
34
+ @metadata = {}
35
+ yield self if block_given?
36
+ end
37
+
38
+ attr_accessor :name
39
+ attr_accessor :properties
40
+ attr_accessor :metadata
41
+ attr_accessor :public_access_level
42
+ end
43
+
44
+ # Public: Create a new container
45
+ #
46
+ # ==== Attributes
47
+ #
48
+ # * +name+ - String. The name of the container.
49
+ # * +options+ - Hash. Optional parameters.
50
+ #
51
+ # ==== Options
52
+ #
53
+ # Accepted key/value pairs in options parameter are:
54
+ # * +:metadata+ - Hash. User defined metadata for the container (optional).
55
+ # * +:public_access_level+ - String. One of "container" or "blob" (optional).
56
+ # * +:timeout+ - Integer. A timeout in seconds.
57
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
58
+ # in the analytics logs when storage analytics logging is enabled.
59
+ #
60
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179468.aspx
61
+ #
62
+ # Returns a Container
63
+ def create_container(name, options = {})
64
+ # Query
65
+ query = {}
66
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
67
+
68
+ # Scheme + path
69
+ uri = container_uri(name, query)
70
+
71
+ # Headers
72
+ headers = {}
73
+ StorageService.add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
74
+ headers["x-ms-blob-public-access"] = options[:public_access_level].to_s if options[:public_access_level]
75
+
76
+ # Call
77
+ response = call(:put, uri, nil, headers, options)
78
+
79
+ # result
80
+ container = Serialization.container_from_headers(response.headers)
81
+ container.name = name
82
+ container.metadata = options[:metadata]
83
+ container
84
+ end
85
+
86
+ # Public: Returns all properties and metadata on the container.
87
+ #
88
+ # ==== Attributes
89
+ #
90
+ # * +name+ - String. The name of the container
91
+ # * +options+ - Hash. Optional parameters.
92
+ #
93
+ # ==== Options
94
+ #
95
+ # Accepted key/value pairs in options parameter are:
96
+ # * +:timeout+ - Integer. A timeout in seconds.
97
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
98
+ # in the analytics logs when storage analytics logging is enabled.
99
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
100
+ # which location the request should be sent to.
101
+ # * +:lease_id+ - String. If specified, Get Container Properties only succeeds if the container’s lease is
102
+ # active and matches this ID. If there is no active lease or the ID does not match, 412
103
+ # (Precondition Failed) is returned.
104
+ #
105
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179370.aspx
106
+ #
107
+ # Returns a Container
108
+ def get_container_properties(name, options = {})
109
+ # Query
110
+ query = {}
111
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
112
+
113
+ headers = options[:lease_id] ? { "x-ms-lease-id" => options[:lease_id] } : {}
114
+
115
+ # Call
116
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
117
+ response = call(:get, container_uri(name, query, options), nil, headers, options)
118
+
119
+ # result
120
+ container = Serialization.container_from_headers(response.headers)
121
+ container.name = name
122
+ container
123
+ end
124
+
125
+ # Public: Returns only user-defined metadata for the specified container.
126
+ #
127
+ # ==== Attributes
128
+ #
129
+ # * +name+ - String. The name of the container
130
+ # * +options+ - Hash. Optional parameters.
131
+ #
132
+ # ==== Options
133
+ #
134
+ # Accepted key/value pairs in options parameter are:
135
+ # * +:timeout+ - Integer. A timeout in seconds.
136
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
137
+ # in the analytics logs when storage analytics logging is enabled.
138
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
139
+ # which location the request should be sent to.
140
+ # * +:lease_id+ - String. If specified, Get Container Metadata only succeeds if the container’s lease is
141
+ # active and matches this ID. If there is no active lease or the ID does not match, 412
142
+ # (Precondition Failed) is returned.
143
+ #
144
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691976.aspx
145
+ #
146
+ # Returns a Container
147
+ def get_container_metadata(name, options = {})
148
+ # Query
149
+ query = { "comp" => "metadata" }
150
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
151
+
152
+ headers = options[:lease_id] ? { "x-ms-lease-id" => options[:lease_id] } : {}
153
+
154
+ # Call
155
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
156
+ response = call(:get, container_uri(name, query, options), nil, headers, options)
157
+
158
+ # result
159
+ container = Serialization.container_from_headers(response.headers)
160
+ container.name = name
161
+ container
162
+ end
163
+
164
+ # Public: Sets custom metadata for the container.
165
+ #
166
+ # ==== Attributes
167
+ #
168
+ # * +name+ - String. The name of the container
169
+ # * +metadata+ - Hash. A Hash of the metadata values
170
+ # * +options+ - Hash. Optional parameters.
171
+ #
172
+ # ==== Options
173
+ #
174
+ # Accepted key/value pairs in options parameter are:
175
+ # * +:timeout+ - Integer. A timeout in seconds.
176
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
177
+ # in the analytics logs when storage analytics logging is enabled.
178
+ # * +:lease_id+ - String. If specified, Set Container Metadata only succeeds if the container’s lease is
179
+ # active and matches this ID. If there is no active lease or the ID does not match, 412
180
+ # (Precondition Failed) is returned.
181
+ #
182
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179362.aspx
183
+ #
184
+ # Returns nil on success
185
+ def set_container_metadata(name, metadata, options = {})
186
+ # Query
187
+ query = { "comp" => "metadata" }
188
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
189
+
190
+ # Headers
191
+ headers = {}
192
+ StorageService.add_metadata_to_headers(metadata, headers) if metadata
193
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
194
+
195
+ # Call
196
+ call(:put, container_uri(name, query), nil, headers, options)
197
+
198
+ # Result
199
+ nil
200
+ end
201
+
202
+ # Public: Gets the access control list (ACL) and any container-level access policies
203
+ # for the container.
204
+ #
205
+ # ==== Attributes
206
+ #
207
+ # * +name+ - String. The name of the container
208
+ # * +options+ - Hash. Optional parameters.
209
+ #
210
+ # ==== Options
211
+ #
212
+ # Accepted key/value pairs in options parameter are:
213
+ # * +:timeout+ - Integer. A timeout in seconds.
214
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
215
+ # in the analytics logs when storage analytics logging is enabled.
216
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
217
+ # which location the request should be sent to.
218
+ # * +:lease_id+ - String. If specified, Get Container ACL only succeeds if the container’s lease is
219
+ # active and matches this ID. If there is no active lease or the ID does not match, 412
220
+ # (Precondition Failed) is returned.
221
+ #
222
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179469.aspx
223
+ #
224
+ # Returns a tuple of (container, signed_identifiers)
225
+ # container - A Azure::Storage::Entity::Blob::Container instance
226
+ # signed_identifiers - A list of Azure::Storage::Entity::SignedIdentifier instances
227
+ #
228
+ def get_container_acl(name, options = {})
229
+ # Query
230
+ query = { "comp" => "acl" }
231
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
232
+
233
+ headers = options[:lease_id] ? { "x-ms-lease-id" => options[:lease_id] } : {}
234
+
235
+ # Call
236
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
237
+ response = call(:get, container_uri(name, query, options), nil, headers, options)
238
+
239
+ # Result
240
+ container = Serialization.container_from_headers(response.headers)
241
+ container.name = name
242
+
243
+ signed_identifiers = nil
244
+ signed_identifiers = Serialization.signed_identifiers_from_xml(response.body) if response.body != nil && response.body.length > 0
245
+
246
+ return container, signed_identifiers
247
+ end
248
+
249
+ # Public: Sets the ACL and any container-level access policies for the container.
250
+ #
251
+ # ==== Attributes
252
+ #
253
+ # * +name+ - String. The name of the container
254
+ # * +public_access_level+ - String. The container public access level
255
+ # * +options+ - Hash. Optional parameters.
256
+ #
257
+ # ==== Options
258
+ #
259
+ # Accepted key/value pairs in options parameter are:
260
+ # * +:signed_identifiers+ - Array. A list of Azure::Storage::Entity::SignedIdentifier instances (optional)
261
+ # * +:timeout+ - Integer. A timeout in seconds.
262
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
263
+ # in the analytics logs when storage analytics logging is enabled.
264
+ # * +:lease_id+ - String. If specified, Set Container ACL only succeeds if the container’s lease is
265
+ # active and matches this ID. If there is no active lease or the ID does not match, 412
266
+ # (Precondition Failed) is returned.
267
+ #
268
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179391.aspx
269
+ #
270
+ # Returns a tuple of (container, signed_identifiers)
271
+ # * +container+ - A Azure::Storage::Entity::Blob::Container instance
272
+ # * +signed_identifiers+ - A list of Azure::Storage::Entity::SignedIdentifier instances
273
+ #
274
+ def set_container_acl(name, public_access_level, options = {})
275
+ # Query
276
+ query = { "comp" => "acl" }
277
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
278
+
279
+ # Scheme + path
280
+ uri = container_uri(name, query)
281
+
282
+ # Headers + body
283
+ headers = {}
284
+ headers["x-ms-blob-public-access"] = public_access_level if public_access_level && public_access_level.to_s.length > 0
285
+ headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
286
+
287
+ signed_identifiers = nil
288
+ signed_identifiers = options[:signed_identifiers] if options[:signed_identifiers]
289
+
290
+ body = nil
291
+ body = Serialization.signed_identifiers_to_xml(signed_identifiers) if signed_identifiers
292
+
293
+ # Call
294
+ response = call(:put, uri, body, headers, options)
295
+
296
+ # Result
297
+ container = Serialization.container_from_headers(response.headers)
298
+ container.name = name
299
+ container.public_access_level = public_access_level
300
+
301
+ return container, signed_identifiers || []
302
+ end
303
+
304
+ # Public: Deletes a container.
305
+ #
306
+ # ==== Attributes
307
+ #
308
+ # * +name+ - String. The name of the container.
309
+ # * +options+ - Hash. Optional parameters.
310
+ #
311
+ # ==== Options
312
+ #
313
+ # Accepted key/value pairs in options parameter are:
314
+ # * +:timeout+ - Integer. A timeout in seconds.
315
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
316
+ # in the analytics logs when storage analytics logging is enabled.
317
+ # * +:lease_id+ - String. Required for version 2012-02-12 and newer if the container has an active lease. To call
318
+ # Delete Container on a container that has an active lease, specify the lease ID in this header.
319
+ # If this header is not specified when there is an active lease, Delete Container will return 409
320
+ # (Conflict). If you specify the wrong lease ID, or a lease ID on a container that does not have
321
+ # an active lease, Delete Container will return 412 (Precondition failed).
322
+ #
323
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179408.aspx
324
+ #
325
+ # Returns nil on success
326
+ def delete_container(name, options = {})
327
+ # Query
328
+ query = {}
329
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
330
+
331
+ headers = options[:lease_id] ? { "x-ms-lease-id" => options[:lease_id] } : {}
332
+
333
+ # Call
334
+ call(:delete, container_uri(name, query), nil, headers, options)
335
+
336
+ # result
337
+ nil
338
+ end
339
+
340
+ # Public: Establishes an exclusive write lock on a container. The lock duration can be 15 to 60 seconds, or can be infinite.
341
+ # To write to a locked container, a client must provide a lease ID.
342
+ #
343
+ # ==== Attributes
344
+ #
345
+ # * +container+ - String. The container name.
346
+ # * +options+ - Hash. Optional parameters.
347
+ #
348
+ # ==== Options
349
+ #
350
+ # Accepted key/value pairs in options parameter are:
351
+ # * +:duration+ - Integer. Default -1. Specifies the duration of the lease, in seconds, or negative one (-1)
352
+ # for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. (optional)
353
+ # * +:proposed_lease_id+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
354
+ # if the proposed lease ID is not in the correct format. (optional)
355
+ # * +:timeout+ - Integer. A timeout in seconds.
356
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
357
+ # in the analytics logs when storage analytics logging is enabled.
358
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
359
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
360
+ # the Blob service returns status code 412 (Precondition Failed).
361
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
362
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
363
+ # the Blob service returns status code 412 (Precondition Failed).
364
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
365
+ # only if the container's ETag value matches the value specified. If the values do not match,
366
+ # the Blob service returns status code 412 (Precondition Failed).
367
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
368
+ # only if the container's ETag value does not match the value specified. If the values are identical,
369
+ # the Blob service returns status code 412 (Precondition Failed).
370
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
371
+ # in cross-origin resource sharing headers on the response.
372
+ #
373
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
374
+ #
375
+ # Returns a String of the new unique lease id. While the lease is active, you must include the lease ID with any request
376
+ # to write, or to renew, change, or release the lease.
377
+ #
378
+ def acquire_container_lease(container, options = {})
379
+ acquire_lease container, nil, options
380
+ end
381
+
382
+ # Public: Renews the lease. The lease can be renewed if the lease ID specified on the request matches that
383
+ # associated with the container. Note that the lease may be renewed even if it has expired as long as the container
384
+ # has not been modified or leased again since the expiration of that lease. When you renew a lease, the
385
+ # lease duration clock resets.
386
+ #
387
+ # ==== Attributes
388
+ #
389
+ # * +container+ - String. The container name.
390
+ # * +lease+ - String. The lease id
391
+ # * +options+ - Hash. Optional parameters.
392
+ #
393
+ # ==== Options
394
+ #
395
+ # Accepted key/value pairs in options parameter are:
396
+ # * +:timeout+ - Integer. A timeout in seconds.
397
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
398
+ # in the analytics logs when storage analytics logging is enabled.
399
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
400
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
401
+ # the Blob service returns status code 412 (Precondition Failed).
402
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
403
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
404
+ # the Blob service returns status code 412 (Precondition Failed).
405
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
406
+ # only if the container's ETag value matches the value specified. If the values do not match,
407
+ # the Blob service returns status code 412 (Precondition Failed).
408
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
409
+ # only if the container's ETag value does not match the value specified. If the values are identical,
410
+ # the Blob service returns status code 412 (Precondition Failed).
411
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
412
+ # in cross-origin resource sharing headers on the response.
413
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
414
+ #
415
+ # Returns the renewed lease id
416
+ def renew_container_lease(container, lease, options = {})
417
+ renew_lease container, nil, lease, options
418
+ end
419
+
420
+ # Public: Change the lease ID.
421
+ #
422
+ # ==== Attributes
423
+ #
424
+ # * +container+ - String. The container name.
425
+ # * +lease+ - String. The existing lease id.
426
+ # * +proposed_lease+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
427
+ # if the proposed lease ID is not in the correct format. (optional).
428
+ # * +options+ - Hash. Optional parameters.
429
+ #
430
+ # ==== Options
431
+ #
432
+ # Accepted key/value pairs in options parameter are:
433
+ # * +:timeout+ - Integer. A timeout in seconds.
434
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
435
+ # in the analytics logs when storage analytics logging is enabled.
436
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to change the lease
437
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
438
+ # the Blob service returns status code 412 (Precondition Failed).
439
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to change the lease
440
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
441
+ # the Blob service returns status code 412 (Precondition Failed).
442
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
443
+ # only if the container's ETag value matches the value specified. If the values do not match,
444
+ # the Blob service returns status code 412 (Precondition Failed).
445
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
446
+ # only if the container's ETag value does not match the value specified. If the values are identical,
447
+ # the Blob service returns status code 412 (Precondition Failed).
448
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
449
+ # in cross-origin resource sharing headers on the response.
450
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
451
+ #
452
+ # Returns the changed lease id
453
+ def change_container_lease(container, lease, proposed_lease, options = {})
454
+ change_lease container, nil, lease, proposed_lease, options
455
+ end
456
+
457
+ # Public: Releases the lease. The lease may be released if the lease ID specified on the request matches that
458
+ # associated with the container. Releasing the lease allows another client to immediately acquire the lease for
459
+ # the container as soon as the release is complete.
460
+ #
461
+ # ==== Attributes
462
+ #
463
+ # * +container+ - String. The container name.
464
+ # * +lease+ - String. The lease id.
465
+ # * +options+ - Hash. Optional parameters.
466
+ #
467
+ # ==== Options
468
+ #
469
+ # Accepted key/value pairs in options parameter are:
470
+ # * +:timeout+ - Integer. A timeout in seconds.
471
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
472
+ # in the analytics logs when storage analytics logging is enabled.
473
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to release the lease
474
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
475
+ # the Blob service returns status code 412 (Precondition Failed).
476
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to release the lease
477
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
478
+ # the Blob service returns status code 412 (Precondition Failed).
479
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
480
+ # only if the container's ETag value matches the value specified. If the values do not match,
481
+ # the Blob service returns status code 412 (Precondition Failed).
482
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
483
+ # only if the container's ETag value does not match the value specified. If the values are identical,
484
+ # the Blob service returns status code 412 (Precondition Failed).
485
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
486
+ # in cross-origin resource sharing headers on the response.
487
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
488
+ #
489
+ # Returns nil on success
490
+ def release_container_lease(container, lease, options = {})
491
+ release_lease container, nil, lease, options
492
+ end
493
+
494
+ # Public: Breaks the lease, if the container has an active lease. Once a lease is broken, it cannot be renewed. Any
495
+ # authorized request can break the lease; the request is not required to specify a matching lease ID. When a
496
+ # lease is broken, the lease break period is allowed to elapse, during which time no lease operation except
497
+ # break and release can be performed on the container. When a lease is successfully broken, the response indicates
498
+ # the interval in seconds until a new lease can be acquired.
499
+ #
500
+ # A lease that has been broken can also be released, in which case another client may immediately acquire the
501
+ # lease on the container.
502
+ #
503
+ # ==== Attributes
504
+ #
505
+ # * +container+ - String. The container name.
506
+ # * +options+ - Hash. Optional parameters.
507
+ #
508
+ # ==== Options
509
+ #
510
+ # Accepted key/value pairs in options parameter are:
511
+ # * +:break_period+ - Integer. The proposed duration of seconds that the lease should continue before it is
512
+ # broken, between 0 and 60 seconds. This break period is only used if it is shorter than
513
+ # the time remaining on the lease. If longer, the time remaining on the lease is used. A
514
+ # new lease will not be available before the break period has expired, but the lease may
515
+ # be held for longer than the break period.
516
+ #
517
+ # If this option is not used, a fixed-duration lease breaks after the remaining lease
518
+ # period elapses, and an infinite lease breaks immediately.
519
+ # * +:timeout+ - Integer. A timeout in seconds.
520
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
521
+ # in the analytics logs when storage analytics logging is enabled.
522
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to break the lease
523
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
524
+ # the Blob service returns status code 412 (Precondition Failed).
525
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to break the lease
526
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
527
+ # the Blob service returns status code 412 (Precondition Failed).
528
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
529
+ # only if the container's ETag value matches the value specified. If the values do not match,
530
+ # the Blob service returns status code 412 (Precondition Failed).
531
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
532
+ # only if the container's ETag value does not match the value specified. If the values are identical,
533
+ # the Blob service returns status code 412 (Precondition Failed).
534
+ # * +:origin+ - String. Optional. Specifies the origin from which the request is issued. The presence of this header results
535
+ # in cross-origin resource sharing headers on the response.
536
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
537
+ #
538
+ # Returns an Integer of the remaining lease time. This value is the approximate time remaining in the lease
539
+ # period, in seconds. This header is returned only for a successful request to break the lease. If the break
540
+ # is immediate, 0 is returned.
541
+ def break_container_lease(container, options = {})
542
+ break_lease container, nil, options
543
+ end
544
+
545
+ # Public: Get a list of Blobs from the server
546
+ #
547
+ # ==== Attributes
548
+ #
549
+ # * +name+ - String. The name of the container to list blobs for.
550
+ # * +options+ - Hash. Optional parameters.
551
+ #
552
+ # ==== Options
553
+ #
554
+ # Accepted key/value pairs in options parameter are:
555
+ # * +:prefix+ - String. Filters the results to return only blobs
556
+ # whose name begins with the specified prefix. (optional)
557
+ # * +:delimiter+ - String. When the request includes this parameter, the operation
558
+ # returns a BlobPrefix element in the response body that acts as a
559
+ # placeholder for all blobs whose names begin with the same substring
560
+ # up to the appearance of the delimiter character. The delimiter may
561
+ # be a single character or a string.
562
+ # * +:marker+ - String. An identifier that specifies the portion of the
563
+ # list to be returned. This value comes from the property
564
+ # Azure::Storage::Common::EnumerationResults.continuation_token when
565
+ # there are more blobs available than were returned. The
566
+ # marker value may then be used here to request the next set
567
+ # of list items. (optional)
568
+ # * +:max_results+ - Integer. Specifies the maximum number of blobs to return.
569
+ # If max_results is not specified, or is a value greater than
570
+ # 5,000, the server will return up to 5,000 items. If it is set
571
+ # to a value less than or equal to zero, the server will return
572
+ # status code 400 (Bad Request). (optional)
573
+ # * +:metadata+ - Boolean. Specifies whether or not to return the blob metadata.
574
+ # (optional, Default=false)
575
+ # * +:snapshots+ - Boolean. Specifies that snapshots should be included in the
576
+ # enumeration. Snapshots are listed from oldest to newest in the
577
+ # response. (optional, Default=false)
578
+ # * +:uncomittedblobs+ - Boolean. Specifies that blobs for which blocks have been uploaded,
579
+ # but which have not been committed using put_block_list, be included
580
+ # in the response. (optional, Default=false)
581
+ # * +:copy+ - Boolean. Specifies that metadata related to any current or previous
582
+ # copy_blob operation should be included in the response.
583
+ # (optional, Default=false)
584
+ # * +:timeout+ - Integer. A timeout in seconds.
585
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
586
+ # in the analytics logs when storage analytics logging is enabled.
587
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
588
+ # which location the request should be sent to.
589
+ #
590
+ # NOTE: Metadata requested with the :metadata parameter must have been stored in
591
+ # accordance with the naming restrictions imposed by the 2009-09-19 version of the Blob
592
+ # service. Beginning with that version, all metadata names must adhere to the naming
593
+ # conventions for C# identifiers.
594
+ #
595
+ # See: http://msdn.microsoft.com/en-us/library/azure/dd135734.aspx
596
+ #
597
+ # Any metadata with invalid names which were previously stored, will be returned with the
598
+ # key "x-ms-invalid-name" in the metadata hash. This may contain multiple values and be an
599
+ # Array (vs a String if it only contains a single value).
600
+ #
601
+ # Returns an Azure::Storage::Common::EnumerationResults
602
+ def list_blobs(name, options = {})
603
+ # Query
604
+ query = { "comp" => "list" }
605
+ query["prefix"] = options[:prefix].gsub(/\\/, "/") if options[:prefix]
606
+ query["delimiter"] = options[:delimiter] if options[:delimiter]
607
+ query["marker"] = options[:marker] if options[:marker]
608
+ query["maxresults"] = options[:max_results].to_s if options[:max_results]
609
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
610
+
611
+ included_datasets = []
612
+ included_datasets.push("metadata") if options[:metadata] == true
613
+ included_datasets.push("snapshots") if options[:snapshots] == true
614
+ included_datasets.push("uncommittedblobs") if options[:uncommittedblobs] == true
615
+ included_datasets.push("copy") if options[:copy] == true
616
+
617
+ query["include"] = included_datasets.join "," if included_datasets.length > 0
618
+
619
+ # Scheme + path
620
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
621
+ uri = container_uri(name, query, options)
622
+
623
+ # Call
624
+ response = call(:get, uri, nil, {}, options)
625
+
626
+ # Result
627
+ if response.success?
628
+ Serialization.blob_enumeration_results_from_xml(response.body)
629
+ else
630
+ response.exception
631
+ end
632
+ end
633
+ end
634
+ end