SQS 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 0.1.7
2
+ 2008-02-21
3
+ * You can now call SQS.conf_file = 'some_file.yml' to set access_key_id and
4
+ secret_access_key. SQS assumes this file is YAML. This way, you don't have to
5
+ store your AWS credentials in your code (and I don't run the risk of committing
6
+ my credentials to SVN every time I do a commit!).
7
+
1
8
  0.1.6
2
9
  2008-02-19
3
10
  * Maintenance release to keep up with Amazon SQS API changes. All but one test should be
data/lib/sqs.rb CHANGED
@@ -8,6 +8,7 @@ require 'erb'
8
8
  require 'net/http'
9
9
  require 'openssl'
10
10
  require 'rexml/document'
11
+ require 'yaml'
11
12
  #include Digest
12
13
  include ERB::Util
13
14
 
@@ -48,6 +49,23 @@ class SQS
48
49
  def self.secret_access_key
49
50
  @@secret_access_key
50
51
  end
52
+
53
+ # Expects YAML
54
+ def self.conf_file=( path )
55
+ @@conf_file = File.expand_path( path )
56
+ settings = YAML.load_file( @@conf_file )
57
+ %w{ access_key_id secret_access_key }.each do |attr|
58
+ self.send( "#{attr}=", settings[attr] )
59
+ end
60
+ rescue
61
+ # Warn, but continue operation
62
+ warn "\n\nWARNING:\n#{$!.message}\n(Check #{caller[0]})"
63
+ end
64
+
65
+ def self.conf_file
66
+ @@conf_file
67
+ end
68
+
51
69
  def self.url_for_auery=( u )
52
70
  @@url_for_query = u
53
71
  end
@@ -208,6 +226,7 @@ class SQS
208
226
  protected
209
227
  @@retry_attempts = 10;
210
228
  @@counter = 0;
229
+ @@conf_file = ''
211
230
  @@secret_access_key = 'Replace this with your secret access key'
212
231
  @@access_key_id = 'Replace this with your access key id'
213
232
  @@url_for_query = 'http://queue.amazonaws.com/'
@@ -115,12 +115,14 @@ class SQS_QueueTest < Test::Unit::TestCase
115
115
  @q.delete!
116
116
  end
117
117
 
118
- begin
119
- q = SQS.get_queue( @queue_prefix )
120
- rescue
121
- assert_equal 'SQS::UnavailableQueue', $!.class.name
122
- else
123
- flunk 'Was supposed to raise an SQS::UnavailableQueue'
118
+ assert_statistically( :of => 3, :after => lambda{ |i,s| sleep 3 } ) do
119
+ begin
120
+ q = SQS.get_queue( @queue_prefix )
121
+ rescue
122
+ 'SQS::UnavailableQueue' == $!.class.name
123
+ else
124
+ false
125
+ end
124
126
  end
125
127
  end
126
128
 
@@ -407,7 +409,7 @@ class SQS_QueueTest < Test::Unit::TestCase
407
409
  end
408
410
 
409
411
  assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :full )
410
- assert_statistically( :of => 6, :after => lambda{ |i,s| sleep 5 } ) do
412
+ assert_statistically( :of => 6, :after => lambda{ |i,s| sleep i < 5 ? 5 : 10 } ) do
411
413
  grants = @q.list_grants
412
414
  4 == grants.size
413
415
  end
@@ -24,14 +24,23 @@ class SQSTest < Test::Unit::TestCase
24
24
 
25
25
  @used_prefixes[@queue_prefix] = true
26
26
 
27
- @q = SQS.create_queue( @queue_prefix ) unless SQStest.skip_live_tests?
27
+ unless SQStest.skip_live_tests?
28
+ @original_access_key_id = SQS.access_key_id
29
+ @original_secret_access_key = SQS.secret_access_key
30
+
31
+ @q = SQS.create_queue( @queue_prefix )
32
+ end
28
33
 
29
34
  SQS.add_reasons_to_retry 'ServiceUnavailable'
30
35
  SQS.remove_reasons_to_retry( SQS.reasons_to_retry.reject { |r| r == 'ServiceUnavailable' } )
31
36
  SQS.retry_attempts = 10
37
+
32
38
  end
33
39
  def teardown
34
40
  unless SQStest.skip_live_tests?
41
+ SQS.access_key_id = @original_access_key_id
42
+ SQS.secret_access_key = @original_secret_access_key
43
+
35
44
  SQS.list_queues( @queue_prefix ).each do |q|
36
45
  begin
37
46
  q.delete! if q.exists?
