azure-storage-file 1.0.0 → 2.0.3

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.
@@ -1,284 +1,284 @@
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/file/serialization"
27
-
28
- module Azure::Storage::File
29
- StorageService = Azure::Storage::Common::Service::StorageService
30
- module Directory
31
- include Azure::Storage::Common::Service
32
-
33
- class Directory
34
- def initialize
35
- @properties = {}
36
- @metadata = {}
37
- yield self if block_given?
38
- end
39
-
40
- attr_accessor :name
41
- attr_accessor :properties
42
- attr_accessor :metadata
43
- end
44
- end
45
-
46
- # Public: Get a list of files or directories under the specified share or directory.
47
- # It lists the contents only for a single level of the directory hierarchy.
48
- #
49
- # ==== Attributes
50
- #
51
- # * +share+ - String. The name of the file share.
52
- # * +directory_path+ - String. The path to the directory.
53
- # * +options+ - Hash. Optional parameters.
54
- #
55
- # ==== Options
56
- #
57
- # Accepted key/value pairs in options parameter are:
58
- #
59
- # * +:prefix+ - String. Filters the results to return only directories and files
60
- # whose name begins with the specified prefix. (optional)
61
- # * +:marker+ - String. An identifier the specifies the portion of the
62
- # list to be returned. This value comes from the property
63
- # Azure::Storage::Common::EnumerationResults.continuation_token when there
64
- # are more shares available than were returned. The
65
- # marker value may then be used here to request the next set
66
- # of list items. (optional)
67
- #
68
- # * +:max_results+ - Integer. Specifies the maximum number of shares to return.
69
- # If max_results is not specified, or is a value greater than
70
- # 5,000, the server will return up to 5,000 items. If it is set
71
- # to a value less than or equal to zero, the server will return
72
- # status code 400 (Bad Request). (optional)
73
- #
74
- # * +:timeout+ - Integer. A timeout in seconds.
75
- #
76
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
77
- # in the analytics logs when storage analytics logging is enabled.
78
- #
79
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
80
- # which location the request should be sent to.
81
- #
82
- # See: https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/list-directories-and-files
83
- #
84
- # Returns an Azure::Storage::Common::EnumerationResults
85
- #
86
- def list_directories_and_files(share, directory_path, options = {})
87
- query = { "comp" => "list" }
88
- unless options.nil?
89
- StorageService.with_query query, "marker", options[:marker]
90
- StorageService.with_query query, "maxresults", options[:max_results].to_s if options[:max_results]
91
- StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
92
- StorageService.with_query query, "prefix", options[:prefix].to_s if options[:prefix]
93
- end
94
-
95
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
96
- uri = directory_uri(share, directory_path, query, options)
97
- response = call(:get, uri, nil, {}, options)
98
-
99
- # Result
100
- if response.success?
101
- Serialization.directories_and_files_enumeration_results_from_xml(response.body)
102
- else
103
- response.exception
104
- end
105
- end
106
-
107
- # Public: Create a new directory
108
- #
109
- # ==== Attributes
110
- #
111
- # * +share+ - String. The name of the file share.
112
- # * +directory_path+ - String. The path to the directory.
113
- # * +options+ - Hash. Optional parameters.
114
- #
115
- # ==== Options
116
- #
117
- # Accepted key/value pairs in options parameter are:
118
- # * +:metadata+ - Hash. User defined metadata for the share (optional).
119
- # * +:timeout+ - Integer. A timeout in seconds.
120
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
121
- # in the analytics logs when storage analytics logging is enabled.
122
- #
123
- # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/create-directory
124
- #
125
- # Returns a Directory
126
- def create_directory(share, directory_path, options = {})
127
- # Query
128
- query = {}
129
- query["timeout"] = options[:timeout].to_s if options[:timeout]
130
-
131
- # Scheme + path
132
- uri = directory_uri(share, directory_path, query)
133
-
134
- # Headers
135
- headers = {}
136
- StorageService.add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
137
-
138
- # Call
139
- response = call(:put, uri, nil, headers, options)
140
-
141
- # result
142
- directory = Serialization.directory_from_headers(response.headers)
143
- directory.name = directory_path
144
- directory.metadata = options[:metadata] if options[:metadata]
145
- directory
146
- end
147
-
148
- # Public: Returns all system properties for the specified directory,
149
- # and can also be used to check the existence of a directory.
150
- # The data returned does not include the files in the directory or any subdirectories.
151
- #
152
- # ==== Attributes
153
- #
154
- # * +share+ - String. The name of the file share.
155
- # * +directory_path+ - String. The path to the directory.
156
- # * +options+ - Hash. Optional parameters.
157
- #
158
- # ==== Options
159
- #
160
- # Accepted key/value pairs in options parameter are:
161
- # * +:timeout+ - Integer. A timeout in seconds.
162
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
163
- # in the analytics logs when storage analytics logging is enabled.
164
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
165
- # which location the request should be sent to.
166
- #
167
- # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-directory-properties
168
- #
169
- # Returns a Directory
170
- def get_directory_properties(share, directory_path, options = {})
171
- # Query
172
- query = {}
173
- query["timeout"] = options[:timeout].to_s if options[:timeout]
174
-
175
- # Call
176
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
177
- response = call(:get, directory_uri(share, directory_path, query, options), nil, {}, options)
178
-
179
- # result
180
- directory = Serialization.directory_from_headers(response.headers)
181
- directory.name = directory_path
182
- directory
183
- end
184
-
185
- # Public: Deletes a directory.
186
- #
187
- # ==== Attributes
188
- #
189
- # * +share+ - String. The name of the file share.
190
- # * +directory_path+ - String. The path to the directory.
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/delete-directory
201
- #
202
- # Returns nil on success
203
- def delete_directory(share, directory_path, options = {})
204
- # Query
205
- query = {}
206
- query["timeout"] = options[:timeout].to_s if options[:timeout]
207
-
208
- # Call
209
- call(:delete, directory_uri(share, directory_path, query), nil, {}, options)
210
-
211
- # result
212
- nil
213
- end
214
-
215
- # Public: Returns only user-defined metadata for the specified directory.
216
- #
217
- # ==== Attributes
218
- #
219
- # * +share+ - String. The name of the file share.
220
- # * +directory_path+ - String. The path to the directory.
221
- # * +options+ - Hash. Optional parameters.
222
- #
223
- # ==== Options
224
- #
225
- # Accepted key/value pairs in options parameter are:
226
- # * +:timeout+ - Integer. A timeout in seconds.
227
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
228
- # in the analytics logs when storage analytics logging is enabled.
229
- # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
230
- # which location the request should be sent to.
231
- #
232
- # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-directory-metadata
233
- #
234
- # Returns a Directory
235
- def get_directory_metadata(share, directory_path, options = {})
236
- # Query
237
- query = { "comp" => "metadata" }
238
- query["timeout"] = options[:timeout].to_s if options[:timeout]
239
-
240
- # Call
241
- options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
242
- response = call(:get, directory_uri(share, directory_path, query, options), nil, {}, options)
243
-
244
- # result
245
- directory = Serialization.directory_from_headers(response.headers)
246
- directory.name = directory_path
247
- directory
248
- end
249
-
250
- # Public: Sets custom metadata for the directory.
251
- #
252
- # ==== Attributes
253
- #
254
- # * +share+ - String. The name of the file share.
255
- # * +directory_path+ - String. The path to the directory.
256
- # * +metadata+ - Hash. A Hash of the metadata values.
257
- # * +options+ - Hash. Optional parameters.
258
- #
259
- # ==== Options
260
- #
261
- # Accepted key/value pairs in options parameter are:
262
- # * +:timeout+ - Integer. A timeout in seconds.
263
- # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
264
- # in the analytics logs when storage analytics logging is enabled.
265
- #
266
- # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/set-directory-metadata
267
- #
268
- # Returns nil on success
269
- def set_directory_metadata(share, directory_path, metadata, options = {})
270
- # Query
271
- query = { "comp" => "metadata" }
272
- query["timeout"] = options[:timeout].to_s if options[:timeout]
273
-
274
- # Headers
275
- headers = {}
276
- StorageService.add_metadata_to_headers(metadata, headers) if metadata
277
-
278
- # Call
279
- call(:put, directory_uri(share, directory_path, query), nil, headers, options)
280
-
281
- # Result
282
- nil
283
- end
284
- end
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/file/serialization"
27
+
28
+ module Azure::Storage::File
29
+ StorageService = Azure::Storage::Common::Service::StorageService
30
+ module Directory
31
+ include Azure::Storage::Common::Service
32
+
33
+ class Directory
34
+ def initialize
35
+ @properties = {}
36
+ @metadata = {}
37
+ yield self if block_given?
38
+ end
39
+
40
+ attr_accessor :name
41
+ attr_accessor :properties
42
+ attr_accessor :metadata
43
+ end
44
+ end
45
+
46
+ # Public: Get a list of files or directories under the specified share or directory.
47
+ # It lists the contents only for a single level of the directory hierarchy.
48
+ #
49
+ # ==== Attributes
50
+ #
51
+ # * +share+ - String. The name of the file share.
52
+ # * +directory_path+ - String. The path to the directory.
53
+ # * +options+ - Hash. Optional parameters.
54
+ #
55
+ # ==== Options
56
+ #
57
+ # Accepted key/value pairs in options parameter are:
58
+ #
59
+ # * +:prefix+ - String. Filters the results to return only directories and files
60
+ # whose name begins with the specified prefix. (optional)
61
+ # * +:marker+ - String. An identifier the specifies the portion of the
62
+ # list to be returned. This value comes from the property
63
+ # Azure::Storage::Common::EnumerationResults.continuation_token when there
64
+ # are more shares available than were returned. The
65
+ # marker value may then be used here to request the next set
66
+ # of list items. (optional)
67
+ #
68
+ # * +:max_results+ - Integer. Specifies the maximum number of shares to return.
69
+ # If max_results is not specified, or is a value greater than
70
+ # 5,000, the server will return up to 5,000 items. If it is set
71
+ # to a value less than or equal to zero, the server will return
72
+ # status code 400 (Bad Request). (optional)
73
+ #
74
+ # * +:timeout+ - Integer. A timeout in seconds.
75
+ #
76
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
77
+ # in the analytics logs when storage analytics logging is enabled.
78
+ #
79
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
80
+ # which location the request should be sent to.
81
+ #
82
+ # See: https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/list-directories-and-files
83
+ #
84
+ # Returns an Azure::Storage::Common::EnumerationResults
85
+ #
86
+ def list_directories_and_files(share, directory_path, options = {})
87
+ query = { "comp" => "list" }
88
+ unless options.nil?
89
+ StorageService.with_query query, "marker", options[:marker]
90
+ StorageService.with_query query, "maxresults", options[:max_results].to_s if options[:max_results]
91
+ StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
92
+ StorageService.with_query query, "prefix", options[:prefix].to_s if options[:prefix]
93
+ end
94
+
95
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
96
+ uri = directory_uri(share, directory_path, query, options)
97
+ response = call(:get, uri, nil, {}, options)
98
+
99
+ # Result
100
+ if response.success?
101
+ Serialization.directories_and_files_enumeration_results_from_xml(response.body)
102
+ else
103
+ response.exception
104
+ end
105
+ end
106
+
107
+ # Public: Create a new directory
108
+ #
109
+ # ==== Attributes
110
+ #
111
+ # * +share+ - String. The name of the file share.
112
+ # * +directory_path+ - String. The path to the directory.
113
+ # * +options+ - Hash. Optional parameters.
114
+ #
115
+ # ==== Options
116
+ #
117
+ # Accepted key/value pairs in options parameter are:
118
+ # * +:metadata+ - Hash. User defined metadata for the share (optional).
119
+ # * +:timeout+ - Integer. A timeout in seconds.
120
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
121
+ # in the analytics logs when storage analytics logging is enabled.
122
+ #
123
+ # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/create-directory
124
+ #
125
+ # Returns a Directory
126
+ def create_directory(share, directory_path, options = {})
127
+ # Query
128
+ query = {}
129
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
130
+
131
+ # Scheme + path
132
+ uri = directory_uri(share, directory_path, query)
133
+
134
+ # Headers
135
+ headers = {}
136
+ StorageService.add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
137
+
138
+ # Call
139
+ response = call(:put, uri, nil, headers, options)
140
+
141
+ # result
142
+ directory = Serialization.directory_from_headers(response.headers)
143
+ directory.name = directory_path
144
+ directory.metadata = options[:metadata] if options[:metadata]
145
+ directory
146
+ end
147
+
148
+ # Public: Returns all system properties for the specified directory,
149
+ # and can also be used to check the existence of a directory.
150
+ # The data returned does not include the files in the directory or any subdirectories.
151
+ #
152
+ # ==== Attributes
153
+ #
154
+ # * +share+ - String. The name of the file share.
155
+ # * +directory_path+ - String. The path to the directory.
156
+ # * +options+ - Hash. Optional parameters.
157
+ #
158
+ # ==== Options
159
+ #
160
+ # Accepted key/value pairs in options parameter are:
161
+ # * +:timeout+ - Integer. A timeout in seconds.
162
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
163
+ # in the analytics logs when storage analytics logging is enabled.
164
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
165
+ # which location the request should be sent to.
166
+ #
167
+ # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-directory-properties
168
+ #
169
+ # Returns a Directory
170
+ def get_directory_properties(share, directory_path, options = {})
171
+ # Query
172
+ query = {}
173
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
174
+
175
+ # Call
176
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
177
+ response = call(:get, directory_uri(share, directory_path, query, options), nil, {}, options)
178
+
179
+ # result
180
+ directory = Serialization.directory_from_headers(response.headers)
181
+ directory.name = directory_path
182
+ directory
183
+ end
184
+
185
+ # Public: Deletes a directory.
186
+ #
187
+ # ==== Attributes
188
+ #
189
+ # * +share+ - String. The name of the file share.
190
+ # * +directory_path+ - String. The path to the directory.
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/delete-directory
201
+ #
202
+ # Returns nil on success
203
+ def delete_directory(share, directory_path, options = {})
204
+ # Query
205
+ query = {}
206
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
207
+
208
+ # Call
209
+ call(:delete, directory_uri(share, directory_path, query), nil, {}, options)
210
+
211
+ # result
212
+ nil
213
+ end
214
+
215
+ # Public: Returns only user-defined metadata for the specified directory.
216
+ #
217
+ # ==== Attributes
218
+ #
219
+ # * +share+ - String. The name of the file share.
220
+ # * +directory_path+ - String. The path to the directory.
221
+ # * +options+ - Hash. Optional parameters.
222
+ #
223
+ # ==== Options
224
+ #
225
+ # Accepted key/value pairs in options parameter are:
226
+ # * +:timeout+ - Integer. A timeout in seconds.
227
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
228
+ # in the analytics logs when storage analytics logging is enabled.
229
+ # * +:location_mode+ - LocationMode. Specifies the location mode used to decide
230
+ # which location the request should be sent to.
231
+ #
232
+ # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-directory-metadata
233
+ #
234
+ # Returns a Directory
235
+ def get_directory_metadata(share, directory_path, options = {})
236
+ # Query
237
+ query = { "comp" => "metadata" }
238
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
239
+
240
+ # Call
241
+ options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
242
+ response = call(:get, directory_uri(share, directory_path, query, options), nil, {}, options)
243
+
244
+ # result
245
+ directory = Serialization.directory_from_headers(response.headers)
246
+ directory.name = directory_path
247
+ directory
248
+ end
249
+
250
+ # Public: Sets custom metadata for the directory.
251
+ #
252
+ # ==== Attributes
253
+ #
254
+ # * +share+ - String. The name of the file share.
255
+ # * +directory_path+ - String. The path to the directory.
256
+ # * +metadata+ - Hash. A Hash of the metadata values.
257
+ # * +options+ - Hash. Optional parameters.
258
+ #
259
+ # ==== Options
260
+ #
261
+ # Accepted key/value pairs in options parameter are:
262
+ # * +:timeout+ - Integer. A timeout in seconds.
263
+ # * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
264
+ # in the analytics logs when storage analytics logging is enabled.
265
+ #
266
+ # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/set-directory-metadata
267
+ #
268
+ # Returns nil on success
269
+ def set_directory_metadata(share, directory_path, metadata, options = {})
270
+ # Query
271
+ query = { "comp" => "metadata" }
272
+ query["timeout"] = options[:timeout].to_s if options[:timeout]
273
+
274
+ # Headers
275
+ headers = {}
276
+ StorageService.add_metadata_to_headers(metadata, headers) if metadata
277
+
278
+ # Call
279
+ call(:put, directory_uri(share, directory_path, query), nil, headers, options)
280
+
281
+ # Result
282
+ nil
283
+ end
284
+ end