aws 1.11.38 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +20 -23
- data/lib/acf/right_acf_interface.rb +17 -17
- data/lib/aws.rb +27 -0
- data/lib/awsbase/right_awsbase.rb +8 -8
- data/lib/ec2/right_ec2.rb +37 -35
- data/lib/ec2/right_mon_interface.rb +25 -15
- data/lib/elb/right_elb_interface.rb +6 -6
- data/lib/right_aws.rb +6 -17
- data/lib/s3/right_s3.rb +58 -58
- data/lib/s3/right_s3_interface.rb +18 -18
- data/lib/sdb/active_sdb.rb +28 -28
- data/lib/sdb/right_sdb_interface.rb +18 -18
- data/lib/sqs/right_sqs.rb +13 -13
- data/lib/sqs/right_sqs_interface.rb +12 -12
- data/test/acf/test_right_acf.rb +10 -8
- data/test/ec2/test_helper.rb +1 -1
- data/test/ec2/test_mon.rb +17 -0
- data/test/ec2/test_right_ec2.rb +9 -7
- data/test/s3/test_helper.rb +2 -1
- data/test/s3/test_right_s3.rb +417 -411
- data/test/s3/test_right_s3_stubbed.rb +11 -9
- data/test/sdb/test_active_sdb.rb +11 -10
- data/test/sdb/test_right_sdb.rb +210 -242
- data/test/sqs/test_right_sqs.rb +190 -269
- data/test/test_credentials.rb +52 -40
- metadata +4 -3
- data/test/sqs/test_right_sqs_gen2.rb +0 -209
@@ -21,10 +21,10 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#
|
23
23
|
|
24
|
-
module
|
24
|
+
module Aws
|
25
25
|
|
26
26
|
#
|
27
|
-
# Right::Aws::
|
27
|
+
# Right::Aws::SqsInterface - RightScale's low-level Amazon SQS interface
|
28
28
|
# for API version 2008-01-01 and later.
|
29
29
|
# For explanations of the semantics
|
30
30
|
# of each call, please refer to Amazon's documentation at
|
@@ -33,10 +33,10 @@ module RightAws
|
|
33
33
|
# This class provides a procedural interface to SQS. Conceptually it is
|
34
34
|
# mostly a pass-through interface to SQS and its API is very similar to the
|
35
35
|
# bare SQS API. For a somewhat higher-level and object-oriented interface, see
|
36
|
-
#
|
36
|
+
# Aws::Sqs.
|
37
37
|
|
38
|
-
class SqsInterface <
|
39
|
-
include
|
38
|
+
class SqsInterface < AwsBase
|
39
|
+
include AwsBaseInterface
|
40
40
|
|
41
41
|
API_VERSION = "2008-01-01"
|
42
42
|
DEFAULT_HOST = "queue.amazonaws.com"
|
@@ -65,7 +65,7 @@ module RightAws
|
|
65
65
|
# Amazon's article "Migrating to Amazon SQS API version 2008-01-01" at:
|
66
66
|
# http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1148
|
67
67
|
#
|
68
|
-
# sqs =
|
68
|
+
# sqs = Aws::SqsInterface.new('1E3GDYEOGFJPIT75KDT40','hgTHt68JY07JKUY08ftHYtERkjgtfERn57DFE379', {:multi_thread => true, :logger => Logger.new('/tmp/x.log')})
|
69
69
|
#
|
70
70
|
# Params is a hash:
|
71
71
|
#
|
@@ -367,7 +367,7 @@ module RightAws
|
|
367
367
|
# PARSERS: Status Response Parser
|
368
368
|
#-----------------------------------------------------------------
|
369
369
|
|
370
|
-
class SqsStatusParser <
|
370
|
+
class SqsStatusParser < AwsParser # :nodoc:
|
371
371
|
def tagend(name)
|
372
372
|
if name == 'ResponseMetadata'
|
373
373
|
@result = true
|
@@ -379,13 +379,13 @@ module RightAws
|
|
379
379
|
# PARSERS: Queue
|
380
380
|
#-----------------------------------------------------------------
|
381
381
|
|
382
|
-
class SqsCreateQueueParser <
|
382
|
+
class SqsCreateQueueParser < AwsParser # :nodoc:
|
383
383
|
def tagend(name)
|
384
384
|
@result = @text if name == 'QueueUrl'
|
385
385
|
end
|
386
386
|
end
|
387
387
|
|
388
|
-
class SqsListQueuesParser <
|
388
|
+
class SqsListQueuesParser < AwsParser # :nodoc:
|
389
389
|
def reset
|
390
390
|
@result = []
|
391
391
|
end
|
@@ -394,7 +394,7 @@ module RightAws
|
|
394
394
|
end
|
395
395
|
end
|
396
396
|
|
397
|
-
class SqsGetQueueAttributesParser <
|
397
|
+
class SqsGetQueueAttributesParser < AwsParser # :nodoc:
|
398
398
|
def reset
|
399
399
|
@result = {}
|
400
400
|
end
|
@@ -410,7 +410,7 @@ module RightAws
|
|
410
410
|
# PARSERS: Messages
|
411
411
|
#-----------------------------------------------------------------
|
412
412
|
|
413
|
-
class SqsReceiveMessageParser <
|
413
|
+
class SqsReceiveMessageParser < AwsParser # :nodoc:
|
414
414
|
def reset
|
415
415
|
@result = []
|
416
416
|
end
|
@@ -427,7 +427,7 @@ module RightAws
|
|
427
427
|
end
|
428
428
|
end
|
429
429
|
|
430
|
-
class SqsSendMessagesParser <
|
430
|
+
class SqsSendMessagesParser < AwsParser # :nodoc:
|
431
431
|
def reset
|
432
432
|
@result = {}
|
433
433
|
end
|
data/test/acf/test_right_acf.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
2
3
|
|
3
4
|
class TestAcf < Test::Unit::TestCase
|
4
5
|
|
@@ -7,15 +8,16 @@ class TestAcf < Test::Unit::TestCase
|
|
7
8
|
STDOUT.sync = true
|
8
9
|
|
9
10
|
def setup
|
10
|
-
|
11
|
-
@
|
11
|
+
TestCredentials.get_credentials
|
12
|
+
@acf= Aws::AcfInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
13
|
+
@s3 = Aws::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
12
14
|
@bucket_name = "right-acf-awesome-test-bucket-0001"
|
13
15
|
@bucket_domain = "#{@bucket_name}.s3.amazonaws.com"
|
14
16
|
end
|
15
17
|
|
16
18
|
def test_01_list_distributions_part1
|
17
19
|
distributions = nil
|
18
|
-
assert_nothing_raised(
|
20
|
+
assert_nothing_raised(Aws::AwsError) do
|
19
21
|
distributions = @acf.list_distributions
|
20
22
|
end
|
21
23
|
assert distributions.is_a?(Array)
|
@@ -23,13 +25,13 @@ class TestAcf < Test::Unit::TestCase
|
|
23
25
|
|
24
26
|
def test_02_try_to_create_for_bad_bucket
|
25
27
|
# a bucket does not exist
|
26
|
-
assert_raise(
|
28
|
+
assert_raise(Aws::AwsError) do
|
27
29
|
@acf.create_distribution("right-cloudfront-awesome-test-bucket-not-exist", "Mustn't to be born", true)
|
28
30
|
end
|
29
31
|
# a bucket is not a domain naming complied guy
|
30
32
|
bucket_name = 'right_cloudfront_awesome_test_bucket_BAD'
|
31
33
|
@s3.bucket(bucket_name, :create)
|
32
|
-
assert_raise(
|
34
|
+
assert_raise(Aws::AwsError) do
|
33
35
|
@acf.create_distribution(bucket_name, "Mustn't to be born", true)
|
34
36
|
end
|
35
37
|
end
|
@@ -87,7 +89,7 @@ class TestAcf < Test::Unit::TestCase
|
|
87
89
|
assert_not_equal config[:e_tag], new_config[:e_tag]
|
88
90
|
|
89
91
|
# try to update the old config again (must fail because ETAG has changed)
|
90
|
-
assert_raise(
|
92
|
+
assert_raise(Aws::AwsError) do
|
91
93
|
@acf.set_distribution_config(old[:aws_id], config)
|
92
94
|
end
|
93
95
|
end
|
@@ -98,7 +100,7 @@ class TestAcf < Test::Unit::TestCase
|
|
98
100
|
# list distributions
|
99
101
|
@acf.list_distributions
|
100
102
|
# list the distributions again - cache should hit
|
101
|
-
assert_raise(
|
103
|
+
assert_raise(Aws::AwsNoChange) do
|
102
104
|
@acf.list_distributions
|
103
105
|
end
|
104
106
|
# disable caching
|
@@ -112,7 +114,7 @@ class TestAcf < Test::Unit::TestCase
|
|
112
114
|
# should fail because
|
113
115
|
if distribution[:status] == 'InProgress'
|
114
116
|
# should fail because the distribution is not deployed yet
|
115
|
-
assert_raise(
|
117
|
+
assert_raise(Aws::AwsError) do
|
116
118
|
@acf.delete_distribution(distribution[:aws_id], distribution[:e_tag])
|
117
119
|
end
|
118
120
|
# wait for a deployed state
|
data/test/ec2/test_helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require File.dirname(__FILE__) + '/../../lib/
|
2
|
+
require File.dirname(__FILE__) + '/../../lib/aws'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
class TestEc2 < Test::Unit::TestCase
|
6
|
+
|
7
|
+
# Some of RightEc2 instance methods concerning instance launching and image registration
|
8
|
+
# are not tested here due to their potentially risk.
|
9
|
+
|
10
|
+
def setup
|
11
|
+
TestCredentials.get_credentials
|
12
|
+
@ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
|
13
|
+
TestCredentials.aws_secret_access_key)
|
14
|
+
@key = 'right_ec2_awesome_test_key'
|
15
|
+
@group = 'right_ec2_awesome_test_security_group'
|
16
|
+
end
|
17
|
+
end
|
data/test/ec2/test_right_ec2.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
require 'pp'
|
3
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
3
4
|
|
4
5
|
class TestEc2 < Test::Unit::TestCase
|
5
6
|
|
@@ -7,7 +8,8 @@ class TestEc2 < Test::Unit::TestCase
|
|
7
8
|
# are not tested here due to their potentially risk.
|
8
9
|
|
9
10
|
def setup
|
10
|
-
|
11
|
+
TestCredentials.get_credentials
|
12
|
+
@ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
|
11
13
|
TestCredentials.aws_secret_access_key)
|
12
14
|
@key = 'right_ec2_awesome_test_key'
|
13
15
|
@group = 'right_ec2_awesome_test_security_group'
|
@@ -45,13 +47,13 @@ class TestEc2 < Test::Unit::TestCase
|
|
45
47
|
images = @ec2.describe_images
|
46
48
|
assert images.size>0, 'Amazon must have at least some public images'
|
47
49
|
# unknown image
|
48
|
-
assert_raise(
|
50
|
+
assert_raise(Aws::AwsError){ @ec2.describe_images(['ami-ABCDEFGH'])}
|
49
51
|
end
|
50
52
|
|
51
53
|
def test_07_describe_instanses
|
52
54
|
assert @ec2.describe_instances
|
53
55
|
# unknown image
|
54
|
-
assert_raise(
|
56
|
+
assert_raise(Aws::AwsError){ @ec2.describe_instances(['i-ABCDEFGH'])}
|
55
57
|
end
|
56
58
|
|
57
59
|
def test_08_delete_security_group
|
@@ -62,11 +64,11 @@ class TestEc2 < Test::Unit::TestCase
|
|
62
64
|
assert @ec2.delete_key_pair(@key), 'Delete_key_pair fail'
|
63
65
|
## Hmmm... Amazon does not through the exception any more. It now just returns a 'true' if the key does not exist any more...
|
64
66
|
## # key must be deleted already
|
65
|
-
## assert_raise(
|
67
|
+
## assert_raise(Aws::AwsError) { @ec2.delete_key_pair(@key) }
|
66
68
|
end
|
67
69
|
|
68
70
|
def test_10_signature_version_0
|
69
|
-
ec2 =
|
71
|
+
ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
|
70
72
|
images = ec2.describe_images
|
71
73
|
assert images.size>0, 'Amazon must have at least some public images'
|
72
74
|
# check that the request has correct signature version
|
@@ -82,7 +84,7 @@ class TestEc2 < Test::Unit::TestCase
|
|
82
84
|
assert regions.size > 0
|
83
85
|
# check an access to regions
|
84
86
|
regions.each do |region|
|
85
|
-
regional_ec2 =
|
87
|
+
regional_ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :region => region)
|
86
88
|
# do we have a correct endpoint server?
|
87
89
|
assert_equal "#{region}.ec2.amazonaws.com", regional_ec2.params[:server]
|
88
90
|
# get a list of images from every region
|
@@ -96,7 +98,7 @@ class TestEc2 < Test::Unit::TestCase
|
|
96
98
|
end
|
97
99
|
|
98
100
|
def test_12_endpoint_url
|
99
|
-
ec2 =
|
101
|
+
ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :endpoint_url => 'a://b.c:0/d/', :region => 'z')
|
100
102
|
# :endpoint_url has a priority hence :region should be ommitted
|
101
103
|
assert_equal 'a', ec2.params[:protocol]
|
102
104
|
assert_equal 'b.c', ec2.params[:server]
|
data/test/s3/test_helper.rb
CHANGED
data/test/s3/test_right_s3.rb
CHANGED
@@ -1,419 +1,425 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
2
3
|
|
3
4
|
class TestS3 < Test::Unit::TestCase
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
6
|
+
RIGHT_OBJECT_TEXT = 'Right test message'
|
7
|
+
|
8
|
+
def setup
|
9
|
+
TestCredentials.get_credentials
|
10
|
+
@s3 = Aws::S3Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
11
|
+
@bucket = TestCredentials.config['amazon']['my_prefix'] + '_awesome_test_bucket_000A1'
|
12
|
+
@bucket2 = TestCredentials.config['amazon']['my_prefix'] + '_awesome_test_bucket_000A2'
|
13
|
+
@key1 = 'test/woohoo1/'
|
14
|
+
@key2 = 'test1/key/woohoo2'
|
15
|
+
@key3 = 'test2/A%B@C_D&E?F+G=H"I'
|
16
|
+
@key1_copy = 'test/woohoo1_2'
|
17
|
+
@key1_new_name = 'test/woohoo1_3'
|
18
|
+
@key2_new_name = 'test1/key/woohoo2_new'
|
19
|
+
@s = Aws::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
#---------------------------
|
27
|
+
# Aws::S3Interface
|
28
|
+
#---------------------------
|
29
|
+
|
30
|
+
def test_01_create_bucket
|
31
|
+
assert @s3.create_bucket(@bucket), 'Create_bucket fail'
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_02_list_all_my_buckets
|
35
|
+
assert @s3.list_all_my_buckets.map{|bucket| bucket[:name]}.include?(@bucket), "#{@bucket} must exist in bucket list"
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_03_list_empty_bucket
|
39
|
+
assert_equal 0, @s3.list_bucket(@bucket).size, "#{@bucket} isn't empty, arrgh!"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_04_put
|
43
|
+
assert @s3.put(@bucket, @key1, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!'), 'Put bucket fail'
|
44
|
+
assert @s3.put(@bucket, @key2, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo2!'), 'Put bucket fail'
|
45
|
+
assert @s3.put(@bucket, @key3, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo3!'), 'Put bucket fail'
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_05_get_and_get_object
|
49
|
+
assert_raise(Aws::AwsError) { @s3.get(@bucket, 'undefined/key') }
|
50
|
+
data1 = @s3.get(@bucket, @key1)
|
51
|
+
assert_equal RIGHT_OBJECT_TEXT, data1[:object], "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
|
52
|
+
assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1), "Get_object text must return '#{RIGHT_OBJECT_TEXT}'"
|
53
|
+
assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
54
|
+
assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key3), "Get_object text must return '#{RIGHT_OBJECT_TEXT}'"
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_06_head
|
58
|
+
assert_equal 'Woohoo1!', @s3.head(@bucket, @key1)['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def test_07_streaming_get
|
63
|
+
resp = String.new
|
64
|
+
assert_raise(Aws::AwsError) do
|
65
|
+
@s3.get(@bucket, 'undefined/key') do |chunk|
|
66
|
+
resp += chunk
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
resp = String.new
|
71
|
+
data1 = @s3.get(@bucket, @key1) do |chunk|
|
72
|
+
resp += chunk
|
73
|
+
end
|
74
|
+
assert_equal RIGHT_OBJECT_TEXT, resp, "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
|
75
|
+
assert_equal @s3.get_object(@bucket, @key1), resp, "Streaming iface must return same as non-streaming"
|
76
|
+
assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_08_keys
|
80
|
+
keys = @s3.list_bucket(@bucket).map{|b| b[:key]}
|
81
|
+
assert_equal keys.size, 3, "There should be 3 keys"
|
82
|
+
assert(keys.include?(@key1))
|
83
|
+
assert(keys.include?(@key2))
|
84
|
+
assert(keys.include?(@key3))
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_09_copy_key
|
88
|
+
#--- test COPY
|
89
|
+
# copy a key
|
90
|
+
assert @s3.copy(@bucket, @key1, @bucket, @key1_copy)
|
91
|
+
# check it was copied well
|
92
|
+
assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1_copy), "copied object must have the same data"
|
93
|
+
# check meta-headers were copied
|
94
|
+
headers = @s3.head(@bucket, @key1_copy)
|
95
|
+
assert_equal 'Woohoo1!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
96
|
+
#--- test REPLACE
|
97
|
+
assert @s3.copy(@bucket, @key1, @bucket, @key1_copy, :replace, 'x-amz-meta-family' => 'oooops!')
|
98
|
+
# check it was copied well
|
99
|
+
assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1_copy), "copied object must have the same data"
|
100
|
+
# check meta-headers were overwrittenn
|
101
|
+
headers = @s3.head(@bucket, @key1_copy)
|
102
|
+
assert_equal 'oooops!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'oooops!'"
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_10_move_key
|
106
|
+
# move a key
|
107
|
+
assert @s3.move(@bucket, @key1, @bucket, @key1_new_name)
|
108
|
+
# check it's data was moved correctly
|
109
|
+
assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1_new_name), "moved object must have the same data"
|
110
|
+
# check meta-headers were moved
|
111
|
+
headers = @s3.head(@bucket, @key1_new_name)
|
112
|
+
assert_equal 'Woohoo1!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
113
|
+
# check the original key is not exists any more
|
114
|
+
keys = @s3.list_bucket(@bucket).map{|b| b[:key]}
|
115
|
+
assert(!keys.include?(@key1))
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_11_rename_key
|
119
|
+
# rename a key
|
120
|
+
assert @s3.rename(@bucket, @key2, @key2_new_name)
|
121
|
+
# check the new key data
|
122
|
+
assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key2_new_name), "moved object must have the same data"
|
123
|
+
# check meta-headers
|
124
|
+
headers = @s3.head(@bucket, @key2_new_name)
|
125
|
+
assert_equal 'Woohoo2!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo2!'"
|
126
|
+
# check the original key is not exists any more
|
127
|
+
keys = @s3.list_bucket(@bucket).map{|b| b[:key]}
|
128
|
+
assert(!keys.include?(@key2))
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_12_retrieve_object
|
132
|
+
assert_raise(Aws::AwsError) { @s3.retrieve_object(:bucket => @bucket, :key => 'undefined/key') }
|
133
|
+
data1 = @s3.retrieve_object(:bucket => @bucket, :key => @key1_new_name)
|
134
|
+
assert_equal RIGHT_OBJECT_TEXT, data1[:object], "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
|
135
|
+
assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_13_delete_folder
|
139
|
+
assert_equal 1, @s3.delete_folder(@bucket, 'test').size, "Only one key(#{@key1}) must be deleted!"
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_14_delete_bucket
|
143
|
+
assert_raise(Aws::AwsError) { @s3.delete_bucket(@bucket) }
|
144
|
+
assert @s3.clear_bucket(@bucket), 'Clear_bucket fail'
|
145
|
+
assert_equal 0, @s3.list_bucket(@bucket).size, 'Bucket must be empty'
|
146
|
+
assert @s3.delete_bucket(@bucket)
|
147
|
+
assert !@s3.list_all_my_buckets.map{|bucket| bucket[:name]}.include?(@bucket), "#{@bucket} must not exist"
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
#---------------------------
|
152
|
+
# Aws::S3 classes
|
153
|
+
#---------------------------
|
154
|
+
|
155
|
+
def test_20_s3
|
156
|
+
# create bucket
|
157
|
+
bucket = @s.bucket(@bucket, true)
|
158
|
+
assert bucket
|
159
|
+
# check that the bucket exists
|
160
|
+
assert @s.buckets.map{|b| b.name}.include?(@bucket)
|
161
|
+
# delete bucket
|
162
|
+
assert bucket.clear
|
163
|
+
assert bucket.delete
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_21_bucket_create_put_get_key
|
167
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, true)
|
168
|
+
# check that the bucket exists
|
169
|
+
assert @s.buckets.map{|b| b.name}.include?(@bucket)
|
170
|
+
assert bucket.keys.empty?
|
171
|
+
# put data
|
172
|
+
assert bucket.put(@key3, RIGHT_OBJECT_TEXT, {'family'=>'123456'})
|
173
|
+
# get data and compare
|
174
|
+
assert_equal RIGHT_OBJECT_TEXT, bucket.get(@key3)
|
175
|
+
# get key object
|
176
|
+
key = bucket.key(@key3, true)
|
177
|
+
assert_equal Aws::S3::Key, key.class
|
178
|
+
assert key.exists?
|
179
|
+
assert_equal '123456', key.meta_headers['family']
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_22_keys
|
183
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
184
|
+
# create first key
|
185
|
+
key3 = Aws::S3::Key.create(bucket, @key3)
|
186
|
+
key3.refresh
|
187
|
+
assert key3.exists?
|
188
|
+
assert_equal '123456', key3.meta_headers['family']
|
189
|
+
# create second key
|
190
|
+
key2 = Aws::S3::Key.create(bucket, @key2)
|
191
|
+
assert !key2.refresh
|
192
|
+
assert !key2.exists?
|
193
|
+
assert_raise(Aws::AwsError) { key2.head }
|
194
|
+
# store key
|
195
|
+
key2.meta_headers = {'family'=>'111222333'}
|
196
|
+
assert key2.put(RIGHT_OBJECT_TEXT)
|
197
|
+
# make sure that the key exists
|
198
|
+
assert key2.refresh
|
199
|
+
assert key2.exists?
|
200
|
+
assert key2.head
|
201
|
+
# get its data
|
202
|
+
assert_equal RIGHT_OBJECT_TEXT, key2.get
|
203
|
+
# drop key
|
204
|
+
assert key2.delete
|
205
|
+
assert !key2.exists?
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_23_rename_key
|
209
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
210
|
+
# -- 1 -- (key based rename)
|
211
|
+
# create a key
|
212
|
+
key = bucket.key('test/copy/1')
|
213
|
+
key.put(RIGHT_OBJECT_TEXT)
|
214
|
+
original_key = key.clone
|
215
|
+
assert key.exists?, "'test/copy/1' should exist"
|
216
|
+
# rename it
|
217
|
+
key.rename('test/copy/2')
|
218
|
+
assert_equal 'test/copy/2', key.name
|
219
|
+
assert key.exists?, "'test/copy/2' should exist"
|
220
|
+
# the original key should not exist
|
221
|
+
assert !original_key.exists?, "'test/copy/1' should not exist"
|
222
|
+
# -- 2 -- (bucket based rename)
|
223
|
+
bucket.rename_key('test/copy/2', 'test/copy/3')
|
224
|
+
assert bucket.key('test/copy/3').exists?, "'test/copy/3' should exist"
|
225
|
+
assert !bucket.key('test/copy/2').exists?, "'test/copy/2' should not exist"
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_24_copy_key
|
229
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
230
|
+
# -- 1 -- (key based copy)
|
231
|
+
# create a key
|
232
|
+
key = bucket.key('test/copy/10')
|
233
|
+
key.put(RIGHT_OBJECT_TEXT)
|
234
|
+
# make copy
|
235
|
+
new_key = key.copy('test/copy/11')
|
236
|
+
# make sure both the keys exist and have a correct data
|
237
|
+
assert key.exists?, "'test/copy/10' should exist"
|
238
|
+
assert new_key.exists?, "'test/copy/11' should exist"
|
239
|
+
assert_equal RIGHT_OBJECT_TEXT, key.get
|
240
|
+
assert_equal RIGHT_OBJECT_TEXT, new_key.get
|
241
|
+
# -- 2 -- (bucket based copy)
|
242
|
+
bucket.copy_key('test/copy/11', 'test/copy/12')
|
243
|
+
assert bucket.key('test/copy/11').exists?, "'test/copy/11' should exist"
|
244
|
+
assert bucket.key('test/copy/12').exists?, "'test/copy/12' should exist"
|
245
|
+
assert_equal RIGHT_OBJECT_TEXT, bucket.key('test/copy/11').get
|
246
|
+
assert_equal RIGHT_OBJECT_TEXT, bucket.key('test/copy/12').get
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_25_move_key
|
250
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
251
|
+
# -- 1 -- (key based copy)
|
252
|
+
# create a key
|
253
|
+
key = bucket.key('test/copy/20')
|
254
|
+
key.put(RIGHT_OBJECT_TEXT)
|
255
|
+
# move
|
256
|
+
new_key = key.move('test/copy/21')
|
257
|
+
# make sure both the keys exist and have a correct data
|
258
|
+
assert !key.exists?, "'test/copy/20' should not exist"
|
259
|
+
assert new_key.exists?, "'test/copy/21' should exist"
|
260
|
+
assert_equal RIGHT_OBJECT_TEXT, new_key.get
|
261
|
+
# -- 2 -- (bucket based copy)
|
262
|
+
bucket.copy_key('test/copy/21', 'test/copy/22')
|
263
|
+
assert bucket.key('test/copy/21').exists?, "'test/copy/21' should not exist"
|
264
|
+
assert bucket.key('test/copy/22').exists?, "'test/copy/22' should exist"
|
265
|
+
assert_equal RIGHT_OBJECT_TEXT, bucket.key('test/copy/22').get
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_26_save_meta
|
269
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
270
|
+
# create a key
|
271
|
+
key = bucket.key('test/copy/30')
|
272
|
+
key.put(RIGHT_OBJECT_TEXT)
|
273
|
+
assert key.meta_headers.blank?
|
274
|
+
# store some meta keys
|
275
|
+
meta = {'family' => 'oops', 'race' => 'troll'}
|
276
|
+
assert_equal meta, key.save_meta(meta)
|
277
|
+
# reload meta
|
278
|
+
assert_equal meta, key.reload_meta
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_27_clear_delete
|
282
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
283
|
+
# add another key
|
284
|
+
bucket.put(@key2, RIGHT_OBJECT_TEXT)
|
285
|
+
# delete 'folder'
|
286
|
+
assert_equal 1, bucket.delete_folder(@key1).size
|
287
|
+
# delete
|
288
|
+
assert_raise(Aws::AwsError) { bucket.delete }
|
289
|
+
bucket.delete(true)
|
290
|
+
end
|
285
291
|
|
286
292
|
# Grantees
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
293
|
+
|
294
|
+
def test_30_create_bucket
|
295
|
+
bucket = @s.bucket(@bucket, true, 'public-read')
|
296
|
+
assert bucket
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_31_list_grantees
|
300
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
301
|
+
# get grantees list
|
302
|
+
grantees = bucket.grantees
|
303
|
+
# check that the grantees count equal to 2 (root, AllUsers)
|
304
|
+
assert_equal 2, grantees.size
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_32_grant_revoke_drop
|
308
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
309
|
+
# Take 'AllUsers' grantee
|
310
|
+
grantee = Aws::S3::Grantee.new(bucket, 'http://acs.amazonaws.com/groups/global/AllUsers')
|
311
|
+
# Check exists?
|
312
|
+
assert grantee.exists?
|
313
|
+
# Add grant as String
|
314
|
+
assert grantee.grant('WRITE')
|
315
|
+
# Add grants as Array
|
316
|
+
assert grantee.grant(['READ_ACP', 'WRITE_ACP'])
|
317
|
+
# Check perms count
|
318
|
+
assert_equal 4, grantee.perms.size
|
319
|
+
# revoke 'WRITE_ACP'
|
320
|
+
assert grantee.revoke('WRITE_ACP')
|
321
|
+
# Check manual perm removal method
|
322
|
+
grantee.perms -= ['READ_ACP']
|
323
|
+
grantee.apply
|
324
|
+
assert_equal 2, grantee.perms.size
|
325
|
+
# Check grantee removal if it has no permissions
|
326
|
+
assert grantee.perms = []
|
327
|
+
assert grantee.apply
|
328
|
+
assert !grantee.exists?
|
329
|
+
# Check multiple perms assignment
|
330
|
+
assert grantee.grant('FULL_CONTROL', 'READ', 'WRITE')
|
331
|
+
assert_equal ['FULL_CONTROL', 'READ', 'WRITE'].sort, grantee.perms.sort
|
332
|
+
# Check multiple perms removal
|
333
|
+
assert grantee.revoke('FULL_CONTROL', 'WRITE')
|
334
|
+
assert_equal ['READ'], grantee.perms
|
335
|
+
# check 'Drop' method
|
336
|
+
assert grantee.drop
|
337
|
+
assert !grantee.exists?
|
338
|
+
assert_equal 1, bucket.grantees.size
|
339
|
+
# Delete bucket
|
340
|
+
bucket.delete(true)
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_33_key_grantees
|
344
|
+
# Create bucket
|
345
|
+
bucket = @s.bucket(@bucket, true)
|
346
|
+
# Create key
|
347
|
+
key = bucket.key(@key1)
|
348
|
+
assert key.put(RIGHT_OBJECT_TEXT, 'public-read')
|
349
|
+
# Get grantees list (must be == 2)
|
350
|
+
grantees = key.grantees
|
351
|
+
assert grantees
|
352
|
+
assert_equal 2, grantees.size
|
353
|
+
# Take one of grantees and give him 'Write' perms
|
354
|
+
grantee = grantees[0]
|
355
|
+
assert grantee.grant('WRITE')
|
356
|
+
# Drop grantee
|
357
|
+
assert grantee.drop
|
358
|
+
# Drop bucket
|
359
|
+
bucket.delete(true)
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_34_bucket_create_put_with_perms
|
363
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, true)
|
364
|
+
# check that the bucket exists
|
365
|
+
assert @s.buckets.map{|b| b.name}.include?(@bucket)
|
366
|
+
assert bucket.keys.empty?
|
367
|
+
# put data (with canned ACL)
|
368
|
+
assert bucket.put(@key1, RIGHT_OBJECT_TEXT, {'family'=>'123456'}, "public-read")
|
369
|
+
# get data and compare
|
370
|
+
assert_equal RIGHT_OBJECT_TEXT, bucket.get(@key1)
|
371
|
+
# get key object
|
372
|
+
key = bucket.key(@key1, true)
|
373
|
+
assert_equal Aws::S3::Key, key.class
|
374
|
+
assert key.exists?
|
375
|
+
assert_equal '123456', key.meta_headers['family']
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_35_key_put_with_perms
|
379
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
380
|
+
# create first key
|
381
|
+
key1 = Aws::S3::Key.create(bucket, @key1)
|
382
|
+
key1.refresh
|
383
|
+
assert key1.exists?
|
384
|
+
assert key1.put(RIGHT_OBJECT_TEXT, "public-read")
|
385
|
+
# get its data
|
386
|
+
assert_equal RIGHT_OBJECT_TEXT, key1.get
|
387
|
+
# drop key
|
388
|
+
assert key1.delete
|
389
|
+
assert !key1.exists?
|
390
|
+
end
|
391
|
+
|
392
|
+
def test_36_set_amazon_problems
|
393
|
+
original_problems = Aws::S3Interface.amazon_problems
|
394
|
+
assert(original_problems.length > 0)
|
395
|
+
Aws::S3Interface.amazon_problems= original_problems << "A New Problem"
|
396
|
+
new_problems = Aws::S3Interface.amazon_problems
|
397
|
+
assert_equal(new_problems, original_problems)
|
398
|
+
|
399
|
+
Aws::S3Interface.amazon_problems= nil
|
400
|
+
assert_nil(Aws::S3Interface.amazon_problems)
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_37_access_logging
|
404
|
+
bucket = Aws::S3::Bucket.create(@s, @bucket, false)
|
405
|
+
targetbucket = Aws::S3::Bucket.create(@s, @bucket2, true)
|
406
|
+
# Take 'AllUsers' grantee
|
407
|
+
grantee = Aws::S3::Grantee.new(targetbucket, 'http://acs.amazonaws.com/groups/s3/LogDelivery')
|
408
|
+
|
409
|
+
assert grantee.grant(['READ_ACP', 'WRITE'])
|
410
|
+
|
411
|
+
assert bucket.enable_logging(:targetbucket => targetbucket, :targetprefix => "loggylogs/")
|
412
|
+
|
413
|
+
assert_equal(bucket.logging_info, {:enabled => true, :targetbucket => @bucket2, :targetprefix => "loggylogs/"})
|
414
|
+
|
415
|
+
assert bucket.disable_logging
|
416
|
+
|
417
|
+
# check 'Drop' method
|
418
|
+
assert grantee.drop
|
419
|
+
|
420
|
+
# Delete bucket
|
421
|
+
bucket.delete(true)
|
422
|
+
targetbucket.delete(true)
|
423
|
+
end
|
418
424
|
|
419
425
|
end
|