azure-storage 0.10.0.preview

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/lib/azure/storage.rb +58 -0
  3. data/lib/azure/storage/autoload.rb +71 -0
  4. data/lib/azure/storage/blob/append.rb +154 -0
  5. data/lib/azure/storage/blob/blob.rb +821 -0
  6. data/lib/azure/storage/blob/blob_service.rb +510 -0
  7. data/lib/azure/storage/blob/block.rb +264 -0
  8. data/lib/azure/storage/blob/container.rb +552 -0
  9. data/lib/azure/storage/blob/page.rb +380 -0
  10. data/lib/azure/storage/blob/serialization.rb +297 -0
  11. data/lib/azure/storage/client.rb +185 -0
  12. data/lib/azure/storage/configurable.rb +137 -0
  13. data/lib/azure/storage/core.rb +33 -0
  14. data/lib/azure/storage/core/auth/shared_access_signature.rb +27 -0
  15. data/lib/azure/storage/core/auth/shared_access_signature_generator.rb +194 -0
  16. data/lib/azure/storage/core/auth/shared_access_signature_signer.rb +49 -0
  17. data/lib/azure/storage/core/auth/shared_key.rb +125 -0
  18. data/lib/azure/storage/core/auth/shared_key_lite.rb +55 -0
  19. data/lib/azure/storage/core/auth/signer.rb +60 -0
  20. data/lib/azure/storage/core/autoload.rb +35 -0
  21. data/lib/azure/storage/core/client_options.rb +334 -0
  22. data/lib/azure/storage/core/client_options_error.rb +39 -0
  23. data/lib/azure/storage/core/constants.rb +1077 -0
  24. data/lib/azure/storage/core/error.rb +47 -0
  25. data/lib/azure/storage/core/filtered_service.rb +54 -0
  26. data/lib/azure/storage/core/http/debug_filter.rb +45 -0
  27. data/lib/azure/storage/core/http/http_error.rb +95 -0
  28. data/lib/azure/storage/core/http/http_filter.rb +62 -0
  29. data/lib/azure/storage/core/http/http_request.rb +182 -0
  30. data/lib/azure/storage/core/http/http_response.rb +105 -0
  31. data/lib/azure/storage/core/http/retry_policy.rb +83 -0
  32. data/lib/azure/storage/core/http/signer_filter.rb +42 -0
  33. data/lib/azure/storage/core/http_client.rb +63 -0
  34. data/lib/azure/storage/core/service.rb +55 -0
  35. data/lib/azure/storage/core/signed_service.rb +54 -0
  36. data/lib/azure/storage/core/sr.rb +83 -0
  37. data/lib/azure/storage/core/utility.rb +254 -0
  38. data/lib/azure/storage/queue/message.rb +39 -0
  39. data/lib/azure/storage/queue/queue.rb +37 -0
  40. data/lib/azure/storage/queue/queue_service.rb +580 -0
  41. data/lib/azure/storage/queue/serialization.rb +113 -0
  42. data/lib/azure/storage/service/access_policy.rb +35 -0
  43. data/lib/azure/storage/service/cors.rb +36 -0
  44. data/lib/azure/storage/service/cors_rule.rb +46 -0
  45. data/lib/azure/storage/service/enumeration_results.rb +30 -0
  46. data/lib/azure/storage/service/logging.rb +45 -0
  47. data/lib/azure/storage/service/metrics.rb +43 -0
  48. data/lib/azure/storage/service/retention_policy.rb +35 -0
  49. data/lib/azure/storage/service/serialization.rb +308 -0
  50. data/lib/azure/storage/service/signed_identifier.rb +39 -0
  51. data/lib/azure/storage/service/storage_service.rb +131 -0
  52. data/lib/azure/storage/service/storage_service_properties.rb +46 -0
  53. data/lib/azure/storage/table/auth/shared_key.rb +68 -0
  54. data/lib/azure/storage/table/auth/shared_key_lite.rb +53 -0
  55. data/lib/azure/storage/table/batch.rb +339 -0
  56. data/lib/azure/storage/table/batch_response.rb +127 -0
  57. data/lib/azure/storage/table/edmtype.rb +136 -0
  58. data/lib/azure/storage/table/entity.rb +40 -0
  59. data/lib/azure/storage/table/guid.rb +33 -0
  60. data/lib/azure/storage/table/query.rb +121 -0
  61. data/lib/azure/storage/table/serialization.rb +117 -0
  62. data/lib/azure/storage/table/table_service.rb +571 -0
  63. data/lib/azure/storage/version.rb +46 -0
  64. metadata +329 -0
