fog-aliyun 0.3.7 → 0.3.12

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,34 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fog
4
- module Storage
5
- class Aliyun
4
+ module Aliyun
5
+ class Storage
6
6
  class Real
7
7
  def list_objects(options = {})
8
- bucket = options[:bucket]
8
+ bucket = options['bucket']
9
9
  bucket ||= @aliyun_oss_bucket
10
- prefix = options[:prefix]
11
- marker = options[:marker]
12
- maxKeys = options[:maxKeys]
13
- delimiter = options[:delimiter]
10
+ prefix = options['prefix']
11
+ marker = options['marker']
12
+ # Set the ListObjects max limitation to 1000
13
+ maxKeys = options['max-keys'] || 1000
14
+ maxKeys = [maxKeys, 1000].min
15
+ delimiter = options['delimiter']
14
16
 
15
17
  path = ''
16
18
  if prefix
17
- path += '?prefix=' + prefix
19
+ path += '/?prefix=' + prefix
18
20
  path += '&marker=' + marker if marker
19
- path += '&max-keys=' + maxKeys if maxKeys
21
+ path += '&max-keys=' + maxKeys.to_s if maxKeys
20
22
  path += '&delimiter=' + delimiter if delimiter
21
23
 
22
24
  elsif marker
23
- path += '?marker=' + marker
24
- path += '&max-keys=' + maxKeys if maxKeys
25
+ path += '/?marker=' + marker
26
+ path += '&max-keys=' + maxKeys.to_s if maxKeys
25
27
  path += '&delimiter=' + delimiter if delimiter
26
28
 
27
29
  elsif maxKeys
28
- path += '?max-keys=' + maxKeys
30
+ path += '/?max-keys=' + maxKeys.to_s
29
31
  path += '&delimiter=' + delimiter if delimiter
30
32
  elsif delimiter
31
- path += '?delimiter=' + delimiter
33
+ path += '/?delimiter=' + delimiter
32
34
  end
33
35
 
34
36
  resource = bucket + '/'
@@ -43,11 +45,9 @@ module Fog
43
45
  XmlSimple.xml_in(xml)
44
46
  end
45
47
 
46
- def list_multipart_uploads(bucket, endpoint, _options = {})
47
- if endpoint.nil?
48
- location = get_bucket_location(bucket)
49
- endpoint = 'http://' + location + '.aliyuncs.com'
50
- end
48
+ def list_multipart_uploads(bucket, location, _options = {})
49
+ location ||= get_bucket_location(bucket)
50
+
51
51
  path = '?uploads'
52
52
  resource = bucket + '/' + path
53
53
 
@@ -57,16 +57,14 @@ module Fog
57
57
  path: path,
58
58
  bucket: bucket,
59
59
  resource: resource,
60
- endpoint: endpoint
60
+ location: location
61
61
  )
62
62
  XmlSimple.xml_in(ret.data[:body])['Upload']
63
63
  end
64
64
 
65
- def list_parts(bucket, object, endpoint, uploadid, _options = {})
66
- if endpoint.nil?
67
- location = get_bucket_location(bucket)
68
- endpoint = 'http://' + location + '.aliyuncs.com'
69
- end
65
+ def list_parts(bucket, object, location, uploadid, _options = {})
66
+ location ||= get_bucket_location(bucket)
67
+
70
68
  path = object + '?uploadId=' + uploadid
71
69
  resource = bucket + '/' + path
72
70
 
@@ -76,7 +74,7 @@ module Fog
76
74
  path: path,
77
75
  bucket: bucket,
78
76
  resource: resource,
79
- endpoint: endpoint
77
+ location: location
80
78
  )
81
79
  XmlSimple.xml_in(ret.data[:body])['Part']
82
80
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fog
4
- module Storage
5
- class Aliyun
4
+ module Aliyun
5
+ class Storage
6
6
  class Real
7
7
  def put_bucket(bucketName)
8
8
  resource = bucketName + '/'
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fog
4
- module Storage
5
- class Aliyun
4
+ module Aliyun
5
+ class Storage
6
6
  class Real
7
7
  # Create a new container
8
8
  #
@@ -12,8 +12,6 @@ module Fog
12
12
  def put_container(name, options = {})
