fog-aliyun 0.3.13 → 0.3.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +109 -0
- data/Gemfile +0 -1
- data/fog-aliyun.gemspec +2 -0
- data/lib/fog/aliyun/models/storage/directories.rb +30 -53
- data/lib/fog/aliyun/models/storage/directory.rb +96 -17
- data/lib/fog/aliyun/models/storage/file.rb +127 -125
- data/lib/fog/aliyun/models/storage/files.rb +62 -156
- data/lib/fog/aliyun/requests/storage/abort_multipart_upload.rb +22 -0
- data/lib/fog/aliyun/requests/storage/complete_multipart_upload.rb +21 -0
- data/lib/fog/aliyun/requests/storage/copy_object.rb +14 -19
- data/lib/fog/aliyun/requests/storage/delete_bucket.rb +3 -10
- data/lib/fog/aliyun/requests/storage/delete_multiple_objects.rb +20 -0
- data/lib/fog/aliyun/requests/storage/delete_object.rb +10 -11
- data/lib/fog/aliyun/requests/storage/get_bucket.rb +26 -125
- data/lib/fog/aliyun/requests/storage/get_bucket_location.rb +33 -0
- data/lib/fog/aliyun/requests/storage/get_object.rb +29 -11
- data/lib/fog/aliyun/requests/storage/get_object_acl.rb +30 -0
- data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +8 -11
- data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +8 -11
- data/lib/fog/aliyun/requests/storage/get_service.rb +13 -0
- data/lib/fog/aliyun/requests/storage/head_object.rb +25 -14
- data/lib/fog/aliyun/requests/storage/initiate_multipart_upload.rb +19 -0
- data/lib/fog/aliyun/requests/storage/list_buckets.rb +6 -24
- data/lib/fog/aliyun/requests/storage/list_objects.rb +10 -67
- data/lib/fog/aliyun/requests/storage/put_bucket.rb +2 -8
- data/lib/fog/aliyun/requests/storage/put_object.rb +16 -142
- data/lib/fog/aliyun/requests/storage/upload_part.rb +24 -0
- data/lib/fog/aliyun/storage.rb +41 -27
- data/lib/fog/aliyun/version.rb +1 -1
- metadata +39 -6
- data/lib/fog/aliyun/requests/storage/delete_container.rb +0 -31
- data/lib/fog/aliyun/requests/storage/get_container.rb +0 -56
- data/lib/fog/aliyun/requests/storage/get_containers.rb +0 -65
- data/lib/fog/aliyun/requests/storage/put_container.rb +0 -30
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
module Fog
|
3
|
+
module Aliyun
|
4
|
+
class Storage
|
5
|
+
class Real
|
6
|
+
# Upload a part for a multipart upload
|
7
|
+
#
|
8
|
+
# @param bucket_name [String] Name of bucket to add part to
|
9
|
+
# @param object_name [String] Name of object to add part to
|
10
|
+
# @param upload_id [String] Id of upload to add part to
|
11
|
+
# @param part_number [String] Index of part in upload
|
12
|
+
# @param data [File||String] Content for part
|
13
|
+
#
|
14
|
+
# @see https://help.aliyun.com/document_detail/31993.html
|
15
|
+
#
|
16
|
+
def upload_part(bucket_name, object_name, upload_id, part_number, data)
|
17
|
+
@oss_protocol.upload_part(bucket_name, object_name, upload_id, part_number) do |sw|
|
18
|
+
sw.write(data)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/fog/aliyun/storage.rb
CHANGED
@@ -9,6 +9,7 @@ AliyunOssSdk= Aliyun::OSS
|
|
9
9
|
module Fog
|
10
10
|
module Aliyun
|
11
11
|
class Storage < Fog::Service
|
12
|
+
COMPLIANT_BUCKET_NAMES = /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
|
12
13
|
DEFAULT_REGION = 'cn-hangzhou'
|
13
14
|
|
14
15
|
DEFAULT_SCHEME = 'https'
|
@@ -19,7 +20,9 @@ module Fog
|
|
19
20
|
|
20
21
|
recognizes :aliyun_oss_endpoint,
|
21
22
|
:aliyun_oss_location,
|
22
|
-
:aliyun_region_id
|
23
|
+
:aliyun_region_id,
|
24
|
+
:aliyun_oss_sdk_log_path
|
25
|
+
|
23
26
|
requires :aliyun_accesskey_id,
|
24
27
|
:aliyun_accesskey_secret,
|
25
28
|
:aliyun_oss_bucket
|
@@ -34,19 +37,23 @@ module Fog
|
|
34
37
|
request :copy_object
|
35
38
|
request :delete_bucket
|
36
39
|
request :delete_object
|
40
|
+
request :delete_multiple_objects
|
37
41
|
request :get_bucket
|
42
|
+
request :get_bucket_location
|
38
43
|
request :get_object
|
44
|
+
request :get_object_acl
|
39
45
|
request :get_object_http_url
|
40
46
|
request :get_object_https_url
|
41
47
|
request :head_object
|
42
48
|
request :put_bucket
|
43
49
|
request :put_object
|
50
|
+
request :get_service
|
44
51
|
request :list_buckets
|
45
52
|
request :list_objects
|
46
|
-
request :
|
47
|
-
request :
|
48
|
-
request :
|
49
|
-
request :
|
53
|
+
request :initiate_multipart_upload
|
54
|
+
request :upload_part
|
55
|
+
request :complete_multipart_upload
|
56
|
+
request :abort_multipart_upload
|
50
57
|
|
51
58
|
class Real
|
52
59
|
# Initialize connection to OSS
|
@@ -72,6 +79,7 @@ module Fog
|
|
72
79
|
attr_reader :aliyun_oss_endpoint
|
73
80
|
attr_reader :aliyun_region_id
|
74
81
|
attr_reader :aliyun_oss_bucket
|
82
|
+
attr_reader :aliyun_oss_sdk_log_path
|
75
83
|
|
76
84
|
def initialize(options = {})
|
77
85
|
# initialize the parameters
|
@@ -80,7 +88,11 @@ module Fog
|
|
80
88
|
@aliyun_accesskey_id = options[:aliyun_accesskey_id]
|
81
89
|
@aliyun_accesskey_secret = options[:aliyun_accesskey_secret]
|
82
90
|
@aliyun_oss_bucket = options[:aliyun_oss_bucket]
|
83
|
-
|
91
|
+
@aliyun_oss_sdk_log_path=options[:aliyun_oss_sdk_log_path]
|
92
|
+
if @aliyun_oss_sdk_log_path && !::File.exist?(@aliyun_oss_sdk_log_path)
|
93
|
+
`touch #{@aliyun_oss_sdk_log_path}`
|
94
|
+
end
|
95
|
+
ENV["ALIYUN_OSS_SDK_LOG_PATH"] = @aliyun_oss_sdk_log_path
|
84
96
|
# check for the parameters
|
85
97
|
missing_credentials = []
|
86
98
|
missing_credentials << :aliyun_oss_bucket unless @aliyun_oss_bucket
|
@@ -106,6 +118,15 @@ module Fog
|
|
106
118
|
:access_key_id => @aliyun_accesskey_id,
|
107
119
|
:access_key_secret => @aliyun_accesskey_secret
|
108
120
|
)
|
121
|
+
|
122
|
+
# initiate a aliyun oss ruby sdk config and using sdk http to invoke the OSS openapi
|
123
|
+
@oss_config = AliyunOssSdk::Config.new(
|
124
|
+
:endpoint => @aliyun_oss_endpoint,
|
125
|
+
:access_key_id => @aliyun_accesskey_id,
|
126
|
+
:access_key_secret => @aliyun_accesskey_secret
|
127
|
+
)
|
128
|
+
@oss_http = AliyunOssSdk::HTTP.new(@oss_config)
|
129
|
+
@oss_protocol = AliyunOssSdk::Protocol.new(@oss_config)
|
109
130
|
end
|
110
131
|
|
111
132
|
def reload
|
@@ -121,36 +142,29 @@ module Fog
|
|
121
142
|
end
|
122
143
|
end
|
123
144
|
|
145
|
+
def object_to_path(object_name=nil)
|
146
|
+
'/' + escape(object_name.to_s).gsub('%2F','/')
|
147
|
+
end
|
148
|
+
|
149
|
+
def escape(string)
|
150
|
+
string.gsub(/([^a-zA-Z0-9_.\-~\/]+)/) {
|
151
|
+
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
124
155
|
def request(params)
|
125
156
|
method = params[:method]
|
126
157
|
time = Time.new.utc
|
127
158
|
date = time.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
128
159
|
|
129
|
-
endpoint = params[:endpoint]
|
130
|
-
location = params[:location]
|
131
|
-
if endpoint
|
132
|
-
uri = URI.parse(endpoint)
|
133
|
-
host = uri.host
|
134
|
-
path = uri.path
|
135
|
-
port = uri.port
|
136
|
-
scheme = uri.scheme
|
137
|
-
elsif location
|
138
|
-
host = location + '.aliyuncs.com'
|
139
|
-
end
|
140
|
-
|
141
|
-
host ||= @host
|
142
|
-
path ||= @path
|
143
|
-
port ||= @port
|
144
|
-
scheme ||= @scheme
|
145
|
-
|
146
160
|
bucket = params[:bucket]
|
147
161
|
tmpHost = if bucket
|
148
|
-
bucket + '.' + host
|
162
|
+
bucket + '.' + @host
|
149
163
|
else
|
150
|
-
host
|
164
|
+
@host
|
151
165
|
end
|
152
166
|
|
153
|
-
@connection = Fog::Core::Connection.new("#{scheme}://#{tmpHost}", @persistent, @connection_options)
|
167
|
+
@connection = Fog::Core::Connection.new("#{@scheme}://#{tmpHost}", @persistent, @connection_options)
|
154
168
|
contentType = params[:contentType]
|
155
169
|
|
156
170
|
begin
|
@@ -166,7 +180,7 @@ module Fog
|
|
166
180
|
'Authorization' => 'OSS ' + @aliyun_accesskey_id + ':' + signature,
|
167
181
|
'Date' => date
|
168
182
|
}.merge!(params[:headers] || {}),
|
169
|
-
path: "#{path}/#{params[:path]}",
|
183
|
+
path: "#{@path}/#{params[:path]}",
|
170
184
|
query: params[:query]))
|
171
185
|
rescue Excon::Errors::HTTPStatusError => error
|
172
186
|
raise case error
|
data/lib/fog/aliyun/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-aliyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Qinsi Deng, Jianxun Li, Jane Han, Guimin He
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,6 +128,34 @@ dependencies:
|
|
128
128
|
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: aliyun-sdk
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.8.0
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.8.0
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: aliyun-sdk
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 0.8.0
|
152
|
+
type: :runtime
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 0.8.0
|
131
159
|
- !ruby/object:Gem::Dependency
|
132
160
|
name: fog-core
|
133
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,6 +228,7 @@ files:
|
|
200
228
|
- ".ruby-gemset"
|
201
229
|
- ".ruby-version"
|
202
230
|
- ".travis.yml"
|
231
|
+
- CHANGELOG.md
|
203
232
|
- CODE_OF_CONDUCT.md
|
204
233
|
- Gemfile
|
205
234
|
- LICENSE.txt
|
@@ -296,22 +325,26 @@ files:
|
|
296
325
|
- lib/fog/aliyun/requests/compute/start_server.rb
|
297
326
|
- lib/fog/aliyun/requests/compute/stop_server.rb
|
298
327
|
- lib/fog/aliyun/requests/compute/unassociate_eip_address.rb
|
328
|
+
- lib/fog/aliyun/requests/storage/abort_multipart_upload.rb
|
329
|
+
- lib/fog/aliyun/requests/storage/complete_multipart_upload.rb
|
299
330
|
- lib/fog/aliyun/requests/storage/copy_object.rb
|
300
331
|
- lib/fog/aliyun/requests/storage/delete_bucket.rb
|
301
|
-
- lib/fog/aliyun/requests/storage/
|
332
|
+
- lib/fog/aliyun/requests/storage/delete_multiple_objects.rb
|
302
333
|
- lib/fog/aliyun/requests/storage/delete_object.rb
|
303
334
|
- lib/fog/aliyun/requests/storage/get_bucket.rb
|
304
|
-
- lib/fog/aliyun/requests/storage/
|
305
|
-
- lib/fog/aliyun/requests/storage/get_containers.rb
|
335
|
+
- lib/fog/aliyun/requests/storage/get_bucket_location.rb
|
306
336
|
- lib/fog/aliyun/requests/storage/get_object.rb
|
337
|
+
- lib/fog/aliyun/requests/storage/get_object_acl.rb
|
307
338
|
- lib/fog/aliyun/requests/storage/get_object_http_url.rb
|
308
339
|
- lib/fog/aliyun/requests/storage/get_object_https_url.rb
|
340
|
+
- lib/fog/aliyun/requests/storage/get_service.rb
|
309
341
|
- lib/fog/aliyun/requests/storage/head_object.rb
|
342
|
+
- lib/fog/aliyun/requests/storage/initiate_multipart_upload.rb
|
310
343
|
- lib/fog/aliyun/requests/storage/list_buckets.rb
|
311
344
|
- lib/fog/aliyun/requests/storage/list_objects.rb
|
312
345
|
- lib/fog/aliyun/requests/storage/put_bucket.rb
|
313
|
-
- lib/fog/aliyun/requests/storage/put_container.rb
|
314
346
|
- lib/fog/aliyun/requests/storage/put_object.rb
|
347
|
+
- lib/fog/aliyun/requests/storage/upload_part.rb
|
315
348
|
- lib/fog/aliyun/storage.rb
|
316
349
|
- lib/fog/aliyun/version.rb
|
317
350
|
- lib/fog/bin/aliyun.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fog
|
4
|
-
module Aliyun
|
5
|
-
class Storage
|
6
|
-
class Real
|
7
|
-
# Delete an existing container
|
8
|
-
#
|
9
|
-
# ==== Parameters
|
10
|
-
# * container<~String> - Name of container to delete
|
11
|
-
# * options
|
12
|
-
#
|
13
|
-
def delete_container(container, options = {})
|
14
|
-
bucket = options[:bucket]
|
15
|
-
bucket ||= @aliyun_oss_bucket
|
16
|
-
object = container + '/'
|
17
|
-
resource = bucket + '/' + object
|
18
|
-
|
19
|
-
request(
|
20
|
-
expects: 204,
|
21
|
-
method: 'DELETE',
|
22
|
-
path: object,
|
23
|
-
bucket: bucket,
|
24
|
-
resource: resource,
|
25
|
-
location: get_bucket_location(bucket)
|
26
|
-
)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fog
|
4
|
-
module Aliyun
|
5
|
-
class Storage
|
6
|
-
class Real
|
7
|
-
def get_container(container, options = {})
|
8
|
-
options = options.reject { |_key, value| value.nil? }
|
9
|
-
|
10
|
-
bucket = options[:bucket]
|
11
|
-
bucket ||= @aliyun_oss_bucket
|
12
|
-
|
13
|
-
marker = options[:marker]
|
14
|
-
maxKeys = options[:maxKeys]
|
15
|
-
delimiter = '/'
|
16
|
-
|
17
|
-
path = ''
|
18
|
-
|
19
|
-
prefix = if container == '' || container == '.' || container.nil?
|
20
|
-
nil
|
21
|
-
else
|
22
|
-
container + '/'
|
23
|
-
end
|
24
|
-
|
25
|
-
if prefix
|
26
|
-
path += '?prefix=' + prefix
|
27
|
-
path += '&marker=' + marker if marker
|
28
|
-
path += '&max-keys=' + maxKeys if maxKeys
|
29
|
-
path += '&delimiter=' + delimiter if delimiter
|
30
|
-
elsif marker
|
31
|
-
path += '?marker=' + marker
|
32
|
-
path += '&max-keys=' + maxKeys if maxKeys
|
33
|
-
path += '&delimiter=' + delimiter if delimiter
|
34
|
-
elsif maxKeys
|
35
|
-
path += '?max-keys=' + maxKeys
|
36
|
-
path += '&delimiter=' + delimiter if delimiter
|
37
|
-
elsif delimiter
|
38
|
-
path += '?delimiter=' + delimiter
|
39
|
-
end
|
40
|
-
|
41
|
-
location = get_bucket_location(bucket)
|
42
|
-
resource = bucket + '/'
|
43
|
-
ret = request(
|
44
|
-
expects: [200, 203, 400],
|
45
|
-
method: 'GET',
|
46
|
-
path: path,
|
47
|
-
resource: resource,
|
48
|
-
bucket: bucket
|
49
|
-
)
|
50
|
-
xml = ret.data[:body]
|
51
|
-
XmlSimple.xml_in(xml)['CommonPrefixes']
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fog
|
4
|
-
module Aliyun
|
5
|
-
class Storage
|
6
|
-
class Real
|
7
|
-
# List existing storage containers
|
8
|
-
#
|
9
|
-
# ==== Parameters
|
10
|
-
# * options<~Hash>:
|
11
|
-
# * 'maxKeys'<~Integer> - Upper limit to number of results returned
|
12
|
-
# * 'marker'<~String> - Only return objects with name greater than this value
|
13
|
-
#
|
14
|
-
# ==== Returns
|
15
|
-
#
|
16
|
-
def get_containers(options = {})
|
17
|
-
options = options.reject { |_key, value| value.nil? }
|
18
|
-
bucket = options[:bucket]
|
19
|
-
bucket ||= @aliyun_oss_bucket
|
20
|
-
prefix = options[:prefix]
|
21
|
-
marker = options[:marker]
|
22
|
-
maxKeys = options[:maxKeys]
|
23
|
-
delimiter = '/'
|
24
|
-
|
25
|
-
path = ''
|
26
|
-
if prefix
|
27
|
-
path += '?prefix=' + prefix
|
28
|
-
path += '&marker=' + marker if marker
|
29
|
-
path += '&max-keys=' + maxKeys if maxKeys
|
30
|
-
path += '&delimiter=' + delimiter if delimiter
|
31
|
-
|
32
|
-
elsif marker
|
33
|
-
path += '?marker=' + marker
|
34
|
-
path += '&max-keys=' + maxKeys if maxKeys
|
35
|
-
path += '&delimiter=' + delimiter if delimiter
|
36
|
-
|
37
|
-
elsif maxKeys
|
38
|
-
path += '?max-keys=' + maxKeys
|
39
|
-
path += '&delimiter=' + delimiter if delimiter
|
40
|
-
|
41
|
-
elsif delimiter
|
42
|
-
path += '?delimiter=' + delimiter
|
43
|
-
end
|
44
|
-
|
45
|
-
endpoint = options[:endpoint]
|
46
|
-
if endpoint.nil?
|
47
|
-
location = get_bucket_location(bucket)
|
48
|
-
end
|
49
|
-
resource = bucket + '/'
|
50
|
-
ret = request(
|
51
|
-
expects: [200, 203, 400],
|
52
|
-
method: 'GET',
|
53
|
-
path: path,
|
54
|
-
resource: resource,
|
55
|
-
endpoint: endpoint,
|
56
|
-
location: location,
|
57
|
-
bucket: bucket
|
58
|
-
)
|
59
|
-
xml = ret.data[:body]
|
60
|
-
XmlSimple.xml_in(xml)['CommonPrefixes']
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fog
|
4
|
-
module Aliyun
|
5
|
-
class Storage
|
6
|
-
class Real
|
7
|
-
# Create a new container
|
8
|
-
#
|
9
|
-
# ==== Parameters
|
10
|
-
# * name<~String> - Name for container
|
11
|
-
#
|
12
|
-
def put_container(name, options = {})
|
13
|
-
bucket = options[:bucket]
|
14
|
-
bucket ||= @aliyun_oss_bucket
|
15
|
-
|
16
|
-
path = name + '/'
|
17
|
-
resource = bucket + '/' + name + '/'
|
18
|
-
request(
|
19
|
-
expects: [200, 203],
|
20
|
-
method: 'PUT',
|
21
|
-
path: path,
|
22
|
-
bucket: bucket,
|
23
|
-
resource: resource,
|
24
|
-
location: get_bucket_location(bucket)
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|