azure-storage 0.11.5.preview → 0.12.0.preview
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,191 @@
|
|
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/core/auth/shared_key'
|
25
|
+
require 'azure/storage/file/serialization'
|
26
|
+
require 'azure/storage/file/file'
|
27
|
+
|
28
|
+
module Azure::Storage
|
29
|
+
module File
|
30
|
+
class FileService < StorageService
|
31
|
+
include Azure::Storage::Core::Utility
|
32
|
+
include Azure::Storage::File::Share
|
33
|
+
include Azure::Storage::File::Directory
|
34
|
+
include Azure::Storage::File
|
35
|
+
|
36
|
+
def initialize(options = {}, &block)
|
37
|
+
client_config = options[:client] || Azure::Storage
|
38
|
+
signer = options[:signer] || client_config.signer || Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
|
39
|
+
super(signer, client_config.storage_account_name, options, &block)
|
40
|
+
@host = client.storage_file_host
|
41
|
+
end
|
42
|
+
|
43
|
+
def call(method, uri, body=nil, headers={}, options={})
|
44
|
+
# Force the request.body to the content encoding of specified in the header
|
45
|
+
if headers && !body.nil? && (body.is_a? String) && ((body.encoding.to_s <=> 'ASCII_8BIT') != 0)
|
46
|
+
if headers['x-ms-content-type'].nil?
|
47
|
+
Service::StorageService.with_header headers, 'x-ms-content-type', "text/plain; charset=#{body.encoding}"
|
48
|
+
else
|
49
|
+
charset = parse_charset_from_content_type(headers['x-ms-content-type'])
|
50
|
+
body.force_encoding(charset) if charset
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
response = super
|
55
|
+
|
56
|
+
# Force the response.body to the content charset of specified in the header.
|
57
|
+
# Content-Type is echo'd back for the blob and is used to store the encoding of the octet stream
|
58
|
+
if !response.nil? && !response.body.nil? && response.headers['Content-Type']
|
59
|
+
charset = parse_charset_from_content_type(response.headers['Content-Type'])
|
60
|
+
response.body.force_encoding(charset) if charset && charset.length > 0
|
61
|
+
end
|
62
|
+
|
63
|
+
response
|
64
|
+
end
|
65
|
+
|
66
|
+
# Public: Get a list of Shares from the server.
|
67
|
+
#
|
68
|
+
# ==== Attributes
|
69
|
+
#
|
70
|
+
# * +options+ - Hash. Optional parameters.
|
71
|
+
#
|
72
|
+
# ==== Options
|
73
|
+
#
|
74
|
+
# Accepted key/value pairs in options parameter are:
|
75
|
+
# * +:prefix+ - String. Filters the results to return only shares
|
76
|
+
# whose name begins with the specified prefix. (optional)
|
77
|
+
#
|
78
|
+
# * +:marker+ - String. An identifier the specifies the portion of the
|
79
|
+
# list to be returned. This value comes from the property
|
80
|
+
# Azure::Service::EnumerationResults.continuation_token when there
|
81
|
+
# are more shares available than were returned. The
|
82
|
+
# marker value may then be used here to request the next set
|
83
|
+
# of list items. (optional)
|
84
|
+
#
|
85
|
+
# * +:max_results+ - Integer. Specifies the maximum number of shares to return.
|
86
|
+
# If max_results is not specified, or is a value greater than
|
87
|
+
# 5,000, the server will return up to 5,000 items. If it is set
|
88
|
+
# to a value less than or equal to zero, the server will return
|
89
|
+
# status code 400 (Bad Request). (optional)
|
90
|
+
#
|
91
|
+
# * +:metadata+ - Boolean. Specifies whether or not to return the share metadata.
|
92
|
+
# (optional, Default=false)
|
93
|
+
#
|
94
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
95
|
+
#
|
96
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
97
|
+
# in the analytics logs when storage analytics logging is enabled.
|
98
|
+
#
|
99
|
+
# See: https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/list-shares
|
100
|
+
#
|
101
|
+
# Returns an Azure::Service::EnumerationResults
|
102
|
+
#
|
103
|
+
def list_shares(options={})
|
104
|
+
query = { }
|
105
|
+
if options
|
106
|
+
StorageService.with_query query, 'prefix', options[:prefix]
|
107
|
+
StorageService.with_query query, 'marker', options[:marker]
|
108
|
+
StorageService.with_query query, 'maxresults', options[:max_results].to_s if options[:max_results]
|
109
|
+
StorageService.with_query query, 'include', 'metadata' if options[:metadata] == true
|
110
|
+
StorageService.with_query query, 'timeout', options[:timeout].to_s if options[:timeout]
|
111
|
+
end
|
112
|
+
|
113
|
+
uri = shares_uri(query)
|
114
|
+
response = call(:get, uri, nil, {}, options)
|
115
|
+
|
116
|
+
Serialization.share_enumeration_results_from_xml(response.body)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Protected: Generate the URI for the collection of shares.
|
120
|
+
#
|
121
|
+
# ==== Attributes
|
122
|
+
#
|
123
|
+
# * +query+ - A Hash of key => value query parameters.
|
124
|
+
#
|
125
|
+
# Returns a URI.
|
126
|
+
#
|
127
|
+
protected
|
128
|
+
def shares_uri(query={})
|
129
|
+
query = { 'comp' => 'list' }.merge(query)
|
130
|
+
generate_uri('', query)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Protected: Generate the URI for a specific share.
|
134
|
+
#
|
135
|
+
# ==== Attributes
|
136
|
+
#
|
137
|
+
# * +name+ - The share name. If this is a URI, we just return this.
|
138
|
+
# * +query+ - A Hash of key => value query parameters.
|
139
|
+
#
|
140
|
+
# Returns a URI.
|
141
|
+
#
|
142
|
+
protected
|
143
|
+
def share_uri(name, query={})
|
144
|
+
return name if name.kind_of? ::URI
|
145
|
+
query = { 'restype' => 'share' }.merge(query)
|
146
|
+
generate_uri(name, query)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Protected: Generate the URI for a specific directory.
|
150
|
+
#
|
151
|
+
# ==== Attributes
|
152
|
+
#
|
153
|
+
# * +share+ - String representing the name of the share.
|
154
|
+
# * +directory_path+ - String representing the path to the directory.
|
155
|
+
# * +directory+ - String representing the name to the directory.
|
156
|
+
# * +query+ - A Hash of key => value query parameters.
|
157
|
+
#
|
158
|
+
# Returns a URI.
|
159
|
+
#
|
160
|
+
protected
|
161
|
+
def directory_uri(share, directory_path, query={})
|
162
|
+
path = directory_path.nil? ? share : ::File.join(share, directory_path)
|
163
|
+
query = { 'restype' => 'directory' }.merge(query)
|
164
|
+
generate_uri(path, query, true)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Protected: Generate the URI for a specific file.
|
168
|
+
#
|
169
|
+
# ==== Attributes
|
170
|
+
#
|
171
|
+
# * +share+ - String representing the name of the share.
|
172
|
+
# * +directory_path+ - String representing the path to the directory.
|
173
|
+
# * +file+ - String representing the name to the file.
|
174
|
+
# * +query+ - A Hash of key => value query parameters.
|
175
|
+
#
|
176
|
+
# Returns a URI.
|
177
|
+
#
|
178
|
+
protected
|
179
|
+
def file_uri(share, directory_path, file, query={})
|
180
|
+
if directory_path.nil?
|
181
|
+
path = ::File.join(share, file)
|
182
|
+
else
|
183
|
+
path = ::File.join(share, directory_path, file)
|
184
|
+
end
|
185
|
+
generate_uri(path, query, true)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
Azure::Storage::FileService = Azure::Storage::File::FileService
|
@@ -0,0 +1,225 @@
|
|
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/service/serialization'
|
25
|
+
|
26
|
+
module Azure::Storage
|
27
|
+
module File
|
28
|
+
module Serialization
|
29
|
+
include Service::Serialization
|
30
|
+
|
31
|
+
def self.share_enumeration_results_from_xml(xml)
|
32
|
+
xml = slopify(xml)
|
33
|
+
expect_node("EnumerationResults", xml)
|
34
|
+
|
35
|
+
results = enumeration_results_from_xml(xml, Azure::Service::EnumerationResults.new)
|
36
|
+
|
37
|
+
return results unless (xml > "Shares").any? && ((xml > "Shares") > "Share").any?
|
38
|
+
|
39
|
+
if xml.Shares.Share.count == 0
|
40
|
+
results.push(share_from_xml(xml.Shares.Share))
|
41
|
+
else
|
42
|
+
xml.Shares.Share.each { |share_node|
|
43
|
+
results.push(share_from_xml(share_node))
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
results
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.share_from_xml(xml)
|
51
|
+
xml = slopify(xml)
|
52
|
+
expect_node("Share", xml)
|
53
|
+
|
54
|
+
Share::Share.new do |share|
|
55
|
+
share.name = xml.Name.text if (xml > "Name").any?
|
56
|
+
share.properties = share_properties_from_xml(xml.Properties) if (xml > "Properties").any?
|
57
|
+
share.metadata = metadata_from_xml(xml.Metadata) if (xml > "Metadata").any?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.share_properties_from_xml(xml)
|
62
|
+
xml = slopify(xml)
|
63
|
+
expect_node("Properties", xml)
|
64
|
+
|
65
|
+
props = {}
|
66
|
+
props[:last_modified] = (xml > "Last-Modified").text if (xml > "Last-Modified").any?
|
67
|
+
props[:etag] = xml.ETag.text if (xml > "ETag").any?
|
68
|
+
props[:quota] = xml.Quota.text if (xml > "Quota").any?
|
69
|
+
props
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.share_from_headers(headers)
|
73
|
+
Share::Share.new do |share|
|
74
|
+
share.properties = share_properties_from_headers(headers)
|
75
|
+
share.quota = quota_from_headers(headers)
|
76
|
+
share.metadata = metadata_from_headers(headers)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.share_properties_from_headers(headers)
|
81
|
+
props = {}
|
82
|
+
props[:last_modified] = headers["Last-Modified"]
|
83
|
+
props[:etag] = headers["ETag"]
|
84
|
+
props
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.quota_from_headers(headers)
|
88
|
+
headers["x-ms-share-quota"] ? headers["x-ms-share-quota"].to_i : nil
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.share_stats_from_xml(xml)
|
92
|
+
xml = slopify(xml)
|
93
|
+
expect_node("ShareStats", xml)
|
94
|
+
xml.ShareUsage.text.to_i
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.directories_and_files_enumeration_results_from_xml(xml)
|
98
|
+
xml = slopify(xml)
|
99
|
+
expect_node("EnumerationResults", xml)
|
100
|
+
|
101
|
+
results = enumeration_results_from_xml(xml, Azure::Service::EnumerationResults.new)
|
102
|
+
|
103
|
+
return results unless (xml > "Entries").any?
|
104
|
+
|
105
|
+
if ((xml > "Entries") > "File").any?
|
106
|
+
if xml.Entries.File.count == 0
|
107
|
+
results.push(file_from_xml(xml.Entries.File))
|
108
|
+
else
|
109
|
+
xml.Entries.File.each { |file_node|
|
110
|
+
results.push(file_from_xml(file_node))
|
111
|
+
}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
if ((xml > "Entries") > "Directory").any?
|
116
|
+
if xml.Entries.Directory.count == 0
|
117
|
+
results.push(directory_from_xml(xml.Entries.Directory))
|
118
|
+
else
|
119
|
+
xml.Entries.Directory.each { |directory_node|
|
120
|
+
results.push(directory_from_xml(directory_node))
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
results
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.file_from_xml(xml)
|
129
|
+
xml = slopify(xml)
|
130
|
+
expect_node("File", xml)
|
131
|
+
|
132
|
+
File.new do |file|
|
133
|
+
file.name = xml.Name.text if (xml > "Name").any?
|
134
|
+
file.properties = file_properties_from_xml(xml.Properties) if (xml > "Properties").any?
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.file_properties_from_xml(xml)
|
139
|
+
xml = slopify(xml)
|
140
|
+
expect_node("Properties", xml)
|
141
|
+
|
142
|
+
props = {}
|
143
|
+
props[:content_length] = (xml > "Content-Length").text.to_i if (xml > "Content-Length").any?
|
144
|
+
props
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.directory_from_xml(xml)
|
148
|
+
xml = slopify(xml)
|
149
|
+
expect_node("Directory", xml)
|
150
|
+
|
151
|
+
Directory::Directory.new do |directory|
|
152
|
+
directory.name = xml.Name.text if (xml > "Name").any?
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.directory_from_headers(headers)
|
157
|
+
Directory::Directory.new do |directory|
|
158
|
+
directory.properties = directory_properties_from_headers(headers)
|
159
|
+
directory.metadata = metadata_from_headers(headers)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.directory_properties_from_headers(headers)
|
164
|
+
props = {}
|
165
|
+
props[:last_modified] = headers["Last-Modified"]
|
166
|
+
props[:etag] = headers["ETag"]
|
167
|
+
props
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.file_from_headers(headers)
|
171
|
+
File.new do |file|
|
172
|
+
file.properties = file_properties_from_headers(headers)
|
173
|
+
file.metadata = metadata_from_headers(headers)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.file_properties_from_headers(headers)
|
178
|
+
props = {}
|
179
|
+
|
180
|
+
props[:last_modified] = headers["Last-Modified"]
|
181
|
+
props[:etag] = headers["ETag"]
|
182
|
+
props[:type] = headers["x-ms-type"]
|
183
|
+
|
184
|
+
props[:content_length] = headers["Content-Length"].to_i unless headers["Content-Length"].nil?
|
185
|
+
props[:content_length] = headers["x-ms-content-length"].to_i unless headers["x-ms-content-length"].nil?
|
186
|
+
|
187
|
+
props[:content_type] = headers["Content-Type"]
|
188
|
+
props[:content_encoding] = headers["Content-Encoding"]
|
189
|
+
props[:content_language] = headers["Content-Language"]
|
190
|
+
props[:content_disposition] = headers["Content-Disposition"]
|
191
|
+
props[:content_md5] = headers["Content-MD5"]
|
192
|
+
props[:cache_control] = headers["Cache-Control"]
|
193
|
+
|
194
|
+
props[:copy_id] = headers["x-ms-copy-id"]
|
195
|
+
props[:copy_status] = headers["x-ms-copy-status"]
|
196
|
+
props[:copy_source] = headers["x-ms-copy-source"]
|
197
|
+
props[:copy_progress] = headers["x-ms-copy-progress"]
|
198
|
+
props[:copy_completion_time] = headers["x-ms-copy-completion-time"]
|
199
|
+
props[:copy_status_description] = headers["x-ms-copy-status-description"]
|
200
|
+
|
201
|
+
props[:accept_ranges] = headers["Accept-Ranges"].to_i if headers["Accept-Ranges"]
|
202
|
+
|
203
|
+
props
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.range_list_from_xml(xml)
|
207
|
+
xml = slopify(xml)
|
208
|
+
expect_node("Ranges", xml)
|
209
|
+
|
210
|
+
range_list = []
|
211
|
+
return range_list unless (xml > "Range").any?
|
212
|
+
|
213
|
+
if xml.Range.count == 0
|
214
|
+
range_list.push [xml.Range.Start.text.to_i, xml.Range.End.text.to_i]
|
215
|
+
else
|
216
|
+
xml.Range.each { |range|
|
217
|
+
range_list.push [range.Start.text.to_i, range.End.text.to_i]
|
218
|
+
}
|
219
|
+
end
|
220
|
+
|
221
|
+
range_list
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
@@ -0,0 +1,363 @@
|
|
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
|
+
module Share
|
28
|
+
include Azure::Storage::Service
|
29
|
+
|
30
|
+
class Share
|
31
|
+
def initialize
|
32
|
+
@properties = {}
|
33
|
+
@metadata = {}
|
34
|
+
yield self if block_given?
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_accessor :name
|
38
|
+
attr_accessor :properties
|
39
|
+
attr_accessor :metadata
|
40
|
+
attr_accessor :quota
|
41
|
+
attr_accessor :usage
|
42
|
+
end
|
43
|
+
|
44
|
+
# Public: Create a new share
|
45
|
+
#
|
46
|
+
# ==== Attributes
|
47
|
+
#
|
48
|
+
# * +name+ - String. The name of the share.
|
49
|
+
# * +options+ - Hash. Optional parameters.
|
50
|
+
#
|
51
|
+
# ==== Options
|
52
|
+
#
|
53
|
+
# Accepted key/value pairs in options parameter are:
|
54
|
+
# * +:metadata+ - Hash. User defined metadata for the share (optional).
|
55
|
+
# * +:quota+ - Integer. The maximum size of the share, in gigabytes.
|
56
|
+
# Must be greater than 0, and less than or equal to 5TB (5120). (optional).
|
57
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
58
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
59
|
+
# in the analytics logs when storage analytics logging is enabled.
|
60
|
+
#
|
61
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/create-share
|
62
|
+
#
|
63
|
+
# Returns a Share
|
64
|
+
def create_share(name, options={})
|
65
|
+
# Query
|
66
|
+
query = { }
|
67
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
68
|
+
|
69
|
+
# Scheme + path
|
70
|
+
uri = share_uri(name, query)
|
71
|
+
|
72
|
+
# Headers
|
73
|
+
headers = StorageService.common_headers
|
74
|
+
StorageService.add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
|
75
|
+
headers['x-ms-share-quota'] = options[:quota].to_s if options[:quota]
|
76
|
+
|
77
|
+
# Call
|
78
|
+
response = call(:put, uri, nil, headers, options)
|
79
|
+
|
80
|
+
# result
|
81
|
+
share = Serialization.share_from_headers(response.headers)
|
82
|
+
share.name = name
|
83
|
+
share.quota = options[:quota] if options[:quota]
|
84
|
+
share.metadata = options[:metadata] if options[:metadata]
|
85
|
+
share
|
86
|
+
end
|
87
|
+
|
88
|
+
# Public: Returns all properties and metadata on the share.
|
89
|
+
#
|
90
|
+
# ==== Attributes
|
91
|
+
#
|
92
|
+
# * +name+ - String. The name of the share
|
93
|
+
# * +options+ - Hash. Optional parameters.
|
94
|
+
#
|
95
|
+
# ==== Options
|
96
|
+
#
|
97
|
+
# Accepted key/value pairs in options parameter are:
|
98
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
99
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
100
|
+
# in the analytics logs when storage analytics logging is enabled.
|
101
|
+
#
|
102
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-share-properties
|
103
|
+
#
|
104
|
+
# Returns a Share
|
105
|
+
def get_share_properties(name, options={})
|
106
|
+
# Query
|
107
|
+
query = { }
|
108
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
109
|
+
|
110
|
+
# Call
|
111
|
+
response = call(:get, share_uri(name, query), nil, {}, options)
|
112
|
+
|
113
|
+
# result
|
114
|
+
share = Serialization.share_from_headers(response.headers)
|
115
|
+
share.name = name
|
116
|
+
share
|
117
|
+
end
|
118
|
+
|
119
|
+
# Public: Sets service-defined properties for the share.
|
120
|
+
#
|
121
|
+
# ==== Attributes
|
122
|
+
#
|
123
|
+
# * +name+ - String. The name of the share
|
124
|
+
# * +options+ - Hash. Optional parameters.
|
125
|
+
#
|
126
|
+
# ==== Options
|
127
|
+
#
|
128
|
+
# Accepted key/value pairs in options parameter are:
|
129
|
+
# * +:quota+ - Integer. The maximum size of the share, in gigabytes.
|
130
|
+
# Must be greater than 0, and less than or equal to 5TB (5120). (optional).
|
131
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
132
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
133
|
+
# in the analytics logs when storage analytics logging is enabled.
|
134
|
+
#
|
135
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/set-share-properties
|
136
|
+
#
|
137
|
+
# Returns nil on success
|
138
|
+
def set_share_properties(name, options={})
|
139
|
+
# Query
|
140
|
+
query = { 'comp' => 'properties' }
|
141
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
142
|
+
|
143
|
+
# Headers
|
144
|
+
headers = StorageService.common_headers
|
145
|
+
headers['x-ms-share-quota'] = options[:quota].to_s if options[:quota]
|
146
|
+
|
147
|
+
# Call
|
148
|
+
call(:put, share_uri(name, query), nil, headers, options)
|
149
|
+
|
150
|
+
# Result
|
151
|
+
nil
|
152
|
+
end
|
153
|
+
|
154
|
+
# Public: Returns only user-defined metadata for the specified share.
|
155
|
+
#
|
156
|
+
# ==== Attributes
|
157
|
+
#
|
158
|
+
# * +name+ - String. The name of the share
|
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-share-metadata
|
169
|
+
#
|
170
|
+
# Returns a Share
|
171
|
+
def get_share_metadata(name, options={})
|
172
|
+
# Query
|
173
|
+
query = { 'comp' => 'metadata' }
|
174
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
175
|
+
|
176
|
+
# Call
|
177
|
+
response = call(:get, share_uri(name, query), nil, {}, options)
|
178
|
+
|
179
|
+
# result
|
180
|
+
share = Serialization.share_from_headers(response.headers)
|
181
|
+
share.name = name
|
182
|
+
share
|
183
|
+
end
|
184
|
+
|
185
|
+
# Public: Sets custom metadata for the share.
|
186
|
+
#
|
187
|
+
# ==== Attributes
|
188
|
+
#
|
189
|
+
# * +name+ - String. The name of the share
|
190
|
+
# * +metadata+ - Hash. A Hash of the metadata values
|
191
|
+
# * +options+ - Hash. Optional parameters.
|
192
|
+
#
|
193
|
+
# ==== Options
|
194
|
+
#
|
195
|
+
# Accepted key/value pairs in options parameter are:
|
196
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
197
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
198
|
+
# in the analytics logs when storage analytics logging is enabled.
|
199
|
+
#
|
200
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/set-share-metadata
|
201
|
+
#
|
202
|
+
# Returns nil on success
|
203
|
+
def set_share_metadata(name, metadata, options={})
|
204
|
+
# Query
|
205
|
+
query = { 'comp' => 'metadata' }
|
206
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
207
|
+
|
208
|
+
# Headers
|
209
|
+
headers = StorageService.common_headers
|
210
|
+
StorageService.add_metadata_to_headers(metadata, headers) if metadata
|
211
|
+
|
212
|
+
# Call
|
213
|
+
call(:put, share_uri(name, query), nil, headers, options)
|
214
|
+
|
215
|
+
# Result
|
216
|
+
nil
|
217
|
+
end
|
218
|
+
|
219
|
+
# Public: Deletes a share.
|
220
|
+
#
|
221
|
+
# ==== Attributes
|
222
|
+
#
|
223
|
+
# * +name+ - String. The name of the share.
|
224
|
+
# * +options+ - Hash. Optional parameters.
|
225
|
+
#
|
226
|
+
# ==== Options
|
227
|
+
#
|
228
|
+
# Accepted key/value pairs in options parameter are:
|
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
|
+
#
|
233
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/delete-share
|
234
|
+
#
|
235
|
+
# Returns nil on success
|
236
|
+
def delete_share(name, options={})
|
237
|
+
# Query
|
238
|
+
query = { }
|
239
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
240
|
+
|
241
|
+
# Call
|
242
|
+
call(:delete, share_uri(name, query), nil, {}, options)
|
243
|
+
|
244
|
+
# result
|
245
|
+
nil
|
246
|
+
end
|
247
|
+
|
248
|
+
# Public: Gets the information about stored access policies for the share.
|
249
|
+
#
|
250
|
+
# ==== Attributes
|
251
|
+
#
|
252
|
+
# * +name+ - String. The name of the share
|
253
|
+
# * +options+ - Hash. Optional parameters.
|
254
|
+
#
|
255
|
+
# ==== Options
|
256
|
+
#
|
257
|
+
# Accepted key/value pairs in options parameter are:
|
258
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
259
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
260
|
+
# in the analytics logs when storage analytics logging is enabled.
|
261
|
+
#
|
262
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-share-acl
|
263
|
+
#
|
264
|
+
# Returns a tuple of (share, signed_identifiers)
|
265
|
+
# share - A Azure::Storage::File::Share::Share instance
|
266
|
+
# signed_identifiers - A list of Azure::Storage::Service::SignedIdentifier instances
|
267
|
+
#
|
268
|
+
def get_share_acl(name, options={})
|
269
|
+
# Query
|
270
|
+
query = { 'comp' => 'acl' }
|
271
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
272
|
+
|
273
|
+
# Call
|
274
|
+
response = call(:get, share_uri(name, query), nil, {}, options)
|
275
|
+
|
276
|
+
# Result
|
277
|
+
share = Serialization.share_from_headers(response.headers)
|
278
|
+
share.name = name
|
279
|
+
|
280
|
+
signed_identifiers = nil
|
281
|
+
signed_identifiers = Serialization.signed_identifiers_from_xml(response.body) if response.body != nil && response.body.length > 0
|
282
|
+
|
283
|
+
return share, signed_identifiers
|
284
|
+
end
|
285
|
+
|
286
|
+
# Public: Sets stored access policies the share.
|
287
|
+
#
|
288
|
+
# ==== Attributes
|
289
|
+
#
|
290
|
+
# * +name+ - String. The name of the share
|
291
|
+
# * +options+ - Hash. Optional parameters.
|
292
|
+
#
|
293
|
+
# ==== Options
|
294
|
+
#
|
295
|
+
# Accepted key/value pairs in options parameter are:
|
296
|
+
# * +:signed_identifiers+ - Array. A list of Azure::Storage::Service::SignedIdentifier instances.
|
297
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
298
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
299
|
+
# in the analytics logs when storage analytics logging is enabled.
|
300
|
+
#
|
301
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/set-share-acl
|
302
|
+
#
|
303
|
+
# Returns a tuple of (share, signed_identifiers)
|
304
|
+
# * +share+ - A Azure::Storage::File::Share::Share instance
|
305
|
+
# * +signed_identifiers+ - A list of Azure::Storage::Service::SignedIdentifier instances
|
306
|
+
#
|
307
|
+
def set_share_acl(name, options={})
|
308
|
+
# Query
|
309
|
+
query = { 'comp' => 'acl' }
|
310
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
311
|
+
|
312
|
+
# Scheme + path
|
313
|
+
uri = share_uri(name, query)
|
314
|
+
|
315
|
+
# Headers + body
|
316
|
+
headers = StorageService.common_headers
|
317
|
+
|
318
|
+
signed_identifiers = options[:signed_identifiers] ? options[:signed_identifiers] : nil
|
319
|
+
body = signed_identifiers ? Serialization.signed_identifiers_to_xml(signed_identifiers) : nil
|
320
|
+
|
321
|
+
# Call
|
322
|
+
response = call(:put, uri, body, headers, options)
|
323
|
+
|
324
|
+
# Result
|
325
|
+
share = Serialization.share_from_headers(response.headers)
|
326
|
+
share.name = name
|
327
|
+
|
328
|
+
return share, signed_identifiers || []
|
329
|
+
end
|
330
|
+
|
331
|
+
# Public: Retrieves statistics related to the share.
|
332
|
+
#
|
333
|
+
# ==== Attributes
|
334
|
+
#
|
335
|
+
# * +name+ - String. The name of the share
|
336
|
+
# * +options+ - Hash. Optional parameters.
|
337
|
+
#
|
338
|
+
# ==== Options
|
339
|
+
#
|
340
|
+
# Accepted key/value pairs in options parameter are:
|
341
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
342
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
343
|
+
# in the analytics logs when storage analytics logging is enabled.
|
344
|
+
#
|
345
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-share-stats
|
346
|
+
#
|
347
|
+
# Returns a Share
|
348
|
+
def get_share_stats(name, options={})
|
349
|
+
# Query
|
350
|
+
query = { 'comp' => 'stats' }
|
351
|
+
query['timeout'] = options[:timeout].to_s if options[:timeout]
|
352
|
+
|
353
|
+
# Call
|
354
|
+
response = call(:get, share_uri(name, query), nil, {}, options)
|
355
|
+
|
356
|
+
# result
|
357
|
+
share = Serialization.share_from_headers(response.headers)
|
358
|
+
share.name = name
|
359
|
+
share.usage = Serialization.share_stats_from_xml(response.body)
|
360
|
+
share
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|