@@ -42,6 +51,7 @@ class SQSTest < Test::Unit::TestCase
42
51
  end
43
52
  end
44
53
  print SQS.counter if SQStest.print_counter?
54
+
45
55
  end
46
56
 
47
57
  unless SQStest.skip_live_tests?
@@ -122,6 +132,26 @@ class SQSTest < Test::Unit::TestCase
122
132
  end
123
133
  end
124
134
 
135
+ def test_bad_conf_file
136
+ assert_nothing_raised do
137
+ SQS.conf_file = 'Should-not-exist.ext'
138
+ end
139
+ end
140
+
141
+ def test_good_conf_file
142
+ f = File.expand_path( File.join( File.dirname( __FILE__ ), 'test_conf.yml' ) )
143
+
144
+ assert_not_equal f, SQS.conf_file
145
+ assert_not_equal 'number 5', SQS.access_key_id
146
+ assert_not_equal 'is alive', SQS.secret_access_key
147
+
148
+ SQS.conf_file = File.join( File.dirname( __FILE__ ), 'test_conf.yml' )
149
+
150
+ assert_equal f, SQS.conf_file
151
+ assert_equal 'number 5', SQS.access_key_id
152
+ assert_equal 'is alive', SQS.secret_access_key
153
+ end
154
+
125
155
  def test_get_exception_class
126
156
  assert_raises ArgumentError do
127
157
  SQS.get_exception_class
@@ -0,0 +1,2 @@
1
+ access_key_id: 'number 5'
2
+ secret_access_key: 'is alive'
@@ -10,20 +10,20 @@ class SQStest
10
10
  def self.print_counter? ; false ; end
11
11
  def self.my_aws_account ; { :email => 'Replace this with your AWS account email address', :display_name => 'Replace this with your AWS display name' } ; end
12
12
  def self.other_aws_account ; { :email => 'Replace this with another valid AWS account email address', :display_name => 'Replace this with another valid AWS display name' } ; end
13
- def self.secret_access_key ; 'Replace this with your secret access key' ; end
14
- def self.access_key_id ; 'Replace this with your access key id' ; end
15
13
  end
16
- # End change these settings
17
- #############################
18
14
 
15
+ # Uncomment these lines to set up your access_key_id and secret_access_key (not the preferred method)
16
+ # SQS.access_key_id = ''
17
+ # SQS.secret_access_key = ''
19
18
 
19
+ # Uncomment this line to point SQS to a YAML file containing your
20
+ # access_key_id and secret_access_key (the preferred method)
21
+ SQS.conf_file = "~/aws.yml"
20
22
 
21
- SQS.secret_access_key = SQStest.secret_access_key
22
- SQS.access_key_id = SQStest.access_key_id
23
+ # End change these settings
24
+ #############################
23
25
 
24
26
  good = Hash.new
25
- good[:access_key_id] = SQS.access_key_id != 'Replace this with your access key id'
26
- good[:secret_access_key] = SQS.secret_access_key != 'Replace this with your secret access key'
27
27
  good[:my_aws_email] = SQStest.my_aws_account[:email] != 'Replace this with your AWS account email address'
28
28
  good[:my_aws_display_name] = SQStest.my_aws_account[:display_name] != 'Replace this with your AWS display name'
29
29
  good[:other_aws_email] = SQStest.other_aws_account[:email] != 'Replace this with another valid AWS account email address'
@@ -31,6 +31,7 @@ good[:other_aws_display_name] = SQStest.other_aws_account[:display_name] != 'Rep
31
31
 
32
32
  message = good.reject{ |k,v| v }.keys.collect{ |k| k.to_s.gsub( /_/, ' ' ) }.join(", ")
33
33
 
34
+
34
35
  unless message.to_s.empty?
35
36
  puts "\nWHOOPS: In order to run these tests, please change the #{ message.index(',') ? 'values' : 'value' } of #{message} in #{File.expand_path( __FILE__ )}\n\n"
36
37
  exit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SQS
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Holt
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-20 00:00:00 -08:00
12
+ date: 2008-02-21 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -34,6 +34,7 @@ files:
34
34
  - test/unit/sqs_queue_test.rb
35
35
  - test/unit/sqs_test.rb
36
36
  - test/unit/test_setup.rb
37
+ - test/unit/test_conf.yml
37
38
  - README
38
39
  - MIT-LICENSE
39
40
  - CHANGELOG
@@ -70,3 +71,4 @@ test_files:
70
71
  - test/unit/sqs_queue_test.rb
71
72
  - test/unit/sqs_test.rb
72
73
  - test/unit/test_setup.rb
74
+ - test/unit/test_conf.yml