azure-storage-blob 1.0.0

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