aliyun-sdk 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +27 -0
  3. data/README.md +0 -0
  4. data/examples/aliyun/oss/bucket.rb +0 -0
  5. data/examples/aliyun/oss/callback.rb +0 -0
  6. data/examples/aliyun/oss/object.rb +0 -0
  7. data/examples/aliyun/oss/resumable_download.rb +0 -0
  8. data/examples/aliyun/oss/resumable_upload.rb +0 -0
  9. data/examples/aliyun/oss/streaming.rb +0 -0
  10. data/examples/aliyun/oss/using_sts.rb +0 -0
  11. data/examples/aliyun/sts/assume_role.rb +0 -0
  12. data/ext/crcx/crc64_ecma.c +0 -0
  13. data/ext/crcx/crcx.c +0 -0
  14. data/ext/crcx/crcx.h +0 -0
  15. data/ext/crcx/extconf.rb +0 -0
  16. data/lib/aliyun/common.rb +0 -0
  17. data/lib/aliyun/common/exception.rb +0 -0
  18. data/lib/aliyun/common/logging.rb +20 -3
  19. data/lib/aliyun/common/struct.rb +0 -0
  20. data/lib/aliyun/oss.rb +0 -0
  21. data/lib/aliyun/oss/bucket.rb +57 -32
  22. data/lib/aliyun/oss/client.rb +6 -2
  23. data/lib/aliyun/oss/config.rb +0 -0
  24. data/lib/aliyun/oss/download.rb +0 -0
  25. data/lib/aliyun/oss/exception.rb +0 -0
  26. data/lib/aliyun/oss/http.rb +8 -5
  27. data/lib/aliyun/oss/iterator.rb +0 -0
  28. data/lib/aliyun/oss/multipart.rb +0 -0
  29. data/lib/aliyun/oss/object.rb +0 -0
  30. data/lib/aliyun/oss/protocol.rb +116 -3
  31. data/lib/aliyun/oss/struct.rb +27 -2
  32. data/lib/aliyun/oss/upload.rb +0 -0
  33. data/lib/aliyun/oss/util.rb +6 -0
  34. data/lib/aliyun/sts.rb +0 -0
  35. data/lib/aliyun/sts/client.rb +1 -1
  36. data/lib/aliyun/sts/config.rb +0 -0
  37. data/lib/aliyun/sts/exception.rb +0 -0
  38. data/lib/aliyun/sts/protocol.rb +1 -1
  39. data/lib/aliyun/sts/struct.rb +0 -0
  40. data/lib/aliyun/sts/util.rb +0 -0
  41. data/lib/aliyun/version.rb +1 -1
  42. data/spec/aliyun/oss/bucket_spec.rb +143 -2
  43. data/spec/aliyun/oss/client/bucket_spec.rb +392 -22
  44. data/spec/aliyun/oss/client/client_spec.rb +25 -0
  45. data/spec/aliyun/oss/client/resumable_download_spec.rb +0 -0
  46. data/spec/aliyun/oss/client/resumable_upload_spec.rb +0 -0
  47. data/spec/aliyun/oss/http_spec.rb +0 -0
  48. data/spec/aliyun/oss/multipart_spec.rb +0 -0
  49. data/spec/aliyun/oss/object_spec.rb +95 -2
  50. data/spec/aliyun/oss/service_spec.rb +0 -0
  51. data/spec/aliyun/oss/util_spec.rb +51 -0
  52. data/spec/aliyun/sts/client_spec.rb +0 -0
  53. data/spec/aliyun/sts/util_spec.rb +0 -0
  54. data/tests/config.rb +0 -0
  55. data/tests/helper.rb +0 -0
  56. data/tests/test_bucket.rb +73 -0
  57. data/tests/test_content_encoding.rb +0 -0
  58. data/tests/test_content_type.rb +0 -0
  59. data/tests/test_crc_check.rb +0 -0
  60. data/tests/test_custom_headers.rb +0 -0
  61. data/tests/test_encoding.rb +0 -0
  62. data/tests/test_large_file.rb +0 -0
  63. data/tests/test_multipart.rb +0 -0
  64. data/tests/test_object_acl.rb +0 -0
  65. data/tests/test_object_key.rb +18 -0
  66. data/tests/test_object_url.rb +20 -0
  67. data/tests/test_resumable.rb +0 -0
  68. metadata +8 -13
