factor-connector-chef 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 374cfde72a6fbc2f4b46b50e1556979a2f67b335
4
- data.tar.gz: 94464ba0a1406322f018513abf4abf017fe5b155
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ N2YxNDgyYzg1YWE0NTYzODc0NjdkYjBjMjE0MDEwODViZGNhODgyOA==
5
+ data.tar.gz: !binary |-
6
+ YmFmNWVlZjExNzVlNjM1MjViYmQ5ZmNiNGEzZTIzNjQwODBiZmZkYw==
5
7
  SHA512:
6
- metadata.gz: c50402b3b55474ba5b6ff06b64c1668d1a49c9ca8de19b28ff1af345027a0e42946b2c0b02e2321a57a8c4bcb3488948ea6b8e6005b55ee7b24869be4dc21cb1
7
- data.tar.gz: b36543bfc3f3c079df3ac094ac8616c7e21272cd0d6531ec4f95127b40c00d3fd937680457979567e5014dd10d9fc2d991eb973bea20452876c081f4cd03e833
8
+ metadata.gz: !binary |-
9
+ MWM5MDlmNDJjNzYzM2FlYTczNjc5N2Y1ZTQzZGNlNTU4ZjUxYjRjZWExMGU1
10
+ MTdiOTQzNGVhN2ZlNmY2NjBlZGE3ZmI1ZjY0YWZlZTk4MzEyYTE5NTE1NmJm
11
+ YjY0YTE4YTIzMGRhM2VhNjA2MjViMTgwOTg0Y2ZiMDI2MjJiYzM=
12
+ data.tar.gz: !binary |-
13
+ MjAyODc1NDFiNjBmNGZjYWM3YzdjYWNjOWUxZmI2MzZhN2FiNjMxZTVmNzY4
14
+ NGFhOGFiM2FmODU2NjMxNWUxYzIyNmU5ZjFlYzM4ZTc3MmRhNTdiYjI4MTE3
15
+ NGY0YjE1ODliZTQ4M2Q3MDhiMDUzZjJiNTQ2OWI0ZThlOWY0MWU=
@@ -0,0 +1,171 @@
1
+ require 'factor-connector-api'
2
+ require 'chef-api'
3
+
4
+ Factor::Connector.service 'chef_clients' do
5
+ action 'all' do |params|
6
+ organization = params['organization']
7
+ chef_server = params['chef_server']
8
+ client_name = params['client_name']
9
+ client_key = params['client_key']
10
+
11
+ fail 'Client Name (client_name) is required' unless client_name
12
+ fail 'Client Private Key (client_key) is required' unless client_key
13
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
14
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
15
+
16
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
17
+
18
+ info 'Setting up private key'
19
+ begin
20
+ private_key_file = Tempfile.new('private')
21
+ private_key_file.write(client_key)
22
+ private_key_file.close
23
+ rescue
24
+ fail 'Failed to setup private key'
25
+ end
26
+
27
+ connection_settings = {
28
+ endpoint: chef_server,
29
+ client: client_name,
30
+ key: private_key_file.path,
31
+ }
32
+
33
+ begin
34
+ chef = ChefAPI::Connection.new connection_settings
35
+ clients = chef.clients.all
36
+ rescue => ex
37
+ fail ex.message
38
+ end
39
+
40
+ action_callback clients.map {|c| c.to_hash}
41
+ end
42
+
43
+ action 'get' do |params|
44
+ organization = params['organization']
45
+ chef_server = params['chef_server']
46
+ client_name = params['client_name']
47
+ key = params['client_key']
48
+ id = params['id']
49
+
50
+ fail 'Client Name (client_name) is required' unless client_name
51
+ fail 'Private Key (client_key) is required' unless key
52
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
53
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
54
+ fail 'Client ID (id) is required' unless id
55
+
56
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
57
+
58
+ info 'Setting up private key'
59
+ begin
60
+ private_key_file = Tempfile.new('private')
61
+ private_key_file.write(key)
62
+ private_key_file.close
63
+ rescue
64
+ fail 'Failed to setup private key'
65
+ end
66
+
67
+ connection_settings = {
68
+ endpoint: chef_server,
69
+ client: client_name,
70
+ key: private_key_file.path,
71
+ }
72
+
73
+ begin
74
+ chef = ChefAPI::Connection.new connection_settings
75
+ content = chef.clients.fetch(id)
76
+ rescue => ex
77
+ fail ex.message
78
+ end
79
+
80
+ fail "Client with id '#{id}' not found" unless content
81
+
82
+ action_callback content.to_hash
83
+ end
84
+
85
+ action 'create' do |params|
86
+ organization = params['organization']
87
+ chef_server = params['chef_server']
88
+ client_name = params['client_name']
89
+ key = params['client_key']
90
+
91
+ fail 'Client Name (client_name) is required' unless client_name
92
+ fail 'Private Key (client_key) is required' unless key
93
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
94
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
95
+ fail 'New Client Name (name) is required' unless params['name']
96
+
97
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
98
+
99
+ info 'Setting up private key'
100
+ begin
101
+ private_key_file = Tempfile.new('private')
102
+ private_key_file.write(key)
103
+ private_key_file.close
104
+ rescue
105
+ fail 'Failed to setup private key'
106
+ end
107
+
108
+ connection_settings = {
109
+ endpoint: chef_server,
110
+ client: client_name,
111
+ key: private_key_file.path,
112
+ }
113
+
114
+ available_params = %w(name admin public_key private_key validator)
115
+ client_params = {}
116
+ available_params.each do |param|
117
+ client_params[param.to_sym] = params[param] if params.include?(param)
118
+ end
119
+
120
+ begin
121
+ info "Creating new client '#{client_params['name']}'"
122
+ chef = ChefAPI::Connection.new connection_settings
123
+ content = chef.clients.create(client_params)
124
+ rescue => ex
125
+ fail ex.message
126
+ end
127
+
128
+ action_callback content.to_hash
129
+ end
130
+
131
+ action 'delete' do |params|
132
+ organization = params['organization']
133
+ chef_server = params['chef_server']
134
+ client_name = params['client_name']
135
+ key = params['client_key']
136
+ id = params['id']
137
+
138
+ fail 'Client Name (client_name) is required' unless client_name
139
+ fail 'Private Key (client_key) is required' unless key
140
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
141
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
142
+ fail 'Client ID (id) is required' unless id
143
+
144
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
145
+
146
+ info 'Setting up private key'
147
+ begin
148
+ private_key_file = Tempfile.new('private')
149
+ private_key_file.write(key)
150
+ private_key_file.close
151
+ rescue
152
+ fail 'Failed to setup private key'
153
+ end
154
+
155
+ connection_settings = {
156
+ endpoint: chef_server,
157
+ client: client_name,
158
+ key: private_key_file.path,
159
+ }
160
+
161
+ begin
162
+ chef = ChefAPI::Connection.new connection_settings
163
+ content = chef.clients.fetch(id)
164
+ content.destroy
165
+ rescue => ex
166
+ fail ex.message
167
+ end
168
+
169
+ action_callback
170
+ end
171
+ end
@@ -0,0 +1,441 @@
1
+ require 'factor-connector-api'
2
+ require 'chef-api'
3
+ require 'deep_merge'
4
+
5
+ Factor::Connector.service 'chef_databags' do
6
+ action 'all' do |params|
7
+ organization = params['organization']
8
+ chef_server = params['chef_server']
9
+ client_name = params['client_name']
10
+ client_key = params['client_key']
11
+
12
+ fail 'Client Name (client_name) is required' unless client_name
13
+ fail 'Client Private Key (client_key) is required' unless client_key
14
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
15
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
16
+
17
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
18
+
19
+ info 'Setting up private key'
20
+ begin
21
+ private_key_file = Tempfile.new('private')
22
+ private_key_file.write(client_key)
23
+ private_key_file.close
24
+ rescue
25
+ fail 'Failed to setup private key'
26
+ end
27
+
28
+ connection_settings = {
29
+ endpoint: chef_server,
30
+ client: client_name,
31
+ key: private_key_file.path,
32
+ }
33
+
34
+ begin
35
+ chef = ChefAPI::Connection.new connection_settings
36
+ contents = chef.data_bags.all
37
+ rescue => ex
38
+ fail ex.message
39
+ end
40
+
41
+ action_callback contents.map {|c| c.to_hash}
42
+ end
43
+
44
+ action 'get' do |params|
45
+ organization = params['organization']
46
+ chef_server = params['chef_server']
47
+ client_name = params['client_name']
48
+ key = params['client_key']
49
+ id = params['id']
50
+
51
+ fail 'Client Name (client_name) is required' unless client_name
52
+ fail 'Private Key (client_key) is required' unless key
53
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
54
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
55
+ fail 'Data Bag ID (id) is required' unless id
56
+
57
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
58
+
59
+ info 'Setting up private key'
60
+ begin
61
+ private_key_file = Tempfile.new('private')
62
+ private_key_file.write(key)
63
+ private_key_file.close
64
+ rescue
65
+ fail 'Failed to setup private key'
66
+ end
67
+
68
+ connection_settings = {
69
+ endpoint: chef_server,
70
+ client: client_name,
71
+ key: private_key_file.path,
72
+ }
73
+
74
+ begin
75
+ chef = ChefAPI::Connection.new connection_settings
76
+ data_bag = chef.data_bags.fetch(id)
77
+ content = data_bag.to_hash
78
+ rescue => ex
79
+ fail ex.message
80
+ end
81
+
82
+ fail "Data Bag with id '#{id}' not found" unless content
83
+
84
+ action_callback content
85
+ end
86
+
87
+ action 'create' do |params|
88
+ organization = params['organization']
89
+ chef_server = params['chef_server']
90
+ client_name = params['client_name']
91
+ key = params['client_key']
92
+ name = params['name']
93
+
94
+ fail 'Client Name (client_name) is required' unless client_name
95
+ fail 'Private Key (client_key) is required' unless key
96
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
97
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
98
+ fail 'New Data Bag Name (name) is required' unless params['name']
99
+
100
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
101
+
102
+ info 'Setting up private key'
103
+ begin
104
+ private_key_file = Tempfile.new('private')
105
+ private_key_file.write(key)
106
+ private_key_file.close
107
+ rescue
108
+ fail 'Failed to setup private key'
109
+ end
110
+
111
+ connection_settings = {
112
+ endpoint: chef_server,
113
+ client: client_name,
114
+ key: private_key_file.path,
115
+ }
116
+
117
+ begin
118
+ chef = ChefAPI::Connection.new connection_settings
119
+ data_bag = chef.data_bags.create(name: name)
120
+ content = chef.data_bags.fetch(name)
121
+ rescue => ex
122
+ fail ex.message
123
+ end
124
+
125
+ action_callback content.to_hash
126
+ end
127
+
128
+ action 'update' do |params|
129
+ organization = params['organization']
130
+ chef_server = params['chef_server']
131
+ client_name = params['client_name']
132
+ key = params['client_key']
133
+ id = params['id']
134
+ name = params['name']
135
+
136
+ fail 'Client Name (client_name) is required' unless client_name
137
+ fail 'Private Key (client_key) is required' unless key
138
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
139
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
140
+ fail 'Data Bag ID (id) is required' unless id
141
+ fail 'New Name (name) is required' unless name
142
+
143
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
144
+
145
+ info 'Setting up private key'
146
+ begin
147
+ private_key_file = Tempfile.new('private')
148
+ private_key_file.write(key)
149
+ private_key_file.close
150
+ rescue
151
+ fail 'Failed to setup private key'
152
+ end
153
+
154
+ connection_settings = {
155
+ endpoint: chef_server,
156
+ client: client_name,
157
+ key: private_key_file.path,
158
+ }
159
+
160
+ begin
161
+ chef = ChefAPI::Connection.new connection_settings
162
+ data_bag = chef.data_bags.update(id, name:name)
163
+ content = data_bag.to_hash
164
+ rescue => ex
165
+ fail ex.message
166
+ end
167
+
168
+ action_callback content
169
+ end
170
+
171
+
172
+ action 'delete' do |params|
173
+ organization = params['organization']
174
+ chef_server = params['chef_server']
175
+ client_name = params['client_name']
176
+ key = params['client_key']
177
+ id = params['id']
178
+
179
+ fail 'Client Name (client_name) is required' unless client_name
180
+ fail 'Private Key (client_key) is required' unless key
181
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
182
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
183
+ fail 'Data Bag ID (id) is required' unless id
184
+
185
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
186
+
187
+ info 'Setting up private key'
188
+ begin
189
+ private_key_file = Tempfile.new('private')
190
+ private_key_file.write(key)
191
+ private_key_file.close
192
+ rescue
193
+ fail 'Failed to setup private key'
194
+ end
195
+
196
+ connection_settings = {
197
+ endpoint: chef_server,
198
+ client: client_name,
199
+ key: private_key_file.path,
200
+ }
201
+
202
+ begin
203
+ chef = ChefAPI::Connection.new connection_settings
204
+ content = chef.data_bags.fetch(id)
205
+ content.destroy
206
+ rescue => ex
207
+ fail ex.message
208
+ end
209
+
210
+ action_callback
211
+ end
212
+
213
+ action 'items' do |params|
214
+ organization = params['organization']
215
+ chef_server = params['chef_server']
216
+ client_name = params['client_name']
217
+ key = params['client_key']
218
+ id = params['id']
219
+
220
+ fail 'Client Name (client_name) is required' unless client_name
221
+ fail 'Private Key (client_key) is required' unless key
222
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
223
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
224
+ fail 'Data Bag ID (id) is required' unless id
225
+
226
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
227
+
228
+ info 'Setting up private key'
229
+ begin
230
+ private_key_file = Tempfile.new('private')
231
+ private_key_file.write(key)
232
+ private_key_file.close
233
+ rescue
234
+ fail 'Failed to setup private key'
235
+ end
236
+
237
+ connection_settings = {
238
+ endpoint: chef_server,
239
+ client: client_name,
240
+ key: private_key_file.path,
241
+ }
242
+
243
+ begin
244
+ chef = ChefAPI::Connection.new connection_settings
245
+ data_bag = chef.data_bags.fetch(id)
246
+ data_bag_items =
247
+ contents = {}
248
+ data_bag.items.all.each do |item|
249
+ contents[item.id.to_s] = item.data
250
+ end
251
+ rescue => ex
252
+ fail ex.message
253
+ end
254
+
255
+ action_callback contents
256
+ end
257
+
258
+ action 'get_item' do |params|
259
+ organization = params['organization']
260
+ chef_server = params['chef_server']
261
+ client_name = params['client_name']
262
+ key = params['client_key']
263
+ databag_id = params['databag']
264
+ id = params['id']
265
+
266
+ fail 'Client Name (client_name) is required' unless client_name
267
+ fail 'Private Key (client_key) is required' unless key
268
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
269
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
270
+ fail 'Data Bag ID (databag) is required' unless databag_id
271
+ fail 'Item ID (id) is required' unless id
272
+
273
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
274
+
275
+ info 'Setting up private key'
276
+ begin
277
+ private_key_file = Tempfile.new('private')
278
+ private_key_file.write(key)
279
+ private_key_file.close
280
+ rescue
281
+ fail 'Failed to setup private key'
282
+ end
283
+
284
+ connection_settings = {
285
+ endpoint: chef_server,
286
+ client: client_name,
287
+ key: private_key_file.path,
288
+ }
289
+
290
+ begin
291
+ chef = ChefAPI::Connection.new connection_settings
292
+ data_bag = chef.data_bags.fetch(databag_id)
293
+ item = data_bag.items.fetch(id)
294
+ content = item.data
295
+ rescue => ex
296
+ fail ex.message
297
+ end
298
+
299
+ action_callback content
300
+ end
301
+
302
+ action 'update_item' do |params|
303
+ organization = params['organization']
304
+ chef_server = params['chef_server']
305
+ client_name = params['client_name']
306
+ key = params['client_key']
307
+ databag_id = params['databag']
308
+ id = params['id']
309
+ data = params['data']
310
+
311
+ fail 'Client Name (client_name) is required' unless client_name
312
+ fail 'Private Key (client_key) is required' unless key
313
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
314
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
315
+ fail 'Data Bag ID (databag) is required' unless databag_id
316
+ fail 'Item ID (id) is required' unless id
317
+ fail 'Data (data) is required' unless data
318
+ fail 'Data (data) must be a Hash' unless data.is_a?(Hash)
319
+
320
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
321
+
322
+ info 'Setting up private key'
323
+ begin
324
+ private_key_file = Tempfile.new('private')
325
+ private_key_file.write(key)
326
+ private_key_file.close
327
+ rescue
328
+ fail 'Failed to setup private key'
329
+ end
330
+
331
+ connection_settings = {
332
+ endpoint: chef_server,
333
+ client: client_name,
334
+ key: private_key_file.path,
335
+ }
336
+
337
+ begin
338
+ chef = ChefAPI::Connection.new connection_settings
339
+ data_bag = chef.data_bags.fetch(databag_id)
340
+ item = data_bag.items.fetch(id)
341
+ item.data.deep_merge! data
342
+ item.save
343
+ content = data_bag.items.fetch(id).data.to_hash
344
+ rescue => ex
345
+ fail ex.message
346
+ end
347
+
348
+ action_callback content
349
+ end
350
+
351
+ action 'delete_item' do |params|
352
+ organization = params['organization']
353
+ chef_server = params['chef_server']
354
+ client_name = params['client_name']
355
+ key = params['client_key']
356
+ databag_id = params['databag']
357
+ id = params['id']
358
+
359
+ fail 'Client Name (client_name) is required' unless client_name
360
+ fail 'Private Key (client_key) is required' unless key
361
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
362
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
363
+ fail 'Data Bag ID (databag) is required' unless databag_id
364
+ fail 'Item ID (id) is required' unless id
365
+
366
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
367
+
368
+ info 'Setting up private key'
369
+ begin
370
+ private_key_file = Tempfile.new('private')
371
+ private_key_file.write(key)
372
+ private_key_file.close
373
+ rescue
374
+ fail 'Failed to setup private key'
375
+ end
376
+
377
+ connection_settings = {
378
+ endpoint: chef_server,
379
+ client: client_name,
380
+ key: private_key_file.path,
381
+ }
382
+
383
+ begin
384
+ chef = ChefAPI::Connection.new connection_settings
385
+ data_bag = chef.data_bags.fetch(databag_id)
386
+ item = data_bag.items.fetch(id)
387
+ item.destroy
388
+ rescue => ex
389
+ fail ex.message
390
+ end
391
+
392
+ action_callback
393
+ end
394
+
395
+ action 'create_item' do |params|
396
+ organization = params['organization']
397
+ chef_server = params['chef_server']
398
+ client_name = params['client_name']
399
+ key = params['client_key']
400
+ databag_id = params['databag']
401
+ id = params['id']
402
+ data = params['data']
403
+
404
+ fail 'Client Name (client_name) is required' unless client_name
405
+ fail 'Private Key (client_key) is required' unless key
406
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
407
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
408
+ fail 'Data Bag ID (databag) is required' unless databag_id
409
+ fail 'Item ID (id) is required' unless id
410
+ fail 'Data (data) is required' unless data
411
+ fail 'Data (data) must be a Hash' unless data.is_a?(Hash)
412
+
413
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
414
+
415
+ info 'Setting up private key'
416
+ begin
417
+ private_key_file = Tempfile.new('private')
418
+ private_key_file.write(key)
419
+ private_key_file.close
420
+ rescue
421
+ fail 'Failed to setup private key'
422
+ end
423
+
424
+ connection_settings = {
425
+ endpoint: chef_server,
426
+ client: client_name,
427
+ key: private_key_file.path,
428
+ }
429
+
430
+ begin
431
+ chef = ChefAPI::Connection.new connection_settings
432
+ data_bag = chef.data_bags.fetch(databag_id)
433
+ item = data_bag.items.create({id:id}.merge(data))
434
+ content = item.to_hash
435
+ rescue => ex
436
+ fail ex.message
437
+ end
438
+
439
+ action_callback content
440
+ end
441
+ end
@@ -0,0 +1,232 @@
1
+ require 'factor-connector-api'
2
+ require 'chef-api'
3
+ require 'deep_merge'
4
+
5
+ Factor::Connector.service 'chef_environments' do
6
+ action 'all' do |params|
7
+ organization = params['organization']
8
+ chef_server = params['chef_server']
9
+ client_name = params['client_name']
10
+ client_key = params['client_key']
11
+
12
+ fail 'Client Name (client_name) is required' unless client_name
13
+ fail 'Client Private Key (client_key) is required' unless client_key
14
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
15
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
16
+
17
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
18
+
19
+ info 'Setting up private key'
20
+ begin
21
+ private_key_file = Tempfile.new('private')
22
+ private_key_file.write(client_key)
23
+ private_key_file.close
24
+ rescue
25
+ fail 'Failed to setup private key'
26
+ end
27
+
28
+ connection_settings = {
29
+ endpoint: chef_server,
30
+ client: client_name,
31
+ key: private_key_file.path,
32
+ }
33
+
34
+ begin
35
+ chef = ChefAPI::Connection.new connection_settings
36
+ contents = chef.environments.all
37
+ rescue => ex
38
+ fail ex.message
39
+ end
40
+
41
+ action_callback contents.map {|c| c.to_hash}
42
+ end
43
+
44
+ action 'get' do |params|
45
+ organization = params['organization']
46
+ chef_server = params['chef_server']
47
+ client_name = params['client_name']
48
+ key = params['client_key']
49
+ id = params['id']
50
+
51
+ fail 'Client Name (client_name) is required' unless client_name
52
+ fail 'Private Key (client_key) is required' unless key
53
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
54
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
55
+ fail 'Environment ID (id) is required' unless id
56
+
57
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
58
+
59
+ info 'Setting up private key'
60
+ begin
61
+ private_key_file = Tempfile.new('private')
62
+ private_key_file.write(key)
63
+ private_key_file.close
64
+ rescue
65
+ fail 'Failed to setup private key'
66
+ end
67
+
68
+ connection_settings = {
69
+ endpoint: chef_server,
70
+ client: client_name,
71
+ key: private_key_file.path,
72
+ }
73
+
74
+ begin
75
+ chef = ChefAPI::Connection.new connection_settings
76
+ content = chef.environments.fetch(id)
77
+ rescue => ex
78
+ fail ex.message
79
+ end
80
+
81
+ fail "Environment with id '#{id}' not found" unless content
82
+
83
+ action_callback content.to_hash
84
+ end
85
+
86
+ action 'create' do |params|
87
+ organization = params['organization']
88
+ chef_server = params['chef_server']
89
+ client_name = params['client_name']
90
+ key = params['client_key']
91
+
92
+ fail 'Client Name (client_name) is required' unless client_name
93
+ fail 'Private Key (client_key) is required' unless key
94
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
95
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
96
+ fail 'New Organization Name (name) is required' unless params['name']
97
+
98
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
99
+
100
+ info 'Setting up private key'
101
+ begin
102
+ private_key_file = Tempfile.new('private')
103
+ private_key_file.write(key)
104
+ private_key_file.close
105
+ rescue
106
+ fail 'Failed to setup private key'
107
+ end
108
+
109
+ connection_settings = {
110
+ endpoint: chef_server,
111
+ client: client_name,
112
+ key: private_key_file.path,
113
+ }
114
+
115
+ available_params = %w(name description default_attributes override_attributes cookbook_versions)
116
+ env_params = {}
117
+ available_params.each do |param|
118
+ env_params[param.to_sym] = params[param] if params.include?(param)
119
+ end
120
+
121
+ begin
122
+ info "Creating new environment '#{env_params['name']}'"
123
+ chef = ChefAPI::Connection.new connection_settings
124
+ content = chef.environments.create(env_params)
125
+ rescue => ex
126
+ fail ex.message
127
+ end
128
+
129
+ action_callback content.to_hash
130
+ end
131
+
132
+ action 'update' do |params|
133
+ organization = params['organization']
134
+ chef_server = params['chef_server']
135
+ client_name = params['client_name']
136
+ key = params['client_key']
137
+ id = params['id']
138
+
139
+ fail 'Client Name (client_name) is required' unless client_name
140
+ fail 'Private Key (client_key) is required' unless key
141
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
142
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
143
+ fail 'Environment ID (id) is required' unless id
144
+
145
+ fail 'Override Attributes (override_attributes) must be a Hash' if params['override_attributes'] && !params['override_attributes'].is_a?(Hash)
146
+ fail 'Default Attributes (default_attributes) must be a Hash' if params['default_attributes'] && !params['default_attributes'].is_a?(Hash)
147
+ fail 'Cookbok Versions (cookbook_versions) must be a Hash' if params['cookbook_versions'] && !params['cookbook_versions'].is_a?(Hash)
148
+
149
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
150
+
151
+ info 'Setting up private key'
152
+ begin
153
+ private_key_file = Tempfile.new('private')
154
+ private_key_file.write(key)
155
+ private_key_file.close
156
+ rescue
157
+ fail 'Failed to setup private key'
158
+ end
159
+
160
+ connection_settings = {
161
+ endpoint: chef_server,
162
+ client: client_name,
163
+ key: private_key_file.path,
164
+ }
165
+
166
+ available_params = %w(name description)
167
+ env_params = {}
168
+ available_params.each do |param|
169
+ env_params[param.to_sym] = params[param] if params.include?(param)
170
+ end
171
+
172
+ begin
173
+ info "Creating new environment '#{env_params['name']}'"
174
+ chef = ChefAPI::Connection.new connection_settings
175
+ environment = chef.environments.update(id, env_params) if env_params != {}
176
+
177
+ if params['default_attributes'] || params['override_attributes'] || params['cookbook_versions']
178
+ environment = chef.environments.fetch(id)
179
+ environment.default_attributes.deep_merge!(params['default_attributes']) if params['default_attributes']
180
+ environment.override_attributes.deep_merge!(params['override_attributes']) if params['override_attributes']
181
+ environment.cookbook_versions.deep_merge!(params['cookbook_versions']) if params['cookbook_versions']
182
+ environment.save
183
+ end
184
+ content = chef.environments.fetch(id)
185
+ rescue => ex
186
+ fail ex.message
187
+ end
188
+
189
+ action_callback content.to_hash
190
+ end
191
+
192
+ action 'delete' do |params|
193
+ organization = params['organization']
194
+ chef_server = params['chef_server']
195
+ client_name = params['client_name']
196
+ key = params['client_key']
197
+ id = params['id']
198
+
199
+ fail 'Client Name (client_name) is required' unless client_name
200
+ fail 'Private Key (client_key) is required' unless key
201
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
202
+ fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
203
+ fail 'Environment ID (id) is required' unless id
204
+
205
+ chef_server ||= "https://api.opscode.com/organizations/#{organization}"
206
+
207
+ info 'Setting up private key'
208
+ begin
209
+ private_key_file = Tempfile.new('private')
210
+ private_key_file.write(key)
211
+ private_key_file.close
212
+ rescue
213
+ fail 'Failed to setup private key'
214
+ end
215
+
216
+ connection_settings = {
217
+ endpoint: chef_server,
218
+ client: client_name,
219
+ key: private_key_file.path,
220
+ }
221
+
222
+ begin
223
+ chef = ChefAPI::Connection.new connection_settings
224
+ content = chef.environments.fetch(id)
225
+ content.destroy
226
+ rescue => ex
227
+ fail ex.message
228
+ end
229
+
230
+ action_callback
231
+ end
232
+ end
@@ -48,10 +48,10 @@ class Net::SSH::Connection::Session
48
48
  end
