fog-aliyun 0.3.17 → 0.4.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +35 -2
  4. data/fog-aliyun.gemspec +4 -3
  5. data/lib/fog/aliyun/compute.rb +7 -5
  6. data/lib/fog/aliyun/models/storage/directories.rb +30 -53
  7. data/lib/fog/aliyun/models/storage/directory.rb +96 -17
  8. data/lib/fog/aliyun/models/storage/file.rb +127 -126
  9. data/lib/fog/aliyun/models/storage/files.rb +43 -124
  10. data/lib/fog/aliyun/requests/compute/attach_disk.rb +3 -1
  11. data/lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb +4 -2
  12. data/lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb +3 -1
  13. data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +4 -2
  14. data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +3 -1
  15. data/lib/fog/aliyun/requests/compute/create_vpc.rb +3 -1
  16. data/lib/fog/aliyun/requests/compute/create_vswitch.rb +3 -1
  17. data/lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb +4 -2
  18. data/lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb +3 -1
  19. data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +4 -2
  20. data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +3 -1
  21. data/lib/fog/aliyun/requests/compute/detach_disk.rb +3 -1
  22. data/lib/fog/aliyun/requests/compute/modify_vpc.rb +3 -1
  23. data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +3 -1
  24. data/lib/fog/aliyun/requests/storage/abort_multipart_upload.rb +22 -0
  25. data/lib/fog/aliyun/requests/storage/complete_multipart_upload.rb +21 -0
  26. data/lib/fog/aliyun/requests/storage/copy_object.rb +14 -18
  27. data/lib/fog/aliyun/requests/storage/delete_bucket.rb +3 -9
  28. data/lib/fog/aliyun/requests/storage/delete_multiple_objects.rb +20 -0
  29. data/lib/fog/aliyun/requests/storage/delete_object.rb +10 -11
  30. data/lib/fog/aliyun/requests/storage/get_bucket.rb +22 -99
  31. data/lib/fog/aliyun/requests/storage/get_bucket_location.rb +33 -0
  32. data/lib/fog/aliyun/requests/storage/get_object.rb +20 -12
  33. data/lib/fog/aliyun/requests/storage/get_object_acl.rb +30 -0
  34. data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +9 -10
  35. data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +9 -10
  36. data/lib/fog/aliyun/requests/storage/get_service.rb +13 -0
  37. data/lib/fog/aliyun/requests/storage/head_object.rb +25 -13
  38. data/lib/fog/aliyun/requests/storage/initiate_multipart_upload.rb +19 -0
  39. data/lib/fog/aliyun/requests/storage/list_buckets.rb +5 -25
  40. data/lib/fog/aliyun/requests/storage/list_objects.rb +10 -62
  41. data/lib/fog/aliyun/requests/storage/put_bucket.rb +2 -8
  42. data/lib/fog/aliyun/requests/storage/put_object.rb +16 -122
  43. data/lib/fog/aliyun/requests/storage/upload_part.rb +24 -0
  44. data/lib/fog/aliyun/storage.rb +20 -4
  45. data/lib/fog/aliyun/version.rb +1 -1
  46. metadata +31 -19
  47. data/lib/fog/aliyun/requests/storage/delete_container.rb +0 -30
  48. data/lib/fog/aliyun/requests/storage/get_container.rb +0 -57
  49. data/lib/fog/aliyun/requests/storage/get_containers.rb +0 -61
  50. data/lib/fog/aliyun/requests/storage/put_container.rb +0 -29
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable'
4
+
3
5
  module Fog
4
6
  module Compute
5
7
  class Aliyun
@@ -19,7 +21,7 @@ module Fog
19
21
 
20
22
  parameters['CidrBlock'] = cidrBlock
21
23
  pathUrl += '&CidrBlock='