@@ -127,6 +127,31 @@ module Aliyun
127
127
  expect(WebMock).to have_requested(:get, "#{bucket}.#{ep1}/#{object}")
128
128
  expect(WebMock).to have_requested(:put, "#{bucket}.#{ep2}/#{object}")
129
129
  end
130
+
131
+ it "should fail with invalid bucket name" do
132
+ bucket = 'INVALID'
133
+ ep1 = 'oss-cn-hangzhou.aliyuncs.com'
134
+ client = Client.new(
135
+ :endpoint => ep1,
136
+ :access_key_id => 'xxx', :access_key_secret => 'yyy')
137
+
138
+ expect {
139
+ client.create_bucket(bucket)
140
+ }.to raise_error(ClientError, "The bucket name is invalid.")
141
+
142
+ expect {
143
+ client.delete_bucket(bucket)
144
+ }.to raise_error(ClientError, "The bucket name is invalid.")
145
+
146
+ expect {
147
+ client.bucket_exists?(bucket)
148
+ }.to raise_error(ClientError, "The bucket name is invalid.")
149
+
150
+ expect {
151
+ client.get_bucket(bucket)
152
+ }.to raise_error(ClientError, "The bucket name is invalid.")
153
+ end
154
+
130
155
  end # construct
131
156
 
132
157
  def mock_buckets(buckets, more = {})
File without changes
File without changes
@@ -611,6 +611,15 @@ module Aliyun
611
611
  })
612
612
  end
613
613
 
614
+ it "should raise Exception on error when setting invalid range" do
615
+ object_name = 'ruby'
616
+ url = get_request_path(object_name)
617
+ stub_request(:get, url)
618
+ expect {
619
+ @protocol.get_object(@bucket, object_name, {:range => [0, 10, 5]}) {}
620
+ }.to raise_error(ClientError)
621
+ end
622
+
614
623
  it "should match modify time and etag" do
615
624
  object_name = 'ruby'
616
625
  url = get_request_path(object_name)
@@ -662,6 +671,22 @@ module Aliyun
662
671
  .with(:body => nil, :query => query)
663
672
  end
664
673
 
674
+ it "should get object with headers" do
675
+ object_name = 'ruby'
676
+ url = get_request_path(object_name)
677
+ headers = {
678
+ 'Range' => 'bytes=0-9'
679
+ }
680
+ stub_request(:get, url)
681
+
682
+ @protocol.get_object(@bucket, object_name, {:headers => headers}) {}
683
+
684
+ expect(WebMock).to have_requested(:get, url)
685
+ .with(:body => nil, :query => {},
686
+ :headers => {
687
+ 'Range' => 'bytes=0-9'
688
+ })
689
+ end
665
690
 
666
691
  it "should raise crc exception on error" do
667
692
  object_name = 'ruby'
@@ -710,6 +735,23 @@ module Aliyun
710
735
  'Range' => 'bytes=0-9'
711
736
  })
712
737
  end
738
+
739
+ it "should get to get object with special chars" do
740
+ object_name = 'ruby///adfadfa//!@#%^*//?key=value&aabc#abc=ad'
741
+ url = get_request_path(object_name)
742
+
743
+ return_content = "hello world"
744
+ stub_request(:get, url).to_return(:body => return_content)
745
+
746
+ content = ""
747
+ @protocol.get_object(@bucket, object_name) {|c| content << c}
748
+
749
+ expect(WebMock).to have_requested(:get, url)
750
+ .with(:body => nil, :query => {})
751
+
752
+ expect(content).to eq(return_content)
753
+ end
754
+
713
755
  end # Get object
714
756
 
715
757
  context "Get object meta" do
@@ -804,7 +846,7 @@ module Aliyun
804
846
 
805
847
  it "should batch delete objects" do