49
49
  end
50
50
 
51
- Factor::Connector.service 'chef' do
51
+ Factor::Connector.service 'chef_knife' do
52
52
  action 'bootstrap' do |params|
53
53
  host_param = params['host']
54
- private_key = params['private_key']
54
+ client_key = params['client_key']
55
55
  validation_key = params['validation_key']
56
56
  runlist = params['runlist']
57
57
  organization = params['organization']
@@ -61,7 +61,7 @@ Factor::Connector.service 'chef' do
61
61
  output = {}
62
62
 
63
63
  fail 'Host is required' unless host_param
64
- fail 'Private Key (private_key) is required' unless private_key
64
+ fail 'Private Key (client_key) is required' unless client_key
65
65
  fail 'Validation Key (validation_key) is required' unless validation_key
66
66
  fail 'Organization (organization) or Chef Server URL (chef_server) is required' unless organization || chef_server
67
67
  fail 'Organization (organization) or Chef Server URL (chef_server) is required, but not both' if organization && chef_server
@@ -83,7 +83,7 @@ Factor::Connector.service 'chef' do
83
83
  info 'Setting up private key'
84
84
  begin
85
85
  private_key_file = Tempfile.new('private')
86
- private_key_file.write(private_key)
86
+ private_key_file.write(client_key)
87
87
  private_key_file.close
