right_aws 1.8.1 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,13 +46,14 @@ require 'sqs/right_sqs'
46
46
  require 'sqs/right_sqs_gen2_interface'
47
47
  require 'sqs/right_sqs_gen2'
48
48
  require 'sdb/right_sdb_interface'
49
+ require 'acf/right_acf_interface'
49
50
 
50
51
 
51
52
  module RightAws #:nodoc:
52
53
  module VERSION #:nodoc:
53
54
  MAJOR = 1
54
- MINOR = 8
55
- TINY = 1
55
+ MINOR = 9
56
+ TINY = 0
56
57
 
57
58
  STRING = [MAJOR, MINOR, TINY].join('.')
58
59
  end
@@ -49,7 +49,7 @@ module RightAws
49
49
 
50
50
  # Creates new RightS3 instance.
51
51
  #
52
- # s3 = RightAws::S3Interface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX', {:multi_thread => true, :logger => Logger.new('/tmp/x.log')}) #=> #<RightS3:0xb7b3c27c>
52
+ # s3 = RightAws::S3Interface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX', {:multi_thread => true, :logger => Logger.new('/tmp/x.log')}) #=> #<RightAws::S3Interface:0xb7b3c27c>
53
53
  #
54
54
  # Params is a hash:
55
55
  #
@@ -99,6 +99,7 @@ module RightAws
99
99
  out_string
100
100
  end
101
101
 
102
+ # http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?BucketRestrictions.html
102
103
  def is_dns_bucket?(bucket_name)
103
104
  bucket_name = bucket_name.to_s
104
105
  return nil unless (3..63) === bucket_name.size
@@ -190,7 +191,7 @@ module RightAws
190
191
  data = "<CreateBucketConfiguration><LocationConstraint>#{headers[:location].to_s.upcase}</LocationConstraint></CreateBucketConfiguration>"
191
192
  end
192
193
  req_hash = generate_rest_request('PUT', headers.merge(:url=>bucket, :data => data))
193
- request_info(req_hash, S3TrueParser.new)
194
+ request_info(req_hash, RightHttp2xxParser.new)
194
195
  rescue Exception => e
195
196
  # if the bucket exists AWS returns an error for the location constraint interface. Drop it
196
197
  e.is_a?(RightAws::AwsError) && e.message.include?('BucketAlreadyOwnedByYou') ? true : on_exception
@@ -250,7 +251,7 @@ module RightAws
250
251
  #
251
252
  def delete_bucket(bucket, headers={})
252
253
  req_hash = generate_rest_request('DELETE', headers.merge(:url=>bucket))
253
- request_info(req_hash, S3TrueParser.new)
254
+ request_info(req_hash, RightHttp2xxParser.new)
254
255
  rescue
255
256
  on_exception
256
257
  end
@@ -392,7 +393,7 @@ module RightAws
392
393
  headers['expect'] = '100-continue'
393
394
  end
394
395
  req_hash = generate_rest_request('PUT', headers.merge(:url=>"#{bucket}/#{CGI::escape key}", :data=>data))
395
- request_info(req_hash, S3TrueParser.new)
396
+ request_info(req_hash, RightHttp2xxParser.new)
396
397
  rescue
397
398
  on_exception
398
399
  end
@@ -452,7 +453,7 @@ module RightAws
452
453
 
453
454
  # Identical in function to store_object, but requires verification that the returned ETag is identical to the checksum passed in by the user as the 'md5' argument.
454
455
  # If the check passes, returns the response metadata with the "verified_md5" field set true. Raises an exception if the checksums conflict.
455
- # This call is implemented as a wrapper around put_object and the user may gain different semantics by creating a custom wrapper.
456
+ # This call is implemented as a wrapper around store_object and the user may gain different semantics by creating a custom wrapper.
456
457
  #
457
458
  # s3.store_object_and_verify(:bucket => "foobucket", :key => "foo", :md5 => "a507841b1bc8115094b00bbe8c1b2954", :data => "polemonium" )
458
459
  # => {"x-amz-id-2"=>"IZN3XsH4FlBU0+XYkFTfHwaiF1tNzrm6dIW2EM/cthKvl71nldfVC0oVQyydzWpb",