@@ -0,0 +1,264 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # The MIT License(MIT)
5
+
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files(the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions :
12
+
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ #--------------------------------------------------------------------------
24
+ module Azure::Storage
25
+ module Blob
26
+ # Represents a Block as part of a BlockList
27
+ # The type should be one of :uncommitted, :committed or :latest
28
+ class Block
29
+
30
+ def initialize
31
+ @type = :latest
32
+ yield self if block_given?
33
+ end
34
+
35
+ attr_accessor :name
36
+ attr_accessor :size
37
+ attr_accessor :type
38
+ end
39
+
40
+ # Public: Creates a new block blob or updates the content of an existing block blob.
41
+ #
42
+ # Updating an existing block blob overwrites any existing metadata on the blob
43
+ # Partial updates are not supported with create_block_blob the content of the
44
+ # existing blob is overwritten with the content of the new blob. To perform a
45
+ # partial update of the content of a block blob, use the create_block_list
46
+ # method.
47
+ #
48
+ # Note that the default content type is application/octet-stream.
49
+ #
50
+ # ==== Attributes
51
+ #
52
+ # * +container+ - String. The container name.
53
+ # * +blob+ - String. The blob name.
54
+ # * +content+ - IO or String. The content of the blob.
55
+ # * +options+ - Hash. Optional parameters.
56
+ #
57
+ # ==== Options
58
+ #
59
+ # Accepted key/value pairs in options parameter are:
60
+ # * +:transactional_md5+ - String. An MD5 hash of the blob content. This hash is used to verify the integrity of the blob during transport.
61
+ # When this header is specified, the storage service checks the hash that has arrived with the one that was sent.
62
+ # If the two hashes do not match, the operation will fail with error code 400 (Bad Request).
63
+ # * +:content_type+ - String. Content type for the blob. Will be saved with blob.
64
+ # * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
65
+ # * +:content_language+ - String. Content language for the blob. Will be saved with blob.
66
+ # * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
67
+ # * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
68
+ # * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
69
+ # and also can be used to attach additional metadata
70
+ # * +:metadata+ - Hash. Custom metadata values to store with the blob.
71
+ # * +:timeout+ - Integer. A timeout in seconds.
72
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
73
+ # only if the blob has been modified since the specified date/time. If the blob has not been modified,
74
+ # the Blob service returns status code 412 (Precondition Failed).
75
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
76
+ # only if the blob has not been modified since the specified date/time. If the blob has been modified,
77
+ # the Blob service returns status code 412 (Precondition Failed).
78
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
79
+ # only if the blob's ETag value matches the value specified. If the values do not match,
80
+ # the Blob service returns status code 412 (Precondition Failed).
81
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
82
+ # only if the blob's ETag value does not match the value specified. If the values are identical,
83
+ # the Blob service returns status code 412 (Precondition Failed).
84
+ #
85
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
86
+ #
87
+ # Returns a Blob
88
+ def create_block_blob(container, blob, content, options={})
89
+ query = { }
90
+ StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
91
+
92
+ uri = blob_uri(container, blob, query)
93
+
94
+ headers = StorageService.service_properties_headers
95
+
96
+ # set x-ms-blob-type to BlockBlob
97
+ StorageService.with_header headers, 'x-ms-blob-type', 'BlockBlob'
98
+
99
+ # set the rest of the optional headers
100
+ StorageService.with_header headers, 'Content-MD5', options[:transactional_md5]
101
+ StorageService.with_header headers, 'x-ms-blob-content-type', options[:content_type]
102
+ StorageService.with_header headers, 'x-ms-blob-content-encoding', options[:content_encoding]
103
+ StorageService.with_header headers, 'x-ms-blob-content-language', options[:content_language]
104
+ StorageService.with_header headers, 'x-ms-blob-content-md5', options[:content_md5]
105
+ StorageService.with_header headers, 'x-ms-blob-cache-control', options[:cache_control]
106
+ StorageService.with_header headers, 'x-ms-blob-content-disposition', options[:content_disposition]
107
+
108
+ StorageService.add_metadata_to_headers options[:metadata], headers
109
+ add_blob_conditional_headers options, headers
110
+
111
+ # call PutBlob with empty body
112
+ response = call(:put, uri, content, headers)
113
+
114
+ result = Serialization.blob_from_headers(response.headers)
115
+ result.name = blob
116
+
117
+ result
118
+ end
119
+
120
+ # Public: Creates a new block to be committed as part of a block blob.
121
+ #
122
+ # ==== Attributes
123
+ #
124
+ # * +container+ - String. The container name.
125
+ # * +blob+ - String. The blob name.
126
+ # * +block_id+ - String. The block id. Note: this should be the raw block id, not Base64 encoded.
127
+ # * +content+ - IO or String. The content of the blob.
128
+ # * +options+ - Hash. Optional parameters.
129
+ #
130
+ # ==== Options
131
+ #
132
+ # Accepted key/value pairs in options parameter are:
133
+ # * +:content_md5+ - String. Content MD5 for the request contents.
134
+ # * +:timeout+ - Integer. A timeout in seconds.
135
+ #
136
+ # See http://msdn.microsoft.com/en-us/library/azure/dd135726.aspx
137
+ #
138
+ # Returns response of the operation
139
+ def put_blob_block(container, blob, block_id, content, options={})
140
+ query = { 'comp' => 'block'}
141
+ StorageService.with_query query, 'blockid', Base64.strict_encode64(block_id)
142
+ StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
143
+
144
+ uri = blob_uri(container, blob, query)
145
+
146
+ headers = StorageService.service_properties_headers
147
+ StorageService.with_header headers, 'Content-MD5', options[:content_md5]
148
+
149
+ response = call(:put, uri, content, headers)
150
+ response.headers['Content-MD5']
151
+ end
152
+
153
+ # Public: Commits existing blob blocks to a blob.
154
+ #
155
+ # This method writes a blob by specifying the list of block IDs that make up the
156
+ # blob. In order to be written as part of a blob, a block must have been
157
+ # successfully written to the server in a prior put_blob_block method.
158
+ #
159
+ # You can call Put Block List to update a blob by uploading only those blocks
160
+ # that have changed, then committing the new and existing blocks together.
161
+ # You can do this by specifying whether to commit a block from the committed
162
+ # block list or from the uncommitted block list, or to commit the most recently
163
+ # uploaded version of the block, whichever list it may belong to.
164
+ #
165
+ # ==== Attributes
166
+ #
167
+ # * +container+ - String. The container name.
168
+ # * +blob+ - String. The blob name.
169
+ # * +block_list+ - Array. A ordered list of lists in the following format:
170
+ # [ ["block_id1", :committed], ["block_id2", :uncommitted], ["block_id3"], ["block_id4", :committed]... ]
171
+ # The first element of the inner list is the block_id, the second is optional
172
+ # and can be either :committed or :uncommitted to indicate in which group of blocks
173
+ # the id should be looked for. If it is omitted, the latest of either group will be used.
174
+ # * +options+ - Hash. Optional parameters.
175
+ #
176
+ # ==== Options
177
+ #
178
+ # Accepted key/value pairs in options parameter are:
179
+ # * +:transactional_md5+ - String. Content MD5 for the request contents (not the blob contents!)
180
+ # * +:content_type+ - String. Content type for the blob. Will be saved with blob.
181
+ # * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
182
+ # * +:content_language+ - String. Content language for the blob. Will be saved with blob.
183
+ # * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
184
+ # * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
185
+ # * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
186
+ # and also can be used to attach additional metadata
187
+ # * +:metadata+ - Hash. Custom metadata values to store with the blob.
188
+ # * +:timeout+ - Integer. A timeout in seconds.
189
+ #
190
+ # This operation also supports the use of conditional headers to commit the block list if a specified condition is met.
191
+ # For more information, see https://msdn.microsoft.com/en-us/library/azure/dd179371.aspx
192
+ #
193
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179467.aspx
194
+ #
195
+ # Returns nil on success
196
+ def commit_blob_blocks(container, blob, block_list, options={})
197
+ query = { 'comp' => 'blocklist'}
198
+ StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
199
+
200
+ uri = blob_uri(container, blob, query)
201
+
202
+ headers = StorageService.service_properties_headers
203
+ unless options.empty?
204
+ StorageService.with_header headers, 'Content-MD5', options[:transactional_md5]
205
+ StorageService.with_header headers, 'x-ms-blob-content-type', options[:content_type]
206
+ StorageService.with_header headers, 'x-ms-blob-content-encoding', options[:content_encoding]
207
+ StorageService.with_header headers, 'x-ms-blob-content-language', options[:content_language]
208
+ StorageService.with_header headers, 'x-ms-blob-content-md5', options[:content_md5]
209
+ StorageService.with_header headers, 'x-ms-blob-cache-control', options[:cache_control]
210
+ StorageService.with_header headers, 'x-ms-blob-content-disposition', options[:content_disposition]
211
+
212
+ StorageService.add_metadata_to_headers(options[:metadata], headers)
213
+ add_blob_conditional_headers(options, headers)
214
+ end
215
+
216
+ body = Serialization.block_list_to_xml(block_list)
217
+ call(:put, uri, body, headers)
218
+ nil
219
+ end
220
+
221
+ # Public: Retrieves the list of blocks that have been uploaded as part of a block blob.
222
+ #
223
+ # There are two block lists maintained for a blob:
224
+ # 1) Committed Block List: The list of blocks that have been successfully
225
+ # committed to a given blob with commitBlobBlocks.
226
+ # 2) Uncommitted Block List: The list of blocks that have been uploaded for a
227
+ # blob using Put Block (REST API), but that have not yet been committed.
228
+ # These blocks are stored in Microsoft Azure in association with a blob, but do
229
+ # not yet form part of the blob.
230
+ #
231
+ # ==== Attributes
232
+ #
233
+ # * +container+ - String. The container name.
234
+ # * +blob+ - String. The blob name.
235
+ # * +options+ - Hash. Optional parameters.
236
+ #
237
+ # ==== Options
238
+ #
239
+ # Accepted key/value pairs in options parameter are:
240
+ # * +:blocklist_type+ - Symbol. One of :all, :committed, :uncommitted. Defaults to :all (optional)
241
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
242
+ # retrieve information from. (optional)
243
+ # * +:timeout+ - Integer. A timeout in seconds.
244
+ #
245
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179400.aspx
246
+ #
247
+ # Returns a list of Azure::Storage::Entity::Blob::Block instances
248
+ def list_blob_blocks(container, blob, options={})
249
+
250
+ options[:blocklist_type] = options[:blocklist_type] || :all
251
+
252
+ query = { 'comp' => 'blocklist'}
253
+ StorageService.with_query query, 'snapshot', options[:snapshot]
254
+ StorageService.with_query query, 'blocklisttype', options[:blocklist_type].to_s if options[:blocklist_type]
255
+ StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
256
+
257
+ uri = blob_uri(container, blob, query)
258
+
259
+ response = call(:get, uri)
260
+
261
+ Serialization.block_list_from_xml(response.body)
262
+ end
263
+ end
264
+ end
@@ -0,0 +1,552 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # The MIT License(MIT)
5
+
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files(the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions :
12
+
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ #--------------------------------------------------------------------------
24
+ require 'azure/storage/blob/serialization'
25
+
26
+ module Azure::Storage::Blob
27
+ module Container
28
+ include Azure::Storage::Service
29
+
30
+ class Container
31
+ def initialize
32
+ @properties = {}
33
+ @metadata = {}
34
+ yield self if block_given?
35
+ end
36
+
37
+ attr_accessor :name
38
+ attr_accessor :properties
39
+ attr_accessor :metadata
40
+ attr_accessor :public_access_level
41
+ end
42
+
43
+ # Public: Create a new container
44
+ #
45
+ # ==== Attributes
46
+ #
47
+ # * +name+ - String. The name of the container.
48
+ # * +options+ - Hash. Optional parameters.
49
+ #
50
+ # ==== Options
51
+ #
52
+ # Accepted key/value pairs in options parameter are:
53
+ # * +:metadata+ - Hash. User defined metadata for the container (optional).
54
+ # * +:public_access_level+ - String. One of "container" or "blob" (optional).
55
+ # * +:timeout+ - Integer. A timeout in seconds.
56
+ #
57
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179468.aspx
58
+ #
59
+ # Returns a Container
60
+ def create_container(name, options={})
61
+ # Query
62
+ query = { }
63
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
64
+
65
+ # Scheme + path
66
+ uri = container_uri(name, query)
67
+
68
+ # Headers
69
+ headers = StorageService.service_properties_headers
70
+ StorageService.add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
71
+ headers['x-ms-blob-public-access'] = options[:public_access_level].to_s if options[:public_access_level]
72
+
73
+ # Call
74
+ response = call(:put, uri, nil, headers)
75
+
76
+ # result
77
+ container = Serialization.container_from_headers(response.headers)
78
+ container.name = name
79
+ container.metadata = options[:metadata]
80
+ container
81
+ end
82
+
83
+ # Public: Returns all properties and metadata on the container.
84
+ #
85
+ # ==== Attributes
86
+ #
87
+ # * +name+ - String. The name of the container
88
+ # * +options+ - Hash. Optional parameters.
89
+ #
90
+ # ==== Options
91
+ #
92
+ # Accepted key/value pairs in options parameter are:
93
+ # * +:timeout+ - Integer. A timeout in seconds.
94
+ #
95
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179370.aspx
96
+ #
97
+ # Returns a Container
98
+ def get_container_properties(name, options={})
99
+ # Query
100
+ query = { }
101
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
102
+
103
+ # Call
104
+ response = call(:get, container_uri(name, query))
105
+
106
+ # result
107
+ container = Serialization.container_from_headers(response.headers)
108
+ container.name = name
109
+ container
110
+ end
111
+
112
+ # Public: Returns only user-defined metadata for the specified container.
113
+ #
114
+ # ==== Attributes
115
+ #
116
+ # * +name+ - String. The name of the container
117
+ # * +options+ - Hash. Optional parameters.
118
+ #
119
+ # ==== Options
120
+ #
121
+ # Accepted key/value pairs in options parameter are:
122
+ # * +:timeout+ - Integer. A timeout in seconds.
123
+ #
124
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691976.aspx
125
+ #
126
+ # Returns a Container
127
+ def get_container_metadata(name, options={})
128
+ # Query
129
+ query = { 'comp' => 'metadata' }
130
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
131
+
132
+ # Call
133
+ response = call(:get, container_uri(name, query))
134
+
135
+ # result
136
+ container = Serialization.container_from_headers(response.headers)
137
+ container.name = name
138
+ container
139
+ end
140
+
141
+ # Public: Sets custom metadata for the container.
142
+ #
143
+ # ==== Attributes
144
+ #
145
+ # * +name+ - String. The name of the container
146
+ # * +metadata+ - Hash. A Hash of the metadata values
147
+ # * +options+ - Hash. Optional parameters.
148
+ #
149
+ # ==== Options
150
+ #
151
+ # Accepted key/value pairs in options parameter are:
152
+ # * +:timeout+ - Integer. A timeout in seconds.
153
+ #
154
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179362.aspx
155
+ #
156
+ # Returns nil on success
157
+ def set_container_metadata(name, metadata, options={})
158
+ # Query
159
+ query = { 'comp' => 'metadata' }
160
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
161
+
162
+ # Headers
163
+ headers = StorageService.service_properties_headers
164
+ StorageService.add_metadata_to_headers(metadata, headers) if metadata
165
+
166
+ # Call
167
+ call(:put, container_uri(name, query), nil, headers)
168
+
169
+ # Result
170
+ nil
171
+ end
172
+
173
+ # Public: Gets the access control list (ACL) and any container-level access policies
174
+ # for the container.
175
+ #
176
+ # ==== Attributes
177
+ #
178
+ # * +name+ - String. The name of the container
179
+ # * +options+ - Hash. Optional parameters.
180
+ #
181
+ # ==== Options
182
+ #
183
+ # Accepted key/value pairs in options parameter are:
184
+ # * +:timeout+ - Integer. A timeout in seconds.
185
+ #
186
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179469.aspx
187
+ #
188
+ # Returns a tuple of (container, signed_identifiers)
189
+ # container - A Azure::Storage::Entity::Blob::Container instance
190
+ # signed_identifiers - A list of Azure::Storage::Entity::SignedIdentifier instances
191
+ #
192
+ def get_container_acl(name, options={})
193
+ # Query
194
+ query = { 'comp' => 'acl' }
195
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
196
+
197
+ # Call
198
+ response = call(:get, container_uri(name, query))
199
+
200
+ # Result
201
+ container = Serialization.container_from_headers(response.headers)
202
+ container.name = name
203
+
204
+ signed_identifiers = nil
205
+ signed_identifiers = Serialization.signed_identifiers_from_xml(response.body) if response.body != nil && response.body.length > 0
206
+
207
+ return container, signed_identifiers
208
+ end
209
+
210
+ # Public: Sets the ACL and any container-level access policies for the container.
211
+ #
212
+ # ==== Attributes
213
+ #
214
+ # * +name+ - String. The name of the container
215
+ # * +public_access_level+ - String. The container public access level
216
+ # * +options+ - Hash. Optional parameters.
217
+ #
218
+ # ==== Options
219
+ #
220
+ # Accepted key/value pairs in options parameter are:
221
+ # * +:signed_identifiers+ - Array. A list of Azure::Storage::Entity::SignedIdentifier instances (optional)
222
+ # * +:timeout+ - Integer. A timeout in seconds.
223
+ #
224
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179391.aspx
225
+ #
226
+ # Returns a tuple of (container, signed_identifiers)
227
+ # * +container+ - A Azure::Storage::Entity::Blob::Container instance
228
+ # * +signed_identifiers+ - A list of Azure::Storage::Entity::SignedIdentifier instances
229
+ #
230
+ def set_container_acl(name, public_access_level, options={})
231
+ # Query
232
+ query = { 'comp' => 'acl' }
233
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
234
+
235
+ # Scheme + path
236
+ uri = container_uri(name, query)
237
+
238
+ # Headers + body
239
+ headers = StorageService.service_properties_headers
240
+ headers['x-ms-blob-public-access'] = public_access_level if public_access_level && public_access_level.to_s.length > 0
241
+
242
+ signed_identifiers = nil
243
+ signed_identifiers = options[:signed_identifiers] if options[:signed_identifiers]
244
+
245
+ body = nil
246
+ body = Serialization.signed_identifiers_to_xml(signed_identifiers) if signed_identifiers
247
+
248
+ # Call
249
+ response = call(:put, uri, body, headers)
250
+
251
+ # Result
252
+ container = Serialization.container_from_headers(response.headers)
253
+ container.name = name
254
+ container.public_access_level = public_access_level
255
+
256
+ return container, signed_identifiers || []
257
+ end
258
+
259
+ # Public: Deletes a container.
260
+ #
261
+ # ==== Attributes
262
+ #
263
+ # * +name+ - String. The name of the container.
264
+ # * +options+ - Hash. Optional parameters.
265
+ #
266
+ # ==== Options
267
+ #
268
+ # Accepted key/value pairs in options parameter are:
269
+ # * +:timeout+ - Integer. A timeout in seconds.
270
+ #
271
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179408.aspx
272
+ #
273
+ # Returns nil on success
274
+ def delete_container(name, options={})
275
+ # Query
276
+ query = { }
277
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
278
+
279
+ # Call
280
+ call(:delete, container_uri(name, query))
281
+
282
+ # result
283
+ nil
284
+ end
285
+
286
+ # Public: Establishes an exclusive write lock on a container. The lock duration can be 15 to 60 seconds, or can be infinite.
287
+ # To write to a locked container, a client must provide a lease ID.
288
+ #
289
+ # ==== Attributes
290
+ #
291
+ # * +container+ - String. The container name.
292
+ # * +options+ - Hash. Optional parameters.
293
+ #
294
+ # ==== Options
295
+ #
296
+ # Accepted key/value pairs in options parameter are:
297
+ # * +:duration+ - Integer. Default -1. Specifies the duration of the lease, in seconds, or negative one (-1)
298
+ # for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. (optional)
299
+ # * +:proposed_lease_id+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
300
+ # if the proposed lease ID is not in the correct format. (optional)
301
+ # * +:timeout+ - Integer. A timeout in seconds.
302
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
303
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
304
+ # the Blob service returns status code 412 (Precondition Failed).
305
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to acquire the lease
306
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
307
+ # the Blob service returns status code 412 (Precondition Failed).
308
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
309
+ # only if the container's ETag value matches the value specified. If the values do not match,
310
+ # the Blob service returns status code 412 (Precondition Failed).
311
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to acquire the lease
312
+ # only if the container's ETag value does not match the value specified. If the values are identical,
313
+ # the Blob service returns status code 412 (Precondition Failed).
314
+ #
315
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
316
+ #
317
+ # Returns a String of the new unique lease id. While the lease is active, you must include the lease ID with any request
318
+ # to write, or to renew, change, or release the lease.
319
+ #
320
+ def acquire_container_lease(container, options={})
321
+ acquire_lease container, nil, options
322
+ end
323
+
324
+ # Public: Renews the lease. The lease can be renewed if the lease ID specified on the request matches that
325
+ # associated with the container. Note that the lease may be renewed even if it has expired as long as the container
326
+ # has not been modified or leased again since the expiration of that lease. When you renew a lease, the
327
+ # lease duration clock resets.
328
+ #
329
+ # ==== Attributes
330
+ #
331
+ # * +container+ - String. The container name.
332
+ # * +lease+ - String. The lease id
333
+ # * +options+ - Hash. Optional parameters.
334
+ #
335
+ # ==== Options
336
+ #
337
+ # Accepted key/value pairs in options parameter are:
338
+ # * +:timeout+ - Integer. A timeout in seconds.
339
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
340
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
341
+ # the Blob service returns status code 412 (Precondition Failed).
342
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to renew the lease
343
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
344
+ # the Blob service returns status code 412 (Precondition Failed).
345
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
346
+ # only if the container's ETag value matches the value specified. If the values do not match,
347
+ # the Blob service returns status code 412 (Precondition Failed).
348
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to renew the lease
349
+ # only if the container's ETag value does not match the value specified. If the values are identical,
350
+ # the Blob service returns status code 412 (Precondition Failed).
351
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
352
+ #
353
+ # Returns the renewed lease id
354
+ def renew_container_lease(container, lease, options={})
355
+ renew_lease container, nil, lease, options
356
+ end
357
+
358
+ # Public: Change the lease ID.
359
+ #
360
+ # ==== Attributes
361
+ #
362
+ # * +container+ - String. The container name.
363
+ # * +lease+ - String. The existing lease id.
364
+ # * +proposed_lease+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
365
+ # if the proposed lease ID is not in the correct format. (optional).
366
+ # * +options+ - Hash. Optional parameters.
367
+ #
368
+ # ==== Options
369
+ #
370
+ # Accepted key/value pairs in options parameter are:
371
+ # * +:timeout+ - Integer. A timeout in seconds.
372
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to change the lease
373
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
374
+ # the Blob service returns status code 412 (Precondition Failed).
375
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to change the lease
376
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
377
+ # the Blob service returns status code 412 (Precondition Failed).
378
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
379
+ # only if the container's ETag value matches the value specified. If the values do not match,
380
+ # the Blob service returns status code 412 (Precondition Failed).
381
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to change the lease
382
+ # only if the container's ETag value does not match the value specified. If the values are identical,
383
+ # the Blob service returns status code 412 (Precondition Failed).
384
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
385
+ #
386
+ # Returns the changed lease id
387
+ def change_container_lease(container, lease, proposed_lease, options={})
388
+ change_lease container, nil, lease, proposed_lease, options
389
+ end
390
+
391
+ # Public: Releases the lease. The lease may be released if the lease ID specified on the request matches that
392
+ # associated with the container. Releasing the lease allows another client to immediately acquire the lease for
393
+ # the container as soon as the release is complete.
394
+ #
395
+ # ==== Attributes
396
+ #
397
+ # * +container+ - String. The container name.
398
+ # * +lease+ - String. The lease id.
399
+ # * +options+ - Hash. Optional parameters.
400
+ #
401
+ # ==== Options
402
+ #
403
+ # Accepted key/value pairs in options parameter are:
404
+ # * +:timeout+ - Integer. A timeout in seconds.
405
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to release the lease
406
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
407
+ # the Blob service returns status code 412 (Precondition Failed).
408
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to release the lease
409
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
410
+ # the Blob service returns status code 412 (Precondition Failed).
411
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
412
+ # only if the container's ETag value matches the value specified. If the values do not match,
413
+ # the Blob service returns status code 412 (Precondition Failed).
414
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to release the lease
415
+ # only if the container's ETag value does not match the value specified. If the values are identical,
416
+ # the Blob service returns status code 412 (Precondition Failed).
417
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
418
+ #
419
+ # Returns nil on success
420
+ def release_container_lease(container, lease, options={})
421
+ release_lease container, nil, lease, options
422
+ end
423
+
424
+ # Public: Breaks the lease, if the container has an active lease. Once a lease is broken, it cannot be renewed. Any
425
+ # authorized request can break the lease; the request is not required to specify a matching lease ID. When a
426
+ # lease is broken, the lease break period is allowed to elapse, during which time no lease operation except
427
+ # break and release can be performed on the container. When a lease is successfully broken, the response indicates
428
+ # the interval in seconds until a new lease can be acquired.
429
+ #
430
+ # A lease that has been broken can also be released, in which case another client may immediately acquire the
431
+ # lease on the container.
432
+ #
433
+ # ==== Attributes
434
+ #
435
+ # * +container+ - String. The container name.
436
+ # * +options+ - Hash. Optional parameters.
437
+ #
438
+ # ==== Options
439
+ #
440
+ # Accepted key/value pairs in options parameter are:
441
+ # * +:break_period+ - Integer. The proposed duration of seconds that the lease should continue before it is
442
+ # broken, between 0 and 60 seconds. This break period is only used if it is shorter than
443
+ # the time remaining on the lease. If longer, the time remaining on the lease is used. A
444
+ # new lease will not be available before the break period has expired, but the lease may
445
+ # be held for longer than the break period.
446
+ #
447
+ # If this option is not used, a fixed-duration lease breaks after the remaining lease
448
+ # period elapses, and an infinite lease breaks immediately.
449
+ # * +:timeout+ - Integer. A timeout in seconds.
450
+ # * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to break the lease
451
+ # only if the container has been modified since the specified date/time. If the container has not been modified,
452
+ # the Blob service returns status code 412 (Precondition Failed).
453
+ # * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to break the lease
454
+ # only if the container has not been modified since the specified date/time. If the container has been modified,
455
+ # the Blob service returns status code 412 (Precondition Failed).
456
+ # * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
457
+ # only if the container's ETag value matches the value specified. If the values do not match,
458
+ # the Blob service returns status code 412 (Precondition Failed).
459
+ # * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to break the lease
460
+ # only if the container's ETag value does not match the value specified. If the values are identical,
461
+ # the Blob service returns status code 412 (Precondition Failed).
462
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
463
+ #
464
+ # Returns an Integer of the remaining lease time. This value is the approximate time remaining in the lease
465
+ # period, in seconds. This header is returned only for a successful request to break the lease. If the break
466
+ # is immediate, 0 is returned.
467
+ def break_container_lease(container, options={})
468
+ break_lease container, nil, options
469
+ end
470
+
471
+ # Public: Get a list of Blobs from the server
472
+ #
473
+ # ==== Attributes
474
+ #
475
+ # * +name+ - String. The name of the container to list blobs for.
476
+ # * +options+ - Hash. Optional parameters.
477
+ #
478
+ # ==== Options
479
+ #
480
+ # Accepted key/value pairs in options parameter are:
481
+ # * +:prefix+ - String. Filters the results to return only blobs
482
+ # whose name begins with the specified prefix. (optional)
483
+ # * +:delimiter+ - String. When the request includes this parameter, the operation
484
+ # returns a BlobPrefix element in the response body that acts as a
485
+ # placeholder for all blobs whose names begin with the same substring
486
+ # up to the appearance of the delimiter character. The delimiter may
487
+ # be a single character or a string.
488
+ # * +:marker+ - String. An identifier that specifies the portion of the
489
+ # list to be returned. This value comes from the property
490
+ # Azure::Service::EnumerationResults.continuation_token when
491
+ # there are more blobs available than were returned. The
492
+ # marker value may then be used here to request the next set
493
+ # of list items. (optional)
494
+ # * +:max_results+ - Integer. Specifies the maximum number of blobs to return.
495
+ # If max_results is not specified, or is a value greater than
496
+ # 5,000, the server will return up to 5,000 items. If it is set
497
+ # to a value less than or equal to zero, the server will return
498
+ # status code 400 (Bad Request). (optional)
499
+ # * +:metadata+ - Boolean. Specifies whether or not to return the blob metadata.
500
+ # (optional, Default=false)
501
+ # * +:snapshots+ - Boolean. Specifies that snapshots should be included in the
502
+ # enumeration. Snapshots are listed from oldest to newest in the
503
+ # response. (optional, Default=false)
504
+ # * +:uncomittedblobs+ - Boolean. Specifies that blobs for which blocks have been uploaded,
505
+ # but which have not been committed using put_block_list, be included
506
+ # in the response. (optional, Default=false)
507
+ # * +:copy+ - Boolean. Specifies that metadata related to any current or previous
508
+ # copy_blob operation should be included in the response.
509
+ # (optional, Default=false)
510
+ # * +:timeout+ - Integer. A timeout in seconds.
511
+ #
512
+ # NOTE: Metadata requested with the :metadata parameter must have been stored in
513
+ # accordance with the naming restrictions imposed by the 2009-09-19 version of the Blob
514
+ # service. Beginning with that version, all metadata names must adhere to the naming
515
+ # conventions for C# identifiers.
516
+ #
517
+ # See: http://msdn.microsoft.com/en-us/library/azure/dd135734.aspx
518
+ #
519
+ # Any metadata with invalid names which were previously stored, will be returned with the
520
+ # key "x-ms-invalid-name" in the metadata hash. This may contain multiple values and be an
521
+ # Array (vs a String if it only contains a single value).
522
+ #
523
+ # Returns an Azure::Service::EnumerationResults
524
+ def list_blobs(name, options={})
525
+ # Query
526
+ query = { 'comp' => 'list' }
527
+ query['prefix'] = options[:prefix].gsub(/\\/, '/') if options[:prefix]
528
+ query['delimiter'] = options[:delimiter] if options[:delimiter]
529
+ query['marker'] = options[:marker] if options[:marker]
530
+ query['maxresults'] = options[:max_results].to_s if options[:max_results]
531
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
532
+
533
+ included_datasets = []
534
+ included_datasets.push('metadata') if options[:metadata] == true
535
+ included_datasets.push('snapshots') if options[:snapshots] == true
536
+ included_datasets.push('uncommittedblobs') if options[:uncommittedblobs] == true
537
+ included_datasets.push('copy') if options[:copy] == true
538
+
539
+ query['include'] = included_datasets.join ',' if included_datasets.length > 0
540
+
541
+ # Scheme + path
542
+ uri = container_uri(name, query)
543
+
544
+ # Call
545
+ response = call(:get, uri)
546
+
547
+ # Result
548
+ Serialization.blob_enumeration_results_from_xml(response.body)
549
+ end
550
+
551
+ end
552
+ end