88
88
  rescue
89
89
  fail 'Failed to setup private key'
metadata CHANGED
@@ -1,99 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor-connector-chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Skierkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.9.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.9.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-scp
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.2.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: factor-connector-api
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.0.13
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.0.13
55
+ - !ruby/object:Gem::Dependency
56
+ name: chef-api
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: deep_merge
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.1
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: codeclimate-test-reporter
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - "~>"
87
+ - - ~>
60
88
  - !ruby/object:Gem::Version
61
- version: 0.3.0
89
+ version: 0.4.5
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - "~>"
94
+ - - ~>
67
95
  - !ruby/object:Gem::Version
68
- version: 0.3.0
96
+ version: 0.4.5
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rspec
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
- - - "~>"
101
+ - - ~>
74
102
  - !ruby/object:Gem::Version
75
103
  version: 3.1.0
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - "~>"
108
+ - - ~>
81
109
  - !ruby/object:Gem::Version
82
110
  version: 3.1.0
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rake
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - "~>"
115
+ - - ~>
88
116
  - !ruby/object:Gem::Version
89
- version: 10.3.2
117
+ version: 10.4.2
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - "~>"
122
+ - - ~>
95
123
  - !ruby/object:Gem::Version
96
- version: 10.3.2
124
+ version: 10.4.2
97
125
  description:
