aliyun-sdk 0.5.0 → 0.7.3

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 (67) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +174 -172
  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 +3 -2
  19. data/lib/aliyun/common/struct.rb +0 -0
  20. data/lib/aliyun/oss.rb +0 -0
  21. data/lib/aliyun/oss/bucket.rb +29 -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 +25 -46
  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 +27 -12
  31. data/lib/aliyun/oss/struct.rb +2 -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 +3 -3
  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 +140 -18
  43. data/spec/aliyun/oss/client/bucket_spec.rb +276 -30
  44. data/spec/aliyun/oss/client/client_spec.rb +26 -1
  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 +10 -10
  49. data/spec/aliyun/oss/object_spec.rb +109 -16
  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_content_encoding.rb +0 -0
  57. data/tests/test_content_type.rb +0 -0
  58. data/tests/test_crc_check.rb +0 -0
  59. data/tests/test_custom_headers.rb +0 -0
  60. data/tests/test_encoding.rb +0 -0
  61. data/tests/test_large_file.rb +0 -0
  62. data/tests/test_multipart.rb +0 -0
  63. data/tests/test_object_acl.rb +0 -0
  64. data/tests/test_object_key.rb +18 -0
  65. data/tests/test_object_url.rb +20 -0
  66. data/tests/test_resumable.rb +0 -0
  67. metadata +8 -10
@@ -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 = {})
@@ -247,7 +272,7 @@ module Aliyun
247
272
  end
248
273
 
249
274
  it "should test bucket existence" do
250
- query = {'acl' => ''}
275
+ query = {'acl' => nil}
251
276
  return_acl = ACL::PUBLIC_READ
252
277
  stub_request(:get, bucket_url)
253
278
  .with(:query => query)
File without changes
@@ -26,8 +26,8 @@ module Aliyun
26
26
  def crc_protocol
27
27
  Protocol.new(
28
28
  Config.new(:endpoint => @endpoint,
29
- :access_key_id => 'xxx',
30
- :access_key_secret => 'yyy',
29
+ :access_key_id => 'xxx',
30
+ :access_key_secret => 'yyy',
31
31
  :upload_crc_enable => true,
32
32
  :download_crc_enable => true))
33
33
  end
@@ -111,7 +111,7 @@ module Aliyun
111
111
  context "Initiate multipart upload" do
112
112
 
113
113
  it "should POST to create transaction" do
114
- query = {'uploads' => ''}
114
+ query = {'uploads' => nil}
115
115
  stub_request(:post, request_path).with(:query => query)
116
116
 
