fog-aliyun 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +114 -0
- data/README.md +61 -3
- data/fog-aliyun.gemspec +9 -4
- data/lib/fog/aliyun/compute.rb +34 -10
- data/lib/fog/aliyun/models/compute/flavor.rb +28 -0
- data/lib/fog/aliyun/models/compute/flavors.rb +13 -0
- data/lib/fog/aliyun/models/compute/image.rb +3 -1
- data/lib/fog/aliyun/models/compute/server.rb +13 -1
- data/lib/fog/aliyun/models/compute/servers.rb +2 -1
- data/lib/fog/aliyun/models/compute/vpcs.rb +1 -1
- data/lib/fog/aliyun/models/storage/directories.rb +34 -17
- data/lib/fog/aliyun/models/storage/directory.rb +102 -14
- data/lib/fog/aliyun/models/storage/file.rb +130 -120
- data/lib/fog/aliyun/models/storage/files.rb +69 -128
- data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +1 -1
- data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +1 -1
- data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +1 -1
- data/lib/fog/aliyun/requests/compute/attach_disk.rb +4 -2
- data/lib/fog/aliyun/requests/compute/create_disk.rb +2 -2
- data/lib/fog/aliyun/requests/compute/create_image.rb +1 -1
- data/lib/fog/aliyun/requests/compute/create_security_group.rb +1 -1
- data/lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb +5 -3
- data/lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb +4 -2
- data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +5 -3
- data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +4 -2
- data/lib/fog/aliyun/requests/compute/create_server.rb +23 -12
- data/lib/fog/aliyun/requests/compute/create_snapshot.rb +1 -1
- data/lib/fog/aliyun/requests/compute/create_vpc.rb +4 -2
- data/lib/fog/aliyun/requests/compute/create_vswitch.rb +4 -2
- data/lib/fog/aliyun/requests/compute/delete_disk.rb +1 -1
- data/lib/fog/aliyun/requests/compute/delete_image.rb +1 -1
- data/lib/fog/aliyun/requests/compute/delete_security_group.rb +1 -1
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb +5 -3
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb +4 -2
- data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +5 -3
- data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +4 -2
- data/lib/fog/aliyun/requests/compute/delete_server.rb +1 -1
- data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +1 -1
- data/lib/fog/aliyun/requests/compute/delete_vpc.rb +1 -1
- data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +1 -1
- data/lib/fog/aliyun/requests/compute/detach_disk.rb +4 -2
- data/lib/fog/aliyun/requests/compute/join_security_group.rb +1 -1
- data/lib/fog/aliyun/requests/compute/leave_security_group.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_disks.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_images.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_route_tables.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_security_groups.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_server_types.rb +3 -3
- data/lib/fog/aliyun/requests/compute/list_servers.rb +10 -10
- data/lib/fog/aliyun/requests/compute/list_snapshots.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_vpcs.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_vrouters.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +1 -1
- data/lib/fog/aliyun/requests/compute/list_zones.rb +1 -1
- data/lib/fog/aliyun/requests/compute/modify_vpc.rb +4 -2
- data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +4 -2
- data/lib/fog/aliyun/requests/compute/reboot_server.rb +1 -1
- data/lib/fog/aliyun/requests/compute/release_eip_address.rb +1 -1
- data/lib/fog/aliyun/requests/compute/start_server.rb +1 -1
- data/lib/fog/aliyun/requests/compute/stop_server.rb +1 -1
- data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +1 -1
- data/lib/fog/aliyun/requests/storage/abort_multipart_upload.rb +22 -0
- data/lib/fog/aliyun/requests/storage/complete_multipart_upload.rb +21 -0
- data/lib/fog/aliyun/requests/storage/copy_object.rb +16 -23
- data/lib/fog/aliyun/requests/storage/delete_bucket.rb +5 -14
- data/lib/fog/aliyun/requests/storage/delete_multiple_objects.rb +20 -0
- data/lib/fog/aliyun/requests/storage/delete_object.rb +12 -35
- data/lib/fog/aliyun/requests/storage/get_bucket.rb +30 -110
- data/lib/fog/aliyun/requests/storage/get_bucket_location.rb +33 -0
- data/lib/fog/aliyun/requests/storage/get_object.rb +29 -24
- data/lib/fog/aliyun/requests/storage/get_object_acl.rb +30 -0
- data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +14 -15
- data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +14 -15
- data/lib/fog/aliyun/requests/storage/get_service.rb +13 -0
- data/lib/fog/aliyun/requests/storage/head_object.rb +27 -18
- data/lib/fog/aliyun/requests/storage/initiate_multipart_upload.rb +19 -0
- data/lib/fog/aliyun/requests/storage/list_buckets.rb +8 -26
- data/lib/fog/aliyun/requests/storage/list_objects.rb +14 -73
- data/lib/fog/aliyun/requests/storage/put_bucket.rb +4 -10
- data/lib/fog/aliyun/requests/storage/put_object.rb +18 -162
- data/lib/fog/aliyun/requests/storage/upload_part.rb +24 -0
- data/lib/fog/aliyun/storage.rb +57 -29
- data/lib/fog/aliyun/version.rb +1 -1
- data/lib/fog/aliyun.rb +6 -9
- data/lib/fog/bin/aliyun.rb +1 -1
- metadata +118 -47
- data/lib/fog/aliyun/requests/storage/delete_container.rb +0 -33
- data/lib/fog/aliyun/requests/storage/get_container.rb +0 -56
- data/lib/fog/aliyun/requests/storage/get_containers.rb +0 -60
- data/lib/fog/aliyun/requests/storage/put_container.rb +0 -32
@@ -1,46 +1,23 @@
|
|
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
|
#
|
9
9
|
# ==== Parameters
|
10
|
-
# *
|
10
|
+
# * bucket_name<~String> - Name of bucket to delete
|
11
|
+
# * object_name<~String> - Name of object to delete
|
11
12
|
#
|
12
|
-
def delete_object(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
method: 'DELETE',
|
21
|
-
path: object,
|
22
|
-
bucket: bucket,
|
23
|
-
resource: resource,
|
24
|
-
endpoint: endpoint
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
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
|
-
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
|
-
)
|
13
|
+
def delete_object(bucket_name, object_name, options = {})
|
14
|
+
# TODO Support versionId
|
15
|
+
# if version_id = options.delete('versionId')
|
16
|
+
# query = {'versionId' => version_id}
|
17
|
+
# else
|
18
|
+
# query = {}
|
19
|
+
# end
|
20
|
+
@oss_http.delete({:bucket => bucket_name, :object => object_name}, {:headers => options})
|
44
21
|
end
|
45
22
|
end
|
46
23
|
end
|
@@ -1,131 +1,51 @@
|
|
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
|
8
|
-
|
9
|
-
endpoint = 'http://' + location + '.aliyuncs.com'
|
10
|
-
resource = bucket + '/'
|
11
|
-
ret = request(
|
12
|
-
expects: [200, 203],
|
13
|
-
method: 'GET',
|
14
|
-
bucket: bucket,
|
15
|
-
resource: resource,
|
16
|
-
endpoint: endpoint
|
17
|
-
)
|
18
|
-
xml = ret.data[:body]
|
19
|
-
XmlSimple.xml_in(xml)
|
7
|
+
def bucket_exists?(bucket_name)
|
8
|
+
@oss_client.bucket_exists?(bucket_name)
|
20
9
|
end
|
21
10
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
11
|
+
def get_bucket(bucket_name, options = {})
|
12
|
+
unless bucket_name
|
13
|
+
raise ArgumentError.new('bucket_name is required')
|
14
|
+
end
|
15
|
+
|
16
|
+
# Set the GetBucket max limitation to 1000
|
17
|
+
maxKeys = options[:max_keys] || 1000
|
18
|
+
maxKeys = maxKeys.to_i
|
19
|
+
maxKeys = [maxKeys, 1000].min
|
20
|
+
|
21
|
+
options[:limit] = maxKeys
|
22
|
+
options.delete(:max_keys)
|
23
|
+
|
24
|
+
@oss_protocol.list_objects(bucket_name, options)
|
33
25
|
end
|
34
26
|
|
35
|
-
def get_bucket_acl(
|
36
|
-
|
37
|
-
endpoint = 'http://' + location + '.aliyuncs.com'
|
38
|
-
attribute = '?acl'
|
39
|
-
resource = bucket + '/' + attribute
|
40
|
-
ret = request(
|
41
|
-
expects: [200, 203],
|
42
|
-
method: 'GET',
|
43
|
-
path: attribute,
|
44
|
-
bucket: bucket,
|
45
|
-
resource: resource,
|
46
|
-
endpoint: endpoint
|
47
|
-
)
|
48
|
-
XmlSimple.xml_in(ret.data[:body])['AccessControlList'][0]['Grant'][0]
|
27
|
+
def get_bucket_acl(bucket_name)
|
28
|
+
@oss_protocol.get_bucket_acl(bucket_name)
|
49
29
|
end
|
50
30
|
|
51
|
-
def get_bucket_CORSRules(
|
52
|
-
|
53
|
-
endpoint = 'http://' + location + '.aliyuncs.com'
|
54
|
-
attribute = '?cors'
|
55
|
-
resource = bucket + '/' + attribute
|
56
|
-
ret = request(
|
57
|
-
expects: [200, 203, 404],
|
58
|
-
method: 'GET',
|
59
|
-
path: attribute,
|
60
|
-
bucket: bucket,
|
61
|
-
resource: resource,
|
62
|
-
endpoint: endpoint
|
63
|
-
)
|
64
|
-
XmlSimple.xml_in(ret.data[:body])['CORSRule'][0] if ret.data[:status] != 404
|
31
|
+
def get_bucket_CORSRules(bucket_name)
|
32
|
+
@oss_protocol.get_bucket_cors(bucket_name)
|
65
33
|
end
|
66
34
|
|
67
|
-
def get_bucket_lifecycle(
|
68
|
-
|
69
|
-
endpoint = 'http://' + location + '.aliyuncs.com'
|
70
|
-
attribute = '?lifecycle'
|
71
|
-
resource = bucket + '/' + attribute
|
72
|
-
ret = request(
|
73
|
-
expects: [200, 203, 404],
|
74
|
-
method: 'GET',
|
75
|
-
path: attribute,
|
76
|
-
bucket: bucket,
|
77
|
-
resource: resource,
|
78
|
-
endpoint: endpoint
|
79
|
-
)
|
80
|
-
XmlSimple.xml_in(ret.data[:body])['Rule'][0] if ret.data[:status] != 404
|
35
|
+
def get_bucket_lifecycle(bucket_name)
|
36
|
+
@oss_protocol.get_bucket_lifecycle(bucket_name)
|
81
37
|
end
|
82
38
|
|
83
|
-
def get_bucket_logging(
|
84
|
-
|
85
|
-
endpoint = 'http://' + location + '.aliyuncs.com'
|
86
|
-
attribute = '?logging'
|
87
|
-
resource = bucket + '/' + attribute
|
88
|
-
ret = request(
|
89
|
-
expects: [200, 203],
|
90
|
-
method: 'GET',
|
91
|
-
path: attribute,
|
92
|
-
bucket: bucket,
|
93
|
-
resource: resource,
|
94
|
-
endpoint: endpoint
|
95
|
-
)
|
96
|
-
XmlSimple.xml_in(ret.data[:body])['LoggingEnabled'][0]['TargetPrefix']
|
39
|
+
def get_bucket_logging(bucket_name)
|
40
|
+
@oss_protocol.get_bucket_logging(bucket_name)
|
97
41
|
end
|
98
42
|
|
99
|
-
def get_bucket_referer(
|
100
|
-
|
101
|
-
endpoint = 'http://' + location + '.aliyuncs.com'
|
102
|
-
attribute = '?referer'
|
103
|
-
resource = bucket + '/' + attribute
|
104
|
-
ret = request(
|
105
|
-
expects: [200, 203],
|
106
|
-
method: 'GET',
|
107
|
-
path: attribute,
|
108
|
-
bucket: bucket,
|
109
|
-
resource: resource,
|
110
|
-
endpoint: endpoint
|
111
|
-
)
|
112
|
-
XmlSimple.xml_in(ret.data[:body])
|
43
|
+
def get_bucket_referer(bucket_name)
|
44
|
+
@oss_protocol.get_bucket_referer(bucket_name)
|
113
45
|
end
|
114
46
|
|
115
|
-
def get_bucket_website(
|
116
|
-
|
117
|
-
endpoint = 'http://' + location + '.aliyuncs.com'
|
118
|
-
attribute = '?website'
|
119
|
-
resource = bucket + '/' + attribute
|
120
|
-
ret = request(
|
121
|
-
expects: [200, 203, 404],
|
122
|
-
method: 'GET',
|
123
|
-
path: attribute,
|
124
|
-
bucket: bucket,
|
125
|
-
resource: resource,
|
126
|
-
endpoint: endpoint
|
127
|
-
)
|
128
|
-
XmlSimple.xml_in(ret.data[:body]) if ret.data[:status] != 404
|
47
|
+
def get_bucket_website(bucket_name)
|
48
|
+
@oss_protocol.get_bucket_website(bucket_name)
|
129
49
|
end
|
130
50
|
end
|
131
51
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
module Fog
|
3
|
+
module Aliyun
|
4
|
+
class Storage
|
5
|
+
class Real
|
6
|
+
|
7
|
+
# Get location constraint for an OSS bucket
|
8
|
+
#
|
9
|
+
# @param bucket_name [String] name of bucket to get location constraint for
|
10
|
+
#
|
11
|
+
# @see https://help.aliyun.com/document_detail/31967.html
|
12
|
+
#
|
13
|
+
# note: The OSS Ruby sdk does not support get_bucket_location and there needs to parse response
|
14
|
+
|
15
|
+
def get_bucket_location(bucket_name)
|
16
|
+
data = @oss_http.get({:bucket => bucket_name, :sub_res => { 'location' => nil} }, {})
|
17
|
+
doc = parse_xml(data.body)
|
18
|
+
doc.at_css("LocationConstraint").text
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def parse_xml(content)
|
24
|
+
doc = Nokogiri::XML(content) do |config|
|
25
|
+
config.options |= Nokogiri::XML::ParseOptions::NOBLANKS
|
26
|
+
end
|
27
|
+
|
28
|
+
doc
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,40 +1,45 @@
|
|
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
|
#
|
9
9
|
# ==== Parameters
|
10
|
-
# *
|
10
|
+
# * object_name<~String> - Name of object to look for
|
11
11
|
#
|
12
|
-
def get_object(
|
12
|
+
def get_object(bucket_name, object_name, options = {}, &block)
|
13
13
|
options = options.reject { |_key, value| value.nil? }
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
unless bucket_name
|
15
|
+
raise ArgumentError.new('bucket_name is required')
|
16
|
+
end
|
17
|
+
unless object_name
|
18
|
+
raise ArgumentError.new('object_name is required')
|
19
|
+
end
|
20
|
+
# Using OSS ruby SDK to fix performance issue
|
21
|
+
http_options = { :headers => {} }
|
22
|
+
http_options[:query] = options.delete('query') || {}
|
23
|
+
|
24
|
+
http_options[:headers].merge!(options)
|
25
|
+
if options['If-Modified-Since']
|
26
|
+
http_options[:headers]['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header
|
27
|
+
end
|
28
|
+
if options['If-Unmodified-Since']
|
29
|
+
http_options[:headers]['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header
|
20
30
|
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
|
|
31
|
-
if
|
32
|
-
|
33
|
-
para[:headers] = { 'Range' => rangeStr }
|
32
|
+
if block_given?
|
33
|
+
http_options[:response_block] = Proc.new {}
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
resources = {
|
37
|
+
:bucket => bucket_name,
|
38
|
+
:object => object_name
|
39
|
+
}
|
40
|
+
|
41
|
+
@oss_http.get(resources, http_options, &block)
|
42
|
+
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fog
|
2
|
+
module Aliyun
|
3
|
+
class Storage
|
4
|
+
class Real
|
5
|
+
|
6
|
+
# Get access control list for an S3 object
|
7
|
+
#
|
8
|
+
# @param bucket_name [String] name of bucket containing object
|
9
|
+
# @param object_name [String] name of object to get access control list for
|
10
|
+
# @param options [Hash]
|
11
|
+
# @option options versionId [String] specify a particular version to retrieve
|
12
|
+
|
13
|
+
def get_object_acl(bucket_name, object_name, options = {})
|
14
|
+
unless bucket_name
|
15
|
+
raise ArgumentError.new('bucket_name is required')
|
16
|
+
end
|
17
|
+
unless object_name
|
18
|
+
raise ArgumentError.new('object_name is required')
|
19
|
+
end
|
20
|
+
|
21
|
+
# At present, sdk does not support versionId
|
22
|
+
# if version_id = options.delete('versionId')
|
23
|
+
# query['versionId'] = version_id
|
24
|
+
# end
|
25
|
+
@oss_protocol.get_object_acl(bucket_name, object_name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,35 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'addressable'
|
4
|
+
|
3
5
|
module Fog
|
4
|
-
module
|
5
|
-
class
|
6
|
+
module Aliyun
|
7
|
+
class Storage
|
6
8
|
class Real
|
7
9
|
# Get an expiring object http url
|
8
10
|
#
|
9
11
|
# ==== Parameters
|
10
|
-
# *
|
11
|
-
# *
|
12
|
+
# * bucket_name<~String> - Name of bucket
|
13
|
+
# * object_name<~String> - Name of object to get expiring url for
|
12
14
|
# * expires<~Integer> - An expiry time for this url
|
13
15
|
#
|
14
16
|
# ==== Returns
|
15
17
|
# * response<~Excon::Response>:
|
16
18
|
# * body<~String> - url for object
|
17
|
-
def get_object_http_url_public(
|
18
|
-
|
19
|
-
|
20
|
-
bucket ||= @aliyun_oss_bucket
|
21
|
-
acl = get_bucket_acl(bucket)
|
22
|
-
location = get_bucket_location(bucket)
|
19
|
+
def get_object_http_url_public(bucket_name, object_name, expires)
|
20
|
+
bucket = @oss_client.get_bucket(bucket_name)
|
21
|
+
acl = bucket.acl()
|
23
22
|
|
24
23
|
if acl == 'private'
|
25
|
-
expires_time = (Time.now.to_i + expires).to_s
|
26
|
-
resource =
|
24
|
+
expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s
|
25
|
+
resource = bucket_name + '/' + object_name
|
27
26
|
signature = sign('GET', expires_time, nil, resource)
|
28
|
-
'http://' +
|
27
|
+
'http://' + bucket_name + '.' + @host + '/' + object_name +
|
29
28
|
'?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
|
30
|
-
'&Signature=' + URI.
|
29
|
+
'&Signature=' + Addressable::URI.encode_component(signature, Addressable::URI::CharacterClasses::UNRESERVED + '|')
|
31
30
|
elsif acl == 'public-read' || acl == 'public-read-write'
|
32
|
-
'http://' +
|
31
|
+
'http://' + bucket_name + '.' + @host + '/' + object_name
|
33
32
|
else
|
34
33
|
'acl is wrong with value:' + acl
|
35
34
|
end
|
@@ -1,35 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'addressable'
|
4
|
+
|
3
5
|
module Fog
|
4
|
-
module
|
5
|
-
class
|
6
|
+
module Aliyun
|
7
|
+
class Storage
|
6
8
|
class Real
|
7
9
|
# Get an expiring object https url from Cloud Files
|
8
10
|
#
|
9
11
|
# ==== Parameters
|
10
|
-
# *
|
11
|
-
# *
|
12
|
+
# * bucket_name<~String> - Name of bucket
|
13
|
+
# * object_name<~String> - Name of object to get expiring url for
|
12
14
|
# * expires<~Integer> - An expiry time for this url
|
13
15
|
#
|
14
16
|
# ==== Returns
|
15
17
|
# * response<~Excon::Response>:
|
16
18
|
# * body<~String> - url for object
|
17
|
-
def get_object_https_url_public(
|
18
|
-
|
19
|
-
|
20
|
-
bucket ||= @aliyun_oss_bucket
|
21
|
-
acl = get_bucket_acl(bucket)
|
22
|
-
location = get_bucket_location(bucket)
|
19
|
+
def get_object_https_url_public(bucket_name, object_name, expires)
|
20
|
+
bucket = @oss_client.get_bucket(bucket_name)
|
21
|
+
acl = bucket.acl()
|
23
22
|
|
24
23
|
if acl == 'private'
|
25
|
-
expires_time = (Time.now.to_i + expires).to_s
|
26
|
-
resource =
|
24
|
+
expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s
|
25
|
+
resource = bucket_name + '/' + object_name
|
27
26
|
signature = sign('GET', expires_time, nil, resource)
|
28
|
-
'https://' +
|
27
|
+
'https://' + bucket_name + '.' + @host + '/' + object_name +
|
29
28
|
'?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
|
30
|
-
'&Signature=' + URI.
|
29
|
+
'&Signature=' + Addressable::URI.encode_component(signature, Addressable::URI::CharacterClasses::UNRESERVED + '|')
|
31
30
|
elsif acl == 'public-read' || acl == 'public-read-write'
|
32
|
-
'https://' +
|
31
|
+
'https://' + bucket_name + '.' + @host + '/' + object_name
|
33
32
|
else
|
34
33
|
'acl is wrong with value:' + acl
|
35
34
|
end
|
@@ -1,29 +1,38 @@
|
|
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
|
#
|
9
9
|
# ==== Parameters
|
10
|
-
# *
|
10
|
+
# * object_name<~String> - Name of object to look for
|
11
11
|
#
|
12
|
-
def head_object(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
)
|
26
|
-
|
12
|
+
def head_object(bucket_name, object_name, options={})
|
13
|
+
unless bucket_name
|
14
|
+
raise ArgumentError.new('bucket_name is required')
|
15
|
+
end
|
16
|
+
unless object_name
|
17
|
+
raise ArgumentError.new('object_name is required')
|
18
|
+
end
|
19
|
+
|
20
|
+
# Currently, the ruby sdk does not support versionId
|
21
|
+
# if version_id = options.delete('versionId')
|
22
|
+
# query = {'versionId' => version_id}
|
23
|
+
# end
|
24
|
+
headers = {}
|
25
|
+
headers['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header if options['If-Modified-Since']
|
26
|
+
headers['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header if options['If-Modified-Since']
|
27
|
+
headers.merge!(options)
|
28
|
+
resources = {
|
29
|
+
:bucket => bucket_name,
|
30
|
+
:object => object_name
|
31
|
+
}
|
32
|
+
http_options = {
|
33
|
+
:headers => headers
|
34
|
+
}
|
35
|
+
@oss_http.head(resources, http_options)
|
27
36
|
end
|
28
37
|
end
|
29
38
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fog
|
2
|
+
module Aliyun
|
3
|
+
class Storage
|
4
|
+
class Real
|
5
|
+
# Initiate a multipart upload
|
6
|
+
#
|
7
|
+
# @param bucket_name [String] Name of bucket to create
|
8
|
+
# @param object_name [String] Name of object to create
|
9
|
+
# @param options [Hash]
|
10
|
+
#
|
11
|
+
# @see https://help.aliyun.com/document_detail/31992.html
|
12
|
+
#
|
13
|
+
def initiate_multipart_upload(bucket_name, object_name, options = {})
|
14
|
+
@oss_protocol.initiate_multipart_upload(bucket_name, object_name, options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,35 +1,17 @@
|
|
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
|
def list_buckets(options = {})
|
8
|
-
|
9
|
-
|
10
|
-
maxKeys =
|
8
|
+
maxKeys = options[:max_keys] || 1000
|
9
|
+
maxKeys = maxKeys.to_i
|
10
|
+
maxKeys = [maxKeys, 1000].min
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
path += '&marker=' + marker if marker
|
16
|
-
path += '&max-keys=' + maxKeys if maxKeys
|
17
|
-
|
18
|
-
elsif marker
|
19
|
-
path += '?marker=' + marker
|
20
|
-
path += '&max-keys=' + maxKeys if maxKeys
|
21
|
-
|
22
|
-
elsif maxKeys
|
23
|
-
path += '?max-keys=' + maxKeys
|
24
|
-
end
|
25
|
-
|
26
|
-
ret = request(
|
27
|
-
expects: [200, 203],
|
28
|
-
method: 'GET',
|
29
|
-
path: path
|
30
|
-
)
|
31
|
-
xml = ret.data[:body]
|
32
|
-
XmlSimple.xml_in(xml)['Buckets'][0]
|
12
|
+
options[:limit] = maxKeys
|
13
|
+
options.delete(:max_keys)
|
14
|
+
@oss_protocol.list_buckets(options)
|
33
15
|
end
|
34
16
|
end
|
35
17
|
end
|