fog-aliyun 0.3.8 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/README.md +61 -3
- data/fog-aliyun.gemspec +2 -0
- data/lib/fog/aliyun.rb +6 -9
- data/lib/fog/aliyun/models/storage/directories.rb +34 -11
- data/lib/fog/aliyun/models/storage/directory.rb +5 -7
- data/lib/fog/aliyun/models/storage/file.rb +16 -16
- data/lib/fog/aliyun/models/storage/files.rb +71 -78
- data/lib/fog/aliyun/requests/storage/copy_object.rb +3 -5
- data/lib/fog/aliyun/requests/storage/delete_bucket.rb +3 -5
- data/lib/fog/aliyun/requests/storage/delete_container.rb +3 -5
- data/lib/fog/aliyun/requests/storage/delete_object.rb +9 -31
- data/lib/fog/aliyun/requests/storage/get_bucket.rb +43 -32
- data/lib/fog/aliyun/requests/storage/get_container.rb +2 -2
- data/lib/fog/aliyun/requests/storage/get_containers.rb +8 -3
- data/lib/fog/aliyun/requests/storage/get_object.rb +12 -25
- data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +2 -2
- data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +2 -2
- data/lib/fog/aliyun/requests/storage/head_object.rb +3 -5
- data/lib/fog/aliyun/requests/storage/list_buckets.rb +2 -2
- data/lib/fog/aliyun/requests/storage/list_objects.rb +23 -25
- data/lib/fog/aliyun/requests/storage/put_bucket.rb +2 -2
- data/lib/fog/aliyun/requests/storage/put_container.rb +3 -5
- data/lib/fog/aliyun/requests/storage/put_object.rb +24 -42
- data/lib/fog/aliyun/storage.rb +24 -10
- data/lib/fog/aliyun/version.rb +1 -1
- data/lib/fog/bin/aliyun.rb +1 -1
- metadata +30 -2
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Fog
|
4
|
-
module
|
5
|
-
class
|
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
|
-
|
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
|
5
|
-
class
|
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
|
-
|
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
|
5
|
-
class
|
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
|
-
|
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
|
5
|
-
class
|
4
|
+
module Aliyun
|
5
|
+
class Storage
|
6
6
|
class Real
|
7
7
|
# Delete an existing object
|
8
8
|
#
|
@@ -10,37 +10,15 @@ module Fog
|
|
10
10
|
# * object<~String> - Name of object to delete
|
11
11
|
#
|
12
12
|
def delete_object(object, options = {})
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
resource = bucket + '/' + object
|
18
|
-
request(
|
19
|
-
expects: 204,
|
20
|
-
method: 'DELETE',
|
21
|
-
path: object,
|
22
|
-
bucket: bucket,
|
23
|
-
resource: resource,
|
24
|
-
endpoint: endpoint
|
25
|
-
)
|
13
|
+
bucket_name = options[:bucket]
|
14
|
+
bucket_name ||= @aliyun_oss_bucket
|
15
|
+
bucket = @oss_client.get_bucket(bucket_name)
|
16
|
+
bucket.delete_object(object)
|
26
17
|
end
|
27
18
|
|
28
|
-
def abort_multipart_upload(
|
29
|
-
|
30
|
-
|
31
|
-
endpoint = 'http://' + location + '.aliyuncs.com'
|
32
|
-
end
|
33
|
-
path = object + '?uploadId=' + uploadid
|
34
|
-
resource = bucket + '/' + path
|
35
|
-
|
36
|
-
ret = request(
|
37
|
-
expects: 204,
|
38
|
-
method: 'DELETE',
|
39
|
-
path: path,
|
40
|
-
bucket: bucket,
|
41
|
-
resource: resource,
|
42
|
-
endpoint: endpoint
|
43
|
-
)
|
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)
|
44
22
|
end
|
45
23
|
end
|
46
24
|
end
|
@@ -1,27 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Fog
|
4
|
-
module
|
5
|
-
class
|
4
|
+
module Aliyun
|
5
|
+
class Storage
|
6
6
|
class Real
|
7
|
-
def get_bucket(bucket)
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
5
|
-
class
|
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
|
-
|
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
|
5
|
-
class
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
5
|
-
class
|
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
|
-
|
22
|
+
location: get_bucket_location(bucket)
|
25
23
|
)
|
26
24
|
ret
|
27
25
|
end
|