117
117
  @protocol.initiate_multipart_upload(
@@ -129,7 +129,7 @@ module Aliyun
129
129
  end
130
130
 
131
131
  it "should return transaction id" do
132
- query = {'uploads' => ''}
132
+ query = {'uploads' => nil}
133
133
  return_txn_id = 'zyx'
134
134
  stub_request(:post, request_path).
135
135
  with(:query => query).
@@ -143,7 +143,7 @@ module Aliyun
143
143
  end
144
144
 
145
145
  it "should raise Exception on error" do
146
- query = {'uploads' => ''}
146
+ query = {'uploads' => nil}
147
147
 
148
148
  code = 'InvalidArgument'
149
149
  message = 'Invalid argument.'
@@ -462,7 +462,7 @@ module Aliyun
462
462
 
463
463
  it "should GET to list multiparts" do
464
464
  request_path = "#{@bucket}.#{@endpoint}/"
465
- query = {'uploads' => ''}
465
+ query = {'uploads' => nil}
466
466
 
467
467
  stub_request(:get, request_path).with(:query => query)
468
468
 
@@ -475,7 +475,7 @@ module Aliyun
475
475
  it "should send extra params when list multiparts" do
476
476
  request_path = "#{@bucket}.#{@endpoint}/"
477
477
  query = {
478
- 'uploads' => '',
478
+ 'uploads' => nil,
479
479
  'prefix' => 'foo-',
480
480
  'upload-id-marker' => 'id-marker',
481
481
  'key-marker' => 'key-marker',
@@ -501,7 +501,7 @@ module Aliyun
501
501
  it "should get multipart transactions" do
502
502
  request_path = "#{@bucket}.#{@endpoint}/"
503
503
  query = {
504
- 'uploads' => '',
504
+ 'uploads' => nil,
505
505
  'prefix' => 'foo-',
506
506
  'upload-id-marker' => 'id-marker',
507
507
  'key-marker' => 'key-marker',
@@ -548,7 +548,7 @@ module Aliyun
548
548
  it "should decode object key" do
549
549
  request_path = "#{@bucket}.#{@endpoint}/"
550
550
  query = {
551
- 'uploads' => '',
551
+ 'uploads' => nil,
552
552
  'prefix' => 'foo-',
553
553
  'upload-id-marker' => 'id-marker',
554
554
  'key-marker' => 'key-marker',
@@ -614,7 +614,7 @@ module Aliyun
614
614
 
615
615
  it "should raise Exception on error" do
616
616
  request_path = "#{@bucket}.#{@endpoint}/"
617
- query = {'uploads' => ''}
617
+ query = {'uploads' => nil}
618
618
 
619
619
  code = 'InvalidArgument'
620
620
  message = 'Invalid argument.'
@@ -20,8 +20,8 @@ module Aliyun
20
20
  def crc_protocol
21
21
  Protocol.new(
22
22
  Config.new(:endpoint => @endpoint,
23
- :access_key_id => 'xxx',
24
- :access_key_secret => 'yyy',
23
+ :access_key_id => 'xxx',
24
+ :access_key_secret => 'yyy',
25
25
  :upload_crc_enable => true,
26
26
  :download_crc_enable => true))
27
27
  end
@@ -236,7 +236,7 @@ module Aliyun
236
236
  object_name = 'ruby'
237
237
  url = get_request_path(object_name)
238
238
 
239
- query = {'append' => '', 'position' => 11}
239
+ query = {'append' => nil, 'position' => 11}
240
240
  return_headers = {'x-oss-next-append-position' => '101'}
241
241
  stub_request(:post, url).with(:query => query)
242
242
  .to_return(:headers => return_headers)
@@ -255,7 +255,7 @@ module Aliyun
255
255
  object_name = 'ruby'
256
256
  url = get_request_path(object_name)
257
257
 
258
- query = {'append' => '', 'position' => 11}
258
+ query = {'append' => nil, 'position' => 11}
259
259
  code = 'ObjectNotAppendable'
260
260
  message = 'Normal object cannot be appended.'
261
261
  stub_request(:post, url).with(:query => query).
@@ -275,7 +275,7 @@ module Aliyun
275
275
  it "should use default content-type" do
276
276
  object_name = 'ruby'
277
277
  url = get_request_path(object_name)
278
- query = {'append' => '', 'position' => 0}
278
+ query = {'append' => nil, 'position' => 0}
279
279
 
280
280
  stub_request(:post, url).with(:query => query)
281
281
 
@@ -292,7 +292,7 @@ module Aliyun
292
292
  it "should use customized content-type" do
293
293
  object_name = 'ruby'
294
294
  url = get_request_path(object_name)
295
- query = {'append' => '', 'position' => 0}
295
+ query = {'append' => nil, 'position' => 0}
296
296
 
297
297
  stub_request(:post, url).with(:query => query)
298
298
 
@@ -311,7 +311,7 @@ module Aliyun
311
311
  it "should set user defined metas" do
312
312
  object_name = 'ruby'
313
313
  url = get_request_path(object_name)
314
- query = {'append' => '', 'position' => 0}
314
+ query = {'append' => nil, 'position' => 0}
315
315
 
316
316
  stub_request(:post, url).with(:query => query)
317
317
 
@@ -335,7 +335,7 @@ module Aliyun
335
335
  content = "hello world"
336
336
  content_crc = Aliyun::OSS::Util.crc(content)
337
337
 
338
- query = {'append' => '', 'position' => 11}
338
+ query = {'append' => nil, 'position' => 11}
339
339
  return_headers = {'x-oss-next-append-position' => '101', :x_oss_hash_crc64ecma => content_crc.to_i + 1}
340
340
  stub_request(:post, url).with(:query => query)
341
341
  .to_return(:headers => return_headers)
@@ -353,7 +353,7 @@ module Aliyun
353
353
  content = "hello world"
354
354
  content_crc = Aliyun::OSS::Util.crc(content)
355
355
 
356
- query = {'append' => '', 'position' => 11}
356
+ query = {'append' => nil, 'position' => 11}
357
357
  return_headers = {'x-oss-next-append-position' => '101', :x_oss_hash_crc64ecma => content_crc}
358
358
  stub_request(:post, url).with(:query => query)
359
359
  .to_return(:headers => return_headers)
@@ -377,11 +377,11 @@ module Aliyun
377
377
  content = "hello world"
378
378
  content_crc = Aliyun::OSS::Util.crc(content)
379
379
 
380
- query = {'append' => '', 'position' => 11}
380
+ query = {'append' => nil, 'position' => 11}
381
381
  return_headers = {'x-oss-next-append-position' => '101', :x_oss_hash_crc64ecma => content_crc + 1}
382
382
  stub_request(:post, url).with(:query => query)
383
383
  .to_return(:headers => return_headers)
384
-
384
+
385
385
  expect(crc_protocol.upload_crc_enable).to eq(true)
386
386
  next_pos = 0
387
387
  expect {
@@ -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' => '', '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)
@@ -824,7 +866,7 @@ module Aliyun
824
866
 
825
867
  it "should decode object key in batch delete response" do
826
868
  url = get_request_path
827
- query = {'delete' => '', 'encoding-type' => KeyEncoding::URL}
869
+ query = {'delete' => nil, 'encoding-type' => KeyEncoding::URL}
828
870
 
829
871
  object_names = (1..5).map do |i|
830
872
  "对象-#{i}"
@@ -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
@@ -851,7 +944,7 @@ module Aliyun
851
944
  object_name = 'ruby'
852
945
  url = get_request_path(object_name)
853
946
 
854
- query = {'acl' => ''}
947
+ query = {'acl' => nil}
855
948
  stub_request(:put, url).with(:query => query)
856
949
 
857
950
  @protocol.put_object_acl(@bucket, object_name, ACL::PUBLIC_READ)
@@ -866,7 +959,7 @@ module Aliyun
866
959
  object_name = 'ruby'
867
960
  url = get_request_path(object_name)
868
961
 
869
- query = {'acl' => ''}
962
+ query = {'acl' => nil}
870
963
  return_acl = ACL::PUBLIC_READ
871
964
 
872
965
  stub_request(:get, url)
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
File without changes
File without changes
File without changes
File without changes