13
13
  bucket = options[:bucket]
14
14
  bucket ||= @aliyun_oss_bucket
15
- location = get_bucket_location(bucket)
16
- endpoint = 'http://' + location + '.aliyuncs.com'
17
15
 
18
16
  path = name + '/'
19
17
  resource = bucket + '/' + name + '/'
@@ -23,7 +21,7 @@ module Fog
23
21
  path: path,
24
22
  bucket: bucket,
25
23
  resource: resource,
26
- endpoint: endpoint
24
+ location: get_bucket_location(bucket)
27
25
  )
28
26
  end
29
27
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fog
4
- module Storage
5
- class Aliyun
4
+ module Aliyun
5
+ class Storage
6
6
  class Real
7
7
  # Put details for object
8
8
  #
@@ -12,9 +12,7 @@ module Fog
12
12
  def put_object(object, file = nil, options = {})
13
13
  bucket = options[:bucket]
14
14
  bucket ||= @aliyun_oss_bucket
15
- location = get_bucket_location(bucket)
16
- endpoint = 'http://' + location + '.aliyuncs.com'
17
- return put_folder(bucket, object, endpoint) if file.nil?
15
+ return put_folder(bucket, object) if file.nil?
18
16
 
19
17
  # put multiparts if object's size is over 100m
20
18
  return put_multipart_object(bucket, object, file) if file.size > 104_857_600
@@ -29,15 +27,13 @@ module Fog
29
27
  bucket: bucket,
30
28
  resource: resource,
31
29
  body: body,
32
- endpoint: endpoint
30
+ location: get_bucket_location(bucket)
33
31
  )
34
32
  end
35
33
 
36
34
  def put_object_with_body(object, body, options = {})
37
35
  bucket = options[:bucket]
38
36
  bucket ||= @aliyun_oss_bucket
39
- location = get_bucket_location(bucket)
40
- endpoint = 'http://' + location + '.aliyuncs.com'
41
37
 
42
38
  resource = bucket + '/' + object
43
39
  request(
@@ -47,15 +43,11 @@ module Fog
47
43
  bucket: bucket,
48
44
  resource: resource,
49
45
  body: body,
50
- endpoint: endpoint
46
+ location: get_bucket_location(bucket)
51
47
  )
52
48
  end
53
49
 
54
- def put_folder(bucket, folder, endpoint)
55
- if endpoint.nil?
56
- location = get_bucket_location(bucket)
57
- endpoint = 'http://' + location + '.aliyuncs.com'
58
- end
50
+ def put_folder(bucket, folder)
59
51
  path = folder + '/'
60
52
  resource = bucket + '/' + folder + '/'
61
53
  request(
@@ -64,27 +56,26 @@ module Fog
64
56
  path: path,
65
57
  bucket: bucket,
66
58
  resource: resource,
67
- endpoint: endpoint
59
+ location: get_bucket_location(bucket)
68
60
  )
69
61
  end
70
62
 
71
63
  def put_multipart_object(bucket, object, file)
72
64
  location = get_bucket_location(bucket)
73
- endpoint = 'http://' + location + '.aliyuncs.com'
74
65
 
75
66
  # find the right uploadid
76
- uploads = list_multipart_uploads(bucket, endpoint)
67
+ uploads = list_multipart_uploads(bucket, location)
77
68
  upload = (uploads&.find { |tmpupload| tmpupload['Key'][0] == object })
78
69
 
79
70
  uploadedSize = 0
80
71
  start_partNumber = 1
81
72
  if !upload.nil?
82
73
  uploadId = upload['UploadId'][0]
83
- parts = list_parts(bucket, object, endpoint, uploadId)
74
+ parts = list_parts(bucket, object, location, uploadId)
84
75
  if !parts.nil? && !parts.empty?
85
76
  if parts[-1]['Size'][0].to_i != 5_242_880
86
77
  # the part is the last one, if its size is over 5m, then finish this upload
87
- complete_multipart_upload(bucket, object, endpoint, uploadId)
78
+ complete_multipart_upload(bucket, object, location, uploadId)
88
79
  return
89
80
  end
90
81
  uploadedSize = (parts[0]['Size'][0].to_i * (parts.size - 1)) + parts[-1]['Size'][0].to_i
