chef-apply 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +26 -0
  3. data/Gemfile.lock +423 -0
  4. data/LICENSE +201 -0
  5. data/README.md +41 -0
  6. data/Rakefile +32 -0
  7. data/bin/chef-run +23 -0
  8. data/chef-apply.gemspec +67 -0
  9. data/i18n/en.yml +513 -0
  10. data/lib/chef_apply.rb +20 -0
  11. data/lib/chef_apply/action/base.rb +158 -0
  12. data/lib/chef_apply/action/converge_target.rb +173 -0
  13. data/lib/chef_apply/action/install_chef.rb +30 -0
  14. data/lib/chef_apply/action/install_chef/base.rb +137 -0
  15. data/lib/chef_apply/action/install_chef/linux.rb +38 -0
  16. data/lib/chef_apply/action/install_chef/windows.rb +54 -0
  17. data/lib/chef_apply/action/reporter.rb +39 -0
  18. data/lib/chef_apply/cli.rb +470 -0
  19. data/lib/chef_apply/cli_options.rb +145 -0
  20. data/lib/chef_apply/config.rb +150 -0
  21. data/lib/chef_apply/error.rb +108 -0
  22. data/lib/chef_apply/errors/ccr_failure_mapper.rb +93 -0
  23. data/lib/chef_apply/file_fetcher.rb +70 -0
  24. data/lib/chef_apply/log.rb +42 -0
  25. data/lib/chef_apply/recipe_lookup.rb +117 -0
  26. data/lib/chef_apply/startup.rb +162 -0
  27. data/lib/chef_apply/status_reporter.rb +42 -0
  28. data/lib/chef_apply/target_host.rb +233 -0
  29. data/lib/chef_apply/target_resolver.rb +202 -0
  30. data/lib/chef_apply/telemeter.rb +162 -0
  31. data/lib/chef_apply/telemeter/patch.rb +32 -0
  32. data/lib/chef_apply/telemeter/sender.rb +121 -0
  33. data/lib/chef_apply/temp_cookbook.rb +159 -0
  34. data/lib/chef_apply/text.rb +77 -0
  35. data/lib/chef_apply/ui/error_printer.rb +261 -0
  36. data/lib/chef_apply/ui/plain_text_element.rb +75 -0
  37. data/lib/chef_apply/ui/terminal.rb +94 -0
  38. data/lib/chef_apply/version.rb +20 -0
  39. metadata +376 -0
