knife-spork 1.7.2 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +35 -35
  3. data/lib/chef/knife/spork-bump.rb +100 -100
  4. data/lib/chef/knife/spork-check.rb +165 -161
  5. data/lib/chef/knife/spork-databag-create.rb +54 -54
  6. data/lib/chef/knife/spork-databag-delete.rb +51 -51
  7. data/lib/chef/knife/spork-databag-edit.rb +54 -54
  8. data/lib/chef/knife/spork-databag-fromfile.rb +88 -88
  9. data/lib/chef/knife/spork-delete.rb +132 -132
  10. data/lib/chef/knife/spork-environment-check.rb +90 -90
  11. data/lib/chef/knife/spork-environment-create.rb +63 -63
  12. data/lib/chef/knife/spork-environment-delete.rb +38 -38
  13. data/lib/chef/knife/spork-environment-edit.rb +40 -40
  14. data/lib/chef/knife/spork-environment-fromfile.rb +46 -46
  15. data/lib/chef/knife/spork-info.rb +34 -34
  16. data/lib/chef/knife/spork-node-create.rb +41 -41
  17. data/lib/chef/knife/spork-node-delete.rb +41 -41
  18. data/lib/chef/knife/spork-node-edit.rb +48 -48
  19. data/lib/chef/knife/spork-node-fromfile.rb +46 -46
  20. data/lib/chef/knife/spork-node-runlistadd.rb +51 -51
  21. data/lib/chef/knife/spork-node-runlistremove.rb +44 -44
  22. data/lib/chef/knife/spork-node-runlistset.rb +44 -44
  23. data/lib/chef/knife/spork-omni.rb +112 -112
  24. data/lib/chef/knife/spork-promote.rb +197 -197
  25. data/lib/chef/knife/spork-role-create.rb +46 -46
  26. data/lib/chef/knife/spork-role-delete.rb +50 -50
  27. data/lib/chef/knife/spork-role-edit.rb +40 -40
  28. data/lib/chef/knife/spork-role-fromfile.rb +65 -65
  29. data/lib/chef/knife/spork-upload.rb +151 -151
  30. data/lib/chef/knife/spork-version.rb +12 -12
  31. data/lib/knife-spork.rb +3 -3
  32. data/lib/knife-spork/plugins.rb +27 -27
  33. data/lib/knife-spork/plugins/campfire.rb +219 -219
  34. data/lib/knife-spork/plugins/eventinator.rb +329 -329
  35. data/lib/knife-spork/plugins/foodcritic.rb +46 -46
  36. data/lib/knife-spork/plugins/git.rb +393 -399
  37. data/lib/knife-spork/plugins/graphite.rb +25 -25
  38. data/lib/knife-spork/plugins/grove.rb +167 -167
  39. data/lib/knife-spork/plugins/hipchat.rb +171 -171
  40. data/lib/knife-spork/plugins/influxdb.rb +28 -28
  41. data/lib/knife-spork/plugins/irccat.rb +332 -332
  42. data/lib/knife-spork/plugins/jabber.rb +133 -133
  43. data/lib/knife-spork/plugins/plugin.rb +117 -117
  44. data/lib/knife-spork/plugins/rubocop.rb +56 -56
  45. data/lib/knife-spork/plugins/slack.rb +125 -125
  46. data/lib/knife-spork/plugins/statusnet.rb +122 -122
  47. data/lib/knife-spork/runner.rb +342 -342
  48. data/lib/knife-spork/version.rb +5 -5
  49. metadata +4 -51
  50. data/.gitignore +0 -21
  51. data/.ruby-gemset +0 -1
  52. data/.ruby-version +0 -1
  53. data/.travis.yml +0 -3
  54. data/CHANGELOG.md +0 -445
  55. data/Gemfile +0 -3
  56. data/README.md +0 -544
  57. data/Rakefile +0 -35
  58. data/knife-spork.gemspec +0 -28
  59. data/plugins/Campfire.md +0 -43
  60. data/plugins/Eventinator.md +0 -30
  61. data/plugins/Foodcritic.md +0 -53
  62. data/plugins/Git.md +0 -53
  63. data/plugins/Graphite.md +0 -30
  64. data/plugins/Grove.md +0 -31
  65. data/plugins/HipChat.md +0 -69
  66. data/plugins/Influxdb.md +0 -25
  67. data/plugins/Irccat.md +0 -50
  68. data/plugins/Jabber.md +0 -61
  69. data/plugins/README.md +0 -70
  70. data/plugins/Rubocop.md +0 -110
  71. data/plugins/Slack.md +0 -48
  72. data/plugins/StatusNet.md +0 -41
  73. data/plugins/Template.md +0 -34
  74. data/spec/spec_helper.rb +0 -10
  75. data/spec/test_helpers.rb +0 -46
  76. data/spec/unit/fixtures/config/spork-config.yml +0 -1
  77. data/spec/unit/fixtures/cookbooks/example/metadata.rb +0 -8
  78. data/spec/unit/fixtures/environments/example.json +0 -12
  79. data/spec/unit/fixtures/knife.rb +0 -6
  80. data/spec/unit/fixtures/test_client.pem +0 -27
  81. data/spec/unit/spork_bump_spec.rb +0 -75
  82. data/spec/unit/spork_info_spec.rb +0 -40
  83. data/spec/unit/spork_promote_spec.rb +0 -77
  84. data/spec/unit/spork_upload_spec.rb +0 -46
