uplink-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 46193e946143cb5bc440d3f81e098a9248ab45b8f9aa7bb4feac913fefaeb0f6
4
+ data.tar.gz: 3434923d626b3a09630a8243b19e57ce6c183f0367179010d506d7854611e80d
5
+ SHA512:
6
+ metadata.gz: 7322122e433dd7af3d4ed0173b7f88affc224a2b108d19b8261a2ed52842cbf836d50b18d7046ba6660206e44978e5aed5221d66c52d5df34c80a1f2a2d52d80
7
+ data.tar.gz: 9797174853941f4656fea3bfe47de1c84d1060a1dc2d897f3b837f3b1514836078c251377ba860395c0575a623407ddf581afd5937df710493898e1ea61e6657
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uplink
4
+ class Access
5
+ attr_reader :access
6
+
7
+ def initialize(access_result)
8
+ @access = access_result[:access]
9
+ end
10
+
11
+ def open_project(auto_close: true)
12
+ result = UplinkLib.uplink_open_project(@access)
13
+ ErrorUtil.handle_result_error(result)
14
+
15
+ project = Project.new(result)
16
+
17
+ yield project
18
+ ensure
19
+ project.close if auto_close && project
20
+ UplinkLib.uplink_free_project_result(result) if result
21
+ end
22
+
23
+ def open_project_with_config(config, auto_close: true)
24
+ config_options = UplinkUtil.build_uplink_config(config)
25
+
26
+ result = UplinkLib.uplink_config_open_project(config_options, @access)
27
+ ErrorUtil.handle_result_error(result)
28
+
29
+ project = Project.new(result)
30
+
31
+ yield project
32
+ ensure
33
+ project.close if auto_close && project
34
+ UplinkLib.uplink_free_project_result(result) if result
35
+ end
36
+
37
+ def satellite_address
38
+ result = UplinkLib.uplink_access_satellite_address(@access)
39
+ ErrorUtil.handle_result_error(result)
40
+
41
+ result[:string]
42
+ ensure
43
+ UplinkLib.uplink_free_string_result(result) if result
44
+ end
45
+
46
+ def serialize
47
+ result = UplinkLib.uplink_access_serialize(@access)
48
+ ErrorUtil.handle_result_error(result)
49
+
50
+ result[:string]
51
+ ensure
52
+ UplinkLib.uplink_free_string_result(result) if result
53
+ end
54
+
55
+ def share(permission, prefixes)
56
+ permission_options = UplinkLib::UplinkPermission.new
57
+ if permission && !permission.empty?
58
+ permission_options[:allow_download] = permission[:allow_download]
59
+ permission_options[:allow_upload] = permission[:allow_upload]
60
+ permission_options[:allow_list] = permission[:allow_list]
61
+ permission_options[:allow_delete] = permission[:allow_delete]
62
+ permission_options[:not_before] = permission[:not_before].to_i if permission[:not_before]
63
+ permission_options[:not_after] = permission[:not_after].to_i if permission[:not_after]
64
+ end
65
+
66
+ prefixes_count = prefixes&.size || 0
67
+ mem_prefixes = nil
68
+
69
+ if prefixes_count.positive?
70
+ mem_prefixes = FFI::MemoryPointer.new(UplinkLib::UplinkSharePrefix, prefixes_count)
71
+
72
+ prefixes.each_with_index do |prefix, i|
73
+ bucket = FFI::MemoryPointer.from_string(prefix[:bucket]) if prefix[:bucket]
74
+ prefix_val = FFI::MemoryPointer.from_string(prefix[:prefix]) if prefix[:prefix]
75
+
76
+ prefix_entry = UplinkLib::UplinkSharePrefix.new(mem_prefixes + (i * UplinkLib::UplinkSharePrefix.size))
77
+ prefix_entry[:bucket] = bucket
78
+ prefix_entry[:prefix] = prefix_val
79
+ end
80
+ end
81
+
82
+ result = UplinkLib.uplink_access_share(@access, permission_options, mem_prefixes, prefixes_count)
83
+ ErrorUtil.handle_result_error(result)
84
+
85
+ yield Access.new(result)
86
+ ensure
87
+ UplinkLib.uplink_free_access_result(result) if result
88
+ end
89
+
90
+ def override_encryption_key(bucket, prefix, encryption_key)
91
+ error = UplinkLib.uplink_access_override_encryption_key(@access, bucket, prefix, encryption_key)
92
+ ErrorUtil.handle_error(error)
93
+ ensure
94
+ UplinkLib.uplink_free_error(error) if error
95
+ end
96
+
97
+ def edge_register_access(config, options = nil)
98
+ register_config = UplinkLib::EdgeConfig.new
99
+
100
+ auth_service_address = FFI::MemoryPointer.from_string(config[:auth_service_address]) if config[:auth_service_address]
101
+ certificate_pem = FFI::MemoryPointer.from_string(config[:certificate_pem]) if config[:certificate_pem]
102
+ register_config[:auth_service_address] = auth_service_address
103
+ register_config[:certificate_pem] = certificate_pem
104
+
105
+ register_options = nil
106
+ if options && !options.empty?
107
+ register_options = UplinkLib::EdgeRegisterAccessOptions.new
108
+ register_options[:is_public] = options[:is_public]
109
+ end
110
+
111
+ result = UplinkLib.edge_register_access(register_config, @access, register_options)
112
+ ErrorUtil.handle_result_error(result)
113
+
114
+ EdgeCredential.new(result)
115
+ ensure
116
+ UplinkLib.edge_free_credentials_result(result) if result
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uplink
4
+ class Bucket
5
+ attr_reader :name, :created
6
+
7
+ def initialize(bucket_result, bucket = nil)
8
+ init_attributes(bucket_result.nil? || bucket_result.null? ? bucket : bucket_result[:bucket])
9
+ end
10
+
11
+ private
12
+
13
+ def init_attributes(bucket)
14
+ return if bucket.nil? || bucket.null?
15
+
16
+ @name = bucket[:name]
17
+ @created = bucket[:created]
18
+ end
19
+ end
20
+
21
+ class BucketIterator
22
+ def initialize(bucket_iterator)
23
+ @bucket_iterator = bucket_iterator
24
+ end
25
+
26
+ def next?
27
+ has_next = UplinkLib.uplink_bucket_iterator_next(@bucket_iterator)
28
+ unless has_next
29
+ begin
30
+ error = UplinkLib.uplink_bucket_iterator_err(@bucket_iterator)
31
+ ErrorUtil.handle_error(error)
32
+ ensure
33
+ UplinkLib.uplink_free_error(error) if error
34
+ end
35
+ end
36
+
37
+ has_next
38
+ end
39
+
40
+ def item
41
+ bucket = UplinkLib.uplink_bucket_iterator_item(@bucket_iterator)
42
+ Bucket.new(nil, bucket)
43
+ ensure
44
+ UplinkLib.uplink_free_bucket(bucket) if bucket
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uplink
4
+ class Download
5
+ def initialize(download_result)
6
+ @download = download_result[:download]
7
+ end
8
+
9
+ def read(bytes, length)
10
+ raise ArgumentError, 'bytes argument is nil' if bytes.nil?
11
+
12
+ mem_bytes = FFI::MemoryPointer.new(:uint8, length)
13
+ result = UplinkLib.uplink_download_read(@download, mem_bytes, length)
14
+
15
+ error_code = ErrorUtil.handle_result_error(result)
16
+ is_eof = (error_code == EOF)
17
+
18
+ bytes_read = result[:bytes_read]
19
+ bytes.concat(mem_bytes.read_array_of_uint8(bytes_read)) if bytes_read.positive?
20
+
21
+ [bytes_read, is_eof]
22
+ ensure
23
+ UplinkLib.uplink_free_read_result(result) if result
24
+ end
25
+
26
+ def info
27
+ result = UplinkLib.uplink_download_info(@download)
28
+ ErrorUtil.handle_result_error(result)
29
+
30
+ Object.new(result)
31
+ ensure
32
+ UplinkLib.uplink_free_object_result(result) if result
33
+ end
34
+
35
+ def close
36
+ error = UplinkLib.uplink_close_download(@download)
37
+ ErrorUtil.handle_error(error)
38
+ ensure
39
+ UplinkLib.uplink_free_error(error) if error
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uplink
4
+ class EdgeCredential
5
+ attr_reader :access_key_id, :secret_key, :endpoint
6
+
7
+ def initialize(edge_credentials_result, edge_credentials = nil)
8
+ init_attributes(edge_credentials_result.nil? || edge_credentials_result.null? ? edge_credentials : edge_credentials_result[:credentials])
9
+ end
10
+
11
+ def join_share_url(base_url, bucket, key, options = nil)
12
+ share_url_options = nil
13
+ if options && !options.empty?
14
+ share_url_options = UplinkLib::EdgeShareURLOptions.new
15
+ share_url_options[:raw] = options[:raw]
16
+ end
17
+
18
+ result = UplinkLib.edge_join_share_url(base_url, @access_key_id, bucket, key, share_url_options)
19
+ ErrorUtil.handle_result_error(result)
20
+
21
+ result[:string]
22
+ ensure
23
+ UplinkLib.uplink_free_string_result(result) if result
24
+ end
25
+
26
+ private
27
+
28
+ def init_attributes(edge_credentials)
29
+ return if edge_credentials.nil? || edge_credentials.null?
30
+
31
+ @access_key_id = edge_credentials[:access_key_id]
32
+ @secret_key = edge_credentials[:secret_key]
33
+ @endpoint = edge_credentials[:endpoint]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uplink
4
+ class ErrorUtil
5
+ class << self
6
+ def handle_result_error(result)
7
+ handle_error(result[:error])
8
+ end
9
+
10
+ def handle_error(error)
11
+ return 0 if error.null?
12
+
13
+ error_code = error[:code]
14
+ return error_code if error_code == EOF
15
+
16
+ err = CODE_TO_ERROR_MAPPING[error_code]
17
+ raise err.new(error_code, error[:message]) if err
18
+
19
+ raise InternalError.new(error_code, error[:message])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uplink
4
+ class Object
5
+ attr_reader :key, :is_prefix, :created, :expires, :content_length, :custom
6
+
7
+ def initialize(object_result, object = nil)
8
+ init_attributes(object_result.nil? || object_result.null? ? object : object_result[:object])
9
+ end
10
+
11
+ private
12
+
13
+ def init_attributes(object)
14
+ return if object.nil? || object.null?
15
+
16
+ @key = object[:key]
17
+ @is_prefix = object[:is_prefix]
18
+ @created, @expires, @content_length = UplinkUtil.get_system_values(object)
19
+ @custom = UplinkUtil.get_custom_metadata(object)
20
+ end
21
+ end
22
+
23
+ class ObjectIterator
24
+ def initialize(object_iterator)
25
+ @object_iterator = object_iterator
26
+ end
27
+
28
+ def next?
29
+ has_next = UplinkLib.uplink_object_iterator_next(@object_iterator)
30
+ unless has_next
31
+ begin
32
+ error = UplinkLib.uplink_object_iterator_err(@object_iterator)
33
+ ErrorUtil.handle_error(error)
34
+ ensure
35
+ UplinkLib.uplink_free_error(error) if error
36
+ end
37
+ end
38
+
39
+ has_next
40
+ end
41
+
42
+ def item
43
+ object = UplinkLib.uplink_object_iterator_item(@object_iterator)
44
+ Object.new(nil, object)
45
+ ensure
46
+ UplinkLib.uplink_free_object(object) if object
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,259 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uplink
4
+ class Project
5
+ def initialize(project_result)
6
+ @project = project_result[:project]
7
+ end
8
+
9
+ def create_bucket(bucket_name)
10
+ result = UplinkLib.uplink_create_bucket(@project, bucket_name)
11
+ ErrorUtil.handle_result_error(result)
12
+
13
+ Bucket.new(result)
14
+ ensure
15
+ UplinkLib.uplink_free_bucket_result(result) if result
16
+ end
17
+
18
+ def ensure_bucket(bucket_name)
19
+ result = UplinkLib.uplink_ensure_bucket(@project, bucket_name)
20
+ ErrorUtil.handle_result_error(result)
21
+
22
+ Bucket.new(result)
23
+ ensure
24
+ UplinkLib.uplink_free_bucket_result(result) if result
25
+ end
26
+
27
+ def stat_bucket(bucket_name)
28
+ result = UplinkLib.uplink_stat_bucket(@project, bucket_name)
29
+ ErrorUtil.handle_result_error(result)
30
+
31
+ Bucket.new(result)
32
+ ensure
33
+ UplinkLib.uplink_free_bucket_result(result) if result
34
+ end
35
+
36
+ def list_buckets(options = nil)
37
+ list_options = nil
38
+ if options && !options.empty?
39
+ list_options = UplinkLib::UplinkListBucketsOptions.new
40
+ cursor = FFI::MemoryPointer.from_string(options[:cursor]) if options[:cursor]
41
+ list_options[:cursor] = cursor
42
+ end
43
+
44
+ iterator = UplinkLib.uplink_list_buckets(@project, list_options)
45
+
46
+ yield BucketIterator.new(iterator)
47
+ ensure
48
+ UplinkLib.uplink_free_bucket_iterator(iterator) if iterator
49
+ end
50
+
51
+ def delete_bucket(bucket_name)
52
+ result = UplinkLib.uplink_delete_bucket(@project, bucket_name)
53
+ ErrorUtil.handle_result_error(result)
54
+
55
+ Bucket.new(result)
56
+ ensure
57
+ UplinkLib.uplink_free_bucket_result(result) if result
58
+ end
59
+
60
+ def delete_bucket_with_objects(bucket_name)
61
+ result = UplinkLib.uplink_delete_bucket_with_objects(@project, bucket_name)
62
+ ErrorUtil.handle_result_error(result)
63
+
64
+ Bucket.new(result)
65
+ ensure
66
+ UplinkLib.uplink_free_bucket_result(result) if result
67
+ end
68
+
69
+ def upload_object(bucket_name, object_key, options = nil)
70
+ upload_options = UplinkUtil.build_upload_options(options)
71
+
72
+ result = UplinkLib.uplink_upload_object(@project, bucket_name, object_key, upload_options)
73
+ ErrorUtil.handle_result_error(result)
74
+
75
+ yield Upload.new(result)
76
+ ensure
77
+ UplinkLib.uplink_free_upload_result(result) if result
78
+ end
79
+
80
+ def begin_upload(bucket_name, object_key, options = nil)
81
+ upload_options = UplinkUtil.build_upload_options(options)
82
+
83
+ result = UplinkLib.uplink_begin_upload(@project, bucket_name, object_key, upload_options)
84
+ ErrorUtil.handle_result_error(result)
85
+
86
+ UploadInfo.new(result)
87
+ ensure
88
+ UplinkLib.uplink_free_upload_info_result(result) if result
89
+ end
90
+
91
+ def upload_part(bucket_name, object_key, upload_id, part_number)
92
+ result = UplinkLib.uplink_upload_part(@project, bucket_name, object_key, upload_id, part_number)
93
+ ErrorUtil.handle_result_error(result)
94
+
95
+ yield PartUpload.new(result)
96
+ ensure
97
+ UplinkLib.uplink_free_part_upload_result(result) if result
98
+ end
99
+
100
+ def commit_upload(bucket_name, object_key, upload_id, options = nil)
101
+ upload_options = nil
102
+ if options && !options.empty?
103
+ custom_metadata = nil
104
+
105
+ if options[:custom_metadata] && !options[:custom_metadata].empty?
106
+ custom_metadata = UplinkUtil.build_custom_metadata(options[:custom_metadata])
107
+ end
108
+
109
+ upload_options = UplinkLib::UplinkCommitUploadOptions.new
110
+ upload_options[:custom_metadata] = custom_metadata
111
+ end
112
+
113
+ result = UplinkLib.uplink_commit_upload(@project, bucket_name, object_key, upload_id, upload_options)
114
+ ErrorUtil.handle_result_error(result)
115
+
116
+ Object.new(result)
117
+ ensure
118
+ UplinkLib.uplink_free_commit_upload_result(result) if result
119
+ end
120
+
121
+ def abort_upload(bucket_name, object_key, upload_id)
122
+ error = UplinkLib.uplink_abort_upload(@project, bucket_name, object_key, upload_id)
123
+ ErrorUtil.handle_error(error)
124
+ ensure
125
+ UplinkLib.uplink_free_error(error) if error
126
+ end
127
+
128
+ def list_uploads(bucket_name, options = nil)
129
+ list_options = nil
130
+ if options && !options.empty?
131
+ list_options = UplinkLib::UplinkListUploadsOptions.new
132
+ cursor = FFI::MemoryPointer.from_string(options[:cursor]) if options[:cursor]
133
+ prefix = FFI::MemoryPointer.from_string(options[:prefix]) if options[:prefix]
134
+ list_options[:cursor] = cursor
135
+ list_options[:prefix] = prefix
136
+ list_options[:recursive] = options[:recursive]
137
+ list_options[:system] = options[:system]
138
+ list_options[:custom] = options[:custom]
139
+ end
140
+
141
+ iterator = UplinkLib.uplink_list_uploads(@project, bucket_name, list_options)
142
+
143
+ yield UploadIterator.new(iterator)
144
+ ensure
145
+ UplinkLib.uplink_free_upload_iterator(iterator) if iterator
146
+ end
147
+
148
+ def list_upload_parts(bucket_name, object_key, upload_id, options = nil)
149
+ list_options = nil
150
+ if options && !options.empty?
151
+ list_options = UplinkLib::UplinkListUploadPartsOptions.new
152
+ cursor = options[:cursor].to_i if options[:cursor]
153
+ list_options[:cursor] = cursor || 0
154
+ end
155
+
156
+ iterator = UplinkLib.uplink_list_upload_parts(@project, bucket_name, object_key, upload_id, list_options)
157
+
158
+ yield UploadPartIterator.new(iterator)
159
+ ensure
160
+ UplinkLib.uplink_free_part_iterator(iterator) if iterator
161
+ end
162
+
163
+ def download_object(bucket_name, object_key, options = nil, auto_close: true)
164
+ download_options = nil
165
+ if options && !options.empty?
166
+ download_options = UplinkLib::UplinkDownloadOptions.new
167
+ download_options[:offset] = options[:offset].to_i if options[:offset]
168
+ download_options[:length] = options[:length].to_i if options[:length]
169
+ end
170
+
171
+ result = UplinkLib.uplink_download_object(@project, bucket_name, object_key, download_options)
172
+ ErrorUtil.handle_result_error(result)
173
+
174
+ download = Download.new(result)
175
+
176
+ yield download
177
+ ensure
178
+ download.close if auto_close && download
179
+ UplinkLib.uplink_free_download_result(result) if result
180
+ end
181
+
182
+ def stat_object(bucket_name, object_key)
183
+ result = UplinkLib.uplink_stat_object(@project, bucket_name, object_key)
184
+ ErrorUtil.handle_result_error(result)
185
+
186
+ Object.new(result)
187
+ ensure
188
+ UplinkLib.uplink_free_object_result(result) if result
189
+ end
190
+
191
+ def list_objects(bucket_name, options = nil)
192
+ list_options = nil
193
+ if options && !options.empty?
194
+ list_options = UplinkLib::UplinkListObjectsOptions.new
195
+ cursor = FFI::MemoryPointer.from_string(options[:cursor]) if options[:cursor]
196
+ prefix = FFI::MemoryPointer.from_string(options[:prefix]) if options[:prefix]
197
+ list_options[:cursor] = cursor
198
+ list_options[:prefix] = prefix
199
+ list_options[:recursive] = options[:recursive]
200
+ list_options[:system] = options[:system]
201
+ list_options[:custom] = options[:custom]
202
+ end
203
+
204
+ iterator = UplinkLib.uplink_list_objects(@project, bucket_name, list_options)
205
+
206
+ yield ObjectIterator.new(iterator)
207
+ ensure
208
+ UplinkLib.uplink_free_object_iterator(iterator) if iterator
209
+ end
210
+
211
+ def update_object_metadata(bucket_name, object_key, new_metadata, options = nil)
212
+ custom_metadata = UplinkUtil.build_custom_metadata(new_metadata)
213
+
214
+ error = UplinkLib.uplink_update_object_metadata(@project, bucket_name, object_key, custom_metadata, options)
215
+ ErrorUtil.handle_error(error)
216
+ ensure
217
+ UplinkLib.uplink_free_error(error) if error
218
+ end
219
+
220
+ def copy_object(old_bucket_name, old_object_key, new_bucket_name, new_object_key, options = nil)
221
+ result = UplinkLib.uplink_copy_object(@project, old_bucket_name, old_object_key, new_bucket_name, new_object_key, options)
222
+ ErrorUtil.handle_result_error(result)
223
+
224
+ Object.new(result)
225
+ ensure
226
+ UplinkLib.uplink_free_object_result(result) if result
227
+ end
228
+
229
+ def move_object(old_bucket_name, old_object_key, new_bucket_name, new_object_key, options = nil)
230
+ error = UplinkLib.uplink_move_object(@project, old_bucket_name, old_object_key, new_bucket_name, new_object_key, options)
231
+ ErrorUtil.handle_error(error)
232
+ ensure
233
+ UplinkLib.uplink_free_error(error) if error
234
+ end
235
+
236
+ def delete_object(bucket_name, object_key)
237
+ result = UplinkLib.uplink_delete_object(@project, bucket_name, object_key)
238
+ ErrorUtil.handle_result_error(result)
239
+
240
+ Object.new(result)
241
+ ensure
242
+ UplinkLib.uplink_free_object_result(result) if result
243
+ end
244
+
245
+ def revoke_access(access)
246
+ error = UplinkLib.uplink_revoke_access(@project, access&.access)
247
+ ErrorUtil.handle_error(error)
248
+ ensure
249
+ UplinkLib.uplink_free_error(error) if error
250
+ end
251
+
252
+ def close
253
+ error = UplinkLib.uplink_close_project(@project)
254
+ ErrorUtil.handle_error(error)
255
+ ensure
256
+ UplinkLib.uplink_free_error(error) if error
257
+ end
258
+ end
259
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uplink
4
+ class StorjError < StandardError
5
+ attr_reader :code
6
+
7
+ def initialize(code, message)
8
+ super(message)
9
+ @code = code
10
+ end
11
+ end
12
+
13
+ class InternalError < StorjError; end
14
+ class CanceledError < StorjError; end
15
+ class InvalidHandleError < StorjError; end
16
+ class TooManyRequestError < StorjError; end
17
+ class BandwidthLimitExceededError < StorjError; end
18
+ class StorageLimitExceededError < StorjError; end
19
+ class SegmentsLimitExceededError < StorjError; end
20
+ class BucketNameInvalidError < StorjError; end
21
+ class BucketAlreadyExistsError < StorjError; end
22
+ class BucketNotEmptyError < StorjError; end
23
+ class BucketNotFoundError < StorjError; end
24
+ class ObjectKeyInvalidError < StorjError; end
25
+ class ObjectKeyNotFoundError < StorjError; end
26
+ class UploadDoneError < StorjError; end
27
+ class EdgeAuthDialFailedError < StorjError; end
28
+ class EdgeRegisterAccessFailedError < StorjError; end
29
+
30
+ EOF = -1
31
+ UPLINK_ERROR_INTERNAL = 0x02
32
+ UPLINK_ERROR_CANCELED = 0x03
33
+ UPLINK_ERROR_INVALID_HANDLE = 0x04
34
+ UPLINK_ERROR_TOO_MANY_REQUESTS = 0x05
35
+ UPLINK_ERROR_BANDWIDTH_LIMIT_EXCEEDED = 0x06
36
+ UPLINK_ERROR_STORAGE_LIMIT_EXCEEDED = 0x07
37
+ UPLINK_ERROR_SEGMENTS_LIMIT_EXCEEDED = 0x08
38
+ UPLINK_ERROR_BUCKET_NAME_INVALID = 0x10
39
+ UPLINK_ERROR_BUCKET_ALREADY_EXISTS = 0x11
40
+ UPLINK_ERROR_BUCKET_NOT_EMPTY = 0x12
41
+ UPLINK_ERROR_BUCKET_NOT_FOUND = 0x13
42
+ UPLINK_ERROR_OBJECT_KEY_INVALID = 0x20
43
+ UPLINK_ERROR_OBJECT_NOT_FOUND = 0x21
44
+ UPLINK_ERROR_UPLOAD_DONE = 0x22
45
+ EDGE_ERROR_AUTH_DIAL_FAILED = 0x30
46
+ EDGE_ERROR_REGISTER_ACCESS_FAILED = 0x31
47
+
48
+ CODE_TO_ERROR_MAPPING = {
49
+ UPLINK_ERROR_INTERNAL => InternalError,
50
+ UPLINK_ERROR_CANCELED => CanceledError,
51
+ UPLINK_ERROR_INVALID_HANDLE => InvalidHandleError,
52
+ UPLINK_ERROR_TOO_MANY_REQUESTS => TooManyRequestError,
53
+ UPLINK_ERROR_BANDWIDTH_LIMIT_EXCEEDED => BandwidthLimitExceededError,
54
+ UPLINK_ERROR_STORAGE_LIMIT_EXCEEDED => StorageLimitExceededError,
55
+ UPLINK_ERROR_SEGMENTS_LIMIT_EXCEEDED => SegmentsLimitExceededError,
56
+ UPLINK_ERROR_BUCKET_NAME_INVALID => BucketNameInvalidError,
57
+ UPLINK_ERROR_BUCKET_ALREADY_EXISTS => BucketAlreadyExistsError,
58
+ UPLINK_ERROR_BUCKET_NOT_EMPTY => BucketNotEmptyError,
59
+ UPLINK_ERROR_BUCKET_NOT_FOUND => BucketNotFoundError,
60
+ UPLINK_ERROR_OBJECT_KEY_INVALID => ObjectKeyInvalidError,
61
+ UPLINK_ERROR_OBJECT_NOT_FOUND => ObjectKeyNotFoundError,
62
+ UPLINK_ERROR_UPLOAD_DONE => UploadDoneError,
63
+ EDGE_ERROR_AUTH_DIAL_FAILED => EdgeAuthDialFailedError,
64
+ EDGE_ERROR_REGISTER_ACCESS_FAILED => EdgeRegisterAccessFailedError
65
+ }.freeze
66
+ end