@@ -92,11 +83,11 @@ module Fog
92
83
  end
93
84
  else
94
85
  # create upload ID
95
- uploadId = initiate_multipart_upload(bucket, object, endpoint)
86
+ uploadId = initiate_multipart_upload(bucket, object, location)
96
87
  end
97
88
 
98
89
  if file.size <= uploadedSize
99
- complete_multipart_upload(bucket, object, endpoint, uploadId)
90
+ complete_multipart_upload(bucket, object, location, uploadId)
100
91
  return
101
92
  end
102
93
 
@@ -105,17 +96,14 @@ module Fog
105
96
 
106
97
  for i in start_partNumber..end_partNumber
107
98
  body = file.read(5_242_880)
108
- upload_part(bucket, object, endpoint, i.to_s, uploadId, body)
99
+ upload_part(bucket, object, location, i.to_s, uploadId, body)
109
100
  end
110
101
 
111
- complete_multipart_upload(bucket, object, endpoint, uploadId)
102
+ complete_multipart_upload(bucket, object, location, uploadId)
112
103
  end
113
104
 
114
- def initiate_multipart_upload(bucket, object, endpoint)
115
- if endpoint.nil?
116
- location = get_bucket_location(bucket)
117
- endpoint = 'http://' + location + '.aliyuncs.com'
118
- end
105
+ def initiate_multipart_upload(bucket, object, location)
106
+ location ||= get_bucket_location(bucket)
119
107
  path = object + '?uploads'
120
108
  resource = bucket + '/' + path
121
109
  ret = request(
@@ -124,16 +112,13 @@ module Fog
124
112
  path: path,
125
113
  bucket: bucket,
126
114
  resource: resource,
127
- endpoint: endpoint
115
+ location: location
128
116
  )
129
117
  XmlSimple.xml_in(ret.data[:body])['UploadId'][0]
130
118
  end
131
119
 
132
- def upload_part(bucket, object, endpoint, partNumber, uploadId, body)
133
- if endpoint.nil?
134
- location = get_bucket_location(bucket)
135
- endpoint = 'http://' + location + '.aliyuncs.com'
136
- end
120
+ def upload_part(bucket, object, location, partNumber, uploadId, body)
121
+ location ||= get_bucket_location(bucket)
137
122
  path = object + '?partNumber=' + partNumber + '&uploadId=' + uploadId
138
123
  resource = bucket + '/' + path
139
124
  request(
@@ -143,16 +128,13 @@ module Fog
143
128
  bucket: bucket,
144
129
  resource: resource,
145
130
  body: body,
146
- endpoint: endpoint
131
+ location: location
147
132
  )
148
133
  end
149
134
 
150
- def complete_multipart_upload(bucket, object, endpoint, uploadId)
151
- if endpoint.nil?
152
- location = get_bucket_location(bucket)
153
- endpoint = 'http://' + location + '.aliyuncs.com'
154
- end
155
- parts = list_parts(bucket, object, endpoint, uploadId, options = {})
135
+ def complete_multipart_upload(bucket, object, location, uploadId)
136
+ location ||= get_bucket_location(bucket)
137
+ parts = list_parts(bucket, object, location, uploadId, options = {})
156
138
  request_part = []
157
139
  return if parts.empty?
158
140
  for i in 0..(parts.size - 1)
@@ -169,7 +151,7 @@ module Fog
169
151
  path: path,
170
152
  bucket: bucket,
171
153
  resource: resource,
172
- endpoint: endpoint,
154
+ location: location,
173
155
  body: body
174
156
  )
175
157
  end
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'xmlsimple'
4
+ require 'aliyun/oss'
5
+
6
+ # Using Aliyun OSS Ruby SDK
7
+ AliyunOssSdk= Aliyun::OSS
4
8
 
5
9
  module Fog
6
- module Storage
7
- class Aliyun < Fog::Service
10
+ module Aliyun
11
+ class Storage < Fog::Service
8
12
  DEFAULT_REGION = 'cn-hangzhou'
9
13
 