806
848
  url = get_request_path
807
- query = {'delete' => nil, 'encoding-type' => KeyEncoding::URL}
849
+ query = {'delete' => nil}
808
850
 
809
851
  object_names = (1..5).map do |i|
810
852
  "object-#{i}"
@@ -814,7 +856,7 @@ module Aliyun
814
856
  .with(:query => query)
815
857
  .to_return(:body => mock_delete_result(object_names))
816
858
 
817
- opts = {:quiet => false, :encoding => KeyEncoding::URL}
859
+ opts = {:quiet => false}
818
860
  deleted = @protocol.batch_delete_objects(@bucket, object_names, opts)
819
861
 
820
862
  expect(WebMock).to have_requested(:post, url)
@@ -844,6 +886,57 @@ module Aliyun
844
886
  .with(:query => query, :body => mock_delete(object_names, opts))
845
887
  expect(deleted).to match_array(object_names)
846
888
  end
889
+
890
+ it "should batch delete objects in quiet mode" do
891
+ url = get_request_path
892
+ query = {'delete' => nil}
893
+
894
+ object_names = (1..5).map do |i|
895
+ "object-#{i}"
896
+ end
897
+
898
+ stub_request(:post, url)
899
+ .with(:query => query)
900
+ .to_return(:body => "")
901
+
902
+ opts = {:quiet => true}
903
+ deleted = @protocol.batch_delete_objects(@bucket, object_names, opts)
904
+
905
+ expect(WebMock).to have_requested(:post, url)
906
+ .with(:query => query, :body => mock_delete(object_names, opts))
907
+ expect(deleted).to match_array([])
908
+ end
909
+
910
+ it "should rasie Exception wiht invalid responsed body" do
911
+ url = get_request_path
912
+ query = {'delete' => nil}
913
+ body = '<DeleteResult>
914
+ <EncodingType>invaid<EncodingType>
915
+ <Deleted>
916
+ <Key>multipart.data</Key>
917
+ </Deleted>
918
+ <Deleted>
919
+ <Key>test.jpg</Key>
920
+ </Deleted>
921
+ <Deleted>
922
+ <Key>demo.jpg</Key>
923
+ </Deleted>
924
+ </DeleteResult>'
925
+
926
+ object_names = (1..5).map do |i|
927
+ "object-#{i}"
928
+ end
929
+
930
+ stub_request(:post, url)
931
+ .with(:query => query)
932
+ .to_return(:body => body)
933
+
934
+ opts = {:quiet => false}
935
+ expect {
936
+ deleted = @protocol.batch_delete_objects(@bucket, object_names, opts)
937
+ }.to raise_error(ClientError)
938
+
939
+ end
847
940
  end # delete object
848
941
 
849
942
  context "acl" do
File without changes
@@ -94,6 +94,57 @@ module Aliyun
94
94
  }.to raise_error(CrcInconsistentError, "The crc of post between client and oss is not inconsistent.")
95
95
  end
96
96
 
97
+ it "should check bucket name valid" do
98
+ expect {
99
+ Util.ensure_bucket_name_valid('abc')
100
+ }.not_to raise_error
101
+
102
+ expect {
103
+ Util.ensure_bucket_name_valid('abc123-321cba')
104
+ }.not_to raise_error
105
+
106
+ expect {
107
+ Util.ensure_bucket_name_valid('abcdefghijklmnopqrstuvwxyz1234567890-0987654321zyxwuvtsrqponmlk')
108
+ }.not_to raise_error
109
+
110
+ #>63
111
+ expect {
112
+ Util.ensure_bucket_name_valid('abcdefghijklmnopqrstuvwxyz1234567890-0987654321zyxwuvtsrqponmlkj')
113
+ }.to raise_error(ClientError, "The bucket name is invalid.")
114
+
115
+ #<3
116
+ expect {
117
+ Util.ensure_bucket_name_valid('12')
118
+ }.to raise_error(ClientError, "The bucket name is invalid.")
119
+
120
+ #not [a-z0-9-]
121
+ expect {
122
+ Util.ensure_bucket_name_valid('Aabc')
123
+ }.to raise_error(ClientError, "The bucket name is invalid.")
124
+
125
+ expect {
126
+ Util.ensure_bucket_name_valid('abc/')
127
+ }.to raise_error(ClientError, "The bucket name is invalid.")
128
+
129
+ expect {
130
+ Util.ensure_bucket_name_valid('abc#')
131
+ }.to raise_error(ClientError, "The bucket name is invalid.")
132
+
133
+ expect {
134
+ Util.ensure_bucket_name_valid('abc?')
135
+ }.to raise_error(ClientError, "The bucket name is invalid.")
136
+
137
+ #start & end not -
138
+ expect {
139
+ Util.ensure_bucket_name_valid('-abc')
140
+ }.to raise_error(ClientError, "The bucket name is invalid.")
141
+
142
+ expect {
143
+ Util.ensure_bucket_name_valid('abc-')
144
+ }.to raise_error(ClientError, "The bucket name is invalid.")
145
+
146
+ end
147
+
97
148
  end # Util
