aliyun-sdk 0.6.0 → 0.8.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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +27 -0
- data/README.md +0 -0
- data/examples/aliyun/oss/bucket.rb +0 -0
- data/examples/aliyun/oss/callback.rb +0 -0
- data/examples/aliyun/oss/object.rb +0 -0
- data/examples/aliyun/oss/resumable_download.rb +0 -0
- data/examples/aliyun/oss/resumable_upload.rb +0 -0
- data/examples/aliyun/oss/streaming.rb +0 -0
- data/examples/aliyun/oss/using_sts.rb +0 -0
- data/examples/aliyun/sts/assume_role.rb +0 -0
- data/ext/crcx/crc64_ecma.c +0 -0
- data/ext/crcx/crcx.c +0 -0
- data/ext/crcx/crcx.h +0 -0
- data/ext/crcx/extconf.rb +0 -0
- data/lib/aliyun/common.rb +0 -0
- data/lib/aliyun/common/exception.rb +0 -0
- data/lib/aliyun/common/logging.rb +20 -3
- data/lib/aliyun/common/struct.rb +0 -0
- data/lib/aliyun/oss.rb +0 -0
- data/lib/aliyun/oss/bucket.rb +57 -32
- data/lib/aliyun/oss/client.rb +6 -2
- data/lib/aliyun/oss/config.rb +0 -0
- data/lib/aliyun/oss/download.rb +0 -0
- data/lib/aliyun/oss/exception.rb +0 -0
- data/lib/aliyun/oss/http.rb +8 -5
- data/lib/aliyun/oss/iterator.rb +0 -0
- data/lib/aliyun/oss/multipart.rb +0 -0
- data/lib/aliyun/oss/object.rb +0 -0
- data/lib/aliyun/oss/protocol.rb +116 -3
- data/lib/aliyun/oss/struct.rb +27 -2
- data/lib/aliyun/oss/upload.rb +0 -0
- data/lib/aliyun/oss/util.rb +6 -0
- data/lib/aliyun/sts.rb +0 -0
- data/lib/aliyun/sts/client.rb +1 -1
- data/lib/aliyun/sts/config.rb +0 -0
- data/lib/aliyun/sts/exception.rb +0 -0
- data/lib/aliyun/sts/protocol.rb +1 -1
- data/lib/aliyun/sts/struct.rb +0 -0
- data/lib/aliyun/sts/util.rb +0 -0
- data/lib/aliyun/version.rb +1 -1
- data/spec/aliyun/oss/bucket_spec.rb +143 -2
- data/spec/aliyun/oss/client/bucket_spec.rb +392 -22
- data/spec/aliyun/oss/client/client_spec.rb +25 -0
- data/spec/aliyun/oss/client/resumable_download_spec.rb +0 -0
- data/spec/aliyun/oss/client/resumable_upload_spec.rb +0 -0
- data/spec/aliyun/oss/http_spec.rb +0 -0
- data/spec/aliyun/oss/multipart_spec.rb +0 -0
- data/spec/aliyun/oss/object_spec.rb +95 -2
- data/spec/aliyun/oss/service_spec.rb +0 -0
- data/spec/aliyun/oss/util_spec.rb +51 -0
- data/spec/aliyun/sts/client_spec.rb +0 -0
- data/spec/aliyun/sts/util_spec.rb +0 -0
- data/tests/config.rb +0 -0
- data/tests/helper.rb +0 -0
- data/tests/test_bucket.rb +73 -0
- data/tests/test_content_encoding.rb +0 -0
- data/tests/test_content_type.rb +0 -0
- data/tests/test_crc_check.rb +0 -0
- data/tests/test_custom_headers.rb +0 -0
- data/tests/test_encoding.rb +0 -0
- data/tests/test_large_file.rb +0 -0
- data/tests/test_multipart.rb +0 -0
- data/tests/test_object_acl.rb +0 -0
- data/tests/test_object_key.rb +18 -0
- data/tests/test_object_url.rb +20 -0
- data/tests/test_resumable.rb +0 -0
- metadata +8 -13
data/lib/aliyun/oss/struct.rb
CHANGED
@@ -74,6 +74,31 @@ module Aliyun
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
##
|
78
|
+
# Bucket Versioning setting. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/versioning.html OSS Bucket versioning}
|
79
|
+
# Attributes:
|
80
|
+
# * status [String] the bucket versioning status, can be 'Enabled' and 'Suspended'
|
81
|
+
# @example Enable bucket versioning
|
82
|
+
# bucket.versioning = BucketVersioning.new(:status => 'Enabled')
|
83
|
+
# @example Suspend bucket versioning
|
84
|
+
# bucket.versioning = BucketVersioning.new(:status => 'Suspended')
|
85
|
+
class BucketVersioning < Common::Struct::Base
|
86
|
+
attrs :status
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# Bucket Encryption setting. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/encryption.html OSS Bucket encryption}
|
91
|
+
# Attributes:
|
92
|
+
# * sse_algorithm [string] Indicates the default server-side encryption method
|
93
|
+
# * kms_master_key_id [string] Indicates the ID of CMK that is currently used.
|
94
|
+
class BucketEncryption < Common::Struct::Base
|
95
|
+
attrs :enable, :sse_algorithm, :kms_master_key_id
|
96
|
+
|
97
|
+
def enabled?
|
98
|
+
enable == true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
77
102
|
##
|
78
103
|
# Bucket website setting. See: {http://help.aliyun.com/document_detail/oss/product-documentation/function/host-static-website.html OSS Website hosting}
|
79
104
|
# Attributes:
|
@@ -107,10 +132,10 @@ module Aliyun
|
|
107
132
|
# * id [String] the unique id of a rule
|
108
133
|
# * enabled [Boolean] whether to enable this rule
|
109
134
|
# * prefix [String] the prefix objects to apply this rule
|
110
|
-
# * expiry [Date] or [
|
135
|
+
# * expiry [Date] or [Integer] the expire time of objects
|
111
136
|
# * if expiry is a Date, it specifies the absolute date to
|
112
137
|
# expire objects
|
113
|
-
# * if expiry is a
|
138
|
+
# * if expiry is a Integer, it specifies the relative date to
|
114
139
|
# expire objects: how many days after the object's last
|
115
140
|
# modification time to expire the object
|
116
141
|
# @example Specify expiry as Date
|
data/lib/aliyun/oss/upload.rb
CHANGED
File without changes
|
data/lib/aliyun/oss/util.rb
CHANGED
data/lib/aliyun/sts.rb
CHANGED
File without changes
|
data/lib/aliyun/sts/client.rb
CHANGED
@@ -25,7 +25,7 @@ module Aliyun
|
|
25
25
|
# @param role [String] the role arn
|
26
26
|
# @param session [String] the session name
|
27
27
|
# @param policy [STS::Policy] the policy
|
28
|
-
# @param duration [
|
28
|
+
# @param duration [Integer] the duration seconds for the
|
29
29
|
# requested token
|
30
30
|
# @return [STS::Token] the sts token
|
31
31
|
def assume_role(role, session, policy = nil, duration = 3600)
|
data/lib/aliyun/sts/config.rb
CHANGED
File without changes
|
data/lib/aliyun/sts/exception.rb
CHANGED
File without changes
|
data/lib/aliyun/sts/protocol.rb
CHANGED
@@ -27,7 +27,7 @@ module Aliyun
|
|
27
27
|
# @param role [String] the role arn
|
28
28
|
# @param session [String] the session name
|
29
29
|
# @param policy [STS::Policy] the policy
|
30
|
-
# @param duration [
|
30
|
+
# @param duration [Integer] the duration seconds for the
|
31
31
|
# requested token
|
32
32
|
# @return [STS::Token] the sts token
|
33
33
|
def assume_role(role, session, policy = nil, duration = 3600)
|
data/lib/aliyun/sts/struct.rb
CHANGED
File without changes
|
data/lib/aliyun/sts/util.rb
CHANGED
File without changes
|
data/lib/aliyun/version.rb
CHANGED
@@ -89,13 +89,32 @@ module Aliyun
|
|
89
89
|
if opts.enabled?
|
90
90
|
xml.LoggingEnabled {
|
91
91
|
xml.TargetBucket opts.target_bucket
|
92
|
-
xml.TargetPrefix opts.target_prefix
|
92
|
+
xml.TargetPrefix opts.target_prefix if opts.target_prefix
|
93
93
|
}
|
94
94
|
end
|
95
95
|
}
|
96
96
|
end.to_xml
|
97
97
|
end
|
98
98
|
|
99
|
+
def mock_versioning(opts)
|
100
|
+
Nokogiri::XML::Builder.new do |xml|
|
101
|
+
xml.VersioningConfiguration {
|
102
|
+
xml.Status opts.status
|
103
|
+
}
|
104
|
+
end.to_xml
|
105
|
+
end
|
106
|
+
|
107
|
+
def mock_encryption(opts)
|
108
|
+
Nokogiri::XML::Builder.new do |xml|
|
109
|
+
xml.ServerSideEncryptionRule {
|
110
|
+
xml.ApplyServerSideEncryptionByDefault {
|
111
|
+
xml.SSEAlgorithm opts.sse_algorithm
|
112
|
+
xml.KMSMasterKeyID opts.kms_master_key_id if opts.kms_master_key_id
|
113
|
+
}
|
114
|
+
}
|
115
|
+
end.to_xml
|
116
|
+
end
|
117
|
+
|
99
118
|
def mock_website(opts)
|
100
119
|
Nokogiri::XML::Builder.new do |xml|
|
101
120
|
xml.WebsiteConfiguration {
|
@@ -354,7 +373,7 @@ module Aliyun
|
|
354
373
|
end
|
355
374
|
end # delete bucket
|
356
375
|
|
357
|
-
context "acl, logging, website, referer, lifecycle" do
|
376
|
+
context "acl, logging, versioning, encryption, website, referer, lifecycle" do
|
358
377
|
it "should update acl" do
|
359
378
|
query = {'acl' => nil}
|
360
379
|
stub_request(:put, request_path).with(:query => query)
|
@@ -392,6 +411,19 @@ module Aliyun
|
|
392
411
|
.with(:query => query, :body => mock_logging(logging_opts))
|
393
412
|
end
|
394
413
|
|
414
|
+
it "should enable logging without target prefix" do
|
415
|
+
query = {'logging' => nil}
|
416
|
+
stub_request(:put, request_path).with(:query => query)
|
417
|
+
|
418
|
+
logging_opts = BucketLogging.new(
|
419
|
+
:enable => true,
|
420
|
+
:target_bucket => 'target-bucket')
|
421
|
+
@protocol.put_bucket_logging(@bucket, logging_opts)
|
422
|
+
|
423
|
+
expect(WebMock).to have_requested(:put, request_path)
|
424
|
+
.with(:query => query, :body => mock_logging(logging_opts))
|
425
|
+
end
|
426
|
+
|
395
427
|
it "should disable logging" do
|
396
428
|
query = {'logging' => nil}
|
397
429
|
stub_request(:put, request_path).with(:query => query)
|
@@ -420,6 +452,23 @@ module Aliyun
|
|
420
452
|
expect(logging.to_s).to eq(logging_opts.to_s)
|
421
453
|
end
|
422
454
|
|
455
|
+
it "should get logging without target-bucket" do
|
456
|
+
query = {'logging' => nil}
|
457
|
+
logging_opts = BucketLogging.new(
|
458
|
+
:enable => false,
|
459
|
+
:target_bucket => nil, :target_prefix => nil)
|
460
|
+
|
461
|
+
stub_request(:get, request_path)
|
462
|
+
.with(:query => query)
|
463
|
+
.to_return(:body => mock_logging(logging_opts))
|
464
|
+
|
465
|
+
logging = @protocol.get_bucket_logging(@bucket)
|
466
|
+
|
467
|
+
expect(WebMock).to have_requested(:get, request_path)
|
468
|
+
.with(:query => query, :body => nil)
|
469
|
+
expect(logging.to_s).to eq(logging_opts.to_s)
|
470
|
+
end
|
471
|
+
|
423
472
|
it "should delete logging" do
|
424
473
|
query = {'logging' => nil}
|
425
474
|
stub_request(:delete, request_path).with(:query => query)
|
@@ -430,6 +479,18 @@ module Aliyun
|
|
430
479
|
.with(:query => query, :body => nil)
|
431
480
|
end
|
432
481
|
|
482
|
+
it "should raise Exception when enable logging" do
|
483
|
+
query = {'logging' => nil}
|
484
|
+
stub_request(:put, request_path).with(:query => query)
|
485
|
+
|
486
|
+
logging_opts = BucketLogging.new(
|
487
|
+
:enable => true,
|
488
|
+
:target_bucket => nil, :target_prefix => nil)
|
489
|
+
expect {
|
490
|
+
@protocol.put_bucket_logging(@bucket, logging_opts)
|
491
|
+
}.to raise_error(ClientError)
|
492
|
+
end
|
493
|
+
|
433
494
|
it "should update website" do
|
434
495
|
query = {'website' => nil}
|
435
496
|
stub_request(:put, request_path).with(:query => query)
|
@@ -442,6 +503,18 @@ module Aliyun
|
|
442
503
|
.with(:query => query, :body => mock_website(website_opts))
|
443
504
|
end
|
444
505
|
|
506
|
+
it "should update website with index only" do
|
507
|
+
query = {'website' => nil}
|
508
|
+
stub_request(:put, request_path).with(:query => query)
|
509
|
+
|
510
|
+
website_opts = BucketWebsite.new(
|
511
|
+
:enable => true, :index => 'index.html', :error => nil)
|
512
|
+
@protocol.put_bucket_website(@bucket, website_opts)
|
513
|
+
|
514
|
+
expect(WebMock).to have_requested(:put, request_path)
|
515
|
+
.with(:query => query, :body => mock_website(website_opts))
|
516
|
+
end
|
517
|
+
|
445
518
|
it "should get website" do
|
446
519
|
query = {'website' => nil}
|
447
520
|
website_opts = BucketWebsite.new(
|
@@ -468,6 +541,18 @@ module Aliyun
|
|
468
541
|
.with(:query => query, :body => nil)
|
469
542
|
end
|
470
543
|
|
544
|
+
it "should raise Exception when update website" do
|
545
|
+
query = {'website' => nil}
|
546
|
+
stub_request(:put, request_path).with(:query => query)
|
547
|
+
|
548
|
+
website_opts = BucketWebsite.new(
|
549
|
+
:enable => true, :index => nil)
|
550
|
+
|
551
|
+
expect {
|
552
|
+
@protocol.put_bucket_website(@bucket, website_opts)
|
553
|
+
}.to raise_error(ClientError)
|
554
|
+
end
|
555
|
+
|
471
556
|
it "should update referer" do
|
472
557
|
query = {'referer' => nil}
|
473
558
|
stub_request(:put, request_path).with(:query => query)
|
@@ -541,6 +626,44 @@ module Aliyun
|
|
541
626
|
.with(:query => query, :body => nil)
|
542
627
|
end
|
543
628
|
|
629
|
+
it "should raise Exception when update lifecycle " do
|
630
|
+
query = {'lifecycle' => nil}
|
631
|
+
stub_request(:put, request_path).with(:query => query)
|
632
|
+
|
633
|
+
rules = (1..5).map do |i|
|
634
|
+
LifeCycleRule.new(
|
635
|
+
:id => i, :enable => i % 2 == 0, :prefix => "foo#{i}",
|
636
|
+
:expiry => 'invalid')
|
637
|
+
end
|
638
|
+
|
639
|
+
expect {
|
640
|
+
@protocol.put_bucket_lifecycle(@bucket, rules)
|
641
|
+
}.to raise_error(ClientError)
|
642
|
+
end
|
643
|
+
|
644
|
+
it "should raise Exception when get lifecycle " do
|
645
|
+
query = {'lifecycle' => nil}
|
646
|
+
body = '<LifecycleConfiguration>
|
647
|
+
<Rule>
|
648
|
+
<ID>delete after one day</ID>
|
649
|
+
<Prefix>logs/</Prefix>
|
650
|
+
<Status>Enabled</Status>
|
651
|
+
<Expiration>
|
652
|
+
<Days>1</Days>
|
653
|
+
<Date>2017-01-01T00:00:00.000Z</Date>
|
654
|
+
</Expiration>
|
655
|
+
</Rule>
|
656
|
+
</LifecycleConfiguration>'
|
657
|
+
|
658
|
+
stub_request(:get, request_path)
|
659
|
+
.with(:query => query)
|
660
|
+
.to_return(:body => body)
|
661
|
+
|
662
|
+
expect {
|
663
|
+
rules = @protocol.get_bucket_lifecycle(@bucket)
|
664
|
+
}.to raise_error(ClientError)
|
665
|
+
end
|
666
|
+
|
544
667
|
it "should set cors" do
|
545
668
|
query = {'cors' => nil}
|
546
669
|
stub_request(:put, request_path).with(:query => query)
|
@@ -558,6 +681,24 @@ module Aliyun
|
|
558
681
|
.with(:query => query, :body => mock_cors(rules))
|
559
682
|
end
|
560
683
|
|
684
|
+
it "should set cors with MaxAgeSeconds " do
|
685
|
+
query = {'cors' => nil}
|
686
|
+
stub_request(:put, request_path).with(:query => query)
|
687
|
+
|
688
|
+
rules = (1..5).map do |i|
|
689
|
+
CORSRule.new(
|
690
|
+
:allowed_origins => (1..3).map {|x| "origin-#{x}"},
|
691
|
+
:allowed_methods => ['PUT', 'GET'],
|
692
|
+
:allowed_headers => (1..3).map {|x| "header-#{x}"},
|
693
|
+
:expose_headers => (1..3).map {|x| "header-#{x}"},
|
694
|
+
:max_age_seconds => 5)
|
695
|
+
end
|
696
|
+
@protocol.set_bucket_cors(@bucket, rules)
|
697
|
+
|
698
|
+
expect(WebMock).to have_requested(:put, request_path)
|
699
|
+
.with(:query => query, :body => mock_cors(rules))
|
700
|
+
end
|
701
|
+
|
561
702
|
it "should get cors" do
|
562
703
|
query = {'cors' => nil}
|
563
704
|
return_rules = (1..5).map do |i|
|
@@ -156,6 +156,350 @@ module Aliyun
|
|
156
156
|
.with(:query => query, :body => nil)
|
157
157
|
end
|
158
158
|
|
159
|
+
it "should set logging setting" do
|
160
|
+
query = {'logging' => nil}
|
161
|
+
|
162
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
163
|
+
xml.BucketLoggingStatus {
|
164
|
+
xml.LoggingEnabled {
|
165
|
+
xml.TargetBucket 'target-bucket'
|
166
|
+
}
|
167
|
+
}
|
168
|
+
end.to_xml
|
169
|
+
|
170
|
+
stub_request(:put, bucket_url).with(:query => query)
|
171
|
+
|
172
|
+
@bucket.logging = BucketLogging.new(:enable => true, :target_bucket => 'target-bucket')
|
173
|
+
|
174
|
+
expect(WebMock).to have_requested(:put, bucket_url)
|
175
|
+
.with(:query => query, :body => body)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should get logging setting" do
|
179
|
+
query = {'logging' => nil}
|
180
|
+
|
181
|
+
retbody = Nokogiri::XML::Builder.new do |xml|
|
182
|
+
xml.BucketLoggingStatus {
|
183
|
+
xml.LoggingEnabled {
|
184
|
+
xml.TargetBucket 'target-bucket'
|
185
|
+
xml.TargetPrefix 'target-prefix'
|
186
|
+
}
|
187
|
+
}
|
188
|
+
end.to_xml
|
189
|
+
|
190
|
+
stub_request(:get, bucket_url)
|
191
|
+
.with(:query => query)
|
192
|
+
.to_return(status: 200, :body => retbody)
|
193
|
+
|
194
|
+
logging = @bucket.logging
|
195
|
+
|
196
|
+
expect(WebMock).to have_requested(:get, bucket_url)
|
197
|
+
.with(:query => query, :body => nil)
|
198
|
+
expect(logging.enable).to eq(true)
|
199
|
+
expect(logging.target_bucket).to eq('target-bucket')
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should set webseit" do
|
204
|
+
query = {'website' => nil}
|
205
|
+
|
206
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
207
|
+
xml.WebsiteConfiguration {
|
208
|
+
xml.IndexDocument {
|
209
|
+
xml.Suffix 'index.html'
|
210
|
+
}
|
211
|
+
}
|
212
|
+
end.to_xml
|
213
|
+
|
214
|
+
stub_request(:put, bucket_url)
|
215
|
+
.with(:query => query)
|
216
|
+
.to_return(status: 200, :body => nil)
|
217
|
+
|
218
|
+
@bucket.website = BucketWebsite.new(:enable => true, :index => 'index.html')
|
219
|
+
|
220
|
+
expect(WebMock).to have_requested(:put, bucket_url)
|
221
|
+
.with(:query => query, :body => body)
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should delete webseit" do
|
225
|
+
query = {'website' => nil}
|
226
|
+
|
227
|
+
stub_request(:delete, bucket_url)
|
228
|
+
.with(:query => query)
|
229
|
+
.to_return(status: 204, :body => nil)
|
230
|
+
|
231
|
+
@bucket.website = BucketWebsite.new(:enable => false)
|
232
|
+
|
233
|
+
expect(WebMock).to have_requested(:delete, bucket_url)
|
234
|
+
.with(:query => query, :body => nil)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should get webseit" do
|
238
|
+
query = {'website' => nil}
|
239
|
+
|
240
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
241
|
+
xml.WebsiteConfiguration {
|
242
|
+
xml.IndexDocument {
|
243
|
+
xml.Suffix 'index.html'
|
244
|
+
}
|
245
|
+
xml.ErrorDocument {
|
246
|
+
xml.Key 'error.html'
|
247
|
+
}
|
248
|
+
}
|
249
|
+
end.to_xml
|
250
|
+
|
251
|
+
stub_request(:get, bucket_url)
|
252
|
+
.with(:query => query)
|
253
|
+
.to_return(status: 200, :body => body)
|
254
|
+
|
255
|
+
website = @bucket.website
|
256
|
+
|
257
|
+
expect(WebMock).to have_requested(:get, bucket_url)
|
258
|
+
.with(:query => query, :body => nil)
|
259
|
+
|
260
|
+
expect(website.enable).to eq(true)
|
261
|
+
expect(website.index).to eq('index.html')
|
262
|
+
expect(website.error).to eq('error.html')
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should set referer" do
|
266
|
+
query = {'referer' => nil}
|
267
|
+
|
268
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
269
|
+
xml.RefererConfiguration {
|
270
|
+
xml.AllowEmptyReferer 'true'
|
271
|
+
xml.RefererList {
|
272
|
+
xml.Referer 'http://www.aliyun.com'
|
273
|
+
}
|
274
|
+
}
|
275
|
+
end.to_xml
|
276
|
+
|
277
|
+
stub_request(:put, bucket_url)
|
278
|
+
.with(:query => query)
|
279
|
+
.to_return(status: 200, :body => nil)
|
280
|
+
|
281
|
+
@bucket.referer = BucketReferer.new(:allow_empty => true, :whitelist => ['http://www.aliyun.com'])
|
282
|
+
|
283
|
+
expect(WebMock).to have_requested(:put, bucket_url)
|
284
|
+
.with(:query => query, :body => body)
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should get referer" do
|
288
|
+
query = {'referer' => nil}
|
289
|
+
|
290
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
291
|
+
xml.RefererConfiguration {
|
292
|
+
xml.AllowEmptyReferer 'true'
|
293
|
+
xml.RefererList {
|
294
|
+
xml.Referer 'http://www.aliyun.com'
|
295
|
+
}
|
296
|
+
}
|
297
|
+
end.to_xml
|
298
|
+
|
299
|
+
stub_request(:get, bucket_url)
|
300
|
+
.with(:query => query)
|
301
|
+
.to_return(status: 200, :body => body)
|
302
|
+
|
303
|
+
referer = @bucket.referer
|
304
|
+
|
305
|
+
expect(WebMock).to have_requested(:get, bucket_url)
|
306
|
+
.with(:query => query, :body => nil)
|
307
|
+
|
308
|
+
expect(referer.allow_empty).to eq(true)
|
309
|
+
expect(referer.whitelist).to eq(['http://www.aliyun.com'])
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should set cors" do
|
313
|
+
query = {'cors' => nil}
|
314
|
+
|
315
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
316
|
+
xml.CORSConfiguration {
|
317
|
+
xml.CORSRule {
|
318
|
+
xml.AllowedOrigin '*'
|
319
|
+
xml.AllowedMethod 'PUT'
|
320
|
+
xml.AllowedHeader 'Authorization'
|
321
|
+
}
|
322
|
+
}
|
323
|
+
end.to_xml
|
324
|
+
|
325
|
+
stub_request(:put, bucket_url)
|
326
|
+
.with(:query => query)
|
327
|
+
.to_return(status: 200, :body => nil)
|
328
|
+
|
329
|
+
rules = [
|
330
|
+
CORSRule.new(
|
331
|
+
:allowed_origins => ['*'],
|
332
|
+
:allowed_methods => ['PUT'],
|
333
|
+
:allowed_headers => ['Authorization'],
|
334
|
+
:expose_headers =>[])
|
335
|
+
]
|
336
|
+
|
337
|
+
@bucket.cors = rules
|
338
|
+
|
339
|
+
expect(WebMock).to have_requested(:put, bucket_url)
|
340
|
+
.with(:query => query, :body => body)
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should delete cors" do
|
344
|
+
query = {'cors' => nil}
|
345
|
+
|
346
|
+
stub_request(:delete, bucket_url)
|
347
|
+
.with(:query => query)
|
348
|
+
.to_return(status: 204, :body => nil)
|
349
|
+
|
350
|
+
@bucket.cors = []
|
351
|
+
|
352
|
+
expect(WebMock).to have_requested(:delete, bucket_url)
|
353
|
+
.with(:query => query, :body => nil)
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should get cors" do
|
357
|
+
query = {'cors' => nil}
|
358
|
+
|
359
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
360
|
+
xml.CORSConfiguration {
|
361
|
+
xml.CORSRule {
|
362
|
+
xml.AllowedOrigin '*'
|
363
|
+
xml.AllowedMethod 'PUT'
|
364
|
+
xml.AllowedHeader 'Authorization'
|
365
|
+
}
|
366
|
+
}
|
367
|
+
end.to_xml
|
368
|
+
|
369
|
+
stub_request(:get, bucket_url)
|
370
|
+
.with(:query => query)
|
371
|
+
.to_return(status: 200, :body => body)
|
372
|
+
|
373
|
+
cors = @bucket.cors
|
374
|
+
|
375
|
+
expect(WebMock).to have_requested(:get, bucket_url)
|
376
|
+
.with(:query => query, :body => nil)
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should set versioning" do
|
380
|
+
query = {'versioning' => nil}
|
381
|
+
|
382
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
383
|
+
xml.VersioningConfiguration {
|
384
|
+
xml.Status 'Enabled'
|
385
|
+
}
|
386
|
+
end.to_xml
|
387
|
+
|
388
|
+
stub_request(:put, bucket_url)
|
389
|
+
.with(:query => query)
|
390
|
+
.to_return(status: 200, :body => nil)
|
391
|
+
|
392
|
+
@bucket.versioning = BucketVersioning.new(:status => 'Enabled')
|
393
|
+
|
394
|
+
expect(WebMock).to have_requested(:put, bucket_url)
|
395
|
+
.with(:query => query, :body => body)
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should get versioning" do
|
399
|
+
query = {'versioning' => nil}
|
400
|
+
|
401
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
402
|
+
xml.VersioningConfiguration {
|
403
|
+
xml.Status 'Enabled'
|
404
|
+
}
|
405
|
+
end.to_xml
|
406
|
+
|
407
|
+
stub_request(:get, bucket_url)
|
408
|
+
.with(:query => query)
|
409
|
+
.to_return(status: 200, :body => body)
|
410
|
+
|
411
|
+
ret = @bucket.versioning
|
412
|
+
|
413
|
+
expect(WebMock).to have_requested(:get, bucket_url)
|
414
|
+
.with(:query => query, :body => nil)
|
415
|
+
|
416
|
+
expect(ret.status).to eq('Enabled')
|
417
|
+
end
|
418
|
+
|
419
|
+
it "should set encryption with aes256" do
|
420
|
+
query = {'encryption' => nil}
|
421
|
+
|
422
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
423
|
+
xml.ServerSideEncryptionRule {
|
424
|
+
xml.ApplyServerSideEncryptionByDefault {
|
425
|
+
xml.SSEAlgorithm 'AES256'
|
426
|
+
}
|
427
|
+
}
|
428
|
+
end.to_xml
|
429
|
+
|
430
|
+
stub_request(:put, bucket_url)
|
431
|
+
.with(:query => query)
|
432
|
+
.to_return(status: 200, :body => nil)
|
433
|
+
|
434
|
+
@bucket.encryption = BucketEncryption.new(:enable => true, :sse_algorithm => 'AES256')
|
435
|
+
|
436
|
+
expect(WebMock).to have_requested(:put, bucket_url)
|
437
|
+
.with(:query => query, :body => body)
|
438
|
+
end
|
439
|
+
|
440
|
+
it "should set encryption with KMS" do
|
441
|
+
query = {'encryption' => nil}
|
442
|
+
|
443
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
444
|
+
xml.ServerSideEncryptionRule {
|
445
|
+
xml.ApplyServerSideEncryptionByDefault {
|
446
|
+
xml.SSEAlgorithm 'KMS'
|
447
|
+
xml.KMSMasterKeyID 'kms-id'
|
448
|
+
}
|
449
|
+
}
|
450
|
+
end.to_xml
|
451
|
+
|
452
|
+
stub_request(:put, bucket_url)
|
453
|
+
.with(:query => query)
|
454
|
+
.to_return(status: 200, :body => nil)
|
455
|
+
|
456
|
+
@bucket.encryption = BucketEncryption.new(
|
457
|
+
:enable => true,
|
458
|
+
:sse_algorithm => 'KMS',
|
459
|
+
:kms_master_key_id => 'kms-id')
|
460
|
+
|
461
|
+
expect(WebMock).to have_requested(:put, bucket_url)
|
462
|
+
.with(:query => query, :body => body)
|
463
|
+
end
|
464
|
+
|
465
|
+
it "should get encryption" do
|
466
|
+
query = {'encryption' => nil}
|
467
|
+
|
468
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
469
|
+
xml.ServerSideEncryptionRule {
|
470
|
+
xml.ApplyServerSideEncryptionByDefault {
|
471
|
+
xml.SSEAlgorithm 'KMS'
|
472
|
+
xml.KMSMasterKeyID 'kms-id'
|
473
|
+
}
|
474
|
+
}
|
475
|
+
end.to_xml
|
476
|
+
|
477
|
+
stub_request(:get, bucket_url)
|
478
|
+
.with(:query => query)
|
479
|
+
.to_return(status: 200, :body => body)
|
480
|
+
|
481
|
+
ret = @bucket.encryption
|
482
|
+
|
483
|
+
expect(WebMock).to have_requested(:get, bucket_url)
|
484
|
+
.with(:query => query, :body => nil)
|
485
|
+
|
486
|
+
expect(ret.sse_algorithm).to eq('KMS')
|
487
|
+
expect(ret.kms_master_key_id).to eq('kms-id')
|
488
|
+
end
|
489
|
+
|
490
|
+
it "should delete encryption" do
|
491
|
+
query = {'encryption' => nil}
|
492
|
+
|
493
|
+
stub_request(:delete, bucket_url)
|
494
|
+
.with(:query => query)
|
495
|
+
.to_return(status: 204, :body => nil)
|
496
|
+
|
497
|
+
@bucket.encryption = BucketEncryption.new(:enable => false)
|
498
|
+
|
499
|
+
expect(WebMock).to have_requested(:delete, bucket_url)
|
500
|
+
.with(:query => query, :body => nil)
|
501
|
+
end
|
502
|
+
|
159
503
|
it "should get bucket url" do
|
160
504
|
expect(@bucket.bucket_url)
|
161
505
|
.to eq('http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com/')
|
@@ -467,29 +811,55 @@ module Aliyun
|
|
467
811
|
expect(signature).to eq(sig)
|
468
812
|
end
|
469
813
|
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
.
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
814
|
+
context 'should use STS' do
|
815
|
+
it "get object url" do
|
816
|
+
sts_bucket = Client.new(
|
817
|
+
:endpoint => @endpoint,
|
818
|
+
:access_key_id => 'xxx',
|
819
|
+
:access_key_secret => 'yyy',
|
820
|
+
:sts_token => 'zzz').get_bucket(@bucket_name)
|
821
|
+
|
822
|
+
object_url = 'http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com/yeah'
|
823
|
+
|
824
|
+
url = sts_bucket.object_url('yeah')
|
825
|
+
path = url[0, url.index('?')]
|
826
|
+
expect(path).to eq(object_url)
|
827
|
+
|
828
|
+
query = {}
|
829
|
+
url[url.index('?') + 1, url.size].split('&')
|
830
|
+
.each { |s| k, v = s.split('='); query[k] = v }
|
831
|
+
|
832
|
+
expect(query.key?('Expires')).to be true
|
833
|
+
expect(query.key?('Signature')).to be true
|
834
|
+
expect(query['OSSAccessKeyId']).to eq('xxx')
|
835
|
+
expect(query['security-token']).to eq('zzz')
|
836
|
+
end
|
837
|
+
|
838
|
+
it "get object url with query string" do
|
839
|
+
sts_bucket = Client.new(
|
840
|
+
:endpoint => @endpoint,
|
841
|
+
:access_key_id => 'xxx',
|
842
|
+
:access_key_secret => 'yyy',
|
843
|
+
:sts_token => 'zzz').get_bucket(@bucket_name)
|
844
|
+
|
845
|
+
param = {
|
846
|
+
'x-oss-process' => 'image/resize,m_fill,h_100,w_100',
|
847
|
+
}
|
848
|
+
url = sts_bucket.object_url('ico.png', true, 60, param)
|
849
|
+
path = url[0, url.index('?')]
|
850
|
+
expect(path).to eq('http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com/ico.png')
|
851
|
+
|
852
|
+
query = {}
|
853
|
+
url[url.index('?') + 1, url.size].split('&')
|
854
|
+
.each { |s| k, v = s.split('='); query[k] = v }
|
855
|
+
|
856
|
+
expect(query.key?('Expires')).to be true
|
857
|
+
expect(query.key?('Signature')).to be true
|
858
|
+
expect(query['OSSAccessKeyId']).to eq('xxx')
|
859
|
+
expect(query['security-token']).to eq('zzz')
|
860
|
+
expect(query['x-oss-process']).to eq('image%2Fresize%2Cm_fill%2Ch_100%2Cw_100')
|
861
|
+
end
|
491
862
|
end
|
492
|
-
|
493
863
|
end # object operations
|
494
864
|
|
495
865
|
context "multipart operations" do
|