fog-xiaozhu 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +149 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +312 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/fog-aliyun.gemspec +33 -0
- data/lib/fog/aliyun/compute.rb +424 -0
- data/lib/fog/aliyun/models/compute/eip_address.rb +57 -0
- data/lib/fog/aliyun/models/compute/eip_addresses.rb +28 -0
- data/lib/fog/aliyun/models/compute/image.rb +66 -0
- data/lib/fog/aliyun/models/compute/images.rb +25 -0
- data/lib/fog/aliyun/models/compute/route_entry.rb +26 -0
- data/lib/fog/aliyun/models/compute/route_entrys.rb +41 -0
- data/lib/fog/aliyun/models/compute/route_table.rb +30 -0
- data/lib/fog/aliyun/models/compute/route_tables.rb +27 -0
- data/lib/fog/aliyun/models/compute/security_group.rb +81 -0
- data/lib/fog/aliyun/models/compute/security_group_rule.rb +47 -0
- data/lib/fog/aliyun/models/compute/security_group_rules.rb +23 -0
- data/lib/fog/aliyun/models/compute/security_groups.rb +32 -0
- data/lib/fog/aliyun/models/compute/server.rb +70 -0
- data/lib/fog/aliyun/models/compute/servers.rb +42 -0
- data/lib/fog/aliyun/models/compute/snapshot.rb +52 -0
- data/lib/fog/aliyun/models/compute/snapshots.rb +38 -0
- data/lib/fog/aliyun/models/compute/volume.rb +101 -0
- data/lib/fog/aliyun/models/compute/volumes.rb +135 -0
- data/lib/fog/aliyun/models/compute/vpc.rb +77 -0
- data/lib/fog/aliyun/models/compute/vpcs.rb +80 -0
- data/lib/fog/aliyun/models/compute/vrouter.rb +35 -0
- data/lib/fog/aliyun/models/compute/vrouters.rb +61 -0
- data/lib/fog/aliyun/models/compute/vswitch.rb +70 -0
- data/lib/fog/aliyun/models/compute/vswitches.rb +80 -0
- data/lib/fog/aliyun/models/storage/directories.rb +39 -0
- data/lib/fog/aliyun/models/storage/directory.rb +48 -0
- data/lib/fog/aliyun/models/storage/file.rb +192 -0
- data/lib/fog/aliyun/models/storage/files.rb +193 -0
- data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +54 -0
- data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +39 -0
- data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +49 -0
- data/lib/fog/aliyun/requests/compute/attach_disk.rb +79 -0
- data/lib/fog/aliyun/requests/compute/create_disk.rb +137 -0
- data/lib/fog/aliyun/requests/compute/create_image.rb +79 -0
- data/lib/fog/aliyun/requests/compute/create_security_group.rb +77 -0
- data/lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb +63 -0
- data/lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb +71 -0
- data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +63 -0
- data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +71 -0
- data/lib/fog/aliyun/requests/compute/create_server.rb +186 -0
- data/lib/fog/aliyun/requests/compute/create_snapshot.rb +46 -0
- data/lib/fog/aliyun/requests/compute/create_vpc.rb +46 -0
- data/lib/fog/aliyun/requests/compute/create_vpn_connection.rb +58 -0
- data/lib/fog/aliyun/requests/compute/create_vpn_customergateway.rb +48 -0
- data/lib/fog/aliyun/requests/compute/create_vswitch.rb +54 -0
- data/lib/fog/aliyun/requests/compute/delete_disk.rb +41 -0
- data/lib/fog/aliyun/requests/compute/delete_image.rb +31 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group.rb +51 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb +63 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb +71 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +63 -0
- data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +71 -0
- data/lib/fog/aliyun/requests/compute/delete_server.rb +48 -0
- data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +31 -0
- data/lib/fog/aliyun/requests/compute/delete_vpc.rb +35 -0
- data/lib/fog/aliyun/requests/compute/delete_vpn_connection.rb +35 -0
- data/lib/fog/aliyun/requests/compute/delete_vpn_customergateway.rb +35 -0
- data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +35 -0
- data/lib/fog/aliyun/requests/compute/detach_disk.rb +41 -0
- data/lib/fog/aliyun/requests/compute/join_security_group.rb +40 -0
- data/lib/fog/aliyun/requests/compute/leave_security_group.rb +40 -0
- data/lib/fog/aliyun/requests/compute/list_disks.rb +150 -0
- data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +55 -0
- data/lib/fog/aliyun/requests/compute/list_images.rb +82 -0
- data/lib/fog/aliyun/requests/compute/list_route_tables.rb +64 -0
- data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +73 -0
- data/lib/fog/aliyun/requests/compute/list_security_groups.rb +78 -0
- data/lib/fog/aliyun/requests/compute/list_server_types.rb +77 -0
- data/lib/fog/aliyun/requests/compute/list_servers.rb +71 -0
- data/lib/fog/aliyun/requests/compute/list_snapshots.rb +97 -0
- data/lib/fog/aliyun/requests/compute/list_vpcs.rb +47 -0
- data/lib/fog/aliyun/requests/compute/list_vpn_connections.rb +49 -0
- data/lib/fog/aliyun/requests/compute/list_vpn_customergateways.rb +43 -0
- data/lib/fog/aliyun/requests/compute/list_vpn_gateways.rb +49 -0
- data/lib/fog/aliyun/requests/compute/list_vrouters.rb +61 -0
- data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +50 -0
- data/lib/fog/aliyun/requests/compute/list_zones.rb +44 -0
- data/lib/fog/aliyun/requests/compute/modify_vpc.rb +73 -0
- data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +45 -0
- data/lib/fog/aliyun/requests/compute/reboot_server.rb +43 -0
- data/lib/fog/aliyun/requests/compute/release_eip_address.rb +29 -0
- data/lib/fog/aliyun/requests/compute/start_server.rb +41 -0
- data/lib/fog/aliyun/requests/compute/stop_server.rb +41 -0
- data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +49 -0
- data/lib/fog/aliyun/requests/storage/copy_object.rb +39 -0
- data/lib/fog/aliyun/requests/storage/delete_bucket.rb +30 -0
- data/lib/fog/aliyun/requests/storage/delete_container.rb +35 -0
- data/lib/fog/aliyun/requests/storage/delete_object.rb +51 -0
- data/lib/fog/aliyun/requests/storage/get_bucket.rb +141 -0
- data/lib/fog/aliyun/requests/storage/get_container.rb +60 -0
- data/lib/fog/aliyun/requests/storage/get_containers.rb +64 -0
- data/lib/fog/aliyun/requests/storage/get_object.rb +45 -0
- data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +43 -0
- data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +43 -0
- data/lib/fog/aliyun/requests/storage/head_object.rb +34 -0
- data/lib/fog/aliyun/requests/storage/list_buckets.rb +40 -0
- data/lib/fog/aliyun/requests/storage/list_objects.rb +91 -0
- data/lib/fog/aliyun/requests/storage/put_bucket.rb +22 -0
- data/lib/fog/aliyun/requests/storage/put_container.rb +35 -0
- data/lib/fog/aliyun/requests/storage/put_object.rb +189 -0
- data/lib/fog/aliyun/storage.rb +233 -0
- data/lib/fog/aliyun/version.rb +5 -0
- data/lib/fog/aliyun.rb +19 -0
- data/lib/fog/bin/aliyun.rb +31 -0
- metadata +311 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Stop the server.
|
6
|
+
#
|
7
|
+
# === Parameters
|
8
|
+
# * server_id <~String> - The ID of the server to be stopped.
|
9
|
+
# === Returns
|
10
|
+
# * success <~Boolean>
|
11
|
+
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.3.1.DGkmH7#/pub/ecs/open-api/instance&stopinstance]
|
12
|
+
def stop_server(server_id)
|
13
|
+
_action = 'StopInstance'
|
14
|
+
_sigNonce = randonStr
|
15
|
+
_time = Time.new.utc
|
16
|
+
|
17
|
+
_parameters = defalutParameters(_action, _sigNonce, _time)
|
18
|
+
_pathURL = defaultAliyunUri(_action, _sigNonce, _time)
|
19
|
+
|
20
|
+
_parameters['InstanceId'] = server_id
|
21
|
+
_pathURL += '&InstanceId=' + server_id
|
22
|
+
|
23
|
+
_signature = sign(@aliyun_accesskey_secret, _parameters)
|
24
|
+
_pathURL += '&Signature=' + _signature
|
25
|
+
|
26
|
+
request(
|
27
|
+
expects: [200, 204],
|
28
|
+
method: 'GET',
|
29
|
+
path: _pathURL
|
30
|
+
)
|
31
|
+
end # def stop_server
|
32
|
+
end # class Real
|
33
|
+
|
34
|
+
class Mock
|
35
|
+
def stop_server(_server_id)
|
36
|
+
true
|
37
|
+
end # def stop_server
|
38
|
+
end # class Mock
|
39
|
+
end # class aliyun
|
40
|
+
end # module Compute
|
41
|
+
end # module Fog
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Disassociate an avalable eip IP address to the given instance.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * server_id<~String> - id of the instance
|
9
|
+
# * allocationId<~String> - id of the EIP
|
10
|
+
# ==== Returns
|
11
|
+
# * response<~Excon::Response>:
|
12
|
+
# * body<~Hash>:
|
13
|
+
# * 'RequestId'<~String> - Id of the request
|
14
|
+
#
|
15
|
+
# {Aliyun API Reference}[https://docs.aliyun.com/?spm=5176.100054.201.106.DGkmH7#/pub/ecs/open-api/network&associateeipaddresss]
|
16
|
+
def unassociate_eip_address(server_id, allocationId, options = {})
|
17
|
+
_action = 'UnassociateEipAddress'
|
18
|
+
_sigNonce = randonStr
|
19
|
+
_time = Time.new.utc
|
20
|
+
|
21
|
+
type = options['instance_type']
|
22
|
+
|
23
|
+
_parameters = defalutParameters(_action, _sigNonce, _time)
|
24
|
+
_pathURL = defaultAliyunUri(_action, _sigNonce, _time)
|
25
|
+
|
26
|
+
_parameters['InstanceId'] = server_id
|
27
|
+
_pathURL += '&InstanceId=' + server_id
|
28
|
+
|
29
|
+
_parameters['AllocationId'] = allocationId
|
30
|
+
_pathURL += '&AllocationId=' + allocationId
|
31
|
+
|
32
|
+
if type
|
33
|
+
_parameters['InstanceType'] = type
|
34
|
+
_pathURL += 'InstanceType=' + type
|
35
|
+
end
|
36
|
+
|
37
|
+
_signature = sign(@aliyun_accesskey_secret, _parameters)
|
38
|
+
_pathURL += '&Signature=' + _signature
|
39
|
+
|
40
|
+
request(
|
41
|
+
expects: [200, 204],
|
42
|
+
method: 'GET',
|
43
|
+
path: _pathURL
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end # aliyun
|
48
|
+
end # compute
|
49
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Copy object
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * source_bucket<~String> - Name of source bucket
|
9
|
+
# * source_object<~String> - Name of source object
|
10
|
+
# * target_bucket<~String> - Name of bucket to create copy in
|
11
|
+
# * target_object<~String> - Name for new copy of object
|
12
|
+
# * options<~Hash> - Additional headers options={}
|
13
|
+
def copy_object(source_bucket, source_object, target_bucket, target_object, options = {})
|
14
|
+
options = options.reject { |_key, value| value.nil? }
|
15
|
+
bucket = options[:bucket]
|
16
|
+
bucket ||= @aliyun_oss_bucket
|
17
|
+
source_bucket ||= bucket
|
18
|
+
target_bucket ||= bucket
|
19
|
+
headers = { 'x-oss-copy-source' => "/#{source_bucket}/#{source_object}" }
|
20
|
+
location = get_bucket_location(target_bucket)
|
21
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
22
|
+
resource = target_bucket + '/' + target_object
|
23
|
+
request(expects: [200, 203],
|
24
|
+
headers: headers,
|
25
|
+
method: 'PUT',
|
26
|
+
path: target_object,
|
27
|
+
bucket: target_bucket,
|
28
|
+
resource: resource,
|
29
|
+
endpoint: endpoint)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Mock
|
34
|
+
def copy_object(source_bucket, source_object, target_bucket, target_object)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Delete an existing bucket
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * bucket<~String> - Name of bucket to delete
|
9
|
+
#
|
10
|
+
def delete_bucket(bucket)
|
11
|
+
location = get_bucket_location(bucket)
|
12
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
13
|
+
resource = bucket + '/'
|
14
|
+
request(
|
15
|
+
expects: 204,
|
16
|
+
method: 'DELETE',
|
17
|
+
bucket: bucket,
|
18
|
+
resource: resource,
|
19
|
+
endpoint: endpoint
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Mock
|
25
|
+
def delete_bucket(bucket)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Delete an existing container
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * container<~String> - Name of container to delete
|
9
|
+
# * options
|
10
|
+
#
|
11
|
+
def delete_container(container, options = {})
|
12
|
+
bucket = options[:bucket]
|
13
|
+
bucket ||= @aliyun_oss_bucket
|
14
|
+
location = get_bucket_location(bucket)
|
15
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
16
|
+
object = container + '/'
|
17
|
+
resource = bucket + '/' + object
|
18
|
+
|
19
|
+
request(
|
20
|
+
expects: 204,
|
21
|
+
method: 'DELETE',
|
22
|
+
path: object,
|
23
|
+
bucket: bucket,
|
24
|
+
resource: resource,
|
25
|
+
endpoint: endpoint
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
class Mock
|
30
|
+
def delete_container(container, options = {})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Delete an existing object
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * object<~String> - Name of object to delete
|
9
|
+
#
|
10
|
+
def delete_object(object, options = {})
|
11
|
+
bucket = options[:bucket]
|
12
|
+
bucket ||= @aliyun_oss_bucket
|
13
|
+
location = get_bucket_location(bucket)
|
14
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
15
|
+
resource = bucket + '/' + object
|
16
|
+
request(
|
17
|
+
expects: 204,
|
18
|
+
method: 'DELETE',
|
19
|
+
path: object,
|
20
|
+
bucket: bucket,
|
21
|
+
resource: resource,
|
22
|
+
endpoint: endpoint
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def abort_multipart_upload(bucket, object, endpoint, uploadid)
|
27
|
+
if nil == endpoint
|
28
|
+
location = get_bucket_location(bucket)
|
29
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
30
|
+
end
|
31
|
+
path = object + '?uploadId=' + uploadid
|
32
|
+
resource = bucket + '/' + path
|
33
|
+
|
34
|
+
ret = request(
|
35
|
+
expects: 204,
|
36
|
+
method: 'DELETE',
|
37
|
+
path: path,
|
38
|
+
bucket: bucket,
|
39
|
+
resource: resource,
|
40
|
+
endpoint: endpoint
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Mock
|
46
|
+
def delete_object(object, options = {})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
def get_bucket(bucket)
|
6
|
+
location = get_bucket_location(bucket)
|
7
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
8
|
+
resource = bucket + '/'
|
9
|
+
ret = request(
|
10
|
+
expects: [200, 203],
|
11
|
+
method: 'GET',
|
12
|
+
bucket: bucket,
|
13
|
+
resource: resource,
|
14
|
+
endpoint: endpoint
|
15
|
+
)
|
16
|
+
xml = ret.data[:body]
|
17
|
+
result = XmlSimple.xml_in(xml)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_bucket_location(bucket)
|
21
|
+
attribute = '?location'
|
22
|
+
resource = bucket + '/' + attribute
|
23
|
+
ret = request(
|
24
|
+
expects: [200, 203],
|
25
|
+
method: 'GET',
|
26
|
+
path: attribute,
|
27
|
+
bucket: bucket,
|
28
|
+
resource: resource
|
29
|
+
)
|
30
|
+
location = XmlSimple.xml_in(ret.data[:body])
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_bucket_acl(bucket)
|
34
|
+
location = get_bucket_location(bucket)
|
35
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
36
|
+
attribute = '?acl'
|
37
|
+
resource = bucket + '/' + attribute
|
38
|
+
ret = request(
|
39
|
+
expects: [200, 203],
|
40
|
+
method: 'GET',
|
41
|
+
path: attribute,
|
42
|
+
bucket: bucket,
|
43
|
+
resource: resource,
|
44
|
+
endpoint: endpoint
|
45
|
+
)
|
46
|
+
acl = XmlSimple.xml_in(ret.data[:body])['AccessControlList'][0]['Grant'][0]
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_bucket_CORSRules(bucket)
|
50
|
+
location = get_bucket_location(bucket)
|
51
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
52
|
+
attribute = '?cors'
|
53
|
+
resource = bucket + '/' + attribute
|
54
|
+
ret = request(
|
55
|
+
expects: [200, 203, 404],
|
56
|
+
method: 'GET',
|
57
|
+
path: attribute,
|
58
|
+
bucket: bucket,
|
59
|
+
resource: resource,
|
60
|
+
endpoint: endpoint
|
61
|
+
)
|
62
|
+
if 404 != ret.data[:status]
|
63
|
+
cors = XmlSimple.xml_in(ret.data[:body])['CORSRule'][0]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_bucket_lifecycle(bucket)
|
68
|
+
location = get_bucket_location(bucket)
|
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
|
+
if 404 != ret.data[:status]
|
81
|
+
lifecycle = XmlSimple.xml_in(ret.data[:body])['Rule'][0]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_bucket_logging(bucket)
|
86
|
+
location = get_bucket_location(bucket)
|
87
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
88
|
+
attribute = '?logging'
|
89
|
+
resource = bucket + '/' + attribute
|
90
|
+
ret = request(
|
91
|
+
expects: [200, 203],
|
92
|
+
method: 'GET',
|
93
|
+
path: attribute,
|
94
|
+
bucket: bucket,
|
95
|
+
resource: resource,
|
96
|
+
endpoint: endpoint
|
97
|
+
)
|
98
|
+
logging = XmlSimple.xml_in(ret.data[:body])['LoggingEnabled'][0]['TargetPrefix']
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_bucket_referer(bucket)
|
102
|
+
location = get_bucket_location(bucket)
|
103
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
104
|
+
attribute = '?referer'
|
105
|
+
resource = bucket + '/' + attribute
|
106
|
+
ret = request(
|
107
|
+
expects: [200, 203],
|
108
|
+
method: 'GET',
|
109
|
+
path: attribute,
|
110
|
+
bucket: bucket,
|
111
|
+
resource: resource,
|
112
|
+
endpoint: endpoint
|
113
|
+
)
|
114
|
+
referer = XmlSimple.xml_in(ret.data[:body])
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_bucket_website(bucket)
|
118
|
+
location = get_bucket_location(bucket)
|
119
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
120
|
+
attribute = '?website'
|
121
|
+
resource = bucket + '/' + attribute
|
122
|
+
ret = request(
|
123
|
+
expects: [200, 203, 404],
|
124
|
+
method: 'GET',
|
125
|
+
path: attribute,
|
126
|
+
bucket: bucket,
|
127
|
+
resource: resource,
|
128
|
+
endpoint: endpoint
|
129
|
+
)
|
130
|
+
if 404 != ret.data[:status]
|
131
|
+
website = XmlSimple.xml_in(ret.data[:body])
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
class Mock
|
136
|
+
def get_bucket(bucket)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
def get_container(container, options = {})
|
6
|
+
options = options.reject { |_key, value| value.nil? }
|
7
|
+
|
8
|
+
bucket = options[:bucket]
|
9
|
+
bucket ||= @aliyun_oss_bucket
|
10
|
+
|
11
|
+
marker = options[:marker]
|
12
|
+
maxKeys = options[:maxKeys]
|
13
|
+
delimiter = '/'
|
14
|
+
|
15
|
+
path = ''
|
16
|
+
|
17
|
+
prefix = if container == '' || container == '.' || container.nil?
|
18
|
+
nil
|
19
|
+
else
|
20
|
+
container + '/'
|
21
|
+
end
|
22
|
+
|
23
|
+
if prefix
|
24
|
+
path += '?prefix=' + prefix
|
25
|
+
path += '&marker=' + marker if marker
|
26
|
+
path += '&max-keys=' + maxKeys if maxKeys
|
27
|
+
path += '&delimiter=' + delimiter if delimiter
|
28
|
+
elsif marker
|
29
|
+
path += '?marker=' + marker
|
30
|
+
path += '&max-keys=' + maxKeys if maxKeys
|
31
|
+
path += '&delimiter=' + delimiter if delimiter
|
32
|
+
elsif maxKeys
|
33
|
+
path += '?max-keys=' + maxKeys
|
34
|
+
path += '&delimiter=' + delimiter if delimiter
|
35
|
+
elsif delimiter
|
36
|
+
path += '?delimiter=' + delimiter
|
37
|
+
end
|
38
|
+
|
39
|
+
location = get_bucket_location(bucket)
|
40
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
41
|
+
resource = bucket + '/'
|
42
|
+
ret = request(
|
43
|
+
expects: [200, 203, 400],
|
44
|
+
method: 'GET',
|
45
|
+
path: path,
|
46
|
+
resource: resource,
|
47
|
+
bucket: bucket
|
48
|
+
)
|
49
|
+
xml = ret.data[:body]
|
50
|
+
result = XmlSimple.xml_in(xml)['CommonPrefixes']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Mock
|
55
|
+
def get_container(container, options = {})
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# List existing storage containers
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * options<~Hash>:
|
9
|
+
# * 'maxKeys'<~Integer> - Upper limit to number of results returned
|
10
|
+
# * 'marker'<~String> - Only return objects with name greater than this value
|
11
|
+
#
|
12
|
+
# ==== Returns
|
13
|
+
#
|
14
|
+
def get_containers(options = {})
|
15
|
+
options = options.reject { |_key, value| value.nil? }
|
16
|
+
bucket = options[:bucket]
|
17
|
+
bucket ||= @aliyun_oss_bucket
|
18
|
+
prefix = options[:prefix]
|
19
|
+
marker = options[:marker]
|
20
|
+
maxKeys = options[:maxKeys]
|
21
|
+
delimiter = '/'
|
22
|
+
|
23
|
+
path = ''
|
24
|
+
if prefix
|
25
|
+
path += '?prefix=' + prefix
|
26
|
+
path += '&marker=' + marker if marker
|
27
|
+
path += '&max-keys=' + maxKeys if maxKeys
|
28
|
+
path += '&delimiter=' + delimiter if delimiter
|
29
|
+
|
30
|
+
elsif marker
|
31
|
+
path += '?marker=' + marker
|
32
|
+
path += '&max-keys=' + maxKeys if maxKeys
|
33
|
+
path += '&delimiter=' + delimiter if delimiter
|
34
|
+
|
35
|
+
elsif maxKeys
|
36
|
+
path += '?max-keys=' + maxKeys
|
37
|
+
path += '&delimiter=' + delimiter if delimiter
|
38
|
+
|
39
|
+
elsif delimiter
|
40
|
+
path += '?delimiter=' + delimiter
|
41
|
+
end
|
42
|
+
|
43
|
+
location = get_bucket_location(bucket)
|
44
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
45
|
+
resource = bucket + '/'
|
46
|
+
ret = request(
|
47
|
+
expects: [200, 203, 400],
|
48
|
+
method: 'GET',
|
49
|
+
path: path,
|
50
|
+
resource: resource,
|
51
|
+
bucket: bucket
|
52
|
+
)
|
53
|
+
xml = ret.data[:body]
|
54
|
+
result = XmlSimple.xml_in(xml)['CommonPrefixes']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Mock
|
59
|
+
def get_containers(options = {})
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Get details for object
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * object<~String> - Name of object to look for
|
9
|
+
#
|
10
|
+
def get_object(object, range = nil, options = {})
|
11
|
+
options = options.reject { |_key, value| value.nil? }
|
12
|
+
bucket = options[:bucket]
|
13
|
+
bucket ||= @aliyun_oss_bucket
|
14
|
+
endpoint = options[:endpoint]
|
15
|
+
if nil == endpoint
|
16
|
+
location = get_bucket_location(bucket)
|
17
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
18
|
+
end
|
19
|
+
resource = bucket + '/' + object
|
20
|
+
para = {
|
21
|
+
expects: [200, 206, 404],
|
22
|
+
method: 'GET',
|
23
|
+
path: object,
|
24
|
+
bucket: bucket,
|
25
|
+
resource: resource,
|
26
|
+
endpoint: endpoint
|
27
|
+
}
|
28
|
+
|
29
|
+
if range
|
30
|
+
rangeStr = 'bytes=' + range
|
31
|
+
para[:headers] = { 'Range' => rangeStr }
|
32
|
+
end
|
33
|
+
|
34
|
+
response = request(para)
|
35
|
+
response.data
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Mock
|
40
|
+
def get_object(object, range = nil, options = {})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Get an expiring object http url
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * container<~String> - Name of container containing object
|
9
|
+
# * object<~String> - Name of object to get expiring url for
|
10
|
+
# * expires<~Time> - An expiry time for this url
|
11
|
+
#
|
12
|
+
# ==== Returns
|
13
|
+
# * response<~Excon::Response>:
|
14
|
+
# * body<~String> - url for object
|
15
|
+
def get_object_http_url_public(object, expires, options = {})
|
16
|
+
options = options.reject { |_key, value| value.nil? }
|
17
|
+
bucket = options[:bucket]
|
18
|
+
bucket ||= @aliyun_oss_bucket
|
19
|
+
acl = get_bucket_acl(bucket)
|
20
|
+
location = get_bucket_location(bucket)
|
21
|
+
|
22
|
+
if 'private' == acl
|
23
|
+
expires_time = (Time.now.to_i + expires).to_s
|
24
|
+
resource = bucket + '/' + object
|
25
|
+
signature = sign('GET', expires_time, nil, resource)
|
26
|
+
url = 'http://' + bucket + '.' + location + '.aliyuncs.com/' + object +
|
27
|
+
'?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
|
28
|
+
'&Signature=' + URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
29
|
+
elsif 'public-read' == acl || 'public-read-write' == acl
|
30
|
+
url = 'http://' + bucket + '.' + location + '.aliyuncs.com/' + object
|
31
|
+
else
|
32
|
+
url = 'acl is wrong with value:' + acl
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Mock
|
38
|
+
def get_object_http_url_public(object, expires, options = {})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Get an expiring object https url from Cloud Files
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * container<~String> - Name of container containing object
|
9
|
+
# * object<~String> - Name of object to get expiring url for
|
10
|
+
# * expires<~Time> - An expiry time for this url
|
11
|
+
#
|
12
|
+
# ==== Returns
|
13
|
+
# * response<~Excon::Response>:
|
14
|
+
# * body<~String> - url for object
|
15
|
+
def get_object_https_url_public(object, expires, options = {})
|
16
|
+
options = options.reject { |_key, value| value.nil? }
|
17
|
+
bucket = options[:bucket]
|
18
|
+
bucket ||= @aliyun_oss_bucket
|
19
|
+
acl = get_bucket_acl(bucket)
|
20
|
+
location = get_bucket_location(bucket)
|
21
|
+
|
22
|
+
if 'private' == acl
|
23
|
+
expires_time = (Time.now.to_i + expires).to_s
|
24
|
+
resource = bucket + '/' + object
|
25
|
+
signature = sign('GET', expires_time, nil, resource)
|
26
|
+
url = 'https://' + bucket + '.' + location + '.aliyuncs.com/' + object +
|
27
|
+
'?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
|
28
|
+
'&Signature=' + URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
|
29
|
+
elsif 'public-read' == acl || 'public-read-write' == acl
|
30
|
+
url = 'https://' + bucket + '.' + location + '.aliyuncs.com/' + object
|
31
|
+
else
|
32
|
+
url = 'acl is wrong with value:' + acl
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Mock
|
38
|
+
def get_object_https_url_public(object, expires, options = {})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Aliyun
|
4
|
+
class Real
|
5
|
+
# Get headers for object
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * object<~String> - Name of object to look for
|
9
|
+
#
|
10
|
+
def head_object(object, options = {})
|
11
|
+
bucket = options[:bucket]
|
12
|
+
bucket ||= @aliyun_oss_bucket
|
13
|
+
location = get_bucket_location(bucket)
|
14
|
+
endpoint = 'http://' + location + '.aliyuncs.com'
|
15
|
+
resource = bucket + '/' + object
|
16
|
+
ret = request(
|
17
|
+
expects: [200, 404],
|
18
|
+
method: 'HEAD',
|
19
|
+
path: object,
|
20
|
+
bucket: bucket,
|
21
|
+
resource: resource,
|
22
|
+
endpoint: endpoint
|
23
|
+
)
|
24
|
+
ret
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Mock
|
29
|
+
def head_object(object, options = {})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|