98
149
 
99
150
  end # OSS
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,73 @@
1
+ require 'minitest/autorun'
2
+ require 'yaml'
3
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
+ require 'aliyun/oss'
5
+ require 'time'
6
+ require_relative 'config'
7
+
8
+ class TestBucket < Minitest::Test
9
+ def setup
10
+ Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
11
+ @client = Aliyun::OSS::Client.new(TestConf.creds)
12
+ @bucket_name = TestConf.bucket + Time.now.to_i.to_s
13
+ @client.create_bucket(@bucket_name)
14
+ @bucket = @client.get_bucket(@bucket_name)
15
+ end
16
+
17
+ def teardown
18
+ @client.delete_bucket(@bucket_name)
19
+ end
20
+
21
+ def test_bucket_versioning
22
+ ret = @bucket.versioning
23
+ assert_nil ret.status
24
+
25
+ @bucket.versioning = Aliyun::OSS::BucketVersioning.new(:status => 'Enabled')
26
+ ret = @bucket.versioning
27
+ assert_equal 'Enabled', ret.status
28
+
29
+ @bucket.versioning = Aliyun::OSS::BucketVersioning.new(:status => 'Suspended')
30
+ ret = @bucket.versioning
31
+ assert_equal 'Suspended', ret.status
32
+
33
+ end
34
+
35
+ def test_bucket_encryption
36
+
37
+ begin
38
+ ret = @bucket.encryption
39
+ assert_raises "should not here"
40
+ rescue => exception
41
+ end
42
+
43
+ @bucket.encryption = Aliyun::OSS::BucketEncryption.new(
44
+ :enable => true,
45
+ :sse_algorithm => 'KMS')
46
+ ret = @bucket.encryption
47
+ assert_equal 'KMS', ret.sse_algorithm
48
+ assert_nil ret.kms_master_key_id
49
+
50
+ @bucket.encryption = Aliyun::OSS::BucketEncryption.new(
51
+ :enable => true,
52
+ :sse_algorithm => 'KMS',
53
+ :kms_master_key_id => 'kms-id')
54
+ ret = @bucket.encryption
55
+ assert_equal 'KMS', ret.sse_algorithm
56
+ assert_equal 'kms-id', ret.kms_master_key_id
57
+
58
+ @bucket.encryption = Aliyun::OSS::BucketEncryption.new(
59
+ :enable => true,
60
+ :sse_algorithm => 'AES256')
61
+ ret = @bucket.encryption
62
+ assert_equal 'AES256', ret.sse_algorithm
63
+ assert_nil ret.kms_master_key_id
64
+
65
+ @bucket.encryption = Aliyun::OSS::BucketEncryption.new(
66
+ :enable => false)
67
+ begin
68
+ ret = @bucket.encryption
69
+ assert_raises "should not here"
70
+ rescue => exception
71
+ end
72
+ end
73
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -17,6 +17,8 @@ class TestObjectKey < Minitest::Test
17
17
  chinese: '杭州・中国',
18
18
  space: '是 空格 yeah +-/\\&*#',
