azure-storage 0.11.5.preview → 0.12.0.preview
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/azure/storage/autoload.rb +8 -0
- data/lib/azure/storage/blob/append.rb +1 -0
- data/lib/azure/storage/blob/blob.rb +9 -9
- data/lib/azure/storage/blob/blob_service.rb +3 -13
- data/lib/azure/storage/blob/block.rb +1 -0
- data/lib/azure/storage/blob/page.rb +6 -2
- data/lib/azure/storage/client.rb +11 -8
- data/lib/azure/storage/client_options.rb +10 -2
- data/lib/azure/storage/configurable.rb +42 -6
- data/lib/azure/storage/core/auth/shared_access_signature_generator.rb +17 -1
- data/lib/azure/storage/core/filter/retry_filter.rb +13 -4
- data/lib/azure/storage/file/directory.rb +268 -0
- data/lib/azure/storage/file/file.rb +602 -0
- data/lib/azure/storage/file/file_service.rb +191 -0
- data/lib/azure/storage/file/serialization.rb +225 -0
- data/lib/azure/storage/file/share.rb +363 -0
- data/lib/azure/storage/queue/queue_service.rb +1 -1
- data/lib/azure/storage/service/storage_service.rb +22 -5
- data/lib/azure/storage/table/table_service.rb +1 -3
- data/lib/azure/storage/version.rb +2 -2
- metadata +7 -2
@@ -0,0 +1,602 @@
|
|
1
|
+
#-------------------------------------------------------------------------
|
2
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
3
|
+
#
|
4
|
+
# The MIT License(MIT)
|
5
|
+
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files(the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions :
|
12
|
+
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
# THE SOFTWARE.
|
23
|
+
#--------------------------------------------------------------------------
|
24
|
+
require 'azure/storage/file/serialization'
|
25
|
+
|
26
|
+
module Azure::Storage::File
|
27
|
+
include Azure::Storage::Service
|
28
|
+
|
29
|
+
class File
|
30
|
+
def initialize
|
31
|
+
@properties = {}
|
32
|
+
@metadata = {}
|
33
|
+
yield self if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_accessor :name
|
37
|
+
attr_accessor :properties
|
38
|
+
attr_accessor :metadata
|
39
|
+
end
|
40
|
+
|
41
|
+
# Public: Creates a new file or replaces a file. Note that it only initializes the file.
|
42
|
+
# To add content to a file, call the put_range operation.
|
43
|
+
#
|
44
|
+
# Updating an existing file overwrites any existing metadata on the file
|
45
|
+
# Partial updates are not supported with create_file. The content of the
|
46
|
+
# existing file is overwritten with the content of the new file. To perform a
|
47
|
+
# partial update of the content of a file, use the put_range method.
|
48
|
+
#
|
49
|
+
# Note that the default content type is application/octet-stream.
|
50
|
+
#
|
51
|
+
# ==== Attributes
|
52
|
+
#
|
53
|
+
# * +share+ - String. The name of the file share.
|
54
|
+
# * +directory_path+ - String. The path to the directory.
|
55
|
+
# * +file+ - String. The name of the file.
|
56
|
+
# * +length+ - Integer. Specifies the maximum byte value for the file, up to 1 TB.
|
57
|
+
# * +options+ - Hash. Optional parameters.
|
58
|
+
#
|
59
|
+
# ==== Options
|
60
|
+
#
|
61
|
+
# Accepted key/value pairs in options parameter are:
|
62
|
+
# * +:content_type+ - String. Content type for the file. Will be saved with file.
|
63
|
+
# * +:content_encoding+ - String. Content encoding for the file. Will be saved with file.
|
64
|
+
# * +:content_language+ - String. Content language for the file. Will be saved with file.
|
65
|
+
# * +:content_md5+ - String. Content MD5 for the file. Will be saved with file.
|
66
|
+
# * +:cache_control+ - String. Cache control for the file. Will be saved with file.
|
67
|
+
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
68
|
+
# and also can be used to attach additional metadata
|
69
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the file.
|
70
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
71
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
72
|
+
# in the analytics logs when storage analytics logging is enabled.
|
73
|
+
#
|
74
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/create-file
|
75
|
+
#
|
76
|
+
# Returns a File
|
77
|
+
def create_file(share, directory_path, file, length, options={})
|
78
|
+
query = { }
|
79
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
80
|
+
|
81
|
+
uri = file_uri(share, directory_path, file, query)
|
82
|
+
|
83
|
+
headers = StorageService.common_headers
|
84
|
+
|
85
|
+
# set x-ms-type to file
|
86
|
+
StorageService.with_header headers, 'x-ms-type', 'file'
|
87
|
+
|
88
|
+
# ensure content-length is 0 and x-ms-content-length is the file length
|
89
|
+
StorageService.with_header headers, 'Content-Length', 0.to_s
|
90
|
+
StorageService.with_header headers, 'x-ms-content-length', length.to_s
|
91
|
+
|
92
|
+
# set the rest of the optional headers
|
93
|
+
StorageService.with_header headers, 'x-ms-content-type', options[:content_type]
|
94
|
+
StorageService.with_header headers, 'x-ms-content-encoding', options[:content_encoding]
|
95
|
+
StorageService.with_header headers, 'x-ms-content-language', options[:content_language]
|
96
|
+
StorageService.with_header headers, 'x-ms-content-md5', options[:content_md5]
|
97
|
+
StorageService.with_header headers, 'x-ms-cache-control', options[:cache_control]
|
98
|
+
StorageService.with_header headers, 'x-ms-content-disposition', options[:content_disposition]
|
99
|
+
|
100
|
+
StorageService.add_metadata_to_headers options[:metadata], headers
|
101
|
+
|
102
|
+
response = call(:put, uri, nil, headers, options)
|
103
|
+
|
104
|
+
result = Serialization.file_from_headers(response.headers)
|
105
|
+
result.name = file
|
106
|
+
result.properties[:content_length] = length
|
107
|
+
result.metadata = options[:metadata] if options[:metadata]
|
108
|
+
result
|
109
|
+
end
|
110
|
+
|
111
|
+
# Public: Reads or downloads a file from the system, including its metadata and properties.
|
112
|
+
#
|
113
|
+
# ==== Attributes
|
114
|
+
#
|
115
|
+
# * +share+ - String. The name of the file share.
|
116
|
+
# * +directory_path+ - String. The path to the directory.
|
117
|
+
# * +file+ - String. The name of the file.
|
118
|
+
# * +options+ - Hash. Optional parameters.
|
119
|
+
#
|
120
|
+
# ==== Options
|
121
|
+
#
|
122
|
+
# Accepted key/value pairs in options parameter are:
|
123
|
+
# * +:start_range+ - Integer. Position of the start range. (optional)
|
124
|
+
# * +:end_range+ - Integer. Position of the end range. (optional)
|
125
|
+
# * +:get_content_md5+ - Boolean. Return the MD5 hash for the range. This option only valid if
|
126
|
+
# start_range and end_range are specified. (optional)
|
127
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
128
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
129
|
+
# in the analytics logs when storage analytics logging is enabled.
|
130
|
+
#
|
131
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-file
|
132
|
+
#
|
133
|
+
# Returns a File and the file body
|
134
|
+
def get_file(share, directory_path, file, options={})
|
135
|
+
query = { }
|
136
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
137
|
+
uri = file_uri(share, directory_path, file, query)
|
138
|
+
|
139
|
+
headers = StorageService.common_headers
|
140
|
+
options[:start_range] = 0 if options[:end_range] and not options[:start_range]
|
141
|
+
if options[:start_range]
|
142
|
+
StorageService.with_header headers, 'x-ms-range', "bytes=#{options[:start_range]}-#{options[:end_range]}"
|
143
|
+
StorageService.with_header headers, 'x-ms-range-get-content-md5', true if options[:get_content_md5]
|
144
|
+
end
|
145
|
+
|
146
|
+
response = call(:get, uri, nil, headers, options)
|
147
|
+
result = Serialization.file_from_headers(response.headers)
|
148
|
+
result.name = file
|
149
|
+
return result, response.body
|
150
|
+
end
|
151
|
+
|
152
|
+
# Public: Returns all properties and metadata on the file.
|
153
|
+
#
|
154
|
+
# ==== Attributes
|
155
|
+
#
|
156
|
+
# * +share+ - String. The name of the file share.
|
157
|
+
# * +directory_path+ - String. The path to the directory.
|
158
|
+
# * +file+ - String. The name of the file.
|
159
|
+
# * +options+ - Hash. Optional parameters.
|
160
|
+
#
|
161
|
+
# ==== Options
|
162
|
+
#
|
163
|
+
# Accepted key/value pairs in options parameter are:
|
164
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
165
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
166
|
+
# in the analytics logs when storage analytics logging is enabled.
|
167
|
+
#
|
168
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-file-properties
|
169
|
+
#
|
170
|
+
# Returns a File
|
171
|
+
def get_file_properties(share, directory_path, file, options={})
|
172
|
+
query = { }
|
173
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
174
|
+
|
175
|
+
headers = StorageService.common_headers
|
176
|
+
|
177
|
+
uri = file_uri(share, directory_path, file, query)
|
178
|
+
|
179
|
+
response = call(:head, uri, nil, headers, options)
|
180
|
+
|
181
|
+
result = Serialization.file_from_headers(response.headers)
|
182
|
+
result.name = file
|
183
|
+
result
|
184
|
+
end
|
185
|
+
|
186
|
+
# Public: Sets system properties defined for a file.
|
187
|
+
#
|
188
|
+
# ==== Attributes
|
189
|
+
#
|
190
|
+
# * +share+ - String. The name of the file share.
|
191
|
+
# * +directory_path+ - String. The path to the directory.
|
192
|
+
# * +file+ - String. The name of the file.
|
193
|
+
# * +options+ - Hash. Optional parameters.
|
194
|
+
#
|
195
|
+
# ==== Options
|
196
|
+
#
|
197
|
+
# Accepted key/value pairs in options parameter are:
|
198
|
+
# * +:content_type+ - String. Content type for the file. Will be saved with file.
|
199
|
+
# * +:content_encoding+ - String. Content encoding for the file. Will be saved with file.
|
200
|
+
# * +:content_language+ - String. Content language for the file. Will be saved with file.
|
201
|
+
# * +:content_md5+ - String. Content MD5 for the file. Will be saved with file.
|
202
|
+
# * +:cache_control+ - String. Cache control for the file. Will be saved with file.
|
203
|
+
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
204
|
+
# and also can be used to attach additional metadata
|
205
|
+
# * +:content_length+ - Integer. Resizes a file to the specified size. If the specified
|
206
|
+
# value is less than the current size of the file, then all ranges above
|
207
|
+
# the specified value are cleared.
|
208
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
209
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
210
|
+
# in the analytics logs when storage analytics logging is enabled.
|
211
|
+
#
|
212
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/set-file-properties
|
213
|
+
#
|
214
|
+
# Returns nil on success.
|
215
|
+
def set_file_properties(share, directory_path, file, options={})
|
216
|
+
query = {'comp' => 'properties'}
|
217
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
218
|
+
uri = file_uri(share, directory_path, file, query)
|
219
|
+
|
220
|
+
headers = StorageService.common_headers
|
221
|
+
|
222
|
+
unless options.empty?
|
223
|
+
StorageService.with_header headers, 'x-ms-content-type', options[:content_type]
|
224
|
+
StorageService.with_header headers, 'x-ms-content-encoding', options[:content_encoding]
|
225
|
+
StorageService.with_header headers, 'x-ms-content-language', options[:content_language]
|
226
|
+
StorageService.with_header headers, 'x-ms-content-md5', options[:content_md5]
|
227
|
+
StorageService.with_header headers, 'x-ms-cache-control', options[:cache_control]
|
228
|
+
StorageService.with_header headers, 'x-ms-content-length', options[:content_length].to_s if options[:content_length]
|
229
|
+
StorageService.with_header headers, 'x-ms-content-disposition', options[:content_disposition]
|
230
|
+
end
|
231
|
+
|
232
|
+
call(:put, uri, nil, headers, options)
|
233
|
+
nil
|
234
|
+
end
|
235
|
+
|
236
|
+
# Public: Resizes a file to the specified size.
|
237
|
+
#
|
238
|
+
# ==== Attributes
|
239
|
+
#
|
240
|
+
# * +share+ - String. The name of the file share.
|
241
|
+
# * +directory_path+ - String. The path to the directory.
|
242
|
+
# * +file+ - String. The name of the file.
|
243
|
+
# * +size+ - String. The file size. Resizes a file to the specified size.
|
244
|
+
# If the specified value is less than the current size of the file,
|
245
|
+
# then all ranges above the specified value are cleared.
|
246
|
+
# * +options+ - Hash. Optional parameters.
|
247
|
+
#
|
248
|
+
# ==== Options
|
249
|
+
#
|
250
|
+
# Accepted key/value pairs in options parameter are:
|
251
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
252
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
253
|
+
# in the analytics logs when storage analytics logging is enabled.
|
254
|
+
#
|
255
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/set-file-properties
|
256
|
+
#
|
257
|
+
# Returns nil on success.
|
258
|
+
def resize_file(share, directory_path, file, size, options={})
|
259
|
+
options = { :content_length => size }.merge(options)
|
260
|
+
set_file_properties share, directory_path, file, options
|
261
|
+
end
|
262
|
+
|
263
|
+
# Public: Writes a range of bytes to a file
|
264
|
+
#
|
265
|
+
# ==== Attributes
|
266
|
+
#
|
267
|
+
# * +share+ - String. The name of the file share.
|
268
|
+
# * +directory_path+ - String. The path to the directory.
|
269
|
+
# * +file+ - String. The name of the file.
|
270
|
+
# * +start_range+ - Integer. Position of first byte of the range.
|
271
|
+
# * +end_range+ - Integer. Position of last byte of of the range. The range can be up to 4 MB in size.
|
272
|
+
# * +content+ - IO or String. Content to write.
|
273
|
+
# * +options+ - Hash. A collection of options.
|
274
|
+
#
|
275
|
+
# ==== Options
|
276
|
+
#
|
277
|
+
# Accepted key/value pairs in options parameter are:
|
278
|
+
# * +:transactional_md5+ - String. An MD5 hash of the content. This hash is used to verify the integrity of the data during transport.
|
279
|
+
# When this header is specified, the storage service checks the hash that has arrived with the one that was sent.
|
280
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
281
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
282
|
+
# in the analytics logs when storage analytics logging is enabled.
|
283
|
+
#
|
284
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/put-range
|
285
|
+
#
|
286
|
+
# Returns a File
|
287
|
+
#
|
288
|
+
def put_file_range(share, directory_path, file, start_range, end_range=nil, content=nil, options={})
|
289
|
+
query = { 'comp' => 'range' }
|
290
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
291
|
+
|
292
|
+
uri = file_uri(share, directory_path, file, query)
|
293
|
+
headers = StorageService.common_headers
|
294
|
+
StorageService.with_header headers, 'Content-MD5', options[:transactional_md5]
|
295
|
+
StorageService.with_header headers, 'x-ms-range', "bytes=#{start_range}-#{end_range}"
|
296
|
+
StorageService.with_header headers, 'x-ms-write', 'update'
|
297
|
+
|
298
|
+
response = call(:put, uri, content, headers, options)
|
299
|
+
|
300
|
+
result = Serialization.file_from_headers(response.headers)
|
301
|
+
result.name = file
|
302
|
+
result
|
303
|
+
end
|
304
|
+
|
305
|
+
# Public: Clears a range of file.
|
306
|
+
#
|
307
|
+
# ==== Attributes
|
308
|
+
#
|
309
|
+
# * +share+ - String. The name of the file share.
|
310
|
+
# * +directory_path+ - String. The path to the directory.
|
311
|
+
# * +file+ - String. The name of the file.
|
312
|
+
# * +start_range+ - Integer. Position of first byte of the range.
|
313
|
+
# * +end_range+ - Integer. Position of last byte of of the range.
|
314
|
+
# * +options+ - Hash. A collection of options.
|
315
|
+
#
|
316
|
+
# ==== Options
|
317
|
+
#
|
318
|
+
# Accepted key/value pairs in options parameter are:
|
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
|
+
#
|
323
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/put-range
|
324
|
+
#
|
325
|
+
# Returns a File
|
326
|
+
def clear_file_range(share, directory_path, file, start_range, end_range=nil, options={})
|
327
|
+
query = { 'comp' => 'range' }
|
328
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
329
|
+
|
330
|
+
uri = file_uri(share, directory_path, file, query)
|
331
|
+
start_range = 0 if !end_range.nil? and start_range.nil?
|
332
|
+
|
333
|
+
headers = StorageService.common_headers
|
334
|
+
StorageService.with_header headers, 'x-ms-range', "bytes=#{start_range}-#{end_range}"
|
335
|
+
StorageService.with_header headers, 'x-ms-write', 'clear'
|
336
|
+
|
337
|
+
response = call(:put, uri, nil, headers, options)
|
338
|
+
|
339
|
+
result = Serialization.file_from_headers(response.headers)
|
340
|
+
result.name = file
|
341
|
+
result
|
342
|
+
end
|
343
|
+
|
344
|
+
# Public: Returns a list of valid ranges for a file.
|
345
|
+
#
|
346
|
+
# ==== Attributes
|
347
|
+
#
|
348
|
+
# * +share+ - String. The name of the file share.
|
349
|
+
# * +directory_path+ - String. The path to the directory.
|
350
|
+
# * +file+ - String. The name of the file.
|
351
|
+
# * +options+ - Hash. Optional parameters.
|
352
|
+
#
|
353
|
+
# ==== Options
|
354
|
+
#
|
355
|
+
# Accepted key/value pairs in options parameter are:
|
356
|
+
# * +:start_range+ - Integer. Position of first byte of the range.
|
357
|
+
# * +:end_range+ - Integer. Position of last byte of of the range.
|
358
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
359
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
360
|
+
# in the analytics logs when storage analytics logging is enabled.
|
361
|
+
#
|
362
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/list-ranges
|
363
|
+
#
|
364
|
+
# Returns a tuple of a File and a list of ranges in the format [ [start, end], [start, end], ... ]
|
365
|
+
#
|
366
|
+
# eg. (Azure::Storage::File::File, [ [0, 511], [512, 1024], ... ])
|
367
|
+
#
|
368
|
+
def list_file_ranges(share, directory_path, file, options={})
|
369
|
+
query = {'comp' => 'rangelist'}
|
370
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
371
|
+
|
372
|
+
uri = file_uri(share, directory_path, file, query)
|
373
|
+
|
374
|
+
options[:start_range] = 0 if options[:end_range] and not options[:start_range]
|
375
|
+
|
376
|
+
headers = StorageService.common_headers
|
377
|
+
StorageService.with_header headers, 'x-ms-range', "bytes=#{options[:start_range]}-#{options[:end_range]}" if options[:start_range]
|
378
|
+
|
379
|
+
response = call(:get, uri, nil, headers, options)
|
380
|
+
|
381
|
+
result = Serialization.file_from_headers(response.headers)
|
382
|
+
result.name = file
|
383
|
+
rangelist = Serialization.range_list_from_xml(response.body)
|
384
|
+
return result, rangelist
|
385
|
+
end
|
386
|
+
|
387
|
+
# Public: Returns only user-defined metadata for the specified file.
|
388
|
+
#
|
389
|
+
# ==== Attributes
|
390
|
+
#
|
391
|
+
# * +share+ - String. The name of the file share.
|
392
|
+
# * +directory_path+ - String. The path to the directory.
|
393
|
+
# * +file+ - String. The name of the file.
|
394
|
+
# * +options+ - Hash. Optional parameters.
|
395
|
+
#
|
396
|
+
# ==== Options
|
397
|
+
#
|
398
|
+
# Accepted key/value pairs in options parameter are:
|
399
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
400
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
401
|
+
# in the analytics logs when storage analytics logging is enabled.
|
402
|
+
#
|
403
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-file-metadata
|
404
|
+
#
|
405
|
+
# Returns a File
|
406
|
+
def get_file_metadata(share, directory_path, file, options={})
|
407
|
+
# Query
|
408
|
+
query = { 'comp' => 'metadata' }
|
409
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
410
|
+
|
411
|
+
# Call
|
412
|
+
response = call(:get, file_uri(share, directory_path, file, query), nil, {}, options)
|
413
|
+
|
414
|
+
# result
|
415
|
+
result = Serialization.file_from_headers(response.headers)
|
416
|
+
result.name = file
|
417
|
+
result
|
418
|
+
end
|
419
|
+
|
420
|
+
# Public: Sets custom metadata for the file.
|
421
|
+
#
|
422
|
+
# ==== Attributes
|
423
|
+
#
|
424
|
+
# * +share+ - String. The name of the file share.
|
425
|
+
# * +directory_path+ - String. The path to the directory.
|
426
|
+
# * +file+ - String. The name of the file.
|
427
|
+
# * +metadata+ - Hash. A Hash of the metadata values.
|
428
|
+
# * +options+ - Hash. Optional parameters.
|
429
|
+
#
|
430
|
+
# ==== Options
|
431
|
+
#
|
432
|
+
# Accepted key/value pairs in options parameter are:
|
433
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
434
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
435
|
+
# in the analytics logs when storage analytics logging is enabled.
|
436
|
+
#
|
437
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/set-file-metadata
|
438
|
+
#
|
439
|
+
# Returns nil on success
|
440
|
+
def set_file_metadata(share, directory_path, file, metadata, options={})
|
441
|
+
# Query
|
442
|
+
query = { 'comp' => 'metadata' }
|
443
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
444
|
+
|
445
|
+
# Headers
|
446
|
+
headers = StorageService.common_headers
|
447
|
+
StorageService.add_metadata_to_headers(metadata, headers) if metadata
|
448
|
+
|
449
|
+
# Call
|
450
|
+
call(:put, file_uri(share, directory_path, file, query), nil, headers, options)
|
451
|
+
|
452
|
+
# Result
|
453
|
+
nil
|
454
|
+
end
|
455
|
+
|
456
|
+
# Public: Deletes a file.
|
457
|
+
#
|
458
|
+
# ==== Attributes
|
459
|
+
#
|
460
|
+
# * +share+ - String. The name of the file share.
|
461
|
+
# * +directory_path+ - String. The path to the directory.
|
462
|
+
# * +file+ - String. The name of the file.
|
463
|
+
# * +options+ - Hash. Optional parameters.
|
464
|
+
#
|
465
|
+
# ==== Options
|
466
|
+
#
|
467
|
+
# Accepted key/value pairs in options parameter are:
|
468
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
469
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
470
|
+
# in the analytics logs when storage analytics logging is enabled.
|
471
|
+
#
|
472
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/delete-file2
|
473
|
+
#
|
474
|
+
# Returns nil on success
|
475
|
+
def delete_file(share, directory_path, file, options={})
|
476
|
+
# Query
|
477
|
+
query = { }
|
478
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
479
|
+
|
480
|
+
# Call
|
481
|
+
call(:delete, file_uri(share, directory_path, file, query), nil, {}, options)
|
482
|
+
|
483
|
+
# result
|
484
|
+
nil
|
485
|
+
end
|
486
|
+
|
487
|
+
# Public: Copies a source file or file to a destination file within the storage account.
|
488
|
+
#
|
489
|
+
# ==== Attributes
|
490
|
+
#
|
491
|
+
# * +destination_share+ - String. The name of the destination file share.
|
492
|
+
# * +destination_directory_path+ - String. The path to the destination directory.
|
493
|
+
# * +destination_file+ - String. The name of the destination file.
|
494
|
+
# * +source_uri+ - String. The source file or file URI to copy from.
|
495
|
+
# * +options+ - Hash. Optional parameters.
|
496
|
+
#
|
497
|
+
# ==== Options
|
498
|
+
#
|
499
|
+
# Accepted key/value pairs in options parameter are:
|
500
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the copy. If this parameter is not
|
501
|
+
# specified, the operation will copy the source file metadata to the destination
|
502
|
+
# file. If this parameter is specified, the destination file is created with the
|
503
|
+
# specified metadata, and metadata is not copied from the source file.
|
504
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
505
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
506
|
+
# in the analytics logs when storage analytics logging is enabled.
|
507
|
+
#
|
508
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/copy-file
|
509
|
+
#
|
510
|
+
# Returns a tuple of (copy_id, copy_status).
|
511
|
+
#
|
512
|
+
# * +copy_id+ - String identifier for this copy operation. Use with get_file or get_file_properties to check
|
513
|
+
# the status of this copy operation, or pass to abort_copy_file to abort a pending copy.
|
514
|
+
# * +copy_status+ - String. The state of the copy operation, with these values:
|
515
|
+
# "success" - The copy completed successfully.
|
516
|
+
# "pending" - The copy is in progress.
|
517
|
+
#
|
518
|
+
def copy_file_from_uri(destination_share, destination_directory_path, destination_file, source_uri, options={})
|
519
|
+
query = { }
|
520
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
521
|
+
|
522
|
+
uri = file_uri(destination_share, destination_directory_path, destination_file, query)
|
523
|
+
headers = StorageService.common_headers
|
524
|
+
StorageService.with_header headers, 'x-ms-copy-source', source_uri
|
525
|
+
StorageService.add_metadata_to_headers options[:metadata], headers unless options.empty?
|
526
|
+
|
527
|
+
response = call(:put, uri, nil, headers, options)
|
528
|
+
return response.headers['x-ms-copy-id'], response.headers['x-ms-copy-status']
|
529
|
+
end
|
530
|
+
|
531
|
+
# Public: Copies a source file to a destination file within the same storage account.
|
532
|
+
#
|
533
|
+
# ==== Attributes
|
534
|
+
#
|
535
|
+
# * +destination_share+ - String. The destination share name to copy to.
|
536
|
+
# * +destination_directory_path+ - String. The path to the destination directory.
|
537
|
+
# * +source_file+ - String. The destination file name to copy to.
|
538
|
+
# * +source_share+ - String. The source share name to copy from.
|
539
|
+
# * +source_directory_path+ - String. The path to the source directory.
|
540
|
+
# * +source_file+ - String. The source file name to copy from.
|
541
|
+
# * +options+ - Hash. Optional parameters.
|
542
|
+
#
|
543
|
+
# ==== Options
|
544
|
+
#
|
545
|
+
# Accepted key/value pairs in options parameter are:
|
546
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the copy. If this parameter is not
|
547
|
+
# specified, the operation will copy the source file metadata to the destination
|
548
|
+
# file. If this parameter is specified, the destination file is created with the
|
549
|
+
# specified metadata, and metadata is not copied from the source file.
|
550
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
551
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
552
|
+
# in the analytics logs when storage analytics logging is enabled.
|
553
|
+
#
|
554
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/copy-file
|
555
|
+
#
|
556
|
+
# Returns a tuple of (copy_id, copy_status).
|
557
|
+
#
|
558
|
+
# * +copy_id+ - String identifier for this copy operation. Use with get_file or get_file_properties to check
|
559
|
+
# the status of this copy operation, or pass to abort_copy_file to abort a pending copy.
|
560
|
+
# * +copy_status+ - String. The state of the copy operation, with these values:
|
561
|
+
# "success" - The copy completed successfully.
|
562
|
+
# "pending" - The copy is in progress.
|
563
|
+
#
|
564
|
+
def copy_file(destination_share, destination_directory_path, destination_file, source_share, source_directory_path, source_file, options={})
|
565
|
+
source_file_uri = file_uri(source_share, source_directory_path, source_file, {}).to_s
|
566
|
+
|
567
|
+
return copy_file_from_uri(destination_share, destination_directory_path, destination_file, source_file_uri, options)
|
568
|
+
end
|
569
|
+
|
570
|
+
# Public: Aborts a pending Copy File operation and leaves a destination file with zero length and full metadata.
|
571
|
+
#
|
572
|
+
# ==== Attributes
|
573
|
+
#
|
574
|
+
# * +share+ - String. The name of the destination file share.
|
575
|
+
# * +directory_path+ - String. The path to the destination directory.
|
576
|
+
# * +file+ - String. The name of the destination file.
|
577
|
+
# * +copy_id+ - String. The copy identifier returned in the copy file operation.
|
578
|
+
# * +options+ - Hash. Optional parameters.
|
579
|
+
#
|
580
|
+
# ==== Options
|
581
|
+
#
|
582
|
+
# Accepted key/value pairs in options parameter are:
|
583
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
584
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
585
|
+
# in the analytics logs when storage analytics logging is enabled.
|
586
|
+
#
|
587
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/abort-copy-file
|
588
|
+
#
|
589
|
+
# Returns nil on success
|
590
|
+
def abort_copy_file(share, directory_path, file, copy_id, options={})
|
591
|
+
query = {'comp' => 'copy'}
|
592
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
593
|
+
StorageService.with_query query, 'copyid', copy_id
|
594
|
+
|
595
|
+
uri = file_uri(share, directory_path, file, query);
|
596
|
+
headers = StorageService.common_headers
|
597
|
+
StorageService.with_header headers, 'x-ms-copy-action', 'abort';
|
598
|
+
|
599
|
+
call(:put, uri, nil, headers, options)
|
600
|
+
nil
|
601
|
+
end
|
602
|
+
end
|