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,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
  # Copy object
8
8
  #
@@ -19,8 +19,6 @@ module Fog
19
19
  source_bucket ||= bucket
20
20
  target_bucket ||= bucket
21
21
  headers = { 'x-oss-copy-source' => "/#{source_bucket}/#{source_object}" }
22
- location = get_bucket_location(target_bucket)
23
- endpoint = 'http://' + location + '.aliyuncs.com'
24
22
  resource = target_bucket + '/' + target_object
25
23
  request(expects: [200, 203],
26
24
  headers: headers,
@@ -28,7 +26,7 @@ module Fog
28
26
  path: target_object,
29
27
  bucket: target_bucket,
30
28
  resource: resource,
31
- endpoint: endpoint)
29
+ location: get_bucket_location(bucket))
32
30
  end
33
31
  end
34
32
  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
  # Delete an existing bucket
8
8
  #
@@ -10,15 +10,13 @@ module Fog
10
10
  # * bucket<~String> - Name of bucket to delete
11
11
  #
12
12
  def delete_bucket(bucket)
13
- location = get_bucket_location(bucket)
14
- endpoint = 'http://' + location + '.aliyuncs.com'
15
13
  resource = bucket + '/'
16
14
  request(
17
15
  expects: 204,
18
16
  method: 'DELETE',
19
17
  bucket: bucket,
20
18
  resource: resource,
21
- endpoint: endpoint
19
+ location: get_bucket_location(bucket)
22
20
  )
23
21
  end
24
22
  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
  # Delete an existing container
8
8
  #
@@ -13,8 +13,6 @@ module Fog
13
13
  def delete_container(container, options = {})
14
14
  bucket = options[:bucket]
15
15
  bucket ||= @aliyun_oss_bucket
16
- location = get_bucket_location(bucket)
17
- endpoint = 'http://' + location + '.aliyuncs.com'
18
16
  object = container + '/'
19
17
  resource = bucket + '/' + object
20
18
 
@@ -24,7 +22,7 @@ module Fog
24
22
  path: object,
25
23
  bucket: bucket,
26
24
  resource: resource,
27
- endpoint: endpoint
25
+ location: get_bucket_location(bucket)
28
26
  )
29
27
  end
30
28
  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
  # Delete an existing object
8
8
  #
@@ -12,8 +12,6 @@ module Fog
12
12
  def delete_object(object, 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
  resource = bucket + '/' + object
18
16
  request(
19
17
  expects: 204,
@@ -21,15 +19,11 @@ module Fog
21
19
  path: object,
22
20
  bucket: bucket,
23
21
  resource: resource,
24
- endpoint: endpoint
22
+ location: get_bucket_location(bucket)
25
23
  )
26
24
  end
27
25
 
28
26
  def abort_multipart_upload(bucket, object, endpoint, uploadid)
29
- if endpoint.nil?
30
- location = get_bucket_location(bucket)
31
- endpoint = 'http://' + location + '.aliyuncs.com'
32
- end
33
27
  path = object + '?uploadId=' + uploadid
34
28
  resource = bucket + '/' + path
35
29
 
@@ -39,7 +33,8 @@ module Fog
39
33
  path: path,
40
34
  bucket: bucket,
41
35
  resource: resource,
42
- endpoint: endpoint
36
+ endpoint: endpoint,
37
+ location: get_bucket_location(bucket)
43
38
  )
44
39
  end
45
40
  end
@@ -1,27 +1,43 @@
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
- def get_bucket(bucket)
8
- location = get_bucket_location(bucket)
9
- # If there is an error, it will return a Hash with error code, host id and others
10
- # If can not get a valid location, will return one using region
11
- if location.class == Hash && location.key?('HostId')
12
- value = location['HostId']
13
- location = value[0].split('.')[1]
14
- else
15
- location = 'oss-' + @aliyun_region_id
7
+ def get_bucket(bucket, options = {})
8
+ prefix = options['prefix']
9
+ marker = options['marker']
10
+ # Set the GetBucket max limitation to 1000
11
+ maxKeys = options['max-keys'] || 1000
12
+ maxKeys = [maxKeys, 1000].min
13
+ delimiter = options['delimiter']
14
+ path = ''
15
+ if prefix
16
+ path += '/?prefix=' + prefix
17
+ path += '&marker=' + marker if marker
18
+ path += '&max-keys=' + maxKeys.to_s if maxKeys
19
+ path += '&delimiter=' + delimiter if delimiter
20
+
21
+ elsif marker
22
+ path += '/?marker=' + marker
23
+ path += '&max-keys=' + maxKeys.to_s if maxKeys
24
+ path += '&delimiter=' + delimiter if delimiter
25
+
26
+ elsif maxKeys
27
+ path += '/?max-keys=' + maxKeys.to_s
28
+ path += '&delimiter=' + delimiter if delimiter
29
+ elsif delimiter
30
+ path += '/?delimiter=' + delimiter
16
31
  end