19
19
  invisible: '' << 1 << 10 << 12 << 7 << 80 << 99,
20
+ specail1: 'testkey/',
21
+ specail2: 'testkey/?key=value#abc=def',
20
22
  xml: 'a<b&c>d +'
21
23
  }
22
24
  end
@@ -57,6 +59,22 @@ class TestObjectKey < Minitest::Test
57
59
  assert_equal key, @bucket.get_object(key).key
58
60
  end
59
61
 
62
+ def test_specail1
63
+ key = get_key(:specail1)
64
+ @bucket.put_object(key)
65
+ all = @bucket.list_objects(prefix: @prefix).map(&:key)
66
+ assert_includes all, key
67
+ assert_equal key, @bucket.get_object(key).key
68
+ end
69
+
70
+ def test_specail2
71
+ key = get_key(:specail2)
72
+ @bucket.put_object(key)
73
+ all = @bucket.list_objects(prefix: @prefix).map(&:key)
74
+ assert_includes all, key
75
+ assert_equal key, @bucket.get_object(key).key
76
+ end
77
+
60
78
  def test_batch_delete
61
79
  keys = @keys.map { |k, _| get_key(k) }
62
80
  keys.each { |k| @bucket.put_object(k) }
@@ -66,4 +66,24 @@ class TestObjectUrl < Minitest::Test
66
66
 
67
67
  assert_equal 200, r.code
68
68
  end
69
+
70
+ def test_signed_url_with_parameters
71
+ key = get_key('example.jpg')
72
+
73
+ @bucket.put_object(key, :file => 'tests/example.jpg', acl: Aliyun::OSS::ACL::PRIVATE)
74
+
75
+ meta = @bucket.get_object(key)
76
+ assert_equal 21839, meta.size
77
+
78
+ parameters = {
79
+ 'x-oss-process' => 'image/resize,m_fill,h_100,w_100',
80
+ }
81
+ signed_url = @bucket.object_url(key, true, 60, parameters)
82
+ r = RestClient.get(signed_url)
83
+ lenth = r.headers[:content_length].to_i
84
+ assert_equal 200, r.code
85
+ assert_equal true, lenth < meta.size
86
+
87
+ end
88
+
69
89
  end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliyun-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tianlong Wu
8
8
  autorequire:
9
9
  bindir: lib/aliyun
10
10
  cert_chain: []
11
- date: 2017-07-23 00:00:00.000000000 Z
11
+ date: 2020-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: 1.7.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,23 +24,20 @@ dependencies:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.6'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: 1.7.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rest-client
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: 2.0.2
33
+ version: '2.0'
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: 2.0.2
40
+ version: '2.0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: bundler
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +200,7 @@ files:
206
200
  - spec/aliyun/sts/util_spec.rb
207
201
  - tests/config.rb
208
202
  - tests/helper.rb
203
+ - tests/test_bucket.rb
209
204
  - tests/test_content_encoding.rb
210
205
  - tests/test_content_type.rb
211
206
  - tests/test_crc_check.rb
@@ -229,15 +224,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
224
  requirements:
230
225
  - - ">="
231
226
  - !ruby/object:Gem::Version
232
- version: 1.9.3
227
+ version: '2.0'
233
228
  required_rubygems_version: !ruby/object:Gem::Requirement
234
229
  requirements:
235
230
  - - ">="
236
231
  - !ruby/object:Gem::Version
237
232
  version: '0'
238
233
  requirements: []
239
- rubyforge_project:
240
- rubygems_version: 2.5.2
234
+ rubygems_version: 3.0.3
241
235
  signing_key:
242
236
  specification_version: 4
243
237
  summary: Aliyun OSS SDK for Ruby
@@ -256,6 +250,7 @@ test_files:
256
250
  - spec/aliyun/sts/util_spec.rb
257
251
  - tests/config.rb
258
252
  - tests/helper.rb
253
+ - tests/test_bucket.rb
259
254
  - tests/test_content_encoding.rb
260
255
  - tests/test_content_type.rb
261
256
  - tests/test_crc_check.rb