@@ -0,0 +1,75 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2017 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module ChefApply
19
+ module UI
20
+ class PlainTextElement
21
+ def initialize(format, opts)
22
+ @orig_format = format
23
+ @format = format
24
+ @output = opts[:output]
25
+ end
26
+
27
+ def run(&block)
28
+ yield
29
+ end
30
+
31
+ def update(params)
32
+ # SOme of this is particular to our usage -
33
+ # prefix does not cause a text update, but does
34
+ # change the prefix for future messages.
35
+ if params.has_key?(:prefix)
36
+ @format = @orig_format.gsub(":prefix", params[:prefix])
37
+ return
38
+ end
39
+
40
+ if @succ
41
+ ind = "OK"
42
+ @succ = false
43
+ log_method = :info
44
+ elsif @err
45
+ ind = "ERR"
46
+ @err = false
47
+ log_method = :error
48
+ else
49
+ log_method = :debug
50
+ ind = " - "
51
+ end
52
+
53
+ # Since this is a generic type, we can replace any component
54
+ # name in this regex - but for now :spinner is the only component
55
+ # we're standing in for.
56
+ msg = @format.gsub(/:spinner/, ind)
57
+ params.each_pair do |k, v|
58
+ msg.gsub!(/:#{k}/, v)
59
+ end
60
+ ChefApply::Log.send(log_method, msg)
61
+ @output.puts(msg)
62
+ end
63
+
64
+ def error
65
+ @err = true
66
+ @succ = false
67
+ end
68
+
69
+ def success
70
+ @succ = true
71
+ @err = false
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,94 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2018 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "tty-spinner"
19
+ require "chef_apply/status_reporter"
20
+ require "chef_apply/config"
21
+ require "chef_apply/log"
22
+ require "chef_apply/ui/plain_text_element"
23
+
24
+ module ChefApply
25
+ module UI
26
+ class Terminal
27
+ class Job
28
+ attr_reader :proc, :prefix, :target_host, :exception
29
+ def initialize(prefix, target_host, &block)
30
+ @proc = block
31
+ @prefix = prefix
32
+ @target_host = target_host
33
+ @error = nil
34
+ end
35
+
36
+ def run(reporter)
37
+ @proc.call(reporter)
38
+ rescue => e
39
+ reporter.error(e.to_s)
40
+ @exception = e
41
+ end
42
+ end
43
+
44
+ class << self
45
+ # To support matching in test
46
+ attr_accessor :location
47
+
48
+ def init(location)
49
+ @location = location
50
+ # In Ruby 2.5+ threads print out to stdout when they raise an exception. This is an agressive
51
+ # attempt to ensure debugging information is not lost, but in our case it is not necessary
52
+ # because we handle all the errors ourself. So we disable this to keep output clean.
53
+ # See https://ruby-doc.org/core-2.5.0/Thread.html#method-c-report_on_exception
54
+ Thread.report_on_exception = false
55
+ end
56
+
57
+ def write(msg)
58
+ @location.write(msg)
59
+ end
60
+
61
+ def output(msg)
62
+ @location.puts msg
63
+ end
64
+
65
+ def render_parallel_jobs(header, jobs)
66
+ multispinner = TTY::Spinner::Multi.new("[:spinner] #{header}", output: @location)
67
+ jobs.each do |a|
68
+ multispinner.register(spinner_prefix(a.prefix)) do |spinner|
69
+ reporter = StatusReporter.new(spinner, prefix: a.prefix, key: :status)
70
+ a.run(reporter)
71
+ end
72
+ end
73
+ multispinner.auto_spin
74
+ end
75
+
76
+ # TODO update this to accept a job instead of a block, for consistency of usage
77
+ # between render_job and render_parallel
78
+ def render_job(msg, prefix: "", &block)
79
+ klass = ChefApply::UI.const_get(ChefApply::Config.dev.spinner)
80
+ spinner = klass.new(spinner_prefix(prefix), output: @location)
81
+ reporter = StatusReporter.new(spinner, prefix: prefix, key: :status)
82
+ reporter.update(msg)
83
+ spinner.run { yield(reporter) }
84
+ end
85
+
86
+ def spinner_prefix(prefix)
87
+ spinner_msg = "[:spinner] "
88
+ spinner_msg += ":prefix " unless prefix.empty?
89
+ spinner_msg + ":status"
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2018 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module ChefApply
19
+ VERSION = "0.1.2"
20
+ end
metadata ADDED
@@ -0,0 +1,376 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-apply
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Chef Software, Inc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mixlib-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mixlib-config
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mixlib-log
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mixlib-install
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: r18n-desktop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: toml-rb
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: train
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pastel
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: tty-spinner
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: chef
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '14.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '14.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: chef-dk
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '3.0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '3.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: chef-telemetry
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: bundler
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rake
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rspec
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: pry
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: simplecov
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: pry-byebug
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: pry-stack_explorer
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: rspec_junit_formatter
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: chefstyle
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ type: :development
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ description: Ad-hoc management of individual nodes and devices.
308
+ email:
309
+ - beta@chef.io
310
+ executables:
311
+ - chef-run
312
+ extensions: []
313
+ extra_rdoc_files: []
314
+ files:
315
+ - Gemfile
316
+ - Gemfile.lock
317
+ - LICENSE
318
+ - README.md
319
+ - Rakefile
320
+ - bin/chef-run
321
+ - chef-apply.gemspec
322
+ - i18n/en.yml
323
+ - lib/chef_apply.rb
324
+ - lib/chef_apply/action/base.rb
325
+ - lib/chef_apply/action/converge_target.rb
326
+ - lib/chef_apply/action/install_chef.rb
327
+ - lib/chef_apply/action/install_chef/base.rb
328
+ - lib/chef_apply/action/install_chef/linux.rb
329
+ - lib/chef_apply/action/install_chef/windows.rb
330
+ - lib/chef_apply/action/reporter.rb
331
+ - lib/chef_apply/cli.rb
332
+ - lib/chef_apply/cli_options.rb
333
+ - lib/chef_apply/config.rb
334
+ - lib/chef_apply/error.rb
335
+ - lib/chef_apply/errors/ccr_failure_mapper.rb
336
+ - lib/chef_apply/file_fetcher.rb
337
+ - lib/chef_apply/log.rb
338
+ - lib/chef_apply/recipe_lookup.rb
339
+ - lib/chef_apply/startup.rb
340
+ - lib/chef_apply/status_reporter.rb
341
+ - lib/chef_apply/target_host.rb
342
+ - lib/chef_apply/target_resolver.rb
343
+ - lib/chef_apply/telemeter.rb
344
+ - lib/chef_apply/telemeter/patch.rb
345
+ - lib/chef_apply/telemeter/sender.rb
346
+ - lib/chef_apply/temp_cookbook.rb
347
+ - lib/chef_apply/text.rb
348
+ - lib/chef_apply/ui/error_printer.rb
349
+ - lib/chef_apply/ui/plain_text_element.rb
350
+ - lib/chef_apply/ui/terminal.rb
351
+ - lib/chef_apply/version.rb
352
+ homepage: https://github.com/chef/chef-apply
353
+ licenses:
354
+ - Apache-2.0
355
+ metadata: {}
356
+ post_install_message:
357
+ rdoc_options: []
358
+ require_paths:
359
+ - lib
360
+ required_ruby_version: !ruby/object:Gem::Requirement
361
+ requirements:
362
+ - - ">="
363
+ - !ruby/object:Gem::Version
364
+ version: 2.5.0
365
+ required_rubygems_version: !ruby/object:Gem::Requirement
366
+ requirements:
367
+ - - ">="
368
+ - !ruby/object:Gem::Version
369
+ version: '0'
370
+ requirements: []
371
+ rubyforge_project:
372
+ rubygems_version: 2.7.6
373
+ signing_key:
374
+ specification_version: 4
375
+ summary: The ad-hoc execution tool for the Chef ecosystem.
376
+ test_files: []