@@ -473,7 +474,7 @@ module RightAws
473
474
  # "content-length"=>"0"}
474
475
  def store_object_and_verify(params)
475
476
  AwsUtils.mandatory_arguments([:md5], params)
476
- r = put_object(params)
477
+ r = store_object(params)
477
478
  r[:verified_md5] ? (return r) : (raise AwsError.new("Uploaded object failed MD5 checksum verification: #{r.inspect}"))
478
479
  end
479
480
 
@@ -548,6 +549,10 @@ module RightAws
548
549
  # "server"=>"AmazonS3",
549
550
  # "content-length"=>"10"},
550
551
  # :object=>"polemonium"}
552
+ # If a block is provided, yields incrementally to the block as
553
+ # the response is read. For large responses, this function is ideal as
554
+ # the response can be 'streamed'. The hash containing header fields is
555
+ # still returned.
551
556
  def retrieve_object(params, &block)
552
557
  AwsUtils.mandatory_arguments([:bucket, :key], params)
553
558
  AwsUtils.allow_only([:bucket, :key, :headers, :md5], params)
@@ -568,7 +573,7 @@ module RightAws
568
573
  # This call is implemented as a wrapper around retrieve_object and the user may gain different semantics by creating a custom wrapper.
569
574
  def retrieve_object_and_verify(params, &block)
570
575
  AwsUtils.mandatory_arguments([:md5], params)
571
- resp = get_object(params, block)
576
+ resp = retrieve_object(params, &block)
572
577
  return resp if resp[:verified_md5]
573
578
  raise AwsError.new("Retrieved object failed MD5 checksum verification: #{resp.inspect}")
574
579
  end
@@ -599,7 +604,7 @@ module RightAws
599
604
  #
600
605
  def delete(bucket, key='', headers={})
601
606
  req_hash = generate_rest_request('DELETE', headers.merge(:url=>"#{bucket}/#{CGI::escape key}"))
602
- request_info(req_hash, S3TrueParser.new)
607
+ request_info(req_hash, RightHttp2xxParser.new)
603
608
  rescue
604
609
  on_exception
605
610
  end
@@ -1160,12 +1165,6 @@ module RightAws
1160
1165
  end
1161
1166
  end
1162
1167
 
1163
- class S3TrueParser < S3HttpResponseParser # :nodoc:
1164
- def parse(response)
1165
- @result = response.is_a?(Net::HTTPSuccess)
1166
- end
1167
- end
1168
-
1169
1168
  class S3HttpResponseBodyParser < S3HttpResponseParser # :nodoc:
1170
1169
  def parse(response)