17
- endpoint = 'http://' + location + '.aliyuncs.com'
32
+
18
33
  resource = bucket + '/'
19
34
  ret = request(
20
35
  expects: [200, 203, 404],
21
36
  method: 'GET',
22
37
  bucket: bucket,
23
38
  resource: resource,
24
- endpoint: endpoint
39
+ location: get_bucket_location(bucket),
40
+ path: path
25
41
  )
26
42
  xml = ret.data[:body]
27
43
  XmlSimple.xml_in(xml)
@@ -37,12 +53,17 @@ module Fog
37
53
  bucket: bucket,
38
54
  resource: resource
39
55
  )
40
- XmlSimple.xml_in(ret.data[:body])
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
41
64
  end
42
65
 
43
66
  def get_bucket_acl(bucket)
44
- location = get_bucket_location(bucket)
45
- endpoint = 'http://' + location + '.aliyuncs.com'
46
67
  attribute = '?acl'
47
68
  resource = bucket + '/' + attribute
48
69
  ret = request(
@@ -51,14 +72,12 @@ module Fog
51
72
  path: attribute,
52
73
  bucket: bucket,
53
74
  resource: resource,
54
- endpoint: endpoint
75
+ location: get_bucket_location(bucket)
55
76
  )
56
77
  XmlSimple.xml_in(ret.data[:body])['AccessControlList'][0]['Grant'][0]
57
78
  end
58
79
 
59
80
  def get_bucket_CORSRules(bucket)
60
- location = get_bucket_location(bucket)
61
- endpoint = 'http://' + location + '.aliyuncs.com'
62
81
  attribute = '?cors'
63
82
  resource = bucket + '/' + attribute
64
83
  ret = request(
@@ -67,14 +86,12 @@ module Fog
67
86
  path: attribute,
68
87
  bucket: bucket,
69
88
  resource: resource,
70
- endpoint: endpoint
89
+ location: get_bucket_location(bucket)
71
90
  )
72
91
  XmlSimple.xml_in(ret.data[:body])['CORSRule'][0] if ret.data[:status] != 404
73
92
  end
74
93
 
75
94
  def get_bucket_lifecycle(bucket)
76
- location = get_bucket_location(bucket)
77
- endpoint = 'http://' + location + '.aliyuncs.com'
78
95
  attribute = '?lifecycle'
79
96
  resource = bucket + '/' + attribute
80
97
  ret = request(
@@ -83,14 +100,12 @@ module Fog
83
100
  path: attribute,
84
101
  bucket: bucket,
85
102
  resource: resource,
86
- endpoint: endpoint
103
+ location: get_bucket_location(bucket)
87
104
  )
88
105
  XmlSimple.xml_in(ret.data[:body])['Rule'][0] if ret.data[:status] != 404
89
106
  end
90
107
 
91
108
  def get_bucket_logging(bucket)
92
- location = get_bucket_location(bucket)
93
- endpoint = 'http://' + location + '.aliyuncs.com'
94
109
  attribute = '?logging'
95
110
  resource = bucket + '/' + attribute
96
111
  ret = request(
@@ -99,14 +114,12 @@ module Fog
99
114
  path: attribute,
100
115
  bucket: bucket,
101
116
  resource: resource,
102
- endpoint: endpoint
117
+ location: get_bucket_location(bucket)
103
118
  )
104
119
  XmlSimple.xml_in(ret.data[:body])['LoggingEnabled'][0]['TargetPrefix']
105
120
  end