22
- pathUrl += URI.encode(cidrBlock, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
24
+ pathUrl += Addressable::URI.encode_component(cidrBlock, Addressable::URI::CharacterClasses::UNRESERVED + '|')
23
25
 
24
26
  parameters['ZoneId'] = @aliyun_zone_id
25
27
  pathUrl += '&ZoneId='
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable'
4
+
3
5
  module Fog
4
6
  module Compute
5
7
  class Aliyun
@@ -19,7 +21,7 @@ module Fog
19
21
 
20
22
  parameters['DestCidrIp'] = destCidrIp
21
23
  pathUrl += '&DestCidrIp='
22
- pathUrl += URI.encode(destCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
24
+ pathUrl += Addressable::URI.encode_component(destCidrIp, Addressable::URI::CharacterClasses::UNRESERVED + '|')
23
25
  nicType ||= 'intranet'
24
26
  parameters['NicType'] = nicType
25
27
  pathUrl += '&NicType='
@@ -29,7 +31,7 @@ module Fog
29
31
  portRange ||= '-1/-1'
30
32
  parameters['PortRange'] = portRange
31
33
  pathUrl += '&PortRange='
32
- pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
34
+ pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')
33
35
 
34
36
  protocol = option[:protocol]
35
37
  protocol ||= 'all'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable'
4
+
3
5
  module Fog
4
6
  module Compute
5
7
  class Aliyun
@@ -30,7 +32,7 @@ module Fog
30
32
  portRange ||= '-1/-1'
31
33
  parameters['PortRange'] = portRange
32
34
  pathUrl += '&PortRange='
33
- pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
35
+ pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')
34
36
 
35
37
  protocol = option[:protocol]
36
38
  protocol ||= 'all'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable'
4
+
3
5
  module Fog
4
6
  module Compute
5
7
  class Aliyun
@@ -19,7 +21,7 @@ module Fog
19
21
 
20
22
  parameters['SourceCidrIp'] = sourceCidrIp
21
23
  pathUrl += '&SourceCidrIp='
22
- pathUrl += URI.encode(sourceCidrIp, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
24
+ pathUrl += Addressable::URI.encode_component(sourceCidrIp, Addressable::URI::CharacterClasses::UNRESERVED + '|')
23
25
  nicType ||= 'intranet'
24
26
  parameters['NicType'] = nicType
25
27
  pathUrl += '&NicType='
@@ -29,7 +31,7 @@ module Fog
29
31
  portRange ||= '-1/-1'
30
32
  parameters['PortRange'] = portRange
31
33
  pathUrl += '&PortRange='
32
- pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
34
+ pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')
33
35
 
34
36
  protocol = option[:protocol]
35
37
  protocol ||= 'all'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable'
4
+
3
5
  module Fog
4
6
  module Compute
5
7
  class Aliyun
@@ -30,7 +32,7 @@ module Fog
30
32
  portRange ||= '-1/-1'
31
33
  parameters['PortRange'] = portRange
32
34
  pathUrl += '&PortRange='
33
- pathUrl += URI.encode(portRange, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
35
+ pathUrl += Addressable::URI.encode_component(portRange, Addressable::URI::CharacterClasses::UNRESERVED + '|')
34
36
 
35
37
  protocol = option[:protocol]
36
38
  protocol ||= 'all'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable'
4
+
3
5
  module Fog
4
6
  module Compute
5
7
  class Aliyun
@@ -25,7 +27,7 @@ module Fog
25
27
  if device
26
28
  parameters['Device'] = device
27
29
  pathUrl += '&Device='
28
- pathUrl += URI.encode(device, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
30
+ pathUrl += Addressable::URI.encode_component(device, Addressable::URI::CharacterClasses::UNRESERVED + '|')
29
31
  end
30
32
  signature = sign(@aliyun_accesskey_secret, parameters)
31
33
  pathUrl += '&Signature='
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable'
4
+
3
5
  module Fog
4
6
  module Compute
5
7
  class Aliyun
@@ -15,7 +17,7 @@ module Fog
15
17
 
16
18
  parameters['VpcId'] = vpcId
17
19
  pathUrl += '&VpcId='
18
- pathUrl += URI.encode(vpcId, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
20
+ pathUrl += Addressable::URI.encode_component(vpcId, Addressable::URI::CharacterClasses::UNRESERVED + '|')
19
21
  name = options[:name]
20
22
  desc = options[:description]
21
23
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable'
4
+
3
5
  module Fog
4
6
  module Compute
5
7
  class Aliyun
@@ -15,7 +17,7 @@ module Fog
15
17
 
16
18
  parameters['VSwitchId'] = vSwitchId
17
19
  pathUrl += '&VSwitchId='
18
- pathUrl += URI.encode(vpcId, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
20
+ pathUrl += Addressable::URI.encode_component(vpcId, Addressable::URI::CharacterClasses::UNRESERVED + '|')
19
21
  name = options[:name]
20
22
  desc = options[:description]
21
23
 
@@ -0,0 +1,22 @@
1
+
2
+ module Fog
3
+ module Aliyun
4
+ class Storage
5
+ class Real
6
+ #
7
+ # Abort a multipart upload
8
+ #
9
+ # @param [String] bucket_name Name of bucket to abort multipart upload on
10
+ # @param [String] object_name Name of object to abort multipart upload on
11
+ # @param [String] upload_id Id of upload to add part to
12
+ #
13
+ # @see https://help.aliyun.com/document_detail/31996.html
14
+ #
15
+ def abort_multipart_upload(bucket_name, object_name, upload_id)
16
+ @oss_protocol.abort_multipart_upload(bucket_name, object_name, upload_id)
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+
2
+ module Fog
3
+ module Aliyun
4
+ class Storage
5
+ class Real
6
+ # Complete a multipart upload
7
+ #
8
+ # @param [String] bucket_name Name of bucket to complete multipart upload for
9
+ # @param [String] object_name Name of object to complete multipart upload for
10
+ # @param [String] upload_id Id of upload to add part to
11
+ # @param [Array] parts Array of etag and number as Strings for parts
12
+ #
13
+ # @see https://help.aliyun.com/document_detail/31995.html
14
+ #
15
+ def complete_multipart_upload(bucket_name, object_name, upload_id, parts)
16
+ @oss_protocol.complete_multipart_upload(bucket_name, object_name, upload_id, parts)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -7,25 +7,21 @@ module Fog
7
7
  # Copy object
8
8
  #
9
9
  # ==== Parameters
10
- # * source_bucket<~String> - Name of source bucket
11
- # * source_object<~String> - Name of source object
12
- # * target_bucket<~String> - Name of bucket to create copy in
13
- # * target_object<~String> - Name for new copy of object
10
+ # * source_bucket_name<~String> - Name of source bucket
11
+ # * source_object_name<~String> - Name of source object
12
+ # * target_bucket_name<~String> - Name of bucket to create copy in
13
+ # * target_object_name<~String> - Name for new copy of object
14
14
  # * options<~Hash> - Additional headers options={}
15
- def copy_object(source_bucket, source_object, target_bucket, target_object, options = {})
16
- options = options.reject { |_key, value| value.nil? }
17
- bucket = options[:bucket]
18
- bucket ||= @aliyun_oss_bucket
19
- source_bucket ||= bucket
20
- target_bucket ||= bucket
21
- headers = { 'x-oss-copy-source' => "/#{source_bucket}/#{source_object}" }
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)
15
+ def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
16
+ headers = { 'x-oss-copy-source' => "/#{source_bucket_name}#{object_to_path(source_object_name)}" }.merge!(options)
17
+ resources = {
18
+ :bucket => target_bucket_name,
19
+ :object => target_object_name
20
+ }
21
+ http_options = {
22
+ :headers => headers
23
+ }
24
+ @oss_http.put(resources, http_options)
29
25
  end
30
26
  end
31
27
  end
@@ -7,16 +7,10 @@ module Fog
7
7
  # Delete an existing bucket
8
8
  #
9
9
  # ==== Parameters
10
- # * bucket<~String> - Name of bucket to delete
10
+ # * bucket_name<~String> - Name of bucket to delete
11
11
  #
12
- def delete_bucket(bucket)
13
- resource = bucket + '/'
14
- request(
15
- expects: 204,
16
- method: 'DELETE',
17
- bucket: bucket,
18
- resource: resource
19
- )
12
+ def delete_bucket(bucket_name)
13
+ @oss_protocol.delete_bucket(bucket_name)
20
14
  end
21
15
  end
22
16
  end
@@ -0,0 +1,20 @@
1
+ module Fog
2
+ module Aliyun
3
+ class Storage
4
+ class Real
5
+
6
+ # Delete multiple objects from OSS
7
+ #
8
+ # @param bucket_name [String] Name of bucket containing object to delete
9
+ # @param object_names [Array] Array of object names to delete
10
+ #
11
+ # @see https://help.aliyun.com/document_detail/31983.html
12
+
13
+ def delete_multiple_objects(bucket_name, object_names, options = {})
14
+ bucket = @oss_client.get_bucket(bucket_name)
15
+ bucket.batch_delete_objects(object_names, options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -7,18 +7,17 @@ module Fog
7
7
  # Delete an existing object
8
8
  #
9
9
  # ==== Parameters
10
- # * object<~String> - Name of object to delete
10
+ # * bucket_name<~String> - Name of bucket to delete
11
+ # * object_name<~String> - Name of object to delete
11
12
  #
12
- def delete_object(object, options = {})
13
- bucket_name = options[:bucket]
14
- bucket_name ||= @aliyun_oss_bucket
15
- bucket = @oss_client.get_bucket(bucket_name)
16
- bucket.delete_object(object)
17
- end
18
-
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)
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})
22
21
  end
23
22
  end
24
23
  end
@@ -8,121 +8,44 @@ module Fog
8
8
  @oss_client.bucket_exists?(bucket_name)
9
9
  end
10
10
 
11
- def get_bucket(bucket, options = {})
12
- prefix = options['prefix']
13
- marker = options['marker']
11
+ def get_bucket(bucket_name, options = {})
12
+ unless bucket_name
13
+ raise ArgumentError.new('bucket_name is required')
14
+ end
15
+
14
16
  # Set the GetBucket max limitation to 1000
15
- maxKeys = options['max-keys'] || 1000
17
+ maxKeys = options[:max_keys] || 1000
16
18
  maxKeys = maxKeys.to_i
17
- maxKeys = [maxKeys, 1000].min.to_s
18
- delimiter = options['delimiter']
19
- path = ''
20
- if prefix
21
- path += '/?prefix=' + prefix
22
- path += '&marker=' + marker if marker
23
- path += '&max-keys=' + maxKeys if maxKeys
24
- path += '&delimiter=' + delimiter if delimiter
19
+ maxKeys = [maxKeys, 1000].min
25
20
 
26
- elsif marker
27
- path += '/?marker=' + marker
28
- path += '&max-keys=' + maxKeys if maxKeys
29
- path += '&delimiter=' + delimiter if delimiter
30
-
31
- elsif maxKeys
32
- path += '/?max-keys=' + maxKeys
33
- path += '&delimiter=' + delimiter if delimiter
34
- elsif delimiter
35
- path += '/?delimiter=' + delimiter
36
- end
21
+ options[:limit] = maxKeys
22
+ options.delete(:max_keys)
37
23
 
38
- resource = bucket + '/'
39
- ret = request(
40
- expects: [200, 203, 404],
41
- method: 'GET',
42
- bucket: bucket,
43
- resource: resource,
44
- path: path
45
- )
46
- xml = ret.data[:body]
47
- XmlSimple.xml_in(xml)
24
+ @oss_protocol.list_objects(bucket_name, options)
48
25
  end
49
26
 
50
- def get_bucket_acl(bucket)
51
- attribute = '?acl'
52
- resource = bucket + '/' + attribute
53
- ret = request(
54
- expects: [200, 203],
55
- method: 'GET',
56
- path: attribute,
57
- bucket: bucket,
58
- resource: resource
59
- )
60
- 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)
61
29
  end
62
30
 
63
- def get_bucket_CORSRules(bucket)
64
- attribute = '?cors'
65
- resource = bucket + '/' + attribute
66
- ret = request(
67
- expects: [200, 203, 404],
68
- method: 'GET',
69
- path: attribute,
70
- bucket: bucket,
71
- resource: resource
72
- )
73
- 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)
74
33
  end
75
34
 
76
- def get_bucket_lifecycle(bucket)
77
- attribute = '?lifecycle'
78
- resource = bucket + '/' + attribute
79
- ret = request(
80
- expects: [200, 203, 404],
81
- method: 'GET',
82
- path: attribute,
83
- bucket: bucket,
84
- resource: resource
85
- )
86
- 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)
87
37
  end
88
38
 
89
- def get_bucket_logging(bucket)
90
- attribute = '?logging'
91
- resource = bucket + '/' + attribute
92
- ret = request(
93
- expects: [200, 203],
94
- method: 'GET',
95
- path: attribute,
96
- bucket: bucket,
97
- resource: resource
98
- )
99
- XmlSimple.xml_in(ret.data[:body])['LoggingEnabled'][0]['TargetPrefix']
39
+ def get_bucket_logging(bucket_name)
40
+ @oss_protocol.get_bucket_logging(bucket_name)
100
41
  end
101
42
 
102
- def get_bucket_referer(bucket)
103
- attribute = '?referer'
104
- resource = bucket + '/' + attribute
105
- ret = request(
106
- expects: [200, 203],
107
- method: 'GET',
108
- path: attribute,
109
- bucket: bucket,
110
- resource: resource
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(bucket)
116
- attribute = '?website'
117
- resource = bucket + '/' + attribute
118
- ret = request(
119
- expects: [200, 203, 404],
120
- method: 'GET',
121
- path: attribute,
122
- bucket: bucket,
123
- resource: resource
124
- )
125
- 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)
126
49
  end
127
50
  end
128
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
@@ -7,30 +7,38 @@ module Fog
7
7
  # Get details for object
8
8
  #
9
9
  # ==== Parameters
10
- # * object<~String> - Name of object to look for
10
+ # * object_name<~String> - Name of object to look for
11
11
  #
12
- def get_object(object, options = {}, &block)
12
+ def get_object(bucket_name, object_name, options = {}, &block)
13
13
  options = options.reject { |_key, value| value.nil? }
14
- bucket_name = options[:bucket]
15
- bucket_name ||= @aliyun_oss_bucket
16
- options.delete(:bucket)
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
17
20
  # Using OSS ruby SDK to fix performance issue
18
- params = { :headers => {} }
19
- params[:query] = options.delete('query') || {}
21
+ http_options = { :headers => {} }
22
+ http_options[:query] = options.delete('query') || {}
20
23
 
21
- params[:headers].merge!(options)
24
+ http_options[:headers].merge!(options)
22
25
  if options['If-Modified-Since']
23
- params[:headers]['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header
26
+ http_options[:headers]['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header
24
27
  end
25
28
  if options['If-Unmodified-Since']
26
- params[:headers]['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header
29
+ http_options[:headers]['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header
27
30
  end
28
31
 
29
32
  if block_given?
30
- params[:response_block] = Proc.new
33
+ http_options[:response_block] = Proc.new {}
31
34
  end
32
35
 
33
- @oss_http.get({:bucket => bucket_name, :object => object}, params, &block)
36
+ resources = {
37
+ :bucket => bucket_name,
38
+ :object => object_name
39
+ }
40
+
41
+ @oss_http.get(resources, http_options, &block)
34
42
 
35
43
  end
36
44
  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,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable'
4
+
3
5
  module Fog
4
6
  module Aliyun
5
7
  class Storage
@@ -7,29 +9,26 @@ module Fog
7
9
  # Get an expiring object http url
8
10
  #
9
11
  # ==== Parameters
10
- # * container<~String> - Name of container containing object
11
- # * object<~String> - Name of object to get expiring url for
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(object, expires, options = {})
18
- options = options.reject { |_key, value| value.nil? }
19
- bucket_name = options[:bucket]
20
- bucket_name ||= @aliyun_oss_bucket
19
+ def get_object_http_url_public(bucket_name, object_name, expires)
21
20
  bucket = @oss_client.get_bucket(bucket_name)
22
21
  acl = bucket.acl()
23
22
 
24
23
  if acl == 'private'
25
24
  expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s
26
- resource = bucket_name + '/' + object
25
+ resource = bucket_name + '/' + object_name
27
26
  signature = sign('GET', expires_time, nil, resource)
28
- 'http://' + bucket_name + '.' + @host + '/' + object +
27
+ 'http://' + bucket_name + '.' + @host + '/' + object_name +
29
28
  '?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
30
- '&Signature=' + URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
29
+ '&Signature=' + Addressable::URI.encode_component(signature, Addressable::URI::CharacterClasses::UNRESERVED + '|')
31
30
  elsif acl == 'public-read' || acl == 'public-read-write'
32
- 'http://' + bucket_name + '.' + @host + '/' + object
31
+ 'http://' + bucket_name + '.' + @host + '/' + object_name
33
32
  else
34
33
  'acl is wrong with value:' + acl
35
34
  end