1171
1170
  @result = {
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/right_aws'
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestS3 < Test::Unit::TestCase
4
+
5
+ RIGHT_OBJECT_TEXT = 'Right test message'
6
+
7
+ STDOUT.sync = true
8
+
9
+ def setup
10
+ @acf= Rightscale::AcfInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
11
+ @s3 = Rightscale::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
12
+ @bucket_name = "right-acf-awesome-test-bucket-0001"
13
+ @bucket_domain = "#{@bucket_name}.s3.amazonaws.com"
14
+ end
15
+
16
+ def test_01_list_distributions_part1
17
+ distributions = nil
18
+ assert_nothing_raised(Rightscale::AwsError) do
19
+ distributions = @acf.list_distributions
20
+ end
21
+ assert distributions.is_a?(Array)
22
+ end
23
+
24
+ def test_02_try_to_create_for_bad_bucket
25
+ # a bucket does not exist
26
+ assert_raise(Rightscale::AwsError) do
27
+ @acf.create_distribution("right-cloudfront-awesome-test-bucket-not-exist", "Mustn't to be born", true)
28
+ end
29
+ # a bucket is not a domain naming complied guy
30
+ bucket_name = 'right_cloudfront_awesome_test_bucket_BAD'
31
+ @s3.bucket(bucket_name, :create)
32
+ assert_raise(Rightscale::AwsError) do
33
+ @acf.create_distribution(bucket_name, "Mustn't to be born", true)
34
+ end
35
+ end
36
+
37
+ def test_03_create
38
+ comment = 'WooHoo!!!'
39
+ # create a test bucket
40
+ @s3.bucket(@bucket_name, :create)
41
+ # create a distribution
42
+ distribution = @acf.create_distribution(@bucket_domain, comment, true)
43
+ assert_equal comment, distribution[:comment]
44
+ assert distribution[:cnames].size == 0
45
+ assert distribution[:enabled]
46
+ end
47
+
48
+ def test_04_list_distributions_part2
49
+ distributions = @acf.list_distributions
50
+ assert distributions.size > 0
51
+ end
52
+
53
+ def get_test_distribution
54
+ @acf.list_distributions.select{ |d| d[:origin] == @bucket_domain }.first
55
+ end
56
+
57
+ def test_05_get_distribution
58
+ old = get_test_distribution
59
+ assert_nothing_raised do
60
+ @acf.get_distribution(old[:aws_id])
61
+ end
62
+ end
63
+
64
+ def test_06_get_and_set_config
65
+ config = nil
66
+ old = get_test_distribution
67
+ assert_nothing_raised do
68
+ config = @acf.get_distribution_config(old[:aws_id])
69
+ end
70
+ # change a config
71
+ config[:enabled] = false
72
+ config[:cnames] << 'x1.myawesomesite.com'
73
+ config[:cnames] << 'x2.myawesomesite.com'
74
+ # set config
75
+ set_config_result = nil
76
+ assert_nothing_raised do
77
+ set_config_result = @acf.set_distribution_config(old[:aws_id], config)
78
+ end
79
+ assert set_config_result
80
+ # reget the config and check
81
+ new_config = nil
82
+ assert_nothing_raised do
83
+ new_config = @acf.get_distribution_config(old[:aws_id])
84
+ end
85
+ assert !new_config[:enabled]
86
+ assert_equal new_config[:cnames].sort, ['x1.myawesomesite.com', 'x2.myawesomesite.com']
87
+ assert_not_equal config[:e_tag], new_config[:e_tag]
88
+
89
+ # try to update the old config again (must fail because ETAG has changed)
90
+ assert_raise(Rightscale::AwsError) do
91
+ @acf.set_distribution_config(old[:aws_id], config)
92
+ end
93
+ end
94
+
95
+ def test_07_caching
96
+ # enable caching
97
+ @acf.params[:cache] = true
98
+ # list distributions
99
+ @acf.list_distributions
100
+ # list the distributions again - cache should hit
101
+ assert_raise(Rightscale::AwsNoChange) do
102
+ @acf.list_distributions
103
+ end
104
+ # disable caching
105
+ @acf.params[:cache] = true
106
+ end
107
+
108
+ def test_08_delete_distribution
109
+ # we need ETAG so use get_distribution
110
+ distribution = @acf.get_distribution(get_test_distribution[:aws_id])
111
+ # try to delete a distribution
112
+ # should fail because
113
+ if distribution[:status] == 'InProgress'
114
+ # should fail because the distribution is not deployed yet
115
+ assert_raise(Rightscale::AwsError) do
116
+ @acf.delete_distribution(distribution[:aws_id], distribution[:e_tag])
117
+ end
118
+ # wait for a deployed state
119
+ print "waiting up to 5 min while the distribution is being deployed: "
120
+ 100.times do
121
+ print '.'
122
+ distribution = @acf.get_distribution(distribution[:aws_id])
123
+ if distribution[:status] == 'Deployed'
124
+ print ' done'
125
+ break
126
+ end
127
+ sleep 3
128
+ end
129
+ puts
130
+ end
131
+
132
+ # only disabled and deployed distribution can be deleted
133
+ assert_equal 'Deployed', distribution[:status]
134
+ assert !distribution[:enabled]
135
+
136
+ # delete the distribution
137
+ assert_nothing_raised do
138
+ @acf.delete_distribution(distribution[:aws_id], distribution[:e_tag])
139
+ end
140
+ end
141
+
142
+ def test_09_drop_bucket
143
+ assert @s3.bucket(@bucket_name).delete
144
+ end
145
+
146
+ end
@@ -11,3 +11,4 @@ require 's3/test_right_s3_stubbed.rb'
11
11
  require 'sqs/test_right_sqs.rb'
12
12
  require 'sqs/test_right_sqs_gen2.rb'
13
13
  require 'sdb/test_right_sdb.rb'
14
+ require 'acf/test_right_acf.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RightScale, Inc.
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-07 00:00:00 -07:00
12
+ date: 2008-11-21 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: right_http_connection
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -21,7 +22,7 @@ dependencies:
21
22
  - !ruby/object:Gem::Version
22
23
  version: 1.2.1
23
24
  version:
24
- description: "== DESCRIPTION: The RightScale AWS gems have been designed to provide a robust, fast, and secure interface to Amazon EC2, EBS, S3, SQS, and SDB. These gems have been used in production by RightScale since late 2006 and are being maintained to track enhancements made by Amazon. The RightScale AWS gems comprise: - RightAws::Ec2 -- interface to Amazon EC2 (Elastic Compute Cloud) and the associated EBS (Elastic Block Store) - RightAws::S3 and RightAws::S3Interface -- interface to Amazon S3 (Simple Storage Service) - RightAws::Sqs and RightAws::SqsInterface -- interface to first-generation Amazon SQS (Simple Queue Service) (API version 2007-05-01) - RightAws::SqsGen2 and RightAws::SqsGen2Interface -- interface to second-generation Amazon SQS (Simple Queue Service) (API version 2008-01-01) - RightAws::SdbInterface and RightAws::ActiveSdb -- interface to Amazon SDB (SimpleDB) == FEATURES:"
25
+ description: "== DESCRIPTION: The RightScale AWS gems have been designed to provide a robust, fast, and secure interface to Amazon EC2, EBS, S3, SQS, SDB, and CloudFront. These gems have been used in production by RightScale since late 2006 and are being maintained to track enhancements made by Amazon. The RightScale AWS gems comprise: - RightAws::Ec2 -- interface to Amazon EC2 (Elastic Compute Cloud) and the associated EBS (Elastic Block Store) - RightAws::S3 and RightAws::S3Interface -- interface to Amazon S3 (Simple Storage Service) - RightAws::Sqs and RightAws::SqsInterface -- interface to first-generation Amazon SQS (Simple Queue Service) (API version 2007-05-01) - RightAws::SqsGen2 and RightAws::SqsGen2Interface -- interface to second-generation Amazon SQS (Simple Queue Service) (API version 2008-01-01) - RightAws::SdbInterface and RightAws::ActiveSdb -- interface to Amazon SDB (SimpleDB) - RightAws::AcfInterface -- interface to Amazon CloudFront, a content distribution service == FEATURES:"
25
26
  email: support@rightscale.com
26
27
  executables: []
27
28
 
@@ -49,6 +50,7 @@ files:
49
50
  - lib/sqs/right_sqs_gen2.rb
50
51
  - lib/sqs/right_sqs_gen2_interface.rb
51
52
  - lib/sqs/right_sqs_interface.rb
53
+ - lib/acf/right_acf_interface.rb
52
54
  - test/ec2/test_helper.rb
53
55
  - test/ec2/test_right_ec2.rb
54
56
  - test/http_connection.rb
@@ -63,6 +65,8 @@ files:
63
65
  - test/sqs/test_right_sqs_gen2.rb
64
66
  - test/test_credentials.rb
65
67
  - test/ts_right_aws.rb
68
+ - test/acf/test_helper.rb
69
+ - test/acf/test_right_acf.rb
66
70
  has_rdoc: true
67
71
  homepage:
68
72
  post_install_message:
@@ -86,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
90
  requirements: []
87
91
 
88
92
  rubyforge_project: rightaws
89
- rubygems_version: 1.0.1
93
+ rubygems_version: 1.3.1
90
94
  signing_key:
91
95
  specification_version: 2
92
96
  summary: Interface classes for the Amazon EC2, SQS, and S3 Web Services