fog-aliyun 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +23 -10
- data/.rubocop.yml +31 -4
- data/.rubocop_todo.yml +83 -55
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/bin/console +4 -3
- data/fog-aliyun.gemspec +19 -18
- data/lib/fog/aliyun.rb +4 -2
- data/lib/fog/aliyun/compute.rb +45 -43
- data/lib/fog/aliyun/models/compute/eip_address.rb +10 -8
- data/lib/fog/aliyun/models/compute/eip_addresses.rb +3 -3
- data/lib/fog/aliyun/models/compute/image.rb +23 -21
- data/lib/fog/aliyun/models/compute/images.rb +2 -0
- data/lib/fog/aliyun/models/compute/route_entry.rb +7 -5
- data/lib/fog/aliyun/models/compute/route_entrys.rb +2 -0
- data/lib/fog/aliyun/models/compute/route_table.rb +6 -4
- data/lib/fog/aliyun/models/compute/route_tables.rb +3 -3
- data/lib/fog/aliyun/models/compute/security_group.rb +7 -5
- data/lib/fog/aliyun/models/compute/security_group_rule.rb +15 -13
- data/lib/fog/aliyun/models/compute/security_group_rules.rb +2 -0
- data/lib/fog/aliyun/models/compute/security_groups.rb +2 -0
- data/lib/fog/aliyun/models/compute/server.rb +28 -26
- data/lib/fog/aliyun/models/compute/servers.rb +3 -3
- data/lib/fog/aliyun/models/compute/snapshot.rb +12 -10
- data/lib/fog/aliyun/models/compute/snapshots.rb +2 -0
- data/lib/fog/aliyun/models/compute/volume.rb +27 -25
- data/lib/fog/aliyun/models/compute/volumes.rb +2 -0
- data/lib/fog/aliyun/models/compute/vpc.rb +12 -10
- data/lib/fog/aliyun/models/compute/vpcs.rb +3 -3
- data/lib/fog/aliyun/models/compute/vrouter.rb +8 -6
- data/lib/fog/aliyun/models/compute/vrouters.rb +3 -3
- data/lib/fog/aliyun/models/compute/vswitch.rb +11 -9
- data/lib/fog/aliyun/models/compute/vswitches.rb +3 -3
- data/lib/fog/aliyun/models/storage/directories.rb +3 -1
- data/lib/fog/aliyun/models/storage/directory.rb +2 -0
- data/lib/fog/aliyun/models/storage/file.rb +18 -16
- data/lib/fog/aliyun/models/storage/files.rb +13 -19
- data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +5 -3
- data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +4 -2
- data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +4 -2
- data/lib/fog/aliyun/requests/compute/attach_disk.rb +7 -5
- data/lib/fog/aliyun/requests/compute/create_disk.rb +15 -13
- data/lib/fog/aliyun/requests/compute/create_image.rb +3 -1
- data/lib/fog/aliyun/requests/compute/create_security_group.rb +11 -9
- data/lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb +13 -11
- data/lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb +12 -10
- data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +13 -11
- data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +12 -10
- data/lib/fog/aliyun/requests/compute/create_server.rb +11 -9
- data/lib/fog/aliyun/requests/compute/create_snapshot.rb +3 -1
- data/lib/fog/aliyun/requests/compute/create_vpc.rb +6 -4
- data/lib/fog/aliyun/requests/compute/create_vpn_connection.rb +8 -6
- data/lib/fog/aliyun/requests/compute/create_vpn_customergateway.rb +6 -6
- data/lib/fog/aliyun/requests/compute/create_vswitch.rb +6 -4
- data/lib/fog/aliyun/requests/compute/delete_disk.rb +8 -6
- data/lib/fog/aliyun/requests/compute/delete_image.rb +3 -1
- data/lib/fog/aliyun/requests/compute/delete_security_group.rb +7 -5
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb +13 -11
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb +12 -10
- data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +13 -11
- data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +12 -10
- data/lib/fog/aliyun/requests/compute/delete_server.rb +2 -0
- data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +3 -1
- data/lib/fog/aliyun/requests/compute/delete_vpc.rb +6 -4
- data/lib/fog/aliyun/requests/compute/delete_vpn_connection.rb +6 -4
- data/lib/fog/aliyun/requests/compute/delete_vpn_customergateway.rb +6 -4
- data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +6 -4
- data/lib/fog/aliyun/requests/compute/detach_disk.rb +6 -4
- data/lib/fog/aliyun/requests/compute/join_security_group.rb +2 -0
- data/lib/fog/aliyun/requests/compute/leave_security_group.rb +2 -0
- data/lib/fog/aliyun/requests/compute/list_disks.rb +5 -3
- data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +5 -3
- data/lib/fog/aliyun/requests/compute/list_images.rb +5 -3
- data/lib/fog/aliyun/requests/compute/list_route_tables.rb +6 -4
- data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +7 -5
- data/lib/fog/aliyun/requests/compute/list_security_groups.rb +10 -8
- data/lib/fog/aliyun/requests/compute/list_server_types.rb +8 -6
- data/lib/fog/aliyun/requests/compute/list_servers.rb +4 -2
- data/lib/fog/aliyun/requests/compute/list_snapshots.rb +4 -2
- data/lib/fog/aliyun/requests/compute/list_vpcs.rb +5 -3
- data/lib/fog/aliyun/requests/compute/list_vpn_connections.rb +49 -49
- data/lib/fog/aliyun/requests/compute/list_vpn_customergateways.rb +42 -43
- data/lib/fog/aliyun/requests/compute/list_vpn_gateways.rb +49 -49
- data/lib/fog/aliyun/requests/compute/list_vrouters.rb +6 -4
- data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +6 -4
- data/lib/fog/aliyun/requests/compute/list_zones.rb +3 -1
- data/lib/fog/aliyun/requests/compute/modify_vpc.rb +7 -5
- data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +6 -4
- data/lib/fog/aliyun/requests/compute/reboot_server.rb +2 -0
- data/lib/fog/aliyun/requests/compute/release_eip_address.rb +4 -2
- data/lib/fog/aliyun/requests/compute/start_server.rb +9 -7
- data/lib/fog/aliyun/requests/compute/stop_server.rb +9 -7
- data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +4 -2
- data/lib/fog/aliyun/requests/storage/copy_object.rb +3 -2
- data/lib/fog/aliyun/requests/storage/delete_bucket.rb +3 -2
- data/lib/fog/aliyun/requests/storage/delete_container.rb +3 -2
- data/lib/fog/aliyun/requests/storage/delete_object.rb +4 -3
- data/lib/fog/aliyun/requests/storage/get_bucket.rb +6 -11
- data/lib/fog/aliyun/requests/storage/get_container.rb +3 -2
- data/lib/fog/aliyun/requests/storage/get_containers.rb +3 -2
- data/lib/fog/aliyun/requests/storage/get_object.rb +4 -3
- data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +5 -4
- data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +5 -4
- data/lib/fog/aliyun/requests/storage/head_object.rb +3 -2
- data/lib/fog/aliyun/requests/storage/list_buckets.rb +3 -2
- data/lib/fog/aliyun/requests/storage/list_objects.rb +5 -4
- data/lib/fog/aliyun/requests/storage/put_bucket.rb +3 -2
- data/lib/fog/aliyun/requests/storage/put_container.rb +3 -2
- data/lib/fog/aliyun/requests/storage/put_object.rb +12 -17
- data/lib/fog/aliyun/storage.rb +41 -52
- data/lib/fog/aliyun/version.rb +3 -1
- data/lib/fog/bin/aliyun.rb +10 -7
- metadata +37 -37
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fog
|
2
4
|
module Storage
|
3
5
|
class Aliyun
|
@@ -27,8 +29,7 @@ module Fog
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
class Mock
|
30
|
-
def delete_container(container, options = {})
|
31
|
-
end
|
32
|
+
def delete_container(container, options = {}); end
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fog
|
2
4
|
module Storage
|
3
5
|
class Aliyun
|
@@ -24,7 +26,7 @@ module Fog
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def abort_multipart_upload(bucket, object, endpoint, uploadid)
|
27
|
-
if nil
|
29
|
+
if endpoint.nil?
|
28
30
|
location = get_bucket_location(bucket)
|
29
31
|
endpoint = 'http://' + location + '.aliyuncs.com'
|
30
32
|
end
|
@@ -43,8 +45,7 @@ module Fog
|
|
43
45
|
end
|
44
46
|
|
45
47
|
class Mock
|
46
|
-
def delete_object(object, options = {})
|
47
|
-
end
|
48
|
+
def delete_object(object, options = {}); end
|
48
49
|
end
|
49
50
|
end
|
50
51
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fog
|
2
4
|
module Storage
|
3
5
|
class Aliyun
|
@@ -59,9 +61,7 @@ module Fog
|
|
59
61
|
resource: resource,
|
60
62
|
endpoint: endpoint
|
61
63
|
)
|
62
|
-
|
63
|
-
cors = XmlSimple.xml_in(ret.data[:body])['CORSRule'][0]
|
64
|
-
end
|
64
|
+
cors = XmlSimple.xml_in(ret.data[:body])['CORSRule'][0] if ret.data[:status] != 404
|
65
65
|
end
|
66
66
|
|
67
67
|
def get_bucket_lifecycle(bucket)
|
@@ -77,9 +77,7 @@ module Fog
|
|
77
77
|
resource: resource,
|
78
78
|
endpoint: endpoint
|
79
79
|
)
|
80
|
-
|
81
|
-
lifecycle = XmlSimple.xml_in(ret.data[:body])['Rule'][0]
|
82
|
-
end
|
80
|
+
lifecycle = XmlSimple.xml_in(ret.data[:body])['Rule'][0] if ret.data[:status] != 404
|
83
81
|
end
|
84
82
|
|
85
83
|
def get_bucket_logging(bucket)
|
@@ -127,14 +125,11 @@ module Fog
|
|
127
125
|
resource: resource,
|
128
126
|
endpoint: endpoint
|
129
127
|
)
|
130
|
-
|
131
|
-
website = XmlSimple.xml_in(ret.data[:body])
|
132
|
-
end
|
128
|
+
website = XmlSimple.xml_in(ret.data[:body]) if ret.data[:status] != 404
|
133
129
|
end
|
134
130
|
end
|
135
131
|
class Mock
|
136
|
-
def get_bucket(bucket)
|
137
|
-
end
|
132
|
+
def get_bucket(bucket); end
|
138
133
|
end
|
139
134
|
end
|
140
135
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fog
|
2
4
|
module Storage
|
3
5
|
class Aliyun
|
@@ -52,8 +54,7 @@ module Fog
|
|
52
54
|
end
|
53
55
|
|
54
56
|
class Mock
|
55
|
-
def get_container(container, options = {})
|
56
|
-
end
|
57
|
+
def get_container(container, options = {}); end
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fog
|
2
4
|
module Storage
|
3
5
|
class Aliyun
|
@@ -12,7 +14,7 @@ module Fog
|
|
12
14
|
bucket = options[:bucket]
|
13
15
|
bucket ||= @aliyun_oss_bucket
|
14
16
|
endpoint = options[:endpoint]
|
15
|
-
if nil
|
17
|
+
if endpoint.nil?
|
16
18
|
location = get_bucket_location(bucket)
|
17
19
|
endpoint = 'http://' + location + '.aliyuncs.com'
|
18
20
|
end
|
@@ -37,8 +39,7 @@ module Fog
|
|
37
39
|
end
|
38
40
|
|
39
41
|
class Mock
|
40
|
-
def get_object(object, range = nil, options = {})
|
41
|
-
end
|
42
|
+
def get_object(object, range = nil, options = {}); end
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fog
|
2
4
|
module Storage
|
3
5
|
class Aliyun
|
@@ -19,14 +21,14 @@ module Fog
|
|
19
21
|
acl = get_bucket_acl(bucket)
|
20
22
|
location = get_bucket_location(bucket)
|
21
23
|
|
22
|
-
if 'private'
|
24
|
+
if acl == 'private'
|
23
25
|
expires_time = (Time.now.to_i + expires).to_s
|
24
26
|
resource = bucket + '/' + object
|
25
27
|
signature = sign('GET', expires_time, nil, resource)
|
26
28
|
url = 'http://' + bucket + '.' + location + '.aliyuncs.com/' + object +
|
27
29
|
'?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
|
28
30
|
'&Signature=' + URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
29
|
-
elsif 'public-read'
|
31
|
+
elsif acl == 'public-read' || acl == 'public-read-write'
|
30
32
|
url = 'http://' + bucket + '.' + location + '.aliyuncs.com/' + object
|
31
33
|
else
|
32
34
|
url = 'acl is wrong with value:' + acl
|
@@ -35,8 +37,7 @@ module Fog
|
|
35
37
|
end
|
36
38
|
|
37
39
|
class Mock
|
38
|
-
def get_object_http_url_public(object, expires, options = {})
|
39
|
-
end
|
40
|
+
def get_object_http_url_public(object, expires, options = {}); end
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fog
|
2
4
|
module Storage
|
3
5
|
class Aliyun
|
@@ -19,14 +21,14 @@ module Fog
|
|
19
21
|
acl = get_bucket_acl(bucket)
|
20
22
|
location = get_bucket_location(bucket)
|
21
23
|
|
22
|
-
if 'private'
|
24
|
+
if acl == 'private'
|
23
25
|
expires_time = (Time.now.to_i + expires).to_s
|
24
26
|
resource = bucket + '/' + object
|
25
27
|
signature = sign('GET', expires_time, nil, resource)
|
26
28
|
url = 'https://' + bucket + '.' + location + '.aliyuncs.com/' + object +
|
27
29
|
'?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
|
28
30
|
'&Signature=' + URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
29
|
-
elsif 'public-read'
|
31
|
+
elsif acl == 'public-read' || acl == 'public-read-write'
|
30
32
|
url = 'https://' + bucket + '.' + location + '.aliyuncs.com/' + object
|
31
33
|
else
|
32
34
|
url = 'acl is wrong with value:' + acl
|
@@ -35,8 +37,7 @@ module Fog
|
|
35
37
|
end
|
36
38
|
|
37
39
|
class Mock
|
38
|
-
def get_object_https_url_public(object, expires, options = {})
|
39
|
-
end
|
40
|
+
def get_object_https_url_public(object, expires, options = {}); end
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fog
|
2
4
|
module Storage
|
3
5
|
class Aliyun
|
@@ -44,7 +46,7 @@ module Fog
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def list_multipart_uploads(bucket, endpoint, _options = {})
|
47
|
-
if nil
|
49
|
+
if endpoint.nil?
|
48
50
|
location = get_bucket_location(bucket)
|
49
51
|
endpoint = 'http://' + location + '.aliyuncs.com'
|
50
52
|
end
|
@@ -63,7 +65,7 @@ module Fog
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def list_parts(bucket, object, endpoint, uploadid, _options = {})
|
66
|
-
if nil
|
68
|
+
if endpoint.nil?
|
67
69
|
location = get_bucket_location(bucket)
|
68
70
|
endpoint = 'http://' + location + '.aliyuncs.com'
|
69
71
|
end
|
@@ -83,8 +85,7 @@ module Fog
|
|
83
85
|
end
|
84
86
|
|
85
87
|
class Mock
|
86
|
-
def list_objects(options = {})
|
87
|
-
end
|
88
|
+
def list_objects(options = {}); end
|
88
89
|
end
|
89
90
|
end
|
90
91
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fog
|
2
4
|
module Storage
|
3
5
|
class Aliyun
|
@@ -12,12 +14,10 @@ module Fog
|
|
12
14
|
bucket ||= @aliyun_oss_bucket
|
13
15
|
location = get_bucket_location(bucket)
|
14
16
|
endpoint = 'http://' + location + '.aliyuncs.com'
|
15
|
-
return put_folder(bucket, object, endpoint) if nil
|
17
|
+
return put_folder(bucket, object, endpoint) if file.nil?
|
16
18
|
|
17
19
|
# put multiparts if object's size is over 100m
|
18
|
-
if file.size > 104_857_600
|
19
|
-
return put_multipart_object(bucket, object, file)
|
20
|
-
end
|
20
|
+
return put_multipart_object(bucket, object, file) if file.size > 104_857_600
|
21
21
|
|
22
22
|
body = file.read
|
23
23
|
|
@@ -52,7 +52,7 @@ module Fog
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def put_folder(bucket, folder, endpoint)
|
55
|
-
if nil
|
55
|
+
if endpoint.nil?
|
56
56
|
location = get_bucket_location(bucket)
|
57
57
|
endpoint = 'http://' + location + '.aliyuncs.com'
|
58
58
|
end
|
@@ -74,19 +74,15 @@ module Fog
|
|
74
74
|
|
75
75
|
# find the right uploadid
|
76
76
|
uploads = list_multipart_uploads(bucket, endpoint)
|
77
|
-
|
78
|
-
upload = uploads.find { |tmpupload| tmpupload['Key'][0] == object }
|
79
|
-
else
|
80
|
-
upload = nil
|
81
|
-
end
|
77
|
+
upload = (uploads&.find { |tmpupload| tmpupload['Key'][0] == object })
|
82
78
|
|
83
79
|
parts = nil
|
84
80
|
uploadedSize = 0
|
85
81
|
start_partNumber = 1
|
86
|
-
if nil
|
82
|
+
if !upload.nil?
|
87
83
|
uploadId = upload['UploadId'][0]
|
88
84
|
parts = list_parts(bucket, object, endpoint, uploadId)
|
89
|
-
if
|
85
|
+
if !parts.nil? && !parts.empty?
|
90
86
|
if parts[-1]['Size'][0].to_i != 5_242_880
|
91
87
|
# the part is the last one, if its size is over 5m, then finish this upload
|
92
88
|
complete_multipart_upload(bucket, object, endpoint, uploadId)
|
@@ -117,7 +113,7 @@ module Fog
|
|
117
113
|
end
|
118
114
|
|
119
115
|
def initiate_multipart_upload(bucket, object, endpoint)
|
120
|
-
if nil
|
116
|
+
if endpoint.nil?
|
121
117
|
location = get_bucket_location(bucket)
|
122
118
|
endpoint = 'http://' + location + '.aliyuncs.com'
|
123
119
|
end
|
@@ -135,7 +131,7 @@ module Fog
|
|
135
131
|
end
|
136
132
|
|
137
133
|
def upload_part(bucket, object, endpoint, partNumber, uploadId, body)
|
138
|
-
if nil
|
134
|
+
if endpoint.nil?
|
139
135
|
location = get_bucket_location(bucket)
|
140
136
|
endpoint = 'http://' + location + '.aliyuncs.com'
|
141
137
|
end
|
@@ -153,7 +149,7 @@ module Fog
|
|
153
149
|
end
|
154
150
|
|
155
151
|
def complete_multipart_upload(bucket, object, endpoint, uploadId)
|
156
|
-
if nil
|
152
|
+
if endpoint.nil?
|
157
153
|
location = get_bucket_location(bucket)
|
158
154
|
endpoint = 'http://' + location + '.aliyuncs.com'
|
159
155
|
end
|
@@ -181,8 +177,7 @@ module Fog
|
|
181
177
|
end
|
182
178
|
|
183
179
|
class Mock
|
184
|
-
def put_object(object, file = nil, options = {})
|
185
|
-
end
|
180
|
+
def put_object(object, file = nil, options = {}); end
|
186
181
|
end
|
187
182
|
end
|
188
183
|
end
|
data/lib/fog/aliyun/storage.rb
CHANGED
@@ -1,29 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xmlsimple'
|
2
4
|
|
3
5
|
module Fog
|
4
6
|
module Storage
|
5
7
|
class Aliyun < Fog::Service
|
6
|
-
|
7
8
|
DEFAULT_REGION = 'cn-hangzhou'
|
8
9
|
|
9
10
|
DEFAULT_SCHEME = 'http'
|
10
11
|
DEFAULT_SCHEME_PORT = {
|
11
|
-
|
12
|
-
|
13
|
-
}
|
12
|
+
'http' => 80,
|
13
|
+
'https' => 443
|
14
|
+
}.freeze
|
14
15
|
|
15
16
|
recognizes :aliyun_oss_endpoint,
|
16
17
|
:aliyun_oss_location,
|
17
18
|
:aliyun_region_id
|
18
|
-
requires
|
19
|
-
|
20
|
-
|
19
|
+
requires :aliyun_accesskey_id,
|
20
|
+
:aliyun_accesskey_secret,
|
21
|
+
:aliyun_oss_bucket
|
21
22
|
|
22
23
|
model_path 'fog/aliyun/models/storage'
|
23
|
-
model
|
24
|
-
collection
|
25
|
-
model
|
26
|
-
collection
|
24
|
+
model :directory
|
25
|
+
collection :directories
|
26
|
+
model :file
|
27
|
+
collection :files
|
27
28
|
|
28
29
|
request_path 'fog/aliyun/requests/storage'
|
29
30
|
request :copy_object
|
@@ -70,11 +71,11 @@ module Fog
|
|
70
71
|
|
71
72
|
def initialize(options = {})
|
72
73
|
# initialize the parameters
|
73
|
-
@aliyun_region_id
|
74
|
-
@aliyun_oss_endpoint
|
75
|
-
@aliyun_accesskey_id
|
74
|
+
@aliyun_region_id = options[:aliyun_region_id] || options[:aliyun_oss_location] || DEFAULT_REGION
|
75
|
+
@aliyun_oss_endpoint = options[:aliyun_oss_endpoint] || region_to_endpoint(@aliyun_region_id)
|
76
|
+
@aliyun_accesskey_id = options[:aliyun_accesskey_id]
|
76
77
|
@aliyun_accesskey_secret = options[:aliyun_accesskey_secret]
|
77
|
-
@aliyun_oss_bucket
|
78
|
+
@aliyun_oss_bucket = options[:aliyun_oss_bucket]
|
78
79
|
|
79
80
|
# check for the parameters
|
80
81
|
missing_credentials = []
|
@@ -87,15 +88,13 @@ module Fog
|
|
87
88
|
|
88
89
|
endpoint = @aliyun_oss_endpoint
|
89
90
|
|
90
|
-
|
91
|
-
@aliyun_oss_endpoint = "#{DEFAULT_SCHEME}://#{endpoint}"
|
92
|
-
end
|
91
|
+
@aliyun_oss_endpoint = "#{DEFAULT_SCHEME}://#{endpoint}" unless endpoint.start_with?(DEFAULT_SCHEME)
|
93
92
|
|
94
93
|
uri = URI.parse(@aliyun_oss_endpoint)
|
95
|
-
@host
|
96
|
-
@path
|
94
|
+
@host = uri.host
|
95
|
+
@path = uri.path
|
97
96
|
@scheme = uri.scheme || DEFAULT_SCHEME
|
98
|
-
@port
|
97
|
+
@port = uri.port || DEFAULT_SCHEME_PORT[@scheme]
|
99
98
|
|
100
99
|
@persistent = options[:persistent] || false
|
101
100
|
end
|
@@ -104,12 +103,12 @@ module Fog
|
|
104
103
|
@connection.reset
|
105
104
|
end
|
106
105
|
|
107
|
-
def region_to_endpoint(region=nil)
|
106
|
+
def region_to_endpoint(region = nil)
|
108
107
|
case region.to_s
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
when ''
|
109
|
+
"oss-#{DEFAULT_REGION}.aliyuncs.com"
|
110
|
+
else
|
111
|
+
"oss-#{region}.aliyuncs.com"
|
113
112
|
end
|
114
113
|
end
|
115
114
|
|
@@ -121,14 +120,14 @@ module Fog
|
|
121
120
|
endpoint = params[:endpoint]
|
122
121
|
if endpoint
|
123
122
|
uri = URI.parse(endpoint)
|
124
|
-
host
|
125
|
-
path
|
126
|
-
port
|
123
|
+
host = uri.host
|
124
|
+
path = uri.path
|
125
|
+
port = uri.port
|
127
126
|
scheme = uri.scheme
|
128
127
|
else
|
129
|
-
host
|
130
|
-
path
|
131
|
-
port
|
128
|
+
host = @host
|
129
|
+
path = @path
|
130
|
+
port = @port
|
132
131
|
scheme = @scheme
|
133
132
|
end
|
134
133
|
|
@@ -144,10 +143,8 @@ module Fog
|
|
144
143
|
|
145
144
|
begin
|
146
145
|
headers = ''
|
147
|
-
|
148
|
-
|
149
|
-
headers += "#{k}:#{v}\n" if k != 'Range'
|
150
|
-
end
|
146
|
+
params[:headers]&.each do |k, v|
|
147
|
+
headers += "#{k}:#{v}\n" if k != 'Range'
|
151
148
|
end
|
152
149
|
signature = sign(method, date, contentType, params[:resource], headers)
|
153
150
|
response = @connection.request(params.merge(headers: {
|
@@ -179,22 +176,14 @@ module Fog
|
|
179
176
|
'/'
|
180
177
|
end
|
181
178
|
|
182
|
-
canonicalizedOSSHeaders =
|
183
|
-
headers
|
184
|
-
else
|
185
|
-
''
|
186
|
-
end
|
179
|
+
canonicalizedOSSHeaders = headers || ''
|
187
180
|
|
188
|
-
contentTypeStr =
|
189
|
-
contentType
|
190
|
-
else
|
191
|
-
''
|
192
|
-
end
|
181
|
+
contentTypeStr = contentType || ''
|
193
182
|
|
194
183
|
stringToSign = method + "\n" + contentmd5 + "\n" + contentTypeStr + "\n" + date + "\n" + canonicalizedOSSHeaders + canonicalizedResource
|
195
184
|
|
196
|
-
digVer =
|
197
|
-
digest =
|
185
|
+
digVer = OpenSSL::Digest.new('sha1')
|
186
|
+
digest = OpenSSL::HMAC.digest(digVer, @aliyun_accesskey_secret, stringToSign)
|
198
187
|
signature = Base64.encode64(digest)
|
199
188
|
signature[-1] = ''
|
200
189
|
|
@@ -204,11 +193,11 @@ module Fog
|
|
204
193
|
|
205
194
|
class Mock
|
206
195
|
def initialize(options = {})
|
207
|
-
@aliyun_oss_endpoint
|
208
|
-
@aliyun_region_id
|
209
|
-
@aliyun_accesskey_id
|
196
|
+
@aliyun_oss_endpoint = options[:aliyun_oss_endpoint]
|
197
|
+
@aliyun_region_id = options[:aliyun_region_id]
|
198
|
+
@aliyun_accesskey_id = options[:aliyun_accesskey_id]
|
210
199
|
@aliyun_accesskey_secret = options[:aliyun_accesskey_secret]
|
211
|
-
@aliyun_oss_bucket
|
200
|
+
@aliyun_oss_bucket = options[:aliyun_oss_bucket]
|
212
201
|
|
213
202
|
# missing_credentials = Array.new
|
214
203
|
# missing_credentials << :aliyun_oss_endpoint unless @aliyun_oss_endpoint
|