right_aws 1.9.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +164 -13
- data/Manifest.txt +28 -1
- data/README.txt +12 -10
- data/Rakefile +56 -29
- data/lib/acf/right_acf_interface.rb +343 -172
- data/lib/acf/right_acf_invalidations.rb +144 -0
- data/lib/acf/right_acf_origin_access_identities.rb +230 -0
- data/lib/acf/right_acf_streaming_interface.rb +229 -0
- data/lib/acw/right_acw_interface.rb +248 -0
- data/lib/as/right_as_interface.rb +698 -0
- data/lib/awsbase/right_awsbase.rb +755 -115
- data/lib/awsbase/support.rb +2 -78
- data/lib/awsbase/version.rb +9 -0
- data/lib/ec2/right_ec2.rb +274 -1294
- data/lib/ec2/right_ec2_ebs.rb +514 -0
- data/lib/ec2/right_ec2_images.rb +444 -0
- data/lib/ec2/right_ec2_instances.rb +797 -0
- data/lib/ec2/right_ec2_monitoring.rb +70 -0
- data/lib/ec2/right_ec2_placement_groups.rb +108 -0
- data/lib/ec2/right_ec2_reserved_instances.rb +243 -0
- data/lib/ec2/right_ec2_security_groups.rb +496 -0
- data/lib/ec2/right_ec2_spot_instances.rb +422 -0
- data/lib/ec2/right_ec2_tags.rb +139 -0
- data/lib/ec2/right_ec2_vpc.rb +598 -0
- data/lib/ec2/right_ec2_vpc2.rb +382 -0
- data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
- data/lib/elb/right_elb_interface.rb +573 -0
- data/lib/emr/right_emr_interface.rb +728 -0
- data/lib/iam/right_iam_access_keys.rb +71 -0
- data/lib/iam/right_iam_groups.rb +195 -0
- data/lib/iam/right_iam_interface.rb +341 -0
- data/lib/iam/right_iam_mfa_devices.rb +67 -0
- data/lib/iam/right_iam_users.rb +251 -0
- data/lib/rds/right_rds_interface.rb +1657 -0
- data/lib/right_aws.rb +30 -13
- data/lib/route_53/right_route_53_interface.rb +641 -0
- data/lib/s3/right_s3.rb +108 -41
- data/lib/s3/right_s3_interface.rb +349 -118
- data/lib/sdb/active_sdb.rb +388 -54
- data/lib/sdb/right_sdb_interface.rb +323 -64
- data/lib/sns/right_sns_interface.rb +286 -0
- data/lib/sqs/right_sqs.rb +1 -2
- data/lib/sqs/right_sqs_gen2.rb +73 -17
- data/lib/sqs/right_sqs_gen2_interface.rb +146 -73
- data/lib/sqs/right_sqs_interface.rb +12 -22
- data/right_aws.gemspec +91 -0
- data/test/README.mdown +39 -0
- data/test/acf/test_right_acf.rb +11 -19
- data/test/awsbase/test_helper.rb +2 -0
- data/test/awsbase/test_right_awsbase.rb +11 -0
- data/test/ec2/test_right_ec2.rb +32 -1
- data/test/elb/test_helper.rb +2 -0
- data/test/elb/test_right_elb.rb +43 -0
- data/test/rds/test_helper.rb +2 -0
- data/test/rds/test_right_rds.rb +120 -0
- data/test/route_53/fixtures/a_record.xml +18 -0
- data/test/route_53/fixtures/alias_record.xml +18 -0
- data/test/route_53/test_helper.rb +2 -0
- data/test/route_53/test_right_route_53.rb +141 -0
- data/test/s3/test_right_s3.rb +176 -42
- data/test/s3/test_right_s3_stubbed.rb +6 -4
- data/test/sdb/test_active_sdb.rb +120 -19
- data/test/sdb/test_batch_put_attributes.rb +54 -0
- data/test/sdb/test_right_sdb.rb +71 -16
- data/test/sns/test_helper.rb +2 -0
- data/test/sns/test_right_sns.rb +153 -0
- data/test/sqs/test_right_sqs.rb +0 -6
- data/test/sqs/test_right_sqs_gen2.rb +104 -49
- data/test/ts_right_aws.rb +1 -0
- metadata +181 -22
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/">
|
3
|
+
<ChangeBatch>
|
4
|
+
<Changes>
|
5
|
+
<Change>
|
6
|
+
<Action>CREATE</Action>
|
7
|
+
<ResourceRecordSet>
|
8
|
+
<Name>right-aws.example.com.</Name>
|
9
|
+
<Type>A</Type>
|
10
|
+
<AliasTarget>
|
11
|
+
<HostedZoneId>Z1234567890123</HostedZoneId>
|
12
|
+
<DNSName>example-load-balancer-1111111111.us-east-1.elb.amazonaws.com.</DNSName>
|
13
|
+
</AliasTarget>
|
14
|
+
</ResourceRecordSet>
|
15
|
+
</Change>
|
16
|
+
</Changes>
|
17
|
+
</ChangeBatch>
|
18
|
+
</ChangeResourceRecordSetsRequest>
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestRoute53 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
STDOUT.sync = true
|
6
|
+
BALANCER_NAME = 'right-aws-test-lb'
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@r53 = Rightscale::Route53Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :logger => Logger.new('/dev/null'))
|
10
|
+
@zone_config = {:name => "right-aws.example.com.", :config => {:comment => 'a comment'}}
|
11
|
+
|
12
|
+
@elb = Rightscale::ElbInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :logger => Logger.new('/dev/null'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
@r53.list_hosted_zones.each do |zone|
|
17
|
+
next unless zone[:name] == @zone_config[:name]
|
18
|
+
zone_id = zone[:aws_id]
|
19
|
+
puts zone_id
|
20
|
+
records = @r53.list_resource_record_sets(zone_id)
|
21
|
+
# The NS and SOA records are provided by AWS and must not be deleted
|
22
|
+
records.reject! { |rr| %w[NS SOA].include? rr[:type] }
|
23
|
+
if records.any?
|
24
|
+
response = @r53.delete_resource_record_sets(zone_id, records)
|
25
|
+
puts response.inspect
|
26
|
+
end
|
27
|
+
puts @r53.delete_hosted_zone(zone_id).inspect
|
28
|
+
end
|
29
|
+
# Uncomment to shut down at the end of the day.
|
30
|
+
# @elb.delete_load_balancer BALANCER_NAME
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_00_list_hosted_zones
|
34
|
+
items = @r53.list_hosted_zones
|
35
|
+
assert items.is_a?(Array)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_create_and_delete_zone
|
39
|
+
response = @r53.create_hosted_zone(@zone_config)
|
40
|
+
assert_equal response[:name], @zone_config[:name]
|
41
|
+
assert response[:aws_id].is_a?(String)
|
42
|
+
assert response[:name_servers].is_a?(Array)
|
43
|
+
|
44
|
+
response2 = @r53.delete_hosted_zone(response[:aws_id])
|
45
|
+
assert_equal response2[:status], 'PENDING'
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_add_and_remove_A_record
|
49
|
+
zone = @r53.create_hosted_zone(@zone_config)
|
50
|
+
zone_id = zone[:aws_id]
|
51
|
+
# add
|
52
|
+
a_record = { :name => 'host.right-aws.example.com.', :type => 'A', :ttl => 600, :resource_records => ['10.0.0.1'] }
|
53
|
+
response = @r53.create_resource_record_sets(zone_id, [a_record.dup]) # .dup since it will get :action => :create
|
54
|
+
assert_equal response[:status], 'PENDING'
|
55
|
+
|
56
|
+
# It should be there now
|
57
|
+
records = @r53.list_resource_record_sets(zone_id)
|
58
|
+
assert records.is_a?(Array)
|
59
|
+
assert records.detect { |rr| rr == a_record }, "Could not find '#{a_record.inspect}' in '#{records.inspect}'"
|
60
|
+
|
61
|
+
# remove
|
62
|
+
response = @r53.delete_resource_record_sets(zone_id, [a_record.dup])
|
63
|
+
assert_equal response[:status], 'PENDING'
|
64
|
+
|
65
|
+
# It should not be there anymore
|
66
|
+
records = @r53.list_resource_record_sets(zone_id)
|
67
|
+
assert records.is_a?(Array)
|
68
|
+
assert ! records.detect { |rr| rr == a_record }, "Record '#{a_record.inspect}' is still in '#{records.inspect}'"
|
69
|
+
|
70
|
+
@r53.delete_hosted_zone(zone_id)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_add_and_remove_Alias_record
|
74
|
+
lb = find_or_create_load_balancer
|
75
|
+
|
76
|
+
zone = @r53.create_hosted_zone(@zone_config)
|
77
|
+
zone_id = zone[:aws_id]
|
78
|
+
|
79
|
+
# add
|
80
|
+
alias_target = { :hosted_zone_id => lb[:canonical_hosted_zone_name_id], :dns_name => lb[:dns_name] }
|
81
|
+
alias_record = { :name => 'right-aws.example.com', :type => 'A', :alias_target => alias_target }
|
82
|
+
response = @r53.create_resource_record_sets(zone_id, [alias_record.dup]) # .dup since it will get :action => :create
|
83
|
+
assert_equal response[:status], 'PENDING'
|
84
|
+
|
85
|
+
# It should be there now
|
86
|
+
records = @r53.list_resource_record_sets(zone_id)
|
87
|
+
assert records.is_a?(Array)
|
88
|
+
record = records.detect { |rr| rr[:alias_target] }
|
89
|
+
assert record, "Could not find '#{alias_record.inspect}' in '#{records.inspect}'"
|
90
|
+
# AWS adds final dots to names
|
91
|
+
assert_equal "#{alias_record[:name]}.", record[:name]
|
92
|
+
assert_equal "#{alias_target[:dns_name]}.", record[:alias_target][:dns_name]
|
93
|
+
|
94
|
+
# remove
|
95
|
+
response = @r53.delete_resource_record_sets(zone_id, [alias_record.dup])
|
96
|
+
assert_equal response[:status], 'PENDING'
|
97
|
+
|
98
|
+
# It should not be there anymore
|
99
|
+
records = @r53.list_resource_record_sets(zone_id)
|
100
|
+
assert records.is_a?(Array)
|
101
|
+
record = records.detect { |rr| rr[:alias_target] }
|
102
|
+
assert ! record, "Record '#{alias_record.inspect}' is still in '#{records.inspect}'"
|
103
|
+
|
104
|
+
@r53.delete_hosted_zone(zone_id)
|
105
|
+
end
|
106
|
+
|
107
|
+
def find_or_create_load_balancer
|
108
|
+
unless @elb.describe_load_balancers.detect { |lb| lb[:load_balancer_name] == BALANCER_NAME }
|
109
|
+
@elb.create_load_balancer(BALANCER_NAME, %w[us-east-1b], [])
|
110
|
+
puts "WARNING: Started load balancer. Remember to shut it down (see teardown)."
|
111
|
+
puts "NOTE: Tests might not pass during first few seconds after load balancer is created."
|
112
|
+
end
|
113
|
+
@elb.describe_load_balancers.detect { |lb| lb[:load_balancer_name] == BALANCER_NAME }
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_rr_sets_to_xml
|
117
|
+
a_record = { :name => 'host.right-aws.example.com.', :type => 'A', :ttl => 600, :resource_records => ['10.0.0.1'], :action => :create }
|
118
|
+
expected = load_fixture('a_record.xml')
|
119
|
+
assert_equal expected, @r53.resource_record_sets_to_xml([a_record], '')
|
120
|
+
|
121
|
+
# Note final full stop
|
122
|
+
alias_target = { :hosted_zone_id => 'Z1234567890123', :dns_name => 'example-load-balancer-1111111111.us-east-1.elb.amazonaws.com.' }
|
123
|
+
alias_record = { :name => 'right-aws.example.com.', :type => 'A', :alias_target => alias_target, :action => :create }
|
124
|
+
expected = load_fixture('alias_record.xml')
|
125
|
+
assert_same_lines expected, @r53.resource_record_sets_to_xml([alias_record], '')
|
126
|
+
end
|
127
|
+
|
128
|
+
def load_fixture (name)
|
129
|
+
File.read(File.join(File.dirname(__FILE__), 'fixtures', name))
|
130
|
+
end
|
131
|
+
|
132
|
+
def assert_same_lines (expected, actual)
|
133
|
+
expected = expected.split "\n"
|
134
|
+
actual = actual.split "\n"
|
135
|
+
previous = []
|
136
|
+
while e = expected.shift and a = actual.shift
|
137
|
+
assert_equal e, a, "After:\n#{previous.join("\n")}"
|
138
|
+
previous << e
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/test/s3/test_right_s3.rb
CHANGED
@@ -3,24 +3,28 @@ require File.dirname(__FILE__) + '/test_helper.rb'
|
|
3
3
|
class TestS3 < Test::Unit::TestCase
|
4
4
|
|
5
5
|
RIGHT_OBJECT_TEXT = 'Right test message'
|
6
|
-
|
6
|
+
INTERFACE = Rightscale::S3Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
7
|
+
CONNECTION = Rightscale::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
8
|
+
|
7
9
|
def setup
|
8
|
-
@s3 =
|
9
|
-
@bucket = '
|
10
|
-
@bucket2 = '
|
10
|
+
@s3 = INTERFACE
|
11
|
+
@bucket = 'right_s3_awesome_test_bucket_000B1_officedrop'
|
12
|
+
@bucket2 = 'right_s3_awesome_test_bucket_000B2_officedrop'
|
11
13
|
@key1 = 'test/woohoo1/'
|
12
14
|
@key2 = 'test1/key/woohoo2'
|
13
15
|
@key3 = 'test2/A%B@C_D&E?F+G=H"I'
|
16
|
+
@key4 = 'test/large_multipart_file_string'
|
17
|
+
@key5 = 'test/large_multipart_file_stream'
|
14
18
|
@key1_copy = 'test/woohoo1_2'
|
15
19
|
@key1_new_name = 'test/woohoo1_3'
|
16
20
|
@key2_new_name = 'test1/key/woohoo2_new'
|
17
|
-
@s =
|
21
|
+
@s = CONNECTION
|
18
22
|
end
|
19
23
|
|
20
24
|
#---------------------------
|
21
25
|
# Rightscale::S3Interface
|
22
26
|
#---------------------------
|
23
|
-
|
27
|
+
|
24
28
|
def test_01_create_bucket
|
25
29
|
assert @s3.create_bucket(@bucket), 'Create_bucket fail'
|
26
30
|
end
|
@@ -32,13 +36,33 @@ class TestS3 < Test::Unit::TestCase
|
|
32
36
|
def test_03_list_empty_bucket
|
33
37
|
assert_equal 0, @s3.list_bucket(@bucket).size, "#{@bucket} isn't empty, arrgh!"
|
34
38
|
end
|
35
|
-
|
39
|
+
|
36
40
|
def test_04_put
|
37
41
|
assert @s3.put(@bucket, @key1, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!'), 'Put bucket fail'
|
38
42
|
assert @s3.put(@bucket, @key2, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo2!'), 'Put bucket fail'
|
39
43
|
assert @s3.put(@bucket, @key3, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo3!'), 'Put bucket fail'
|
40
44
|
end
|
41
|
-
|
45
|
+
|
46
|
+
def test_04_put_multipart_string
|
47
|
+
test_text = ""
|
48
|
+
for i in 1..100000
|
49
|
+
test_text << "Testing test text #{i}\n"
|
50
|
+
end
|
51
|
+
assert @s3.store_object_multipart({:bucket => @bucket, :key => @key4, :data => StringIO.new(test_text)}), 'Put bucket multipart fail'
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_04b_store_object_multipart_stream
|
55
|
+
rd, wr = IO.pipe
|
56
|
+
producer = Thread.new(wr) do |out|
|
57
|
+
for i in 1..100000
|
58
|
+
out.write("Testing stream text #{i}\n")
|
59
|
+
end
|
60
|
+
out.close
|
61
|
+
end
|
62
|
+
assert @s3.store_object_multipart({:bucket => @bucket, :key => @key5, :data => rd , :part_size => (20*1024*1024)}), 'Put bucket multipart fail'
|
63
|
+
rd.close
|
64
|
+
end
|
65
|
+
|
42
66
|
def test_05_get_and_get_object
|
43
67
|
assert_raise(Rightscale::AwsError) { @s3.get(@bucket, 'undefined/key') }
|
44
68
|
data1 = @s3.get(@bucket, @key1)
|
@@ -47,7 +71,7 @@ class TestS3 < Test::Unit::TestCase
|
|
47
71
|
assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
48
72
|
assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key3), "Get_object text must return '#{RIGHT_OBJECT_TEXT}'"
|
49
73
|
end
|
50
|
-
|
74
|
+
|
51
75
|
def test_06_head
|
52
76
|
assert_equal 'Woohoo1!', @s3.head(@bucket,@key1)['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
53
77
|
end
|
@@ -55,7 +79,7 @@ class TestS3 < Test::Unit::TestCase
|
|
55
79
|
|
56
80
|
def test_07_streaming_get
|
57
81
|
resp = String.new
|
58
|
-
assert_raise(Rightscale::AwsError) do
|
82
|
+
assert_raise(Rightscale::AwsError) do
|
59
83
|
@s3.get(@bucket, 'undefined/key') do |chunk|
|
60
84
|
resp += chunk
|
61
85
|
end
|
@@ -69,15 +93,17 @@ class TestS3 < Test::Unit::TestCase
|
|
69
93
|
assert_equal @s3.get_object(@bucket, @key1), resp, "Streaming iface must return same as non-streaming"
|
70
94
|
assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
71
95
|
end
|
72
|
-
|
96
|
+
|
73
97
|
def test_08_keys
|
74
98
|
keys = @s3.list_bucket(@bucket).map{|b| b[:key]}
|
75
|
-
assert_equal keys.size,
|
99
|
+
assert_equal keys.size, 5, "There should be 5 keys"
|
76
100
|
assert(keys.include?(@key1))
|
77
101
|
assert(keys.include?(@key2))
|
78
102
|
assert(keys.include?(@key3))
|
103
|
+
assert(keys.include?(@key4))
|
104
|
+
assert(keys.include?(@key5))
|
79
105
|
end
|
80
|
-
|
106
|
+
|
81
107
|
def test_09_copy_key
|
82
108
|
#--- test COPY
|
83
109
|
# copy a key
|
@@ -130,7 +156,7 @@ class TestS3 < Test::Unit::TestCase
|
|
130
156
|
def test_13_delete_folder
|
131
157
|
assert_equal 1, @s3.delete_folder(@bucket, 'test').size, "Only one key(#{@key1}) must be deleted!"
|
132
158
|
end
|
133
|
-
|
159
|
+
|
134
160
|
def test_14_delete_bucket
|
135
161
|
assert_raise(Rightscale::AwsError) { @s3.delete_bucket(@bucket) }
|
136
162
|
assert @s3.clear_bucket(@bucket), 'Clear_bucket fail'
|
@@ -138,9 +164,10 @@ class TestS3 < Test::Unit::TestCase
|
|
138
164
|
assert @s3.delete_bucket(@bucket)
|
139
165
|
assert !@s3.list_all_my_buckets.map{|bucket| bucket[:name]}.include?(@bucket), "#{@bucket} must not exist"
|
140
166
|
end
|
141
|
-
|
142
|
-
|
143
|
-
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
144
171
|
|
145
172
|
#---------------------------
|
146
173
|
# Rightscale::S3 classes
|
@@ -198,7 +225,7 @@ class TestS3 < Test::Unit::TestCase
|
|
198
225
|
assert key2.delete
|
199
226
|
assert !key2.exists?
|
200
227
|
end
|
201
|
-
|
228
|
+
|
202
229
|
def test_23_rename_key
|
203
230
|
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
204
231
|
# -- 1 -- (key based rename)
|
@@ -218,7 +245,7 @@ class TestS3 < Test::Unit::TestCase
|
|
218
245
|
assert bucket.key('test/copy/3').exists?, "'test/copy/3' should exist"
|
219
246
|
assert !bucket.key('test/copy/2').exists?, "'test/copy/2' should not exist"
|
220
247
|
end
|
221
|
-
|
248
|
+
|
222
249
|
def test_24_copy_key
|
223
250
|
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
224
251
|
# -- 1 -- (key based copy)
|
@@ -239,7 +266,7 @@ class TestS3 < Test::Unit::TestCase
|
|
239
266
|
assert_equal RIGHT_OBJECT_TEXT, bucket.key('test/copy/11').get
|
240
267
|
assert_equal RIGHT_OBJECT_TEXT, bucket.key('test/copy/12').get
|
241
268
|
end
|
242
|
-
|
269
|
+
|
243
270
|
def test_25_move_key
|
244
271
|
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
245
272
|
# -- 1 -- (key based copy)
|
@@ -258,20 +285,20 @@ class TestS3 < Test::Unit::TestCase
|
|
258
285
|
assert bucket.key('test/copy/22').exists?, "'test/copy/22' should exist"
|
259
286
|
assert_equal RIGHT_OBJECT_TEXT, bucket.key('test/copy/22').get
|
260
287
|
end
|
261
|
-
|
288
|
+
|
262
289
|
def test_26_save_meta
|
263
290
|
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
264
291
|
# create a key
|
265
292
|
key = bucket.key('test/copy/30')
|
266
293
|
key.put(RIGHT_OBJECT_TEXT)
|
267
|
-
assert key.meta_headers.
|
294
|
+
assert key.meta_headers.right_blank?
|
268
295
|
# store some meta keys
|
269
296
|
meta = {'family' => 'oops','race' => 'troll'}
|
270
297
|
assert_equal meta, key.save_meta(meta)
|
271
298
|
# reload meta
|
272
299
|
assert_equal meta, key.reload_meta
|
273
300
|
end
|
274
|
-
|
301
|
+
|
275
302
|
def test_27_clear_delete
|
276
303
|
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
277
304
|
# add another key
|
@@ -280,16 +307,16 @@ class TestS3 < Test::Unit::TestCase
|
|
280
307
|
assert_equal 1, bucket.delete_folder(@key1).size
|
281
308
|
# delete
|
282
309
|
assert_raise(Rightscale::AwsError) { bucket.delete }
|
283
|
-
bucket.delete(true)
|
310
|
+
bucket.delete(:force => true)
|
284
311
|
end
|
285
312
|
|
286
313
|
# Grantees
|
287
|
-
|
314
|
+
|
288
315
|
def test_30_create_bucket
|
289
316
|
bucket = @s.bucket(@bucket, true, 'public-read')
|
290
317
|
assert bucket
|
291
318
|
end
|
292
|
-
|
319
|
+
|
293
320
|
def test_31_list_grantees
|
294
321
|
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
295
322
|
# get grantees list
|
@@ -297,10 +324,10 @@ class TestS3 < Test::Unit::TestCase
|
|
297
324
|
# check that the grantees count equal to 2 (root, AllUsers)
|
298
325
|
assert_equal 2, grantees.size
|
299
326
|
end
|
300
|
-
|
327
|
+
|
301
328
|
def test_32_grant_revoke_drop
|
302
329
|
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
303
|
-
# Take 'AllUsers' grantee
|
330
|
+
# Take 'AllUsers' grantee
|
304
331
|
grantee = Rightscale::S3::Grantee.new(bucket,'http://acs.amazonaws.com/groups/global/AllUsers')
|
305
332
|
# Check exists?
|
306
333
|
assert grantee.exists?
|
@@ -331,9 +358,9 @@ class TestS3 < Test::Unit::TestCase
|
|
331
358
|
assert !grantee.exists?
|
332
359
|
assert_equal 1, bucket.grantees.size
|
333
360
|
# Delete bucket
|
334
|
-
bucket.delete(true)
|
361
|
+
bucket.delete(:force => true)
|
335
362
|
end
|
336
|
-
|
363
|
+
|
337
364
|
def test_33_key_grantees
|
338
365
|
# Create bucket
|
339
366
|
bucket = @s.bucket(@bucket, true)
|
@@ -350,7 +377,7 @@ class TestS3 < Test::Unit::TestCase
|
|
350
377
|
# Drop grantee
|
351
378
|
assert grantee.drop
|
352
379
|
# Drop bucket
|
353
|
-
bucket.delete(true)
|
380
|
+
bucket.delete(:force => true)
|
354
381
|
end
|
355
382
|
|
356
383
|
def test_34_bucket_create_put_with_perms
|
@@ -393,27 +420,134 @@ class TestS3 < Test::Unit::TestCase
|
|
393
420
|
RightAws::S3Interface.amazon_problems= nil
|
394
421
|
assert_nil(RightAws::S3Interface.amazon_problems)
|
395
422
|
end
|
396
|
-
|
423
|
+
|
397
424
|
def test_37_access_logging
|
398
425
|
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
399
426
|
targetbucket = Rightscale::S3::Bucket.create(@s, @bucket2, true)
|
400
|
-
# Take 'AllUsers' grantee
|
427
|
+
# Take 'AllUsers' grantee
|
401
428
|
grantee = Rightscale::S3::Grantee.new(targetbucket,'http://acs.amazonaws.com/groups/s3/LogDelivery')
|
402
|
-
|
429
|
+
|
403
430
|
assert grantee.grant(['READ_ACP', 'WRITE'])
|
404
|
-
|
431
|
+
|
405
432
|
assert bucket.enable_logging(:targetbucket => targetbucket, :targetprefix => "loggylogs/")
|
406
|
-
|
407
|
-
|
433
|
+
sleep 10
|
434
|
+
|
435
|
+
assert_equal({:enabled => true, :targetbucket => @bucket2, :targetprefix => "loggylogs/"}, bucket.logging_info)
|
408
436
|
|
409
437
|
assert bucket.disable_logging
|
410
|
-
|
438
|
+
|
411
439
|
# check 'Drop' method
|
412
440
|
assert grantee.drop
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
441
|
+
end
|
442
|
+
|
443
|
+
def test_40_delete_buckets
|
444
|
+
Rightscale::S3::Bucket.create(@s, @bucket, false).delete(:force => true)
|
445
|
+
Rightscale::S3::Bucket.create(@s, @bucket2, false).delete(:force => true)
|
446
|
+
end
|
447
|
+
|
448
|
+
def test_41_add_cache_control_response_parameter
|
449
|
+
@cache_control = 'max-age=3600'
|
450
|
+
perform_request( 'response-cache-control' => @cache_control ) do |response|
|
451
|
+
assert_equal response['Cache-Control'], @cache_control
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_42_add_cache_control_and_content_type_and_content_disposition
|
456
|
+
@cache_control = 'max-age=3600'
|
457
|
+
@content_type = 'text/plain'
|
458
|
+
@content_disposition = 'attachment; filename=sample.txt'
|
459
|
+
perform_request(
|
460
|
+
'response-cache-control' => @cache_control,
|
461
|
+
'response-content-type' => @content_type,
|
462
|
+
'response-content-disposition' => @content_disposition
|
463
|
+
) do |response|
|
464
|
+
assert_equal response['Cache-Control'], @cache_control
|
465
|
+
assert_equal response['Content-Type'], @content_type
|
466
|
+
assert_equal response['Content-Disposition'], @content_disposition
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
def test_43_add_expires_and_content_type_and_content_disposition
|
471
|
+
@expires = 'Sun, 26 Jun 2011 02:58:26 GMT'
|
472
|
+
@content_type = 'text/plain'
|
473
|
+
@content_disposition = 'attachment; filename=sample.txt'
|
474
|
+
perform_request(
|
475
|
+
'response-expires' => @expires,
|
476
|
+
'response-content-type' => @content_type,
|
477
|
+
'response-content-disposition' => @content_disposition
|
478
|
+
) do |response|
|
479
|
+
assert_equal response['Expires'], @expires
|
480
|
+
assert_equal response['Content-Type'], @content_type
|
481
|
+
assert_equal response['Content-Disposition'], @content_disposition
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
def test_44_delete_multiple
|
486
|
+
bucket = RightAws::S3::Bucket.create(@s, @bucket, true)
|
487
|
+
|
488
|
+
key1 = Rightscale::S3::Key.create(bucket, @key1)
|
489
|
+
key2 = Rightscale::S3::Key.create(bucket, @key2)
|
490
|
+
key3 = Rightscale::S3::Key.create(bucket, @key3)
|
491
|
+
|
492
|
+
assert @s3.put(@bucket, @key1, RIGHT_OBJECT_TEXT), 'Put bucket fail'
|
493
|
+
assert @s3.put(@bucket, @key2, RIGHT_OBJECT_TEXT), 'Put bucket fail'
|
494
|
+
assert @s3.put(@bucket, @key3, RIGHT_OBJECT_TEXT), 'Put bucket fail'
|
495
|
+
|
496
|
+
key1.refresh
|
497
|
+
key2.refresh
|
498
|
+
key3.refresh
|
499
|
+
|
500
|
+
assert key1.exists?
|
501
|
+
assert key2.exists?
|
502
|
+
assert key3.exists?
|
503
|
+
|
504
|
+
result = @s3.delete_multiple(@bucket, [@key1, @key2, @key3])
|
505
|
+
assert result.empty?
|
506
|
+
|
507
|
+
key1.refresh
|
508
|
+
key2.refresh
|
509
|
+
key3.refresh
|
510
|
+
|
511
|
+
assert !key1.exists?
|
512
|
+
assert !key2.exists?
|
513
|
+
assert !key3.exists?
|
514
|
+
end
|
515
|
+
|
516
|
+
def test_45_delete_multiple_more_than_1000_objects
|
517
|
+
n = 1200
|
518
|
+
keys = (1..n).map { |i| "key-#{i}"}
|
519
|
+
|
520
|
+
keys.each do |key|
|
521
|
+
assert @s3.put(@bucket, key, RIGHT_OBJECT_TEXT), 'Put bucket fail'
|
522
|
+
end
|
523
|
+
|
524
|
+
result = @s3.delete_multiple(@bucket, keys)
|
525
|
+
assert result.empty?
|
526
|
+
|
527
|
+
keys_after = @s3.list_bucket(@bucket).map { |obj| obj[:key] }
|
528
|
+
|
529
|
+
keys.each do |key|
|
530
|
+
assert !keys_after.include?(key)
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
private
|
535
|
+
|
536
|
+
def request( uri )
|
537
|
+
url = URI.parse( uri )
|
538
|
+
|
539
|
+
http = Net::HTTP.new(url.host, 80)
|
540
|
+
# http.use_ssl = true
|
541
|
+
# http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
542
|
+
http.request(Net::HTTP::Get.new( url.request_uri ))
|
543
|
+
end
|
544
|
+
|
545
|
+
def perform_request( headers, &block )
|
546
|
+
@s3.create_bucket( @bucket )
|
547
|
+
@s3.put( @bucket, @key2, RIGHT_OBJECT_TEXT )
|
548
|
+
response = request( @s3.get_link( @bucket, @key2, nil, {}, headers ) )
|
549
|
+
block.call( response )
|
550
|
+
@s3.force_delete_bucket(@bucket)
|
417
551
|
end
|
418
552
|
|
419
553
|
end
|