fog-aliyun 0.3.12 → 0.3.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c47b8a9b6a56d553d1b0161be29b2d2444671f41f083e8af34707bd1eadc1718
4
- data.tar.gz: 17e83f9d11b7ae7b1802941ddb13427346bbd971b563d7ac04436f7d036d7ef7
3
+ metadata.gz: cff686947955adaead48c9bb70ec405a2ca807240ba53d7e86fe1da27b63ab4f
4
+ data.tar.gz: bec5610976802d1cefccbe9f8788943747cfe31059cf0d6b04d0ae589caace46
5
5
  SHA512:
6
- metadata.gz: 52060f2e1a3881ccb72ccc6e5fbeddd988bd2820416c419a7409e714c6d4f08fb7b37f5f98ff1e8fc66b47c0f2aa5656349da06e939edfb0c78c4adba05bf1ef
7
- data.tar.gz: 30bdcf81e3e78e2983545d391ef2062ebc49975bee90c9d93226f30a631b3eaa7627916b179d15c684b38211bbd2e9e78e84210a2471b8185c5c3d21fbfe3001
6
+ metadata.gz: 7bb3975226a2af2d130be85b64f057d61cab8564bd6ef9fc349080efa0008d79dff5149a3124142436bcf30ef893314e27d195b8706c9bc6c634d88c5452a33b
7
+ data.tar.gz: e21803702da802d2a3051c63428af92b0fb66c9f8a95f62c2c9c76a31ea80fa6ae0ee74081c9ee72d5c0570dae0f60c2764f8094d9692c39f8d93e1ade320ea0
@@ -0,0 +1,103 @@
1
+ ## 0.3.19 (Unreleased)
2
+ ## 0.3.18 (August 03, 2020)
3
+
4
+ IMPROVEMENTS:
5
+
6
+ - reconstruct perform test [GH-148](https://github.com/fog/fog-aliyun/pull/148)
7
+ - Reconstruct fog-aliyun by using oss [GH-147](https://github.com/fog/fog-aliyun/pull/147)
8
+ - reconstruct cover case test [GH-146](https://github.com/fog/fog-aliyun/pull/146)
9
+ - reconstruct case test [GH-144](https://github.com/fog/fog-aliyun/pull/144)
10
+ - reconstruct parts two of file [GH-143](https://github.com/fog/fog-aliyun/pull/143)
11
+ - implement blobstore for cloud_controller_ng [GH-142](https://github.com/fog/fog-aliyun/pull/142)
12
+ - reconstruct parts of file [GH-141](https://github.com/fog/fog-aliyun/pull/141)
13
+ - reconstruct the files [GH-140](https://github.com/fog/fog-aliyun/pull/140)
14
+ - reconstruct the directory [GH-139](https://github.com/fog/fog-aliyun/pull/139)
15
+ - reconstruct the directories [GH-138](https://github.com/fog/fog-aliyun/pull/138)
16
+ - improve files.get code [GH-137](https://github.com/fog/fog-aliyun/pull/137)
17
+ - add testcase for testing head notexistfile [GH-136](https://github.com/fog/fog-aliyun/pull/136)
18
+ - improve head_object using oss sdk [GH-135](https://github.com/fog/fog-aliyun/pull/135)
19
+
20
+ BUG FIXES:
21
+
22
+ - fix files all options problem [GH-149](https://github.com/fog/fog-aliyun/pull/149)
23
+
24
+ ## 0.3.17 (July 06, 2020)
25
+
26
+ IMPROVEMENTS:
27
+ - adater oss_sdk_log_path [GH-125](https://github.com/fog/fog-aliyun/pull/125)
28
+ - update ruby sdk to 0.7.3 [GH-124](https://github.com/fog/fog-aliyun/pull/124)
29
+ - adapter maxkeys conversion problem [GH-123](https://github.com/fog/fog-aliyun/pull/123)
30
+ - [Enhance tests][Auth & Connectivity scenarios] Test that API cannot be accessed using incorrect credentials [GH-117](https://github.com/fog/fog-aliyun/pull/117)
31
+ - [Enhance tests][Auth & Connectivity scenarios] Test that API can be accessed using valid credentials [GH-116](https://github.com/fog/fog-aliyun/pull/116)
32
+ - adapter custom log environment variable [GH-114](https://github.com/fog/fog-aliyun/pull/114)
33
+ - [Enhance tests][Buckets scenarios] (NEGATIVE TEST) Test that error is thrown when trying to access non-existing bucket [GH-110](https://github.com/fog/fog-aliyun/pull/110)
34
+ - [Enhance tests][Buckets scenarios] (NEGATIVE TEST) Test that error is thrown when trying to create already existing bucket [GH-109](https://github.com/fog/fog-aliyun/pull/109)
35
+ - [Enhance tests][Buckets scenarios] Test that it is possible to destroy a bucket [GH-108](https://github.com/fog/fog-aliyun/pull/108)
36
+ - [Enhance tests][Buckets scenarios] Test that it is possible to create a new bucket [GH-107](https://github.com/fog/fog-aliyun/pull/107)
37
+ - [Enhance tests][Buckets scenarios] Test that it is possible to list all buckets [GH-105](https://github.com/fog/fog-aliyun/pull/105)
38
+ - [Enhance tests][Files & Directory scenarios] Test getting bucket when directory exists named with the same name as a bucket [GH-101](https://github.com/fog/fog-aliyun/pull/101)
39
+ - [Enhance tests][Files & Directory scenarios] Test file copy operations [GH-100](https://github.com/fog/fog-aliyun/pull/100)
40
+ - reset the last PR [GH-133](https://github.com/fog/fog-aliyun/pull/133)
41
+ - improve put_object_with_body and head_object using sdk do_request [GH-131](https://github.com/fog/fog-aliyun/pull/131)
42
+
43
+ BUG FIXES:
44
+ - fix max key again [GH-128](https://github.com/fog/fog-aliyun/pull/128)
45
+ - fix downloading object when pushing app twice [GH-127](https://github.com/fog/fog-aliyun/pull/127)
46
+ - fix max key [GH-126](https://github.com/fog/fog-aliyun/pull/126)
47
+ - fix max-keys conversion problem [GH-121](https://github.com/fog/fog-aliyun/pull/121)
48
+ - fix @aliyun_oss_sdk_log_path is nil [GH-132](https://github.com/fog/fog-aliyun/pull/132)
49
+
50
+ ## 0.3.16 (June 18, 2020)
51
+
52
+ IMPROVEMENTS:
53
+ - [Enhance tests][Files & Directory scenarios] Test get nested directories and files in nested directory [GH-98](https://github.com/fog/fog-aliyun/pull/98)
54
+ - remove get_bucket_location and use ruby sdk to improve performance when uploading object [GH-97](https://github.com/fog/fog-aliyun/pull/97)
55
+ - using bucket_exist to checking bucket [GH-95](https://github.com/fog/fog-aliyun/pull/95)
56
+ - add change log [GH-94](https://github.com/fog/fog-aliyun/pull/94)
57
+
58
+ BUG FIXES:
59
+ - fix delete all of files bug when specifying a prefix [GH-102](https://github.com/fog/fog-aliyun/pull/102)
60
+
61
+ ## 0.3.15 (June 05, 2020)
62
+
63
+ BUG FIXES:
64
+ - change dependence ruby sdk to gems [GH-92](https://github.com/fog/fog-aliyun/pull/92)
65
+
66
+ ## 0.3.13 (June 02, 2020)
67
+
68
+ IMPROVEMENTS:
69
+ - using ruby sdk to delete object [GH-90](https://github.com/fog/fog-aliyun/pull/90)
70
+
71
+ ## 0.3.12 (May 28, 2020 )
72
+
73
+ BUG FIXES:
74
+ - add missing dependence [GH-88](https://github.com/fog/fog-aliyun/pull/88)
75
+
76
+ ## 0.3.11 (May 25, 2020)
77
+
78
+ IMPROVEMENTS:
79
+ - using oss ruby sdk to improve downloading object performance [GH-86](https://github.com/fog/fog-aliyun/pull/86)
80
+ - Add performance tests [GH-85](https://github.com/fog/fog-aliyun/pull/85)
81
+ - [Enhance tests][Entity operations]Add tests for each type of entity that validates the CURD operations [GH-84](https://github.com/fog/fog-aliyun/pull/84)
82
+ - [Enhance tests][Auth & Connectivity scenarios] Test region is selected according to provider configuration [GH-83](https://github.com/fog/fog-aliyun/pull/83)
83
+ - [Enhance tests][Files & Directory scenarios] test file listing using parameters such as prefix, marker, delimeter and maxKeys [GH-82](https://github.com/fog/fog-aliyun/pull/82)
84
+ - [Enhance tests][Files & Directory scenarios]test directory listing using parameters such as prefix, marker, delimeter and maxKeys [GH-81](https://github.com/fog/fog-aliyun/pull/81)
85
+ - [Enhance tests][Files & Directory scenarios]Test that it is possible to upload (write) large file (multi part upload) [GH-79](https://github.com/fog/fog-aliyun/pull/79)
86
+ - upgrade deprecated code [GH-78](https://github.com/fog/fog-aliyun/pull/78)
87
+ - improve fog/integration_spec [GH-77](https://github.com/fog/fog-aliyun/pull/77)
88
+ - [Enhance tests][Files & Directory scenarios]Test that it is possible to upload (write) a file [GH-76](https://github.com/fog/fog-aliyun/pull/76)
89
+ - upgrade deprecated code [GH-74](https://github.com/fog/fog-aliyun/pull/74)
90
+ - support https scheme [GH-71](https://github.com/fog/fog-aliyun/pull/71)
91
+ - [Enhance tests][Files & Directory scenarios]Test that it is possible to destroy a file/directory [GH-69](https://github.com/fog/fog-aliyun/pull/69)
92
+ - improve fog/integration_spec [GH-68](https://github.com/fog/fog-aliyun/pull/68)
93
+ - Implement basic integration tests [GH-66](https://github.com/fog/fog-aliyun/pull/66)
94
+
95
+ ## 0.3.10 (May 07, 2020)
96
+
97
+ IMPROVEMENTS:
98
+ - Set max limitation to 1000 when get objects [GH-64](https://github.com/fog/fog-aliyun/pull/64)
99
+
100
+ ## 0.3.9 (May 07, 2020)
101
+
102
+ BUG FIXES:
103
+ - diectories.get supports options to filter the specified objects [GH-62](https://github.com/fog/fog-aliyun/pull/62)
@@ -28,11 +28,11 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'rubocop'
29
29
  spec.add_development_dependency 'simplecov'
30
30
  spec.add_development_dependency 'memory_profiler'
31
- spec.add_development_dependency 'aliyun-sdk'
31
+ spec.add_development_dependency 'aliyun-sdk', '~> 0.7.3'
32
32
 
33
+ spec.add_dependency 'aliyun-sdk', '~> 0.7.3'
33
34
  spec.add_dependency 'fog-core'
34
35
  spec.add_dependency 'fog-json'
35
36
  spec.add_dependency 'ipaddress', '~> 0.8'
36
37
  spec.add_dependency 'xml-simple', '~> 1.1'
37
- spec.add_dependency 'aliyun-sdk'
38
38
  end
@@ -120,7 +120,8 @@ module Fog
120
120
  directory_key + '/' + key
121
121
  end
122
122
  if body.is_a?(::File)
123
- data = service.put_object(object, body, options.merge(bucket: bucket_name)).data
123
+ service.put_object(object, body, options.merge(bucket: bucket_name))
124
+ data = service.head_object(object, bucket: bucket_name)
124
125
  elsif body.is_a?(String)
125
126
  data = service.put_object_with_body(object, body, options.merge(bucket: bucket_name)).data
126
127
  else
@@ -36,14 +36,11 @@ module Fog
36
36
  # The bucket name can not contain '/', so if directory_key, return directory.
37
37
  if directory_key.include? '/'
38
38
  directory_key
39
+ elsif service.bucket_exists?(directory_key)
40
+ bucket_name = directory_key
41
+ directory_key = ''
39
42
  else
40
- data = service.get_bucket(directory_key)
41
- if data.class == Hash && data.key?('Code') && !data['Code'].nil? && !data['Code'].empty?
42
- directory_key
43
- else
44
- bucket_name = directory_key
45
- directory_key = ''
46
- end
43
+ directory_key
47
44
  end
48
45
  end
49
46
  return bucket_name, directory_key
@@ -51,37 +48,24 @@ module Fog
51
48
 
52
49
  def all(options = {})
53
50
  requires :directory
54
- bucket_name, directory_key = check_directory_key(directory.key)
55
- remap_attributes(options, {
56
- :delimiter => 'delimiter',
57
- :marker => 'marker',
58
- :max_keys => 'max-keys',
59
- :prefix => 'prefix'
60
- })
61
- prefix_value = options['prefix']
62
- prefix_value = directory_key + '/' + prefix if directory_key != '' && directory_key != '.' && !directory_key.nil?
63
- options['prefix'] = prefix_value
64
- options['bucket'] = bucket_name
65
- files = service.list_objects(options)['Contents']
66
- return if files.nil?
67
- data = []
68
- i = 0
69
- files.each do |file|
70
- next unless file['Key'][0][-1] != '/'
71
- content_length = file['Size'][0].to_i
72
- key = file['Key'][0]
73
- lastModified = file['LastModified'][0]
74
- last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '')
75
- type = file['Type'][0]
76
- data[i] = { content_length: content_length,
77
- key: key,
78
- last_modified: last_modified,
79
- etag: file['ETag'][0],
80
- object_type: type }
81
- i += 1
51
+ options = {
52
+ 'delimiter' => delimiter,
53
+ 'marker' => marker,
54
+ 'max-keys' => max_keys.to_i,
55
+ 'prefix' => prefix
56
+ }.merge!(options)
57
+ options = options.reject {|key,value| value.nil? || value.to_s.empty?}
58
+ merge_attributes(options)
59
+ parent = directory.collection.get(
60
+ directory.key,
61
+ options
62
+ )
63
+ if parent
64
+ merge_attributes(parent.files.attributes)
65
+ load(parent.files.map {|file| file.attributes})
66
+ else
67
+ nil
82
68
  end
83
-
84
- load(data)
85
69
  end
86
70
 
87
71
  alias each_file_this_page each
@@ -101,7 +85,7 @@ module Fog
101
85
  end
102
86
  end
103
87
 
104
- def get(key)
88
+ def get(key, options = {}, &block)
105
89
  requires :directory
106
90
  bucket_name, directory_key = check_directory_key(directory.key)
107
91
  object = if directory_key == ''
@@ -110,24 +94,25 @@ module Fog
110
94
  directory_key + '/' + key
111
95
  end
112
96
  begin
113
- data = service.get_object(object, nil, bucket: bucket_name)
114
- lastModified = data['headers'][:last_modified]
97
+ data = service.get_object(object, options.merge({bucket: bucket_name}), &block)
98
+ headers = data.headers
99
+ lastModified = headers[:last_modified]
115
100
  last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '')
116
101
 
117
- date = data['headers'][:date]
102
+ date = headers[:date]
118
103
  date = (Time.parse(date).localtime if !date.nil? && date != '')
119
104
  file_data = {
120
- body: data[:body],
121
- content_length: data['headers'][:content_length].to_i,
105
+ body: data.body,
106
+ content_length: headers[:content_length].to_i,
122
107
  key: key,
123
108
  last_modified: last_modified,
124
- content_type: data['headers'][:content_type],
125
- etag: data['headers'][:etag],
109
+ content_type: headers[:content_type],
110
+ etag: headers[:etag],
126
111
  date: date,
127
- connection: data['headers'][:connection],
128
- accept_ranges: data['headers'][:accept_ranges],
129
- server: data['headers'][:server],
130
- object_type: data['headers'][:x_oss_object_type]
112
+ connection: headers[:connection],
113
+ accept_ranges: headers[:accept_ranges],
114
+ server: headers[:server],
115
+ object_type: headers[:x_oss_object_type]
131
116
  }
132
117
 
133
118
  new(file_data)
@@ -25,8 +25,7 @@ module Fog
25
25
  method: 'PUT',
26
26
  path: target_object,
27
27
  bucket: target_bucket,
28
- resource: resource,
29
- location: get_bucket_location(bucket))
28
+ resource: resource)
30
29
  end
31
30
  end
32
31
  end
@@ -15,8 +15,7 @@ module Fog
15
15
  expects: 204,
16
16
  method: 'DELETE',
17
17
  bucket: bucket,
18
- resource: resource,
19
- location: get_bucket_location(bucket)
18
+ resource: resource
20
19
  )
21
20
  end
22
21
  end
@@ -21,8 +21,7 @@ module Fog
21
21
  method: 'DELETE',
22
22
  path: object,
23
23
  bucket: bucket,
24
- resource: resource,
25
- location: get_bucket_location(bucket)
24
+ resource: resource
26
25
  )
27
26
  end
28
27
  end
@@ -10,32 +10,15 @@ module Fog
10
10
  # * object<~String> - Name of object to delete
11
11
  #
12
12
  def delete_object(object, options = {})
13
- bucket = options[:bucket]
14
- bucket ||= @aliyun_oss_bucket
15
- resource = bucket + '/' + object
16
- request(
17
- expects: 204,
18
- method: 'DELETE',
19
- path: object,
20
- bucket: bucket,
21
- resource: resource,
22
- location: get_bucket_location(bucket)
23
- )
13
+ bucket_name = options[:bucket]
14
+ bucket_name ||= @aliyun_oss_bucket
15
+ bucket = @oss_client.get_bucket(bucket_name)
16
+ bucket.delete_object(object)
24
17
  end
25
18
 
26
- def abort_multipart_upload(bucket, object, endpoint, uploadid)
27
- path = object + '?uploadId=' + uploadid
28
- resource = bucket + '/' + path
29
-
30
- ret = request(
31
- expects: 204,
32
- method: 'DELETE',
33
- path: path,
34
- bucket: bucket,
35
- resource: resource,
36
- endpoint: endpoint,
37
- location: get_bucket_location(bucket)
38
- )
19
+ def abort_multipart_upload(bucket_name, object, upload_id)
20
+ bucket = @oss_client.get_bucket(bucket_name)
21
+ bucket.abort_upload(upload_id, object)
39
22
  end
40
23
  end
41
24
  end
@@ -4,27 +4,32 @@ module Fog
4
4
  module Aliyun
5
5
  class Storage
6
6
  class Real
7
+ def bucket_exists?(bucket_name)
8
+ @oss_client.bucket_exists?(bucket_name)
9
+ end
10
+
7
11
  def get_bucket(bucket, options = {})
8
12
  prefix = options['prefix']
9
13
  marker = options['marker']
10
14
  # Set the GetBucket max limitation to 1000
11
15
  maxKeys = options['max-keys'] || 1000
12
- maxKeys = [maxKeys, 1000].min
16
+ maxKeys = maxKeys.to_i
17
+ maxKeys = [maxKeys, 1000].min.to_s
13
18
  delimiter = options['delimiter']
14
19
  path = ''
15
20
  if prefix
16
21
  path += '/?prefix=' + prefix
17
22
  path += '&marker=' + marker if marker
18
- path += '&max-keys=' + maxKeys.to_s if maxKeys
23
+ path += '&max-keys=' + maxKeys if maxKeys
19
24
  path += '&delimiter=' + delimiter if delimiter
20
25
 
21
26
  elsif marker
22
27
  path += '/?marker=' + marker
23
- path += '&max-keys=' + maxKeys.to_s if maxKeys
28
+ path += '&max-keys=' + maxKeys if maxKeys
24
29
  path += '&delimiter=' + delimiter if delimiter
25
30
 
26
31
  elsif maxKeys
27
- path += '/?max-keys=' + maxKeys.to_s
32
+ path += '/?max-keys=' + maxKeys
28
33
  path += '&delimiter=' + delimiter if delimiter
29
34
  elsif delimiter
30
35
  path += '/?delimiter=' + delimiter
@@ -36,33 +41,12 @@ module Fog
36
41
  method: 'GET',
37
42
  bucket: bucket,
38
43
  resource: resource,
39
- location: get_bucket_location(bucket),
40
44
  path: path
41
45
  )
42
46
  xml = ret.data[:body]
43
47
  XmlSimple.xml_in(xml)
44
48
  end
45
49
 
46
- def get_bucket_location(bucket)
47
- attribute = '?location'
48
- resource = bucket + '/' + attribute
49
- ret = request(
50
- expects: [200, 203, 403, 404],
51
- method: 'GET',
52
- path: attribute,
53
- bucket: bucket,
54
- resource: resource
55
- )
56
- # If there is an error, it will return a Hash with error code, host id and others
57
- # If can not get a valid location, will return one using region
58
- location = XmlSimple.xml_in(ret.data[:body])
59
- if location.class == Hash && location.key?('HostId')
60
- value = location['HostId']
61
- location = value[0].split('.')[1]
62
- end
63
- location ||= 'oss-' + @aliyun_region_id
64
- end
65
-
66
50
  def get_bucket_acl(bucket)
67
51
  attribute = '?acl'
68
52
  resource = bucket + '/' + attribute
@@ -71,8 +55,7 @@ module Fog
71
55
  method: 'GET',
72
56
  path: attribute,
73
57
  bucket: bucket,
74
- resource: resource,
75
- location: get_bucket_location(bucket)
58
+ resource: resource
76
59
  )
77
60
  XmlSimple.xml_in(ret.data[:body])['AccessControlList'][0]['Grant'][0]
78
61
  end
@@ -85,8 +68,7 @@ module Fog
85
68
  method: 'GET',
86
69
  path: attribute,
87
70
  bucket: bucket,
88
- resource: resource,
89
- location: get_bucket_location(bucket)
71
+ resource: resource
90
72
  )
91
73
  XmlSimple.xml_in(ret.data[:body])['CORSRule'][0] if ret.data[:status] != 404
92
74
  end
@@ -99,8 +81,7 @@ module Fog
99
81
  method: 'GET',
100
82
  path: attribute,
101
83
  bucket: bucket,
102
- resource: resource,
103
- location: get_bucket_location(bucket)
84
+ resource: resource
104
85
  )
105
86
  XmlSimple.xml_in(ret.data[:body])['Rule'][0] if ret.data[:status] != 404
106
87
  end
@@ -113,8 +94,7 @@ module Fog
113
94
  method: 'GET',
114
95
  path: attribute,
115
96
  bucket: bucket,
116
- resource: resource,
117
- location: get_bucket_location(bucket)
97
+ resource: resource
118
98
  )
119
99
  XmlSimple.xml_in(ret.data[:body])['LoggingEnabled'][0]['TargetPrefix']
120
100
  end
@@ -127,8 +107,7 @@ module Fog
127
107
  method: 'GET',
128
108
  path: attribute,
129
109
  bucket: bucket,
130
- resource: resource,
131
- location: get_bucket_location(bucket)
110
+ resource: resource
132
111
  )
133
112
  XmlSimple.xml_in(ret.data[:body])
134
113
  end
@@ -141,8 +120,7 @@ module Fog
141
120
  method: 'GET',
142
121
  path: attribute,
143
122
  bucket: bucket,
144
- resource: resource,
145
- location: get_bucket_location(bucket)
123
+ resource: resource
146
124
  )
147
125
  XmlSimple.xml_in(ret.data[:body]) if ret.data[:status] != 404
148
126
  end
@@ -11,7 +11,9 @@ module Fog
11
11
  bucket ||= @aliyun_oss_bucket
12
12
 
13
13
  marker = options[:marker]
14
- maxKeys = options[:maxKeys]
14
+ maxKeys = options[:maxKeys]||1000
15
+ maxKeys = maxKeys.to_i
16
+ maxKeys = [maxKeys,1000].min.to_s
15
17
  delimiter = '/'
16
18
 
17
19
  path = ''
@@ -38,7 +40,6 @@ module Fog
38
40
  path += '?delimiter=' + delimiter
39
41
  end
40
42
 
41
- location = get_bucket_location(bucket)
42
43
  resource = bucket + '/'
43
44
  ret = request(
44
45
  expects: [200, 203, 400],
@@ -19,7 +19,9 @@ module Fog
19
19
  bucket ||= @aliyun_oss_bucket
20
20
  prefix = options[:prefix]
21
21
  marker = options[:marker]
22
- maxKeys = options[:maxKeys]
22
+ maxKeys = options[:maxKeys]||1000
23
+ maxKeys = maxKeys.to_i
24
+ maxKeys = [maxKeys,1000].min.to_s
23
25
  delimiter = '/'
24
26
 
25
27
  path = ''
@@ -42,18 +44,12 @@ module Fog
42
44
  path += '?delimiter=' + delimiter
43
45
  end
44
46
 
45
- endpoint = options[:endpoint]
46
- if endpoint.nil?
47
- location = get_bucket_location(bucket)
48
- end
49
47
  resource = bucket + '/'
50
48
  ret = request(
51
49
  expects: [200, 203, 400],
52
50
  method: 'GET',
53
51
  path: path,
54
52
  resource: resource,
55
- endpoint: endpoint,
56
- location: location,
57
53
  bucket: bucket
58
54
  )
59
55
  xml = ret.data[:body]
@@ -9,19 +9,29 @@ module Fog
9
9
  # ==== Parameters
10
10
  # * object<~String> - Name of object to look for
11
11
  #
12
- def get_object(object, range = nil, options = {})
12
+ def get_object(object, options = {}, &block)
13
13
  options = options.reject { |_key, value| value.nil? }
14
14
  bucket_name = options[:bucket]
15
15
  bucket_name ||= @aliyun_oss_bucket
16
+ options.delete(:bucket)
16
17
  # Using OSS ruby SDK to fix performance issue
17
- bucket = @oss_client.get_bucket(bucket_name)
18
- body = Array.new
19
- obj = bucket.get_object(object) do |chunk|
20
- body << chunk
18
+ params = { :headers => {} }
19
+ params[:query] = options.delete('query') || {}
20
+
21
+ params[:headers].merge!(options)
22
+ if options['If-Modified-Since']
23
+ params[:headers]['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header
24
+ end
25
+ if options['If-Unmodified-Since']
26
+ params[:headers]['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header
27
+ end
28
+
29
+ if block_given?
30
+ params[:response_block] = Proc.new
21
31
  end
22
- response = {}
23
- obj.instance_variables.each {|var| response[var.to_s.delete("@")] = obj.instance_variable_get(var) }
24
- response.merge({:body => body.join('')})
32
+
33
+ @oss_http.get({:bucket => bucket_name, :object => object}, params, &block)
34
+
25
35
  end
26
36
  end
27
37
  end
@@ -16,20 +16,20 @@ module Fog
16
16
  # * body<~String> - url for object
17
17
  def get_object_http_url_public(object, expires, options = {})
18
18
  options = options.reject { |_key, value| value.nil? }
19
- bucket = options[:bucket]
20
- bucket ||= @aliyun_oss_bucket
21
- acl = get_bucket_acl(bucket)
22
- location = get_bucket_location(bucket)
19
+ bucket_name = options[:bucket]
20
+ bucket_name ||= @aliyun_oss_bucket
21
+ bucket = @oss_client.get_bucket(bucket_name)
22
+ acl = bucket.acl()
23
23
 
24
24
  if acl == 'private'
25
25
  expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s
26
- resource = bucket + '/' + object
26
+ resource = bucket_name + '/' + object
27
27
  signature = sign('GET', expires_time, nil, resource)
28
- 'http://' + bucket + '.' + location + '.aliyuncs.com/' + object +
28
+ 'http://' + bucket_name + '.' + @host + '/' + object +
29
29
  '?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
30
30
  '&Signature=' + URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
31
31
  elsif acl == 'public-read' || acl == 'public-read-write'
32
- 'http://' + bucket + '.' + location + '.aliyuncs.com/' + object
32
+ 'http://' + bucket_name + '.' + @host + '/' + object
33
33
  else
34
34
  'acl is wrong with value:' + acl
35
35
  end
@@ -16,20 +16,20 @@ module Fog
16
16
  # * body<~String> - url for object
17
17
  def get_object_https_url_public(object, expires, options = {})
18
18
  options = options.reject { |_key, value| value.nil? }
19
- bucket = options[:bucket]
20
- bucket ||= @aliyun_oss_bucket
21
- acl = get_bucket_acl(bucket)
22
- location = get_bucket_location(bucket)
19
+ bucket_name = options[:bucket]
20
+ bucket_name ||= @aliyun_oss_bucket
21
+ bucket = @oss_client.get_bucket(bucket_name)
22
+ acl = bucket.acl()
23
23
 
24
24
  if acl == 'private'
25
25
  expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s
26
- resource = bucket + '/' + object
26
+ resource = bucket_name + '/' + object
27
27
  signature = sign('GET', expires_time, nil, resource)
28
- 'https://' + bucket + '.' + location + '.aliyuncs.com/' + object +
28
+ 'https://' + bucket_name + '.' + @host + '/' + object +
29
29
  '?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
30
30
  '&Signature=' + URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
31
31
  elsif acl == 'public-read' || acl == 'public-read-write'
32
- 'https://' + bucket + '.' + location + '.aliyuncs.com/' + object
32
+ 'https://' + bucket_name + '.' + @host + '/' + object
33
33
  else
34
34
  'acl is wrong with value:' + acl
35
35
  end
@@ -10,16 +10,15 @@ module Fog
10
10
  # * object<~String> - Name of object to look for
11
11
  #
12
12
  def head_object(object, options = {})
13
- bucket = options[:bucket]
14
- bucket ||= @aliyun_oss_bucket
15
- resource = bucket + '/' + object
13
+ bucket_name = options[:bucket]
14
+ bucket_name ||= @aliyun_oss_bucket
15
+ resource = bucket_name + '/' + object
16
16
  ret = request(
17
17
  expects: [200, 404],
18
18
  method: 'HEAD',
19
19
  path: object,
20
- bucket: bucket,
21
- resource: resource,
22
- location: get_bucket_location(bucket)
20
+ bucket: bucket_name,
21
+ resource: resource
23
22
  )
24
23
  ret
25
24
  end
@@ -7,7 +7,9 @@ module Fog
7
7
  def list_buckets(options = {})
8
8
  prefix = options[:prefix]
9
9
  marker = options[:marker]
10
- maxKeys = options[:maxKeys]
10
+ maxKeys = options[:maxKeys] || 1000
11
+ maxKeys = maxKeys.to_i
12
+ maxKeys =[maxKeys,1000].min.to_s
11
13
 
12
14
  path = ''
13
15
  if prefix
@@ -10,24 +10,25 @@ module Fog
10
10
  prefix = options['prefix']
11
11
  marker = options['marker']
12
12
  # Set the ListObjects max limitation to 1000
13
- maxKeys = options['max-keys'] || 1000
14
- maxKeys = [maxKeys, 1000].min
13
+ maxKeys = options[:maxKeys]||1000
14
+ maxKeys = maxKeys.to_i
15
+ maxKeys = [maxKeys,1000].min.to_s
15
16
  delimiter = options['delimiter']
16
17
 
17
18
  path = ''
18
19
  if prefix
19
20
  path += '/?prefix=' + prefix
20
21
  path += '&marker=' + marker if marker
21
- path += '&max-keys=' + maxKeys.to_s if maxKeys
22
+ path += '&max-keys=' + maxKeys if maxKeys
22
23
  path += '&delimiter=' + delimiter if delimiter
23
24
 
24
25
  elsif marker
25
26
  path += '/?marker=' + marker
26
- path += '&max-keys=' + maxKeys.to_s if maxKeys
27
+ path += '&max-keys=' + maxKeys if maxKeys
27
28
  path += '&delimiter=' + delimiter if delimiter
28
29
 
29
30
  elsif maxKeys
30
- path += '/?max-keys=' + maxKeys.to_s
31
+ path += '/?max-keys=' + maxKeys
31
32
  path += '&delimiter=' + delimiter if delimiter
32
33
  elsif delimiter
33
34
  path += '/?delimiter=' + delimiter
@@ -45,9 +46,7 @@ module Fog
45
46
  XmlSimple.xml_in(xml)
46
47
  end
47
48
 
48
- def list_multipart_uploads(bucket, location, _options = {})
49
- location ||= get_bucket_location(bucket)
50
-
49
+ def list_multipart_uploads(bucket, _options = {})
51
50
  path = '?uploads'
52
51
  resource = bucket + '/' + path
53
52
 
@@ -56,15 +55,12 @@ module Fog
56
55
  method: 'GET',
57
56
  path: path,
58
57
  bucket: bucket,
59
- resource: resource,
60
- location: location
58
+ resource: resource
61
59
  )
62
60
  XmlSimple.xml_in(ret.data[:body])['Upload']
63
61
  end
64
62
 
65
- def list_parts(bucket, object, location, uploadid, _options = {})
66
- location ||= get_bucket_location(bucket)
67
-
63
+ def list_parts(bucket, object, uploadid, _options = {})
68
64
  path = object + '?uploadId=' + uploadid
69
65
  resource = bucket + '/' + path
70
66
 
@@ -73,8 +69,7 @@ module Fog
73
69
  method: 'GET',
74
70
  path: path,
75
71
  bucket: bucket,
76
- resource: resource,
77
- location: location
72
+ resource: resource
78
73
  )
79
74
  XmlSimple.xml_in(ret.data[:body])['Part']
80
75
  end
@@ -20,8 +20,7 @@ module Fog
20
20
  method: 'PUT',
21
21
  path: path,
22
22
  bucket: bucket,
23
- resource: resource,
24
- location: get_bucket_location(bucket)
23
+ resource: resource
25
24
  )
26
25
  end
27
26
  end
@@ -10,40 +10,29 @@ module Fog
10
10
  # * object<~String> - Name of object to look for
11
11
  #
12
12
  def put_object(object, file = nil, options = {})
13
- bucket = options[:bucket]
14
- bucket ||= @aliyun_oss_bucket
15
- return put_folder(bucket, object) if file.nil?
16
-
17
- # put multiparts if object's size is over 100m
18
- return put_multipart_object(bucket, object, file) if file.size > 104_857_600
19
-
20
- body = file.read
21
-
22
- resource = bucket + '/' + object
23
- request(
24
- expects: [200, 203],
25
- method: 'PUT',
26
- path: object,
27
- bucket: bucket,
28
- resource: resource,
29
- body: body,
30
- location: get_bucket_location(bucket)
31
- )
13
+ bucket_name = options[:bucket]
14
+ bucket_name ||= @aliyun_oss_bucket
15
+ bucket = @oss_client.get_bucket(bucket_name)
16
+ return bucket.put_object(object) if file.nil?
17
+ # With a single PUT operation you can upload objects up to 5 GB in size.
18
+ if file.size > 5_368_709_120
19
+ bucket.resumable_upload(object, file.path)
20
+ end
21
+ bucket.put_object(object, :file => file.path)
32
22
  end
33
23
 
34
24
  def put_object_with_body(object, body, options = {})
35
- bucket = options[:bucket]
36
- bucket ||= @aliyun_oss_bucket
25
+ bucket_name = options[:bucket]
26
+ bucket_name ||= @aliyun_oss_bucket
37
27
 
38
- resource = bucket + '/' + object
28
+ resource = bucket_name + '/' + object
39
29
  request(
40
30
  expects: [200, 203],
41
31
  method: 'PUT',
42
32
  path: object,
43
- bucket: bucket,
33
+ bucket: bucket_name,
44
34
  resource: resource,
45
- body: body,
46
- location: get_bucket_location(bucket)
35
+ body: body
47
36
  )
48
37
  end
49
38
 
@@ -55,27 +44,24 @@ module Fog
55
44
  method: 'PUT',
56
45
  path: path,
57
46
  bucket: bucket,
58
- resource: resource,
59
- location: get_bucket_location(bucket)
47
+ resource: resource
60
48
  )
61
49
  end
62
50
 
63
51
  def put_multipart_object(bucket, object, file)
64
- location = get_bucket_location(bucket)
65
-
66
52
  # find the right uploadid
67
- uploads = list_multipart_uploads(bucket, location)
53
+ uploads = list_multipart_uploads(bucket)
68
54
  upload = (uploads&.find { |tmpupload| tmpupload['Key'][0] == object })
69
55
 
70
56
  uploadedSize = 0
71
57
  start_partNumber = 1
72
58
  if !upload.nil?
73
59
  uploadId = upload['UploadId'][0]
74
- parts = list_parts(bucket, object, location, uploadId)
60
+ parts = list_parts(bucket, object, uploadId)
75
61
  if !parts.nil? && !parts.empty?
76
62
  if parts[-1]['Size'][0].to_i != 5_242_880
77
63
  # the part is the last one, if its size is over 5m, then finish this upload
78
- complete_multipart_upload(bucket, object, location, uploadId)
64
+ complete_multipart_upload(bucket, object, uploadId)
79
65
  return
80
66
  end
81
67
  uploadedSize = (parts[0]['Size'][0].to_i * (parts.size - 1)) + parts[-1]['Size'][0].to_i
@@ -83,11 +69,11 @@ module Fog
83
69
  end
84
70
  else
85
71
  # create upload ID
86
- uploadId = initiate_multipart_upload(bucket, object, location)
72
+ uploadId = initiate_multipart_upload(bucket, object)
87
73
  end
88
74
 
89
75
  if file.size <= uploadedSize
90
- complete_multipart_upload(bucket, object, location, uploadId)
76
+ complete_multipart_upload(bucket, object, uploadId)
91
77
  return
92
78
  end
93
79
 
@@ -96,14 +82,13 @@ module Fog
96
82
 
97
83
  for i in start_partNumber..end_partNumber
98
84
  body = file.read(5_242_880)
99
- upload_part(bucket, object, location, i.to_s, uploadId, body)
85
+ upload_part(bucket, object, i.to_s, uploadId, body)
100
86
  end
101
87
 
102
- complete_multipart_upload(bucket, object, location, uploadId)
88
+ complete_multipart_upload(bucket, object, uploadId)
103
89
  end
104
90
 
105
- def initiate_multipart_upload(bucket, object, location)
106
- location ||= get_bucket_location(bucket)
91
+ def initiate_multipart_upload(bucket, object)
107
92
  path = object + '?uploads'
108
93
  resource = bucket + '/' + path
109
94
  ret = request(
@@ -111,14 +96,12 @@ module Fog
111
96
  method: 'POST',
112
97
  path: path,
113
98
  bucket: bucket,
114
- resource: resource,
115
- location: location
99
+ resource: resource
116
100
  )
117
101
  XmlSimple.xml_in(ret.data[:body])['UploadId'][0]
118
102
  end
119
103
 
120
- def upload_part(bucket, object, location, partNumber, uploadId, body)
121
- location ||= get_bucket_location(bucket)
104
+ def upload_part(bucket, object, partNumber, uploadId, body)
122
105
  path = object + '?partNumber=' + partNumber + '&uploadId=' + uploadId
123
106
  resource = bucket + '/' + path
124
107
  request(
@@ -127,14 +110,12 @@ module Fog
127
110
  path: path,
128
111
  bucket: bucket,
129
112
  resource: resource,
130
- body: body,
131
- location: location
113
+ body: body
132
114
  )
133
115
  end
134
116
 
135
- def complete_multipart_upload(bucket, object, location, uploadId)
136
- location ||= get_bucket_location(bucket)
137
- parts = list_parts(bucket, object, location, uploadId, options = {})
117
+ def complete_multipart_upload(bucket, object, uploadId)
118
+ parts = list_parts(bucket, object, uploadId, options = {})
138
119
  request_part = []
139
120
  return if parts.empty?
140
121
  for i in 0..(parts.size - 1)
@@ -151,7 +132,6 @@ module Fog
151
132
  path: path,
152
133
  bucket: bucket,
153
134
  resource: resource,
154
- location: location,
155
135
  body: body
156
136
  )
157
137
  end
@@ -19,7 +19,9 @@ module Fog
19
19
 
20
20
  recognizes :aliyun_oss_endpoint,
21
21
  :aliyun_oss_location,
22
- :aliyun_region_id
22
+ :aliyun_region_id,
23
+ :aliyun_oss_sdk_log_path
24
+
23
25
  requires :aliyun_accesskey_id,
24
26
  :aliyun_accesskey_secret,
25
27
  :aliyun_oss_bucket
@@ -72,6 +74,7 @@ module Fog
72
74
  attr_reader :aliyun_oss_endpoint
73
75
  attr_reader :aliyun_region_id
74
76
  attr_reader :aliyun_oss_bucket
77
+ attr_reader :aliyun_oss_sdk_log_path
75
78
 
76
79
  def initialize(options = {})
77
80
  # initialize the parameters
@@ -80,7 +83,11 @@ module Fog
80
83
  @aliyun_accesskey_id = options[:aliyun_accesskey_id]
81
84
  @aliyun_accesskey_secret = options[:aliyun_accesskey_secret]
82
85
  @aliyun_oss_bucket = options[:aliyun_oss_bucket]
83
-
86
+ @aliyun_oss_sdk_log_path=options[:aliyun_oss_sdk_log_path]
87
+ if @aliyun_oss_sdk_log_path && !::File.exist?(@aliyun_oss_sdk_log_path)
88
+ `touch #{@aliyun_oss_sdk_log_path}`
89
+ end
90
+ ENV["ALIYUN_OSS_SDK_LOG_PATH"] = @aliyun_oss_sdk_log_path
84
91
  # check for the parameters
85
92
  missing_credentials = []
86
93
  missing_credentials << :aliyun_oss_bucket unless @aliyun_oss_bucket
@@ -106,6 +113,14 @@ module Fog
106
113
  :access_key_id => @aliyun_accesskey_id,
107
114
  :access_key_secret => @aliyun_accesskey_secret
108
115
  )
116
+
117
+ # initiate a aliyun oss ruby sdk config and using sdk http to invoke the OSS openapi
118
+ @oss_config = AliyunOssSdk::Config.new(
119
+ :endpoint => @aliyun_oss_endpoint,
120
+ :access_key_id => @aliyun_accesskey_id,
121
+ :access_key_secret => @aliyun_accesskey_secret
122
+ )
123
+ @oss_http = AliyunOssSdk::HTTP.new(@oss_config)
109
124
  end
110
125
 
111
126
  def reload
@@ -126,31 +141,14 @@ module Fog
126
141
  time = Time.new.utc
127
142
  date = time.strftime('%a, %d %b %Y %H:%M:%S GMT')
128
143
 
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
144
  bucket = params[:bucket]
147
145
  tmpHost = if bucket
148
- bucket + '.' + host
146
+ bucket + '.' + @host
149
147
  else
150
- host
148
+ @host
151
149
  end
152
150
 
153
- @connection = Fog::Core::Connection.new("#{scheme}://#{tmpHost}", @persistent, @connection_options)
151
+ @connection = Fog::Core::Connection.new("#{@scheme}://#{tmpHost}", @persistent, @connection_options)
154
152
  contentType = params[:contentType]
155
153
 
156
154
  begin
@@ -166,7 +164,7 @@ module Fog
166
164
  'Authorization' => 'OSS ' + @aliyun_accesskey_id + ':' + signature,
167
165
  'Date' => date
168
166
  }.merge!(params[:headers] || {}),
169
- path: "#{path}/#{params[:path]}",
167
+ path: "#{@path}/#{params[:path]}",
170
168
  query: params[:query]))
171
169
  rescue Excon::Errors::HTTPStatusError => error
172
170
  raise case error
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fog
4
4
  module Aliyun
5
- VERSION = '0.3.12'
5
+ VERSION = '0.3.18'
6
6
  end
7
7
  end
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.12
4
+ version: 0.3.18
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-05-28 00:00:00.000000000 Z
11
+ date: 2020-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,16 +132,30 @@ dependencies:
132
132
  name: aliyun-sdk
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - ">="
135
+ - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '0'
137
+ version: 0.7.3
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
- - - ">="
142
+ - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '0'
144
+ version: 0.7.3
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.7.3
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: 0.7.3
145
159
  - !ruby/object:Gem::Dependency
146
160
  name: fog-core
147
161
  requirement: !ruby/object:Gem::Requirement
@@ -198,20 +212,6 @@ dependencies:
198
212
  - - "~>"
199
213
  - !ruby/object:Gem::Version
200
214
  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'
215
215
  description: As a FOG provider, fog-aliyun support aliyun OSS/ECS. It will support
216
216
  more aliyun services later.
217
217
  email:
@@ -228,6 +228,7 @@ files:
228
228
  - ".ruby-gemset"
229
229
  - ".ruby-version"
230
230
  - ".travis.yml"
231
+ - CHANGELOG.md
231
232
  - CODE_OF_CONDUCT.md
232
233
  - Gemfile
233
234
  - LICENSE.txt