bq-chef-handler-sns 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 97fe10733493f0533ffbf2fcbe075baa737286ab6b550249dc8b033fce5be73d
4
+ data.tar.gz: fec354d7e472c987c6ae244a6c20d356cc3693153fcb208abbe8798c097655a1
5
+ SHA512:
6
+ metadata.gz: 6f84e6935790b6f200144069fa375945129290c65edb73c124dbe39a44a9ab461b3efa1714c16d489ae2e5691982381a23e45758a233522d22291b3a65382173
7
+ data.tar.gz: 4ad13830db3694708ba1b6f09deab53db1dff8181c9381fe9dd9f4b758aec8e42b706b54c600d5c52028f77df02654eb14fe401064a8642a466b38d73993bfef
data/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2014 Xabier de Zuazo
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,354 @@
1
+ # Chef Handler SNS
2
+ [![Gem Version](http://img.shields.io/gem/v/chef-handler-sns.svg?style=flat)](http://badge.fury.io/rb/chef-handler-sns)
3
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg?style=flat)](http://www.rubydoc.info/gems/chef-handler-sns)
4
+ [![GitHub](http://img.shields.io/badge/github-zuazo/chef--handler--sns-blue.svg?style=flat)](https://github.com/zuazo/chef-handler-sns)
5
+ [![License](https://img.shields.io/github/license/zuazo/chef-handler-sns.svg?style=flat)](#license-and-author)
6
+
7
+ [![Dependency Status](http://img.shields.io/gemnasium/zuazo/chef-handler-sns.svg?style=flat)](https://gemnasium.com/zuazo/chef-handler-sns)
8
+ [![Code Climate](http://img.shields.io/codeclimate/github/zuazo/chef-handler-sns.svg?style=flat)](https://codeclimate.com/github/zuazo/chef-handler-sns)
9
+ [![Build Status](http://img.shields.io/travis/zuazo/chef-handler-sns.svg?style=flat)](https://travis-ci.org/zuazo/chef-handler-sns)
10
+ [![Coverage Status](http://img.shields.io/coveralls/zuazo/chef-handler-sns.svg?style=flat)](https://coveralls.io/r/zuazo/chef-handler-sns?branch=master)
11
+ [![Inline docs](http://inch-ci.org/github/zuazo/chef-handler-sns.svg?branch=master&style=flat)](http://inch-ci.org/github/zuazo/chef-handler-sns)
12
+
13
+ A simple Chef report handler that reports status of a Chef run through [Amazon SNS](http://aws.amazon.com/sns/), [including IAM roles support](#usage-with-amazon-iam-roles).
14
+
15
+ [Amazon SNS](http://aws.amazon.com/sns/) can send notifications by SMS, email, [Amazon SQS](http://aws.amazon.com/sqs/) queues or to any HTTP endpoint.
16
+
17
+ We recommend using the [`chef_handler_sns` cookbook](https://supermarket.chef.io/cookbooks/chef_handler_sns) for easy installation.
18
+
19
+ This Chef Handler is heavily based on [Joshua Timberman](https://github.com/jtimberman) examples.
20
+
21
+ * https://docs.chef.io/handlers.html#exception-report-handlers
22
+
23
+ ## Requirements
24
+
25
+ * Amazon AWS: uses Amazon SNS service.
26
+ * Ruby `2` or higher (recommended `2.1` or higher).
27
+
28
+ ## Usage
29
+
30
+ You can install this handler in two ways:
31
+
32
+ ### Method 1: in the Chef Config File
33
+
34
+ You can install the RubyGem and configure Chef to use it:
35
+
36
+ $ gem install chef-handler-sns
37
+
38
+ Then add to the configuration (`/etc/chef/solo.rb` for chef-solo or `/etc/chef/client.rb` for chef-client):
39
+
40
+ ```ruby
41
+ require 'chef/handler/sns'
42
+
43
+ # Create the handler
44
+ sns_handler = Chef::Handler::Sns.new
45
+
46
+ # Your Amazon AWS credentials
47
+ sns_handler.access_key '***AMAZON-KEY***'
48
+ sns_handler.secret_key '***AMAZON-SECRET***'
49
+
50
+ # Some Amazon SNS configurations
51
+ sns_handler.topic_arn 'arn:aws:sns:***'
52
+ sns_handler.region 'us-east-1' # optional
53
+
54
+ # Add your handler
55
+ exception_handlers << sns_handler
56
+ ```
57
+
58
+ ### Method 2: in a Recipe with the `chef_handler` LWRP
59
+
60
+ **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
+
62
+ Use the [`chef_handler` LWRP](https://supermarket.chef.io/cookbooks/chef_handler), creating a recipe with the following:
63
+
64
+ ```ruby
65
+ # Handler configuration options
66
+ argument_array = [
67
+ access_key: '***AMAZON-KEY***',
68
+ secret_key: '***AMAZON-SECRET***',
69
+ topic_arn: 'arn:aws:sns:***'
70
+ ]
71
+
72
+ # Install the `chef-handler-sns` RubyGem during the compile phase
73
+ chef_gem 'chef-handler-sns' do
74
+ compile_time true # Only for Chef 12
75
+ end
76
+
77
+ # Then activate the handler with the `chef_handler` LWRP
78
+ chef_handler 'Chef::Handler::Sns' do
79
+ source 'chef/handler/sns'
80
+ arguments argument_array
81
+ supports exception: true
82
+ action :enable
83
+ end
84
+ ```
85
+
86
+ See the [`chef_handler_sns` cookbook provider code](https://github.com/zuazo/chef_handler_sns-cookbook/blob/master/providers/default.rb) for a more complete working example.
87
+
88
+ ### Method 3: Using the `chef-client` Cookbook
89
+
90
+ You can also use the `node['chef_client']['config']` attribute of the [`chef-client`](https://github.com/chef-cookbooks/chef-client/tree/v4.3.2#start-report-exception-handlers) cookbook:
91
+
92
+ ```ruby
93
+ node.default['chef_client']['config']['exception_handlers'] = [{
94
+ 'class' => 'Chef::Handler::Sns',
95
+ 'arguments' => {
96
+ access_key: '***AMAZON-KEY***',
97
+ secret_key: '***AMAZON-SECRET***',
98
+ topic_arn: 'arn:aws:sns:***'
99
+ }.map { |k, v| "#{k}: #{v.inspect}" }
100
+ }]
101
+ ```
102
+
103
+ ### Usage with Amazon IAM Roles
104
+
105
+ 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:
106
+
107
+ #### IAM Roles Method 1: in the Chef Config File
108
+
109
+ You can install the RubyGem and configure Chef to use it:
110
+
111
+ $ gem install chef-handler-sns
112
+
113
+ Then add to the configuration (`/etc/chef/solo.rb` for chef-solo or `/etc/chef/client.rb` for chef-client):
114
+
115
+ ```ruby
116
+ require 'chef/handler/sns'
117
+
118
+ exception_handlers << Chef::Handler::Sns.new(
119
+ topic_arn: 'arn:aws:sns:us-east-1:12341234:MyTopicName'
120
+ )
121
+ ```
122
+
123
+ #### IAM Roles Method 2: in a Recipe with the `chef_handler` LWRP
124
+
125
+ Use the [`chef_handler` LWRP](https://supermarket.chef.io/cookbooks/chef_handler), creating a recipe with the following:
126
+
127
+ ```ruby
128
+ # Install the `chef-handler-sns` RubyGem during the compile phase
129
+ chef_gem 'chef-handler-sns' do
130
+ compile_time true # Only for Chef 12
131
+ end
132
+
133
+ # Then activate the handler with the `chef_handler` LWRP
134
+ chef_handler 'Chef::Handler::Sns' do
135
+ source 'chef/handler/sns'
136
+ arguments topic_arn: 'arn:aws:sns:us-east-1:12341234:MyTopicName'
137
+ supports exception: true
138
+ action :enable
139
+ end
140
+ ```
141
+
142
+ ### IAM Roles Method 3: Using the `chef-client` Cookbook
143
+
144
+ You can also use the `node['chef_client']['config']` attribute of the [`chef-client`](https://github.com/chef-cookbooks/chef-client/tree/v4.3.2#start-report-exception-handlers) cookbook:
145
+
146
+ ```ruby
147
+ node.default['chef_client']['config']['exception_handlers'] = [{
148
+ 'class' => 'Chef::Handler::Sns',
149
+ 'arguments' => ['topic_arn: "arn:aws:sns:***"']
150
+ }]
151
+ ```
152
+
153
+ #### OpsWorks: Filter Notifications by Activity
154
+
155
+ An optional array of OpsWorks activities can be supplied. If the array is set, notifications will
156
+ only be triggered for the activities in the array, everything else will be discarded.
157
+
158
+ ```ruby
159
+ argument_array = [
160
+ filter_opsworks_activities: %w(deploy configure)
161
+ ]
162
+ ```
163
+
164
+ ## Handler Configuration Options
165
+
166
+ The following options are available to configure the handler:
167
+
168
+ * `access_key` - AWS access key (required, but will try to read it from Ohai with IAM roles).
169
+ * `secret_key` - AWS secret key (required, but will try to read it from Ohai with IAM roles).
170
+ * `token` - AWS security token (optional, read from Ohai with IAM roles). Set to `false` to disable the token detected by Ohai.
171
+ * `topic_arn` - AWS topic ARN name (required).
172
+ * `message_structure` - Set this option to `json` if you want to send a different message for each protocol. You must set your [message body template](#body_template-configuration-option) properly. Valid value: `json` (optional).
173
+ * `region` - AWS region (optional).
174
+ * `subject` - Message subject string in erubis format (optional).
175
+ * `body_template` - Full path of an erubis template file to use for the message body (optional).
176
+ * `filter_opsworks_activities` - An array of OpsWorks activities to be triggered with (optional). When set, everything else will be discarded.
177
+
178
+ **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`.
179
+
180
+ ### `subject` Configuration Option
181
+
182
+ Here is an example of the `subject` configuration option using the ruby configuration file (`solo.rb` or `client.rb`):
183
+
184
+ ```ruby
185
+ sns_handler.subject(
186
+ "Chef-run: <%= node.name %> - <%= run_status.success? ? 'ok' : 'error' %>"
187
+ )
188
+ ```
189
+
190
+ Using the [`chef_handler` LWRP](https://supermarket.chef.io/cookbooks/chef_handler):
191
+
192
+ ```ruby
193
+ argument_array = [
194
+ access_key: '***AMAZON-KEY***',
195
+ secret_key: '***AMAZON-SECRET***',
196
+ topic_arn: 'arn:aws:sns:***',
197
+ subject:
198
+ "Chef-run: <%= node.name %> - <%= run_status.success? ? 'ok' : 'error' %>"
199
+ # [...]
200
+ ]
201
+
202
+ chef_handler 'Chef::Handler::Sns' do
203
+ # [...]
204
+ arguments argument_array
205
+ end
206
+ ```
207
+
208
+ The following variables are accessible inside the template:
209
+
210
+ * `start_time` - The time the chef run started.
211
+ * `end_time` - The time the chef run ended.
212
+ * `elapsed_time` - The time elapsed between the start and finish of the chef run.
213
+ * `run_context` - The Chef::RunContext object used by the chef run.
214
+ * `exception` - The uncaught Exception that terminated the chef run, or nil if the run completed successfully.
215
+ * `backtrace` - The backtrace captured by the uncaught exception that terminated the chef run, or nil if the run completed successfully.
216
+ * `node` - The Chef::Node for this client run.
217
+ * `all_resources` - An Array containing all resources in the chef-run resource collection.
218
+ * `updated_resources` - An Array containing all resources that were updated during the chef run.
219
+ * `success?` - Was the chef run successful? True if the chef run did not raise an uncaught exception.
220
+ * `failed?` - Did the chef run fail? True if the chef run raised an uncaught exception.
221
+
222
+ ### `body_template` Configuration Option
223
+
224
+ This configuration option needs to contain the full path of an Erubis template. For example:
225
+
226
+ ```ruby
227
+ # recipe 'myapp::sns_handler'
228
+
229
+ cookbook_file 'chef_handler_sns_body.erb' do
230
+ path '/tmp/chef_handler_sns_body.erb'
231
+ # [...]
232
+ end
233
+
234
+ argument_array = [
235
+ access_key: '***AMAZON-KEY***',
236
+ secret_key: '***AMAZON-SECRET***',
237
+ topic_arn: 'arn:aws:sns:***',
238
+ body_template: '/tmp/chef_handler_sns_body.erb'
239
+ # [...]
240
+ ]
241
+
242
+ chef_handler 'Chef::Handler::Sns' do
243
+ # [...]
244
+ arguments argument_array
245
+ end
246
+ ```
247
+
248
+ ```erb
249
+ <%# file 'myapp/files/default/chef_handler_sns_body.erb' %>
250
+
251
+ Node Name: <%= node.name %>
252
+ <% if node.attribute?('fqdn') -%>
253
+ Hostname: <%= node.fqdn %>
254
+ <% end -%>
255
+
256
+ Chef Run List: <%= node.run_list.to_s %>
257
+ Chef Environment: <%= node.chef_environment %>
258
+
259
+ <% if node.attribute?('ec2') -%>
260
+ Instance Id: <%= node.ec2.instance_id %>
261
+ Instance Public Hostname: <%= node.ec2.public_hostname %>
262
+ Instance Hostname: <%= node.ec2.hostname %>
263
+ Instance Public IPv4: <%= node.ec2.public_ipv4 %>
264
+ Instance Local IPv4: <%= node.ec2.local_ipv4 %>
265
+ <% end -%>
266
+
267
+ Chef Client Elapsed Time: <%= elapsed_time.to_s %>
268
+ Chef Client Start Time: <%= start_time.to_s %>
269
+ Chef Client Start Time: <%= end_time.to_s %>
270
+
271
+ <% if exception -%>
272
+ Exception: <%= run_status.formatted_exception %>
273
+ Stacktrace:
274
+ <%= Array(backtrace).join("\n") %>
275
+
276
+ <% end -%>
277
+ ```
278
+
279
+ See the [subject](#subject) documentation for more details on the variables accessible inside the template.
280
+
281
+ If you set `message_structure` to `json`, the body template must:
282
+
283
+ * be a syntactically valid JSON; and
284
+ * contain at least a top-level JSON key of `default` with a value that is a string.
285
+
286
+ You can define other top-level keys that define the message you want to send to a specific transport protocol (e.g., "http").
287
+ ```erb
288
+ <%# file 'myapp/files/default/chef_handler_sns_body.erb' %>
289
+ {
290
+ "default": "Message body text here.",
291
+ "email": "Message body text here.",
292
+ "http": "Message body text here."
293
+ }
294
+ ```
295
+ See the [AWS SNS](http://docs.aws.amazon.com/sns/latest/api/API_Publish.html#API_Publish_RequestParameters) documentation for more details on SNS message format.
296
+
297
+ ## IAM Role Credentials from Ohai
298
+
299
+ IAM Role information and credentials are gathered from Ohai by default if they exists.
300
+
301
+ 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)).
302
+
303
+ These are the used Ohai attributes:
304
+
305
+ ```
306
+ ec2
307
+ ├── placement_availability_zone: region is set from here.
308
+ └── iam
309
+ └── security-credentials
310
+ └── IAMRoleName
311
+ ├── AccessKeyId
312
+ ├── SecretAccessKey
313
+ └── Token
314
+ ```
315
+
316
+ ## Testing
317
+
318
+ See [TESTING.md](https://github.com/zuazo/chef-handler-sns/blob/master/TESTING.md).
319
+
320
+ ## Contributing
321
+
322
+ Please do not hesitate to [open an issue](https://github.com/zuazo/chef-handler-sns/issues/new) with any questions or problems.
323
+
324
+ See [CONTRIBUTING.md](https://github.com/zuazo/chef-handler-sns/blob/master/CONTRIBUTING.md).
325
+
326
+ ## TODO
327
+
328
+ See [TODO.md](https://github.com/zuazo/chef-handler-sns/blob/master/TODO.md).
329
+
330
+ ## License and Author
331
+
332
+ | | |
333
+ |:---------------------|:-----------------------------------------|
334
+ | **Author:** | [Xabier de Zuazo](https://github.com/zuazo) (<xabier@zuazo.org>)
335
+ | **Contributor:** | [Florian Holzhauer](https://github.com/fh)
336
+ | **Contributor:** | [Michael Hobbs](https://github.com/michaelshobbs)
337
+ | **Contributor:** | [Hugo Lopes Tavares](https://github.com/hltbra)
338
+ | **Contributor:** | [Dmitry Averkiev](https://github.com/d-averkiev)
339
+ | **Copyright:** | Copyright (c) 2015 Xabier de Zuazo
340
+ | **Copyright:** | Copyright (c) 2013-2014 Onddo Labs, SL.
341
+ | **License:** | Apache License, Version 2.0
342
+
343
+ Licensed under the Apache License, Version 2.0 (the "License");
344
+ you may not use this file except in compliance with the License.
345
+ You may obtain a copy of the License at
346
+
347
+ http://www.apache.org/licenses/LICENSE-2.0
348
+
349
+ Unless required by applicable law or agreed to in writing, software
350
+ distributed under the License is distributed on an "AS IS" BASIS,
351
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
352
+ See the License for the specific language governing permissions and
353
+ limitations under the License.
354
+
@@ -0,0 +1,130 @@
1
+ #
2
+ # Author:: Xabier de Zuazo (<xabier@zuazo.org>)
3
+ # Copyright:: Copyright (c) 2015 Xabier de Zuazo
4
+ # Copyright:: Copyright (c) 2014 Onddo Labs, SL.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ class Chef
21
+ class Handler
22
+ class Sns < ::Chef::Handler
23
+ module Config
24
+ #
25
+ # Gets Chef Handler SNS default configuration from
26
+ # [Ohai](https://docs.chef.io/ohai.html) information.
27
+ #
28
+ class Ohai
29
+ #
30
+ # AWS region name.
31
+ #
32
+ # Not used, read from the topic ARN.
33
+ #
34
+ # @return [String] Region.
35
+ #
36
+ attr_reader :region
37
+
38
+ #
39
+ # AWS access key.
40
+ #
41
+ # @return [String] Access key.
42
+ #
43
+ attr_reader :access_key
44
+
45
+ #
46
+ # AWS secret key.
47
+ #
48
+ # @return [String] Secret key.
49
+ #
50
+ attr_reader :secret_key
51
+
52
+ #
53
+ # AWS token.
54
+ #
55
+ # @return [String] token.
56
+ #
57
+ attr_reader :token
58
+
59
+ #
60
+ # Constructs a {Chef::Handler::Sns::Config::Ohai} object.
61
+ #
62
+ # @param node [Chef::Node] Node object to read Ohai information from.
63
+ #
64
+ # @api public
65
+ #
66
+ def initialize(node)
67
+ read_config(node)
68
+ end
69
+
70
+ protected
71
+
72
+ #
73
+ # Reads AWS region information from Ohai.
74
+ #
75
+ # Old code. This is currently not used. We are reading region
76
+ # information from Topic ARN.
77
+ #
78
+ # @param ec2 [Hash] These are attributes below `node['ec2']`.
79
+ #
80
+ # @return void
81
+ #
82
+ # @api private
83
+ #
84
+ def read_region_config(ec2)
85
+ return unless ec2.attribute?('placement_availability_zone') &&
86
+ ec2['placement_availability_zone'].is_a?(String)
87
+ @region = ec2['placement_availability_zone'].chop
88
+ end
89
+
90
+ #
91
+ # Reads the IAM credentials from Ohai.
92
+ #
93
+ # @param ec2 [Hash] These are attributes below `node['ec2']`.
94
+ #
95
+ # @return void
96
+ #
97
+ # @api private
98
+ #
99
+ def read_iam_config(ec2)
100
+ return unless ec2.attribute?('iam') &&
101
+ ec2['iam'].attribute?('security-credentials')
102
+ _iam_role, credentials =
103
+ ec2['iam']['security-credentials'].to_hash.first
104
+ return if credentials.nil?
105
+ @access_key = credentials['AccessKeyId']
106
+ @secret_key = credentials['SecretAccessKey']
107
+ @token = credentials['Token']
108
+ end
109
+
110
+ #
111
+ # Reads configuration information from Ohai.
112
+ #
113
+ # Reads both region information and IAM credentials.
114
+ #
115
+ # @param node [Chef::Node] Node object to read information from.
116
+ #
117
+ # @return void
118
+ #
119
+ # @api private
120
+ #
121
+ def read_config(node)
122
+ return unless node.attribute?('ec2')
123
+ read_region_config(node['ec2'])
124
+ read_iam_config(node['ec2'])
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end