@@ -1,28 +1,28 @@
1
- require 'knife-spork/plugins/plugin'
2
-
3
- module KnifeSpork
4
- module Plugins
5
- class Influxdb < Plugin
6
- name :influxdb
7
- hooks :after_upload
8
-
9
- def perform
10
- safe_require 'influxdb'
11
- conn = InfluxDB::Client.new(config.database, host: config.host, port: config.port, username: config.username, password: config.password, use_ssl: config.ssl)
12
- environments.each do |environment|
13
- begin
14
- data = {
15
- user: current_user,
16
- cookbook: cookbook.name,
17
- version: cookbook.version
18
- }
19
- conn.write_point(config.series, data)
20
- rescue Exception => e
21
- ui.error 'Could not write data to influxdb'
22
- ui.error e.to_s
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
1
+ require 'knife-spork/plugins/plugin'
2
+
3
+ module KnifeSpork
4
+ module Plugins
5
+ class Influxdb < Plugin
6
+ name :influxdb
7
+ hooks :after_upload
8
+
9
+ def perform
10
+ safe_require 'influxdb'
11
+ conn = InfluxDB::Client.new(config.database, host: config.host, port: config.port, username: config.username, password: config.password, use_ssl: config.ssl)
12
+ environments.each do |environment|
13
+ begin
14
+ data = {
15
+ user: current_user,
16
+ cookbook: cookbook.name,
17
+ version: cookbook.version
18
+ }
19
+ conn.write_point(config.series, data)
20
+ rescue Exception => e
21
+ ui.error 'Could not write data to influxdb'
22
+ ui.error e.to_s
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,332 +1,332 @@
1
- require 'knife-spork/plugins/plugin'
2
-
3
- module KnifeSpork
4
- module Plugins
5
- class Irccat < Plugin
6
- name :irccat
7
-
8
- TEMPLATES = {
9
- :upload => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded #TEAL%{cookbooks}#NORMAL',
10
- :delete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted the following cookbooks: #TEAL%{misc_output}#NORMAL',
11
- :promote => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} promoted #TEAL%{cookbooks}#NORMAL to %{environment} %{gist}',
12
- :environmentfromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded environment #TEAL%{object_name}#NORMAL %{gist}',
13
- :environmentedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited environment #TEAL%{object_name}#NORMAL %{gist}',
14
- :environmentcreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created environment #TEAL%{object_name}#NORMAL %{gist}',
15
- :environmentdelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted environment #TEAL%{object_name}#NORMAL %{gist}',
16
- :rolefromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded role #TEAL%{object_name}#NORMAL %{gist}',
17
- :roleedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited role #TEAL%{object_name}#NORMAL %{gist}',
18
- :rolecreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created role #TEAL%{object_name}#NORMAL %{gist}',
19
- :roledelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted role #TEAL%{object_name}#NORMAL %{gist}',
20
- :databagedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited data bag item #TEAL%{object_name}:%{object_secondary_name}#NORMAL %{gist}',
21
- :databagdelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted data bag #TEAL%{object_name}#NORMAL %{gist}',
22
- :databagitemdelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted data bag item #TEAL%{object_name}:%{object_secondary_name}#NORMAL %{gist}',
23
- :databagcreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created data bag #TEAL%{object_name}#NORMAL %{gist}',
24
- :databagfromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded data bag item #TEAL%{object_name}:%{object_secondary_name}#NORMAL %{gist}',
25
- :nodeedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited node #TEAL%{object_name}#NORMAL %{gist}',
26
- :nodedelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted node #TEAL%{object_name}#NORMAL %{gist}',
27
- :nodecreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created node #TEAL%{object_name}#NORMAL %{gist}',
28
- :nodefromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded node #TEAL%{object_name}#NORMAL %{gist}',
29
- :noderunlistadd => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} added run_list items to #TEAL%{object_name}: %{object_secondary_name}#NORMAL %{gist}',
30
- :noderunlistremove => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} removed run_list items from #TEAL%{object_name}: %{object_secondary_name}#NORMAL %{gist}',
31
- :noderunlistset => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} set the run_list for #TEAL%{object_name} to %{object_secondary_name}#NORMAL %{gist}'
32
- }
33
-
34
- def perform; end
35
-
36
- def after_upload
37
- irccat(template(:upload) % {
38
- :organization => organization,
39
- :current_user => current_user,
40
- :cookbooks => cookbooks.collect { |c| "#{c.name}@#{c.version}" }.join(", ")
41
- })
42
- end
43
-
44
- def after_delete
45
- irccat(template(:delete) % {
46
- :organization => organization,
47
- :current_user => current_user,
48
- :misc_output => misc_output
49
- })
50
- end
51
-
52
- def after_promote_remote
53
- environments.each do |environment|
54
- diff = environment_diffs[environment.name]
55
- env_gist = env_gist(environment, diff) if config.gist
56
- display_gist(env_gist) if env_gist
57
- irccat(template(:promote) % {
58
- :organization => organization,
59
- :current_user => current_user,
60
- :cookbooks => cookbooks.collect{ |c| "#{c.name}@#{c.version}" }.join(", "),
61
- :environment => environment.name,
62
- :gist => env_gist
63
- })
64
- end
65
- end
66
-
67
- def after_environmentfromfile
68
- environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
69
- display_gist(environment_gist) if environment_gist
70
- irccat(template(:environmentfromfile) % {
71
- :organization => organization,
72
- :current_user => current_user,
73
- :object_name => object_name,
74
- :gist => environment_gist
75
- })
76
- end
77
-
78
- def after_environmentedit
79
- environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
80
- display_gist(environment_gist) if environment_gist
81
- irccat(template(:environmentedit) % {
82
- :organization => organization,
83
- :current_user => current_user,
84
- :object_name => object_name,
85
- :gist => environment_gist
86
- })
87
- end
88
-
89
- def after_environmentcreate
90
- environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
91
- display_gist(environment_gist) if environment_gist
92
- irccat(template(:environmentcreate) % {
93
- :organization => organization,
94
- :current_user => current_user,
95
- :object_name => object_name,
96
- :gist => environment_gist
97
- })
98
- end
99
-
100
- def after_environmentdelete
101
- environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
102
- display_gist(environment_gist) if environment_gist
103
- irccat(template(:environmentdelete) % {
104
- :organization => organization,
105
- :current_user => current_user,
106
- :object_name => object_name,
107
- :gist => environment_gist
108
- })
109
- end
110
-
111
- def after_rolefromfile
112
- role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
113
- display_gist(role_gist) if role_gist
114
- irccat(template(:rolefromfile) % {
115
- :organization => organization,
116
- :current_user => current_user,
117
- :object_name => object_name,
118
- :gist => role_gist
119
- })
120
- end
121
-
122
- def after_roleedit
123
- role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
124
- display_gist(role_gist) if role_gist
125
- irccat(template(:roleedit) % {
126
- :organization => organization,
127
- :current_user => current_user,
128
- :object_name => object_name,
129
- :gist => role_gist
130
- })
131
- end
132
-
133
- def after_rolecreate
134
- role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
135
- display_gist(role_gist) if role_gist
136
- irccat(template(:rolecreate) % {
137
- :organization => organization,
138
- :current_user => current_user,
139
- :object_name => object_name,
140
- :gist => role_gist
141
- })
142
- end
143
-
144
- def after_roledelete
145
- role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
146
- display_gist(role_gist) if role_gist
147
- irccat(template(:roledelete) % {
148
- :organization => organization,
149
- :current_user => current_user,
150
- :object_name => object_name,
151
- :gist => role_gist
152
- })
153
- end
154
-
155
- def after_databagedit
156
- databag_gist = object_gist("databag item", "#{object_name}:#{object_secondary_name}", object_difference) if config.gist and !object_difference.empty?
157
- display_gist(databag_gist) if databag_gist
158
- irccat(template(:databagedit) % {
159
- :organization => organization,
160
- :current_user => current_user,
161
- :object_name => object_name,
162
- :object_secondary_name => object_secondary_name,
163
- :gist => databag_gist
164
- })
165
- end
166
-
167
- def after_databagdelete
168
- databag_gist = object_gist("databag item", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
169
- display_gist(databag_gist) if databag_gist
170
- irccat(template(:databagdelete) % {
171
- :organization => organization,
172
- :current_user => current_user,
173
- :object_name => object_name,
174
- :gist => databag_gist
175
- })
176
- end
177
-
178
- def after_databagitemdelete
179
- databag_gist = object_gist("databag item", "#{object_name}:#{object_secondary_name}", object_difference) if config.gist and !object_difference.empty?
180
- display_gist(databag_gist) if databag_gist
181
- irccat(template(:databagitemdelete) % {
182
- :organization => organization,
183
- :current_user => current_user,
184
- :object_name => object_name,
185
- :object_secondary_name => object_secondary_name,
186
- :gist => databag_gist
187
- })
188
- end
189
-
190
- def after_databagcreate
191
- databag_gist = object_gist("databag", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
192
- display_gist(databag_gist) if databag_gist
193
- irccat(template(:databagcreate) % {
194
- :organization => organization,
195
- :current_user => current_user,
196
- :object_name => object_name,
197
- :gist => databag_gist
198
- })
199
- end
200
-
201
- def after_databagfromfile
202
- databag_gist = object_gist("databag", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
203
- display_gist(databag_gist) if databag_gist
204
- irccat(template(:databagfromfile) % {
205
- :organization => organization,
206
- :current_user => current_user,
207
- :object_name => object_name,
208
- :object_secondary_name => object_secondary_name,
209
- :gist => databag_gist
210
- })
211
- end
212
-
213
- def after_nodeedit
214
- node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
215
- display_gist(node_gist) if node_gist
216
- irccat(template(:nodeedit) % {
217
- :organization => organization,
218
- :current_user => current_user,
219
- :object_name => object_name,
220
- :gist => node_gist
221
- })
222
- end
223
-
224
- def after_nodedelete
225
- node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
226
- display_gist(node_gist) if node_gist
227
- irccat(template(:nodedelete) % {
228
- :organization => organization,
229
- :current_user => current_user,
230
- :object_name => object_name,
231
- :gist => node_gist
232
- })
233
- end
234
-
235
- def after_nodecreate
236
- node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
237
- display_gist(node_gist) if node_gist
238
- irccat(template(:nodecreate) % {
239
- :organization => organization,
240
- :current_user => current_user,
241
- :object_name => object_name,
242
- :gist => node_gist
243
- })
244
- end
245
-
246
- def after_nodefromfile
247
- node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
248
- display_gist(node_gist) if node_gist
249
- irccat(template(:nodefromfile) % {
250
- :organization => organization,
251
- :current_user => current_user,
252
- :object_name => object_name,
253
- :gist => node_gist
254
- })
255
- end
256
-
257
- def after_noderunlistadd
258
- node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
259
- display_gist(node_gist) if node_gist
260
- irccat(template(:noderunlistadd) % {
261
- :organization => organization,
262
- :current_user => current_user,
263
- :object_name => object_name,
264
- :object_secondary_name => object_secondary_name,
265
- :gist => node_gist
266
- })
267
- end
268
-
269
- def after_noderunlistremove
270
- node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
271
- display_gist(node_gist) if node_gist
272
- irccat(template(:noderunlistremove) % {
273
- :organization => organization,
274
- :current_user => current_user,
275
- :object_name => object_name,
276
- :object_secondary_name => object_secondary_name,
277
- :gist => node_gist
278
- })
279
- end
280
-
281
- def after_noderunlistset
282
- node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
283
- display_gist(node_gist) if node_gist
284
- irccat(template(:noderunlistset) % {
285
- :organization => organization,
286
- :current_user => current_user,
287
- :object_name => object_name,
288
- :object_secondary_name => object_secondary_name,
289
- :gist => node_gist
290
- })
291
- end
292
-
293
- private
294
- def irccat(message)
295
- channels.each do |channel|
296
- begin
297
- # Write the message using a TCP Socket
298
- socket = TCPSocket.open(config.server, config.port)
299
- socket.write("#{channel} #{message}")
300
- rescue Exception => e
301
- ui.error 'Failed to post message with irccat.'
302
- ui.error e.to_s
303
- ensure
304
- socket.close unless socket.nil?
305
- end
306
- end
307
- end
308
-
309
- def env_gist(environment, diff)
310
- msg = "Environment #{environment} uploaded at #{Time.now.getutc} by #{current_user}\n\nConstraints updated on server in this version:\n\n#{diff.collect { |k, v| "#{k}: #{v}\n" }.join}"
311
- %x[ echo "#{msg}" | #{config.gist}]
312
- end
313
-
314
- def display_gist(gist)
315
- ui.info "Gist generated at #{gist}"
316
- end
317
-
318
- def object_gist(object_type, object_name, object_diff)
319
- msg = "#{object_type.capitalize} #{object_name} changed at #{Time.now.getutc} by #{current_user}\n\nDiff is as follows:\n\n#{object_diff}"
320
- %x[ echo "#{msg}" | #{config.gist}]
321
- end
322
-
323
- def channels
324
- [ config.channel || config.channels ].flatten
325
- end
326
-
327
- def template(name)
328
- (config.template && config.template[name]) || TEMPLATES[name]
329
- end
330
- end
331
- end
332
- end
1
+ require 'knife-spork/plugins/plugin'
2
+
3
+ module KnifeSpork
4
+ module Plugins
5
+ class Irccat < Plugin
6
+ name :irccat
7
+
8
+ TEMPLATES = {
9
+ :upload => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded #TEAL%{cookbooks}#NORMAL',
10
+ :delete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted the following cookbooks: #TEAL%{misc_output}#NORMAL',
11
+ :promote => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} promoted #TEAL%{cookbooks}#NORMAL to %{environment} %{gist}',
12
+ :environmentfromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded environment #TEAL%{object_name}#NORMAL %{gist}',
13
+ :environmentedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited environment #TEAL%{object_name}#NORMAL %{gist}',
14
+ :environmentcreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created environment #TEAL%{object_name}#NORMAL %{gist}',
15
+ :environmentdelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted environment #TEAL%{object_name}#NORMAL %{gist}',
16
+ :rolefromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded role #TEAL%{object_name}#NORMAL %{gist}',
17
+ :roleedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited role #TEAL%{object_name}#NORMAL %{gist}',
18
+ :rolecreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created role #TEAL%{object_name}#NORMAL %{gist}',
19
+ :roledelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted role #TEAL%{object_name}#NORMAL %{gist}',
20
+ :databagedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited data bag item #TEAL%{object_name}:%{object_secondary_name}#NORMAL %{gist}',
21
+ :databagdelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted data bag #TEAL%{object_name}#NORMAL %{gist}',
22
+ :databagitemdelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted data bag item #TEAL%{object_name}:%{object_secondary_name}#NORMAL %{gist}',
23
+ :databagcreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created data bag #TEAL%{object_name}#NORMAL %{gist}',
24
+ :databagfromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded data bag item #TEAL%{object_name}:%{object_secondary_name}#NORMAL %{gist}',
25
+ :nodeedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited node #TEAL%{object_name}#NORMAL %{gist}',
26
+ :nodedelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted node #TEAL%{object_name}#NORMAL %{gist}',
27
+ :nodecreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created node #TEAL%{object_name}#NORMAL %{gist}',
28
+ :nodefromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded node #TEAL%{object_name}#NORMAL %{gist}',
29
+ :noderunlistadd => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} added run_list items to #TEAL%{object_name}: %{object_secondary_name}#NORMAL %{gist}',
30
+ :noderunlistremove => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} removed run_list items from #TEAL%{object_name}: %{object_secondary_name}#NORMAL %{gist}',
31
+ :noderunlistset => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} set the run_list for #TEAL%{object_name} to %{object_secondary_name}#NORMAL %{gist}'
32
+ }
33
+
34
+ def perform; end
35
+
36
+ def after_upload
37
+ irccat(template(:upload) % {
38
+ :organization => organization,
39
+ :current_user => current_user,
40
+ :cookbooks => cookbooks.collect { |c| "#{c.name}@#{c.version}" }.join(", ")
41
+ })
42
+ end
43
+
44
+ def after_delete
45
+ irccat(template(:delete) % {
46
+ :organization => organization,
47
+ :current_user => current_user,
48
+ :misc_output => misc_output
49
+ })
50
+ end
51
+
52
+ def after_promote_remote
53
+ environments.each do |environment|
54
+ diff = environment_diffs[environment.name]
55
+ env_gist = env_gist(environment, diff) if config.gist
56
+ display_gist(env_gist) if env_gist
57
+ irccat(template(:promote) % {
58
+ :organization => organization,
59
+ :current_user => current_user,
60
+ :cookbooks => cookbooks.collect{ |c| "#{c.name}@#{c.version}" }.join(", "),
61
+ :environment => environment.name,
62
+ :gist => env_gist
63
+ })
64
+ end
65
+ end
66
+
67
+ def after_environmentfromfile
68
+ environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
69
+ display_gist(environment_gist) if environment_gist
70
+ irccat(template(:environmentfromfile) % {
71
+ :organization => organization,
72
+ :current_user => current_user,
73
+ :object_name => object_name,
74
+ :gist => environment_gist
75
+ })
76
+ end
77
+
78
+ def after_environmentedit
79
+ environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
80
+ display_gist(environment_gist) if environment_gist
81
+ irccat(template(:environmentedit) % {
82
+ :organization => organization,
83
+ :current_user => current_user,
84
+ :object_name => object_name,
85
+ :gist => environment_gist
86
+ })
87
+ end
88
+
89
+ def after_environmentcreate
90
+ environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
91
+ display_gist(environment_gist) if environment_gist
92
+ irccat(template(:environmentcreate) % {
93
+ :organization => organization,
94
+ :current_user => current_user,
95
+ :object_name => object_name,
96
+ :gist => environment_gist
97
+ })
98
+ end
99
+
100
+ def after_environmentdelete
101
+ environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
102
+ display_gist(environment_gist) if environment_gist
103
+ irccat(template(:environmentdelete) % {
104
+ :organization => organization,
105
+ :current_user => current_user,
106
+ :object_name => object_name,
107
+ :gist => environment_gist
108
+ })
109
+ end
110
+
111
+ def after_rolefromfile
112
+ role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
113
+ display_gist(role_gist) if role_gist
114
+ irccat(template(:rolefromfile) % {
115
+ :organization => organization,
116
+ :current_user => current_user,
117
+ :object_name => object_name,
118
+ :gist => role_gist
119
+ })
120
+ end
121
+
122
+ def after_roleedit
123
+ role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
124
+ display_gist(role_gist) if role_gist
125
+ irccat(template(:roleedit) % {
126
+ :organization => organization,
127
+ :current_user => current_user,
128
+ :object_name => object_name,
129
+ :gist => role_gist
130
+ })
131
+ end
132
+
133
+ def after_rolecreate
134
+ role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
135
+ display_gist(role_gist) if role_gist
136
+ irccat(template(:rolecreate) % {
137
+ :organization => organization,
138
+ :current_user => current_user,
139
+ :object_name => object_name,
140
+ :gist => role_gist
141
+ })
142
+ end
143
+
144
+ def after_roledelete
145
+ role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
146
+ display_gist(role_gist) if role_gist
147
+ irccat(template(:roledelete) % {
148
+ :organization => organization,
149
+ :current_user => current_user,
150
+ :object_name => object_name,
151
+ :gist => role_gist
152
+ })
153
+ end
154
+
155
+ def after_databagedit
156
+ databag_gist = object_gist("databag item", "#{object_name}:#{object_secondary_name}", object_difference) if config.gist and !object_difference.empty?
157
+ display_gist(databag_gist) if databag_gist
158
+ irccat(template(:databagedit) % {
159
+ :organization => organization,
160
+ :current_user => current_user,
161
+ :object_name => object_name,
162
+ :object_secondary_name => object_secondary_name,
163
+ :gist => databag_gist
164
+ })
165
+ end
166
+
167
+ def after_databagdelete
168
+ databag_gist = object_gist("databag item", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
169
+ display_gist(databag_gist) if databag_gist
170
+ irccat(template(:databagdelete) % {
171
+ :organization => organization,
172
+ :current_user => current_user,
173
+ :object_name => object_name,
174
+ :gist => databag_gist
175
+ })
176
+ end
177
+
178
+ def after_databagitemdelete
179
+ databag_gist = object_gist("databag item", "#{object_name}:#{object_secondary_name}", object_difference) if config.gist and !object_difference.empty?
180
+ display_gist(databag_gist) if databag_gist
181
+ irccat(template(:databagitemdelete) % {
182
+ :organization => organization,
183
+ :current_user => current_user,
184
+ :object_name => object_name,
185
+ :object_secondary_name => object_secondary_name,
186
+ :gist => databag_gist
187
+ })
188
+ end
189
+
190
+ def after_databagcreate
191
+ databag_gist = object_gist("databag", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
192
+ display_gist(databag_gist) if databag_gist
193
+ irccat(template(:databagcreate) % {
194
+ :organization => organization,
195
+ :current_user => current_user,
196
+ :object_name => object_name,
197
+ :gist => databag_gist
198
+ })
199
+ end
200
+
201
+ def after_databagfromfile
202
+ databag_gist = object_gist("databag", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
203
+ display_gist(databag_gist) if databag_gist
204
+ irccat(template(:databagfromfile) % {
205
+ :organization => organization,
206
+ :current_user => current_user,
207
+ :object_name => object_name,
208
+ :object_secondary_name => object_secondary_name,
209
+ :gist => databag_gist
210
+ })
211
+ end
212
+
213
+ def after_nodeedit
214
+ node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
215
+ display_gist(node_gist) if node_gist
216
+ irccat(template(:nodeedit) % {
217
+ :organization => organization,
218
+ :current_user => current_user,
219
+ :object_name => object_name,
220
+ :gist => node_gist
221
+ })
222
+ end
223
+
224
+ def after_nodedelete
225
+ node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
226
+ display_gist(node_gist) if node_gist
227
+ irccat(template(:nodedelete) % {
228
+ :organization => organization,
229
+ :current_user => current_user,
230
+ :object_name => object_name,
231
+ :gist => node_gist
232
+ })
233
+ end
234
+
235
+ def after_nodecreate
236
+ node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
237
+ display_gist(node_gist) if node_gist
238
+ irccat(template(:nodecreate) % {
239
+ :organization => organization,
240
+ :current_user => current_user,
241
+ :object_name => object_name,
242
+ :gist => node_gist
243
+ })
244
+ end
245
+
246
+ def after_nodefromfile
247
+ node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
248
+ display_gist(node_gist) if node_gist
249
+ irccat(template(:nodefromfile) % {
250
+ :organization => organization,
251
+ :current_user => current_user,
252
+ :object_name => object_name,
253
+ :gist => node_gist
254
+ })
255
+ end
256
+
257
+ def after_noderunlistadd
258
+ node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
259
+ display_gist(node_gist) if node_gist
260
+ irccat(template(:noderunlistadd) % {
261
+ :organization => organization,
262
+ :current_user => current_user,
263
+ :object_name => object_name,
264
+ :object_secondary_name => object_secondary_name,
265
+ :gist => node_gist
266
+ })
267
+ end
268
+
269
+ def after_noderunlistremove
270
+ node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
271
+ display_gist(node_gist) if node_gist
272
+ irccat(template(:noderunlistremove) % {
273
+ :organization => organization,
274
+ :current_user => current_user,
275
+ :object_name => object_name,
276
+ :object_secondary_name => object_secondary_name,
277
+ :gist => node_gist
278
+ })
279
+ end
280
+
281
+ def after_noderunlistset
282
+ node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
283
+ display_gist(node_gist) if node_gist
284
+ irccat(template(:noderunlistset) % {
285
+ :organization => organization,
286
+ :current_user => current_user,
287
+ :object_name => object_name,
288
+ :object_secondary_name => object_secondary_name,
289
+ :gist => node_gist
290
+ })
291
+ end
292
+
293
+ private
294
+ def irccat(message)
295
+ channels.each do |channel|
296
+ begin
297
+ # Write the message using a TCP Socket
298
+ socket = TCPSocket.open(config.server, config.port)
299
+ socket.write("#{channel} #{message}")
300
+ rescue Exception => e
301
+ ui.error 'Failed to post message with irccat.'
302
+ ui.error e.to_s
303
+ ensure
304
+ socket.close unless socket.nil?
305
+ end
306
+ end
307
+ end
308
+
309
+ def env_gist(environment, diff)
310
+ msg = "Environment #{environment} uploaded at #{Time.now.getutc} by #{current_user}\n\nConstraints updated on server in this version:\n\n#{diff.collect { |k, v| "#{k}: #{v}\n" }.join}"
311
+ %x[ echo "#{msg}" | #{config.gist}]
312
+ end
313
+
314
+ def display_gist(gist)
315
+ ui.info "Gist generated at #{gist}"
316
+ end
317
+
318
+ def object_gist(object_type, object_name, object_diff)
319
+ msg = "#{object_type.capitalize} #{object_name} changed at #{Time.now.getutc} by #{current_user}\n\nDiff is as follows:\n\n#{object_diff}"
320
+ %x[ echo "#{msg}" | #{config.gist}]
321
+ end
322
+
323
+ def channels
324
+ [ config.channel || config.channels ].flatten
325
+ end
326
+
327
+ def template(name)
328
+ (config.template && config.template[name]) || TEMPLATES[name]
329
+ end
330
+ end
331
+ end
332
+ end