10
- DEFAULT_SCHEME = 'http'
14
+ DEFAULT_SCHEME = 'https'
11
15
  DEFAULT_SCHEME_PORT = {
12
16
  'http' => 80,
13
17
  'https' => 443
@@ -97,6 +101,11 @@ module Fog
97
101
  @port = uri.port || DEFAULT_SCHEME_PORT[@scheme]
98
102
 
99
103
  @persistent = options[:persistent] || false
104
+ @oss_client = AliyunOssSdk::Client.new(
105
+ :endpoint => @aliyun_oss_endpoint,
106
+ :access_key_id => @aliyun_accesskey_id,
107
+ :access_key_secret => @aliyun_accesskey_secret
108
+ )
100
109
  end
101
110
 
102
111
  def reload
@@ -118,19 +127,22 @@ module Fog
118
127
  date = time.strftime('%a, %d %b %Y %H:%M:%S GMT')
119
128
 
120
129
  endpoint = params[:endpoint]
130
+ location = params[:location]
121
131
  if endpoint
122
132
  uri = URI.parse(endpoint)
123
133
  host = uri.host
124
134
  path = uri.path
125
135
  port = uri.port
126
136
  scheme = uri.scheme
127
- else
128
- host = @host
129
- path = @path
130
- port = @port
131
- scheme = @scheme
137
+ elsif location
138
+ host = location + '.aliyuncs.com'
132
139
  end
133
140
 
141
+ host ||= @host
142
+ path ||= @path
143
+ port ||= @port
144
+ scheme ||= @scheme
145
+
134
146
  bucket = params[:bucket]
135
147
  tmpHost = if bucket
136
148
  bucket + '.' + host
@@ -143,8 +155,10 @@ module Fog
143
155
 
144
156
  begin
145
157
  headers = ''
146
- params[:headers]&.each do |k, v|
158
+ if params[:headers]
159
+ params[:headers].each do |k, v|
147
160
  headers += "#{k}:#{v}\n" if k != 'Range'
161
+ end
148
162
  end
149
163
  signature = sign(method, date, contentType, params[:resource], headers)
150
164
  response = @connection.request(params.merge(headers: {
@@ -157,7 +171,7 @@ module Fog
157
171
  rescue Excon::Errors::HTTPStatusError => error
158
172
  raise case error
159
173
  when Excon::Errors::NotFound
160
- Fog::Storage::Aliyun::NotFound.slurp(error)
174
+ Fog::Aliyun::Storage::NotFound.slurp(error)
161
175
  else
162
176
  error
163
177
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fog
4
4
  module Aliyun
5
- VERSION = '0.3.7'
5
+ VERSION = '0.3.12'
6
6
  end
7
7
  end
@@ -5,7 +5,7 @@ class Aliyun < Fog::Bin
5
5
  def class_for(key)
6
6
  case key
7
7
  when :storage
8
- Fog::Storage::Aliyun
8
+ Fog::Aliyun::Storage
9
9
  when :compute
10
10
  Fog::Compute::Aliyun
11
11
  else
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.7
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
- - Qinsi Deng, Jianxun Li, Jane Han
7
+ - Qinsi Deng, Jianxun Li, Jane Han, Guimin He
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-12 00:00:00.000000000 Z
11
+ date: 2020-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,48 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: simplecov
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: memory_profiler
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
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'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
103
145
  - !ruby/object:Gem::Dependency
104
146
  name: fog-core
105
147
  requirement: !ruby/object:Gem::Requirement
@@ -156,10 +198,25 @@ dependencies:
156
198
  - - "~>"
157
199
  - !ruby/object:Gem::Version
158
200
  version: '1.1'
201
+ - !ruby/object:Gem::Dependency
202
+ name: aliyun-sdk
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ type: :runtime
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
159
215
  description: As a FOG provider, fog-aliyun support aliyun OSS/ECS. It will support
160
216
  more aliyun services later.
161
217
  email:
162
218
  - dengqinsi@sina.com
219
+ - guimin.hgm@alibaba-inc.com
163
220
  executables: []
164
221
  extensions: []
165
222
  extra_rdoc_files: []
@@ -308,5 +365,5 @@ requirements: []
308
365
  rubygems_version: 3.0.6
309
366
  signing_key:
310
367
  specification_version: 4
311
- summary: Fog provider for Aliyun Web Services.
368
+ summary: Fog provider for Alibaba Cloud Web Services.
312
369
  test_files: []