106
121
 
107
122
  def get_bucket_referer(bucket)
108
- location = get_bucket_location(bucket)
109
- endpoint = 'http://' + location + '.aliyuncs.com'
110
123
  attribute = '?referer'
111
124
  resource = bucket + '/' + attribute
112
125
  ret = request(
@@ -115,14 +128,12 @@ module Fog
115
128
  path: attribute,
116
129
  bucket: bucket,
117
130
  resource: resource,
118
- endpoint: endpoint
131
+ location: get_bucket_location(bucket)
119
132
  )
120
133
  XmlSimple.xml_in(ret.data[:body])
121
134
  end
122
135
 
123
136
  def get_bucket_website(bucket)
124
- location = get_bucket_location(bucket)
125
- endpoint = 'http://' + location + '.aliyuncs.com'
126
137
  attribute = '?website'
127
138
  resource = bucket + '/' + attribute
128
139
  ret = request(
@@ -131,7 +142,7 @@ module Fog
131
142
  path: attribute,
132
143
  bucket: bucket,
133
144
  resource: resource,
134
- endpoint: endpoint
145
+ location: get_bucket_location(bucket)
135
146
  )
136
147
  XmlSimple.xml_in(ret.data[:body]) if ret.data[:status] != 404
137
148
  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 get_container(container, options = {})
8
8
  options = options.reject { |_key, value| value.nil? }
@@ -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
  # List existing storage containers
8
8
  #
@@ -42,13 +42,18 @@ module Fog
42
42
  path += '?delimiter=' + delimiter
43
43
  end
44
44
 
45
- location = get_bucket_location(bucket)
45
+ endpoint = options[:endpoint]
46
+ if endpoint.nil?
47
+ location = get_bucket_location(bucket)
48
+ end
46
49
  resource = bucket + '/'
47
50
  ret = request(
48
51
  expects: [200, 203, 400],
49
52
  method: 'GET',
50
53
  path: path,
51
54
  resource: resource,
55
+ endpoint: endpoint,
56
+ location: location,
52
57
  bucket: bucket
53
58
  )
54
59
  xml = ret.data[:body]
@@ -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
  # Get details for object
8
8
  #
@@ -11,30 +11,17 @@ module Fog
11
11
  #
12
12
  def get_object(object, range = nil, options = {})
13
13
  options = options.reject { |_key, value| value.nil? }
14
- bucket = options[:bucket]
15
- bucket ||= @aliyun_oss_bucket
16
- endpoint = options[:endpoint]
17
- if endpoint.nil?
18
- location = get_bucket_location(bucket)
19
- endpoint = 'http://' + location + '.aliyuncs.com'
14
+ bucket_name = options[:bucket]
15
+ bucket_name ||= @aliyun_oss_bucket
16
+ # 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
20
21
  end
21
- resource = bucket + '/' + object
22
- para = {
23
- expects: [200, 206, 404],
24
- method: 'GET',
25
- path: object,
26
- bucket: bucket,
27
- resource: resource,
28
- endpoint: endpoint
29
- }
30
-
31
- if range
32
- rangeStr = 'bytes=' + range
33
- para[:headers] = { 'Range' => rangeStr }
34
- end
35
-
36
- response = request(para)
37
- response.data
22
+ response = {}
23
+ obj.instance_variables.each {|var| response[var.to_s.delete("@")] = obj.instance_variable_get(var) }
24
+ response.merge({:body => body.join('')})
38
25
  end
39
26
  end
40
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
  # Get an expiring object http url
8
8
  #
@@ -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
  # Get an expiring object https url from Cloud Files
8
8
  #
@@ -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
  # Get headers for object
8
8
  #
@@ -12,8 +12,6 @@ module Fog
12
12
  def head_object(object, 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
  resource = bucket + '/' + object
18
16
  ret = request(
19
17
  expects: [200, 404],
@@ -21,7 +19,7 @@ module Fog
21
19
  path: object,
22
20
  bucket: bucket,
23
21
  resource: resource,
24
- endpoint: endpoint
22
+ location: get_bucket_location(bucket)
25
23
  )
26
24
  ret
27
25
  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 list_buckets(options = {})
8
8
  prefix = options[:prefix]