chef-handler-sns 1.1.0 → 1.2.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +84 -12
- data/lib/chef/handler/sns/config.rb +1 -1
- data/lib/chef/handler/sns/version.rb +1 -1
- data/test/test_chef_handler_sns_config.rb +13 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75a18e73a5d271e121792cb61dd8ceffa4b9a71f
|
4
|
+
data.tar.gz: d6a1e0119112e417d988b18ef27e1fa4d07782f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37f868ea988256a0a84dac96a480bb90d33bc37f031b07d3589285fc1a53ce4d94791801fa50726a7191976c1ac2073053f78d31f4d9bbae9bb569c9789e46ac
|
7
|
+
data.tar.gz: bdfc6b843d17ce232b9eb1bb45aafc3235f70f2e11359c082b596b352136592a8f3bd98ebeb83aa788d34ce56e5ff8aaefd071a9323a436146c6ea223e1fb8f4
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ This Chef Handler is heavily based on [Joshua Timberman](https://github.com/jtim
|
|
31
31
|
|
32
32
|
You can install this handler in two ways:
|
33
33
|
|
34
|
-
### Method 1:
|
34
|
+
### Method 1: in the Chef Config File
|
35
35
|
|
36
36
|
You can install the RubyGem and configure Chef to use it:
|
37
37
|
|
@@ -57,7 +57,9 @@ sns_handler.region "us-east-1" # optional
|
|
57
57
|
exception_handlers << sns_handler
|
58
58
|
```
|
59
59
|
|
60
|
-
### Method 2:
|
60
|
+
### Method 2: in a Recipe with the chef_handler LWRP
|
61
|
+
|
62
|
+
**Note:** This method will not catch errors before the convergence phase. Use the previous method if you want to be able to report such errors.
|
61
63
|
|
62
64
|
Use the [chef_handler LWRP](http://community.opscode.com/cookbooks/chef_handler), creating a recipe with the following:
|
63
65
|
|
@@ -84,6 +86,8 @@ chef_handler "Chef::Handler::Sns" do
|
|
84
86
|
end
|
85
87
|
```
|
86
88
|
|
89
|
+
#### Method 2.1: in a Recipe with the chef_handler LWRP Using Gem < 1.8.6
|
90
|
+
|
87
91
|
If you have an old version of gem package (< 1.8.6) without `find_by_name` or old chef-client (< 0.10.10) without `chef_gem`, you can try creating a recipe similar to the following:
|
88
92
|
|
89
93
|
```ruby
|
@@ -120,11 +124,59 @@ chef_handler "Chef::Handler::Sns" do
|
|
120
124
|
end
|
121
125
|
```
|
122
126
|
|
123
|
-
|
127
|
+
#### Method 2.2: in a Recipe with the chef_handler LWRP Inside AWS OpsWorks
|
128
|
+
|
129
|
+
If you are inside [AWS OpsWorks](http://aws.amazon.com/opsworks/) or running Chef inside _Bundler_, you might receive the following error:
|
130
|
+
|
131
|
+
Gem::LoadError
|
132
|
+
--------------
|
133
|
+
Could not find 'chef-handler-sns' (>= 0) among XX total gem(s)
|
134
|
+
|
135
|
+
To fix this error, you should get the handler installation path using a code similar to the following:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
# Handler configuration options
|
139
|
+
argument_array = [
|
140
|
+
:access_key => "***AMAZON-KEY***",
|
141
|
+
:secret_key => "***AMAZON-SECRET***",
|
142
|
+
:topic_arn => "arn:aws:sns:***",
|
143
|
+
]
|
144
|
+
|
145
|
+
# Depends on the `xml` cookbook to install nokogiri
|
146
|
+
include_recipe "xml::ruby"
|
147
|
+
|
148
|
+
# Install the `chef-handler-sns` RubyGem during the compile phase
|
149
|
+
chef_gem "chef-handler-sns"
|
150
|
+
|
151
|
+
# Get the installed `chef-handler-sns` gem path from Bundler
|
152
|
+
sns_handler_path = nil
|
153
|
+
bundle_path = ::File.join(Bundler.bundle_path.to_s, "specifications")
|
154
|
+
Dir[::File.join(bundle_path, "*.gemspec")].each do |path|
|
155
|
+
spec = Gem::Specification.load(path.untaint)
|
156
|
+
if spec.name == "chef-handler-sns"
|
157
|
+
sns_handler_path = spec.lib_dirs_glob
|
158
|
+
end
|
159
|
+
end
|
160
|
+
if sns_handler_path.nil?
|
161
|
+
Chef::Application.fatal!("chef-handler-sns not found inside Bundler path: #{bundle_path}")
|
162
|
+
end
|
163
|
+
|
164
|
+
# Then activate the handler with the `chef_handler` LWRP
|
165
|
+
chef_handler "Chef::Handler::Sns" do
|
166
|
+
source "#{Gem::Specification.find_by_name("chef-handler-sns").lib_dirs_glob}/chef/handler/sns"
|
167
|
+
arguments argument_array
|
168
|
+
supports :exception => true
|
169
|
+
action :enable
|
170
|
+
end
|
171
|
+
```
|
172
|
+
|
173
|
+
See the [`chef_handler_sns` cookbook provider code](https://github.com/onddo/chef_handler_sns-cookbook/blob/master/providers/default.rb) for a more complete working example.
|
174
|
+
|
175
|
+
### Usage with Amazon IAM Roles
|
124
176
|
|
125
177
|
If you are using AWS [IAM roles](http://docs.aws.amazon.com/IAM/latest/UserGuide/WorkingWithRoles.html) with your server, probably you only need to specify the `topic_arn` parameter. A few simple examples:
|
126
178
|
|
127
|
-
#### Method 1:
|
179
|
+
#### Method 1: in the Chef Config File
|
128
180
|
|
129
181
|
You can install the RubyGem and configure Chef to use it:
|
130
182
|
|
@@ -140,7 +192,7 @@ exception_handlers << Chef::Handler::Sns.new({
|
|
140
192
|
})
|
141
193
|
```
|
142
194
|
|
143
|
-
#### Method 2:
|
195
|
+
#### Method 2: in a Recipe with the chef_handler LWRP
|
144
196
|
|
145
197
|
Use the [chef_handler LWRP](http://community.opscode.com/cookbooks/chef_handler), creating a recipe with the following:
|
146
198
|
|
@@ -160,13 +212,13 @@ chef_handler "Chef::Handler::Sns" do
|
|
160
212
|
end
|
161
213
|
```
|
162
214
|
|
163
|
-
|
164
|
-
An optional array of
|
215
|
+
#### OpsWorks: Filter Notifications by Activity
|
216
|
+
An optional array of OpsWorks activities can be supplied. If the array is set, notifications will
|
165
217
|
only be triggered for the activities in the array, everything else will be discarded.
|
166
218
|
|
167
219
|
```ruby
|
168
220
|
argument_array = [
|
169
|
-
:filter_opsworks_activities => [
|
221
|
+
:filter_opsworks_activities => ["deploy","configure"]
|
170
222
|
]
|
171
223
|
```
|
172
224
|
|
@@ -176,11 +228,12 @@ The following options are available to configure the handler:
|
|
176
228
|
|
177
229
|
* `access_key` - AWS access key (required, but will try to read it from ohai with IAM roles).
|
178
230
|
* `secret_key` - AWS secret key (required, but will try to read it from ohai with IAM roles).
|
179
|
-
* `token` - AWS security token (optional, read from ohai with IAM roles).
|
231
|
+
* `token` - AWS security token (optional, read from ohai with IAM roles). Set to `false` to disable the token detected by ohai.
|
180
232
|
* `topic_arn` - AWS topic ARN name (required).
|
181
233
|
* `region` - AWS region (optional).
|
182
234
|
* `subject` - Message subject string in erubis format (optional).
|
183
235
|
* `body_template` - Full path of an erubis template file to use for the message body (optional).
|
236
|
+
* `filter_opsworks_activities` - An array of OpsWorks activities to be triggered with (optional). When set, everything else will be discarded.
|
184
237
|
|
185
238
|
**Note:** When the machine has an IAM role, will try to read the credentials from ohai. So in the best case, you only need to specify the `topic_arn`.
|
186
239
|
|
@@ -189,7 +242,7 @@ The following options are available to configure the handler:
|
|
189
242
|
Here is an example of the `subject` configuration option using the ruby configuration file (`solo.rb` or `client.rb`):
|
190
243
|
|
191
244
|
```ruby
|
192
|
-
sns_handler.subject: "Chef-run: <%= node.name %> - <%= run_status.success? ?
|
245
|
+
sns_handler.subject: "Chef-run: <%= node.name %> - <%= run_status.success? ? "ok" : "error" %>"
|
193
246
|
```
|
194
247
|
|
195
248
|
Using the [chef_handler LWRP](http://community.opscode.com/cookbooks/chef_handler):
|
@@ -198,7 +251,7 @@ argument_array = [
|
|
198
251
|
:access_key => "***AMAZON-KEY***",
|
199
252
|
:secret_key => "***AMAZON-SECRET***",
|
200
253
|
:topic_arn => "arn:aws:sns:***",
|
201
|
-
:subject => "Chef-run: <%= node.name %> - <%= run_status.success? ?
|
254
|
+
:subject => "Chef-run: <%= node.name %> - <%= run_status.success? ? "ok" : "error" %>",
|
202
255
|
# [...]
|
203
256
|
]
|
204
257
|
chef_handler "Chef::Handler::Sns" do
|
@@ -279,7 +332,26 @@ Stacktrace:
|
|
279
332
|
|
280
333
|
See the [subject](#subject) documentation for more details on the variables accesible inside the template.
|
281
334
|
|
282
|
-
##
|
335
|
+
## IAM Role Credentials from Ohai
|
336
|
+
|
337
|
+
IAM Role information and credentials are gathered from ohai by default if they exists.
|
338
|
+
|
339
|
+
No aditional ohai plugin is required. This is natively supported by ohai since version `6.16.0` ([OHAI-400](https://tickets.opscode.com/browse/OHAI-400)).
|
340
|
+
|
341
|
+
These are the used ohai attributes:
|
342
|
+
|
343
|
+
```
|
344
|
+
ec2
|
345
|
+
├── placement_availability_zone: region is set from here.
|
346
|
+
└── iam
|
347
|
+
└── security-credentials
|
348
|
+
└── IAMRoleName
|
349
|
+
├── AccessKeyId
|
350
|
+
├── SecretAccessKey
|
351
|
+
└── Token
|
352
|
+
```
|
353
|
+
|
354
|
+
## Running the Tests
|
283
355
|
|
284
356
|
Minitest tests can be run as usual:
|
285
357
|
|
@@ -17,6 +17,7 @@ describe Chef::Handler::Sns::Config do
|
|
17
17
|
@config_params = {
|
18
18
|
:access_key => '***AMAZON-KEY***',
|
19
19
|
:secret_key => '***AMAZON-SECRET***',
|
20
|
+
:token => '***AMAZON-TOKEN***',
|
20
21
|
:topic_arn => 'arn:aws:sns:***',
|
21
22
|
}
|
22
23
|
@node = Chef::Node.new
|
@@ -54,13 +55,24 @@ describe Chef::Handler::Sns::Config do
|
|
54
55
|
@sns_config.send(option, "test")
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
+
it "should set '#{option}' option correctly" do
|
59
|
+
@sns_config.send(option, "test")
|
60
|
+
|
61
|
+
assert_equal @sns_config.send(option), "test"
|
62
|
+
end
|
63
|
+
|
64
|
+
[ true, 25, Object.new ].each do |bad_value|
|
58
65
|
it "should throw and exception wen '#{option}' option is set to #{bad_value.to_s}" do
|
59
66
|
assert_raises(Chef::Exceptions::ValidationFailed) { @sns_config.send(option, bad_value) }
|
60
67
|
end
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
71
|
+
it 'should accept false value to reset the token' do
|
72
|
+
@sns_config.token(false)
|
73
|
+
assert_equal @sns_config.token, false
|
74
|
+
end
|
75
|
+
|
64
76
|
it 'should throw an exception when the body template file does not exist' do
|
65
77
|
@sns_config.body_template('/tmp/nonexistent-template.erb')
|
66
78
|
::File.stubs(:exists?).with(@sns_config.body_template).returns(false)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-handler-sns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Onddo Labs, SL.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -155,9 +155,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
|
-
- - '
|
158
|
+
- - '>'
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version:
|
160
|
+
version: 1.3.1
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
163
|
rubygems_version: 2.0.6
|