babysitter 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -34,12 +34,17 @@ Babysitter can also make use of Amazons Simple Notification Service to provide n
34
34
 
35
35
  Babysitter.configure do |c|
36
36
  c.enable_simple_notification_service(
37
- access_key_id: "YOUR_ACCESS_KEY_ID",
38
- secret_address_key: "YOUR_SECRET_ADDRESS_KEY",
39
- topic_arn: "my-topic-arn"
37
+ topic_arn: "my-topic-arn",
38
+ credentials: -> {
39
+ access_key_id: "YOUR_ACCESS_KEY_ID",
40
+ secret_address_key: "YOUR_SECRET_ADDRESS_KEY",
41
+ }
40
42
  )
41
43
  end
42
44
 
45
+ The credentials should be supplied as a Proc so that they are only requested when they are required. This supports the use of temporary
46
+ credentials with IAM and prevents any credentials fetched at configuration time having expired at some point later when an error occurs.
47
+
43
48
  ### Monitoring
44
49
 
45
50
  monitor = Babysitter.monitor("statsd.bucket.name")
@@ -4,20 +4,28 @@ module Babysitter
4
4
  module ExceptionNotifiers
5
5
  class SimpleNotificationService
6
6
  def initialize(opts = {})
7
- topic_arn = opts.delete(:topic_arn)
8
- raise ArgumentError, "topic_arn is required." if topic_arn.nil?
7
+ @topic_arn = opts.delete(:topic_arn)
8
+ @get_credentials = opts.delete(:credentials)
9
+ raise ArgumentError, "topic_arn is required." if @topic_arn.nil?
10
+ raise ArgumentError, "credentials is required and must be a Proc." if @get_credentials.nil? || !@get_credentials.is_a?(Proc)
9
11
 
10
- @sns = AWS::SNS.new(opts)
11
- @topic = @sns.topics[topic_arn]
12
12
  validate_topic
13
13
  end
14
14
 
15
15
  def notify(subject, msg)
16
- @topic.publish(msg, subject: sanitise_subject(subject))
16
+ topic.publish(msg, subject: sanitise_subject(subject))
17
17
  end
18
18
 
19
19
  private
20
20
 
21
+ def sns
22
+ AWS::SNS.new(@get_credentials.call)
23
+ end
24
+
25
+ def topic
26
+ sns.topics[@topic_arn]
27
+ end
28
+
21
29
  def sanitise_subject(subject)
22
30
  sanitised = /\s*([^\x00-\x1F]*)/.match(subject)[1]
23
31
 
@@ -27,7 +35,7 @@ module Babysitter
27
35
  end
28
36
 
29
37
  def validate_topic
30
- @topic.display_name
38
+ topic.display_name
31
39
  end
32
40
  end
33
41
  end
@@ -1,3 +1,3 @@
1
1
  module Babysitter
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -4,9 +4,14 @@ module Babysitter
4
4
  module ExceptionNotifiers
5
5
  describe SimpleNotificationService do
6
6
  subject { SimpleNotificationService.new(valid_opts) }
7
+ let(:get_credentials_lambda) { -> {
8
+ {
9
+ access_key_id: 'an-access-key-id',
10
+ secret_access_key: 'a-secret-address-key',
11
+ }
12
+ } }
7
13
  let(:valid_opts) { {
8
- access_key_id: 'an-access-key-id',
9
- secret_access_key: 'a-secret-address-key',
14
+ credentials: get_credentials_lambda,
10
15
  topic_arn: 'my-topic-arn'
11
16
  } }
12
17
  let(:sns) { double :sns, topics: { 'my-topic-arn' => topic } }
@@ -16,11 +21,22 @@ module Babysitter
16
21
  end
17
22
 
18
23
  it 'requires a topic_arn' do
19
- -> { SimpleNotificationService.new() }.should raise_error(ArgumentError, /topic_arn/)
24
+ valid_opts.delete :topic_arn
25
+ -> { subject }.should raise_error(ArgumentError, /topic_arn/)
26
+ end
27
+
28
+ it "requires credentials" do
29
+ valid_opts.delete :credentials
30
+ -> { subject }.should raise_error(ArgumentError, /credentials/)
31
+ end
32
+
33
+ it 'requires a block to retrieve AWS credentials' do
34
+ valid_opts[:credentials] = {}
35
+ -> { subject }.should raise_error(ArgumentError, /credentials/)
20
36
  end
21
37
 
22
38
  it 'uses the options passed to configure the credentials for sns' do
23
- AWS::SNS.should_receive(:new).with(valid_opts.reject { |key| key == :topic_arn } )
39
+ AWS::SNS.should_receive(:new).with(get_credentials_lambda.call)
24
40
  subject
25
41
  end
26
42
 
@@ -33,6 +49,11 @@ module Babysitter
33
49
  let(:message) { "the message" }
34
50
  let(:notification_subject) { "the subject" }
35
51
 
52
+ it 'again uses the options passed to configure the credentials for sns' do
53
+ AWS::SNS.should_receive(:new).with(get_credentials_lambda.call).twice
54
+ subject.notify(notification_subject, message)
55
+ end
56
+
36
57
  it 'publishes to the topic specified' do
37
58
  topic.should_receive(:publish)
38
59
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babysitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-02-11 00:00:00.000000000 Z
15
+ date: 2013-02-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: fozzie
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 1.8.25
150
+ rubygems_version: 1.8.24
151
151
  signing_key:
152
152
  specification_version: 3
153
153
  summary: Babysits long-running processes and reports progress or failures