azure-storage-blob2 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5273b006499ab7dbc0bfc1b37ca910e109ba123599862fa621f4c9d3fc5f259c
4
- data.tar.gz: 913d13a7648ae2e50fd9fc2a29d963bb1348671950fedab948e9eafd533b9b98
3
+ metadata.gz: cfe567a3dd49e66bcddc8a1d599c34fee2718bfd4ca038b6fe32662b86ed321b
4
+ data.tar.gz: c1b44759803be6fbc50040d3bf985d1d560710bd6b075de59c66008edafba904
5
5
  SHA512:
6
- metadata.gz: 83be0949dceb177450b52444284b74b87a4ecc81d47e2e7a42d691ede97066fb4b2bc37f805582d585589111b108b8d2dc4e2f600b33dcaf29056e835ed50634
7
- data.tar.gz: e3578f23d8ba9ff624e54df1c4bd5394ee2cd635c30ec7e0d0cb0ee86d03351121d547eef0495f811b985f4fe4e3e80e9079091669fb2d2e967471f4dee4e39d
6
+ metadata.gz: a0dec0629408d08d74ffa451382c16a0f3eb55bf7f2bd2969cbdda8ea64b7a9cbfbc620f9d982a0f6e479628914509a8025b1f95d68eb43caea1b0b9d37140b7
7
+ data.tar.gz: d219fbae5abced857dca0b87aaa8029d58df6e207af44c051c9e03d960cdd8bd0e5ffe3cc1230bb5d75aceb12d47e4ba2a39f21fe93ec70bf354e91a523b28be
@@ -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