98
126
  email:
99
127
  - maciej@factor.io
@@ -101,7 +129,10 @@ executables: []
101
129
  extensions: []
102
130
  extra_rdoc_files: []
103
131
  files:
104
- - "./lib/factor/connector/chef.rb"
132
+ - ./lib/factor/connector/chef_clients.rb
133
+ - ./lib/factor/connector/chef_databags.rb
134
+ - ./lib/factor/connector/chef_environments.rb
135
+ - ./lib/factor/connector/chef_knife.rb
105
136
  homepage: https://factor.io
106
137
  licenses: []
107
138
  metadata: {}
@@ -111,17 +142,17 @@ require_paths:
111
142
  - lib
112
143
  required_ruby_version: !ruby/object:Gem::Requirement
113
144
  requirements:
114
- - - ">="
145
+ - - ! '>='
115
146
  - !ruby/object:Gem::Version
116
147
  version: '0'
117
148
  required_rubygems_version: !ruby/object:Gem::Requirement
118
149
  requirements:
119
- - - ">="
150
+ - - ! '>='
120
151
  - !ruby/object:Gem::Version
121
152
  version: '0'
122
153
  requirements: []
123
154
  rubyforge_project:
124
- rubygems_version: 2.2.2
155
+ rubygems_version: 2.4.5
125
156
  signing_key:
126
157
  specification_version: 4
127
158
  summary: Factor.io Connector for Chef