chef-dk 0.15.9 → 0.15.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +26 -24
- data/README.md +5 -1
- data/acceptance/Gemfile.lock +20 -18
- data/lib/chef-dk/command/generator_commands/base.rb +148 -148
- data/lib/chef-dk/command/generator_commands/build_cookbook.rb +5 -0
- data/lib/chef-dk/command/generator_commands/cookbook.rb +3 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/serverspec_spec_helper.rb +8 -8
- data/lib/chef-dk/skeletons/code_generator/recipes/app.rb +97 -97
- data/lib/chef-dk/skeletons/code_generator/recipes/build_cookbook.rb +64 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +15 -1
- data/lib/chef-dk/skeletons/code_generator/templates/default/serverspec_default_spec.rb.erb +9 -9
- data/lib/chef-dk/version.rb +1 -1
- data/omnibus_overrides.rb +1 -1
- data/spec/shared/custom_generator_cookbook.rb +7 -1
- data/spec/shared/setup_git_committer_config.rb +54 -0
- data/spec/unit/command/generator_commands/app_spec.rb +169 -169
- data/spec/unit/command/generator_commands/build_cookbook_spec.rb +39 -5
- data/spec/unit/command/generator_commands/cookbook_spec.rb +22 -14
- data/version_policy.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e87089b35b30751ae9567f0080c2996c898f17b3
|
4
|
+
data.tar.gz: 2e05638bf24897d7283505439dad1d1c143a66c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1f75f5bb375d4e6cdf30e0fbb5f812e03da223457db5a8fe02473b4b561c859be3d3ac1c315470bcf001557381bfdba6ce34ac5ba0cb777ba4c1b021c45f219
|
7
|
+
data.tar.gz: aa92306d5b471efc5aa59d2c2c09ae57ec2cf40928b0b3c191a24f5e1c5d0309f2a4d2e64005a43e8d2027e715590b9b0b6fedfccc94d08dd9adbb9c5b9e3978
|
data/Gemfile.lock
CHANGED
@@ -94,7 +94,7 @@ GIT
|
|
94
94
|
PATH
|
95
95
|
remote: .
|
96
96
|
specs:
|
97
|
-
chef-dk (0.15.
|
97
|
+
chef-dk (0.15.15)
|
98
98
|
chef (~> 12.5)
|
99
99
|
chef-provisioning (~> 1.2)
|
100
100
|
cookbook-omnifetch (~> 0.2, >= 0.2.2)
|
@@ -124,16 +124,16 @@ GEM
|
|
124
124
|
addressable (>= 2.3.1)
|
125
125
|
extlib (>= 0.9.15)
|
126
126
|
multi_json (>= 1.0.0)
|
127
|
-
aws-sdk (2.3.
|
128
|
-
aws-sdk-resources (= 2.3.
|
129
|
-
aws-sdk-core (2.3.
|
127
|
+
aws-sdk (2.3.14)
|
128
|
+
aws-sdk-resources (= 2.3.14)
|
129
|
+
aws-sdk-core (2.3.14)
|
130
130
|
jmespath (~> 1.0)
|
131
|
-
aws-sdk-resources (2.3.
|
132
|
-
aws-sdk-core (= 2.3.
|
131
|
+
aws-sdk-resources (2.3.14)
|
132
|
+
aws-sdk-core (= 2.3.14)
|
133
133
|
aws-sdk-v1 (1.66.0)
|
134
134
|
json (~> 1.4)
|
135
135
|
nokogiri (>= 1.4.4)
|
136
|
-
berkshelf (4.3.
|
136
|
+
berkshelf (4.3.5)
|
137
137
|
addressable (~> 2.3, >= 2.3.4)
|
138
138
|
berkshelf-api-client (~> 2.0, >= 2.0.2)
|
139
139
|
buff-config (~> 1.0)
|
@@ -145,6 +145,7 @@ GEM
|
|
145
145
|
faraday (~> 0.9)
|
146
146
|
httpclient (~> 2.7)
|
147
147
|
minitar (~> 0.5, >= 0.5.4)
|
148
|
+
mixlib-archive (~> 0.1)
|
148
149
|
octokit (~> 4.0)
|
149
150
|
retryable (~> 2.0)
|
150
151
|
ridley (~> 4.5)
|
@@ -171,7 +172,7 @@ GEM
|
|
171
172
|
celluloid-io (0.16.2)
|
172
173
|
celluloid (>= 0.16.0)
|
173
174
|
nio4r (>= 1.1.0)
|
174
|
-
chef-provisioning (1.
|
175
|
+
chef-provisioning (1.8.0)
|
175
176
|
cheffish (>= 1.3.1, < 3.0)
|
176
177
|
inifile (>= 2.0.2)
|
177
178
|
mixlib-install (~> 1.0)
|
@@ -179,7 +180,7 @@ GEM
|
|
179
180
|
net-ssh (>= 2.9, < 4.0)
|
180
181
|
net-ssh-gateway (~> 1.2.0)
|
181
182
|
winrm (~> 1.3)
|
182
|
-
chef-provisioning-aws (1.
|
183
|
+
chef-provisioning-aws (1.10.0)
|
183
184
|
aws-sdk (>= 2.1.26, < 3.0)
|
184
185
|
aws-sdk-v1 (>= 1.59.0)
|
185
186
|
chef-provisioning (~> 1.4)
|
@@ -349,7 +350,7 @@ GEM
|
|
349
350
|
fog-serverlove (0.1.2)
|
350
351
|
fog-core
|
351
352
|
fog-json
|
352
|
-
fog-softlayer (1.1.
|
353
|
+
fog-softlayer (1.1.2)
|
353
354
|
fog-core
|
354
355
|
fog-json
|
355
356
|
fog-storm_on_demand (0.1.1)
|
@@ -364,7 +365,7 @@ GEM
|
|
364
365
|
fog-voxel (0.1.0)
|
365
366
|
fog-core
|
366
367
|
fog-xml
|
367
|
-
fog-vsphere (0.
|
368
|
+
fog-vsphere (0.8.0)
|
368
369
|
fog-core
|
369
370
|
rbvmomi (~> 1.8)
|
370
371
|
fog-xenserver (0.2.3)
|
@@ -426,17 +427,17 @@ GEM
|
|
426
427
|
inflecto (0.0.2)
|
427
428
|
inifile (3.0.0)
|
428
429
|
iniparse (1.4.2)
|
429
|
-
inspec (0.
|
430
|
+
inspec (0.26.0)
|
430
431
|
hashie (~> 3.4)
|
431
432
|
json (~> 1.8)
|
432
433
|
method_source (~> 0.8)
|
433
434
|
pry (~> 0)
|
434
|
-
r-train (~> 0.12)
|
435
435
|
rainbow (~> 2)
|
436
436
|
rspec (~> 3)
|
437
437
|
rspec-its (~> 1.2)
|
438
438
|
rubyzip (~> 1.1)
|
439
439
|
thor (~> 0.19)
|
440
|
+
train (~> 0.13)
|
440
441
|
ipaddress (0.8.3)
|
441
442
|
jmespath (1.2.4)
|
442
443
|
json_pure (>= 1.8.1)
|
@@ -456,7 +457,7 @@ GEM
|
|
456
457
|
test-kitchen (~> 1.4)
|
457
458
|
knife-push (1.0.1)
|
458
459
|
chef (>= 11.10.4)
|
459
|
-
knife-spork (1.6.
|
460
|
+
knife-spork (1.6.2)
|
460
461
|
app_conf (>= 0.4.0)
|
461
462
|
chef (>= 11.0.0)
|
462
463
|
diffy (>= 3.0.1)
|
@@ -484,6 +485,7 @@ GEM
|
|
484
485
|
mini_portile2 (2.0.0)
|
485
486
|
minitar (0.5.4)
|
486
487
|
minitest (5.9.0)
|
488
|
+
mixlib-archive (0.1.0)
|
487
489
|
mixlib-authentication (1.4.1)
|
488
490
|
mixlib-log
|
489
491
|
mixlib-cli (1.6.0)
|
@@ -557,17 +559,9 @@ GEM
|
|
557
559
|
pry-stack_explorer (0.4.9.2)
|
558
560
|
binding_of_caller (>= 0.7)
|
559
561
|
pry (>= 0.9.11)
|
560
|
-
r-train (0.12.1)
|
561
|
-
docker-api (~> 1.26)
|
562
|
-
json (~> 1.8)
|
563
|
-
mixlib-shellout (~> 2.0)
|
564
|
-
net-scp (~> 1.2)
|
565
|
-
net-ssh (>= 2.9, < 4.0)
|
566
|
-
winrm (~> 1.6)
|
567
|
-
winrm-fs (~> 0.3)
|
568
562
|
rack (1.6.4)
|
569
563
|
rainbow (2.1.0)
|
570
|
-
rake (11.
|
564
|
+
rake (11.2.2)
|
571
565
|
rb-fsevent (0.9.7)
|
572
566
|
rb-inotify (0.9.7)
|
573
567
|
ffi (>= 0.5.0)
|
@@ -665,7 +659,7 @@ GEM
|
|
665
659
|
uuid (~> 2.0)
|
666
660
|
syslog-logger (1.6.8)
|
667
661
|
systemu (2.6.5)
|
668
|
-
test-kitchen (1.
|
662
|
+
test-kitchen (1.10.0)
|
669
663
|
mixlib-install (~> 1.0, >= 1.0.4)
|
670
664
|
mixlib-shellout (>= 1.2, < 3.0)
|
671
665
|
net-scp (~> 1.1)
|
@@ -676,6 +670,14 @@ GEM
|
|
676
670
|
thread_safe (0.3.5)
|
677
671
|
timers (4.0.4)
|
678
672
|
hitimes
|
673
|
+
train (0.13.1)
|
674
|
+
docker-api (~> 1.26)
|
675
|
+
json (~> 1.8)
|
676
|
+
mixlib-shellout (~> 2.0)
|
677
|
+
net-scp (~> 1.2)
|
678
|
+
net-ssh (>= 2.9, < 4.0)
|
679
|
+
winrm (~> 1.6)
|
680
|
+
winrm-fs (~> 0.3)
|
679
681
|
treetop (1.6.5)
|
680
682
|
polyglot (~> 0.3)
|
681
683
|
trollop (2.1.2)
|
data/README.md
CHANGED
@@ -10,6 +10,8 @@ Chef Development Kit (ChefDK) brings Chef and the development tools developed by
|
|
10
10
|
* [Test Kitchen][]
|
11
11
|
* [ChefSpec][]
|
12
12
|
* [Foodcritic][]
|
13
|
+
* [Delivery CLI][]
|
14
|
+
* [Push Jobs Client][]
|
13
15
|
|
14
16
|
This repository contains the code for the `chef` command. The full
|
15
17
|
package is built with omnibus. Project and component build definitions
|
@@ -48,7 +50,7 @@ To download a specific version, append the `-version` flag. EG, `-version 0.9.0
|
|
48
50
|
|
49
51
|
## Usage
|
50
52
|
|
51
|
-
For help with [Berkshelf][], [Test Kitchen][], [ChefSpec][] or [
|
53
|
+
For help with [Berkshelf][], [Test Kitchen][], [ChefSpec][], [Foodcritic][], [Delivery CLI][] or [Push Jobs Client][],
|
52
54
|
visit those projects' homepages for documentation and guides. For help with
|
53
55
|
`chef-client` and `knife`, visit the [Chef documentation][]
|
54
56
|
and [Learn Chef][].
|
@@ -319,3 +321,5 @@ packaging, and building works.
|
|
319
321
|
[Foodcritic]: http://foodcritic.io "Foodcritic"
|
320
322
|
[Learn Chef]: https://learn.chef.io "Learn Chef"
|
321
323
|
[Test Kitchen]: http://kitchen.ci "Test Kitchen"
|
324
|
+
[Delivery CLI]: https://docs.chef.io/ctl_delivery.html "Delivery CLI"
|
325
|
+
[Push Jobs Client]: https://docs.chef.io/push_jobs.html#push-jobs-client "Push Jobs Client"
|
data/acceptance/Gemfile.lock
CHANGED
@@ -11,13 +11,13 @@ GEM
|
|
11
11
|
specs:
|
12
12
|
addressable (2.4.0)
|
13
13
|
artifactory (2.3.2)
|
14
|
-
aws-sdk (2.3.
|
15
|
-
aws-sdk-resources (= 2.3.
|
16
|
-
aws-sdk-core (2.3.
|
14
|
+
aws-sdk (2.3.14)
|
15
|
+
aws-sdk-resources (= 2.3.14)
|
16
|
+
aws-sdk-core (2.3.14)
|
17
17
|
jmespath (~> 1.0)
|
18
|
-
aws-sdk-resources (2.3.
|
19
|
-
aws-sdk-core (= 2.3.
|
20
|
-
berkshelf (4.3.
|
18
|
+
aws-sdk-resources (2.3.14)
|
19
|
+
aws-sdk-core (= 2.3.14)
|
20
|
+
berkshelf (4.3.5)
|
21
21
|
addressable (~> 2.3, >= 2.3.4)
|
22
22
|
berkshelf-api-client (~> 2.0, >= 2.0.2)
|
23
23
|
buff-config (~> 1.0)
|
@@ -29,6 +29,7 @@ GEM
|
|
29
29
|
faraday (~> 0.9)
|
30
30
|
httpclient (~> 2.7)
|
31
31
|
minitar (~> 0.5, >= 0.5.4)
|
32
|
+
mixlib-archive (~> 0.1)
|
32
33
|
octokit (~> 4.0)
|
33
34
|
retryable (~> 2.0)
|
34
35
|
ridley (~> 4.5)
|
@@ -75,17 +76,17 @@ GEM
|
|
75
76
|
hashie (3.4.4)
|
76
77
|
hitimes (1.2.4)
|
77
78
|
httpclient (2.7.2)
|
78
|
-
inspec (0.
|
79
|
+
inspec (0.26.0)
|
79
80
|
hashie (~> 3.4)
|
80
81
|
json (~> 1.8)
|
81
82
|
method_source (~> 0.8)
|
82
83
|
pry (~> 0)
|
83
|
-
r-train (~> 0.12)
|
84
84
|
rainbow (~> 2)
|
85
85
|
rspec (~> 3)
|
86
86
|
rspec-its (~> 1.2)
|
87
87
|
rubyzip (~> 1.1)
|
88
88
|
thor (~> 0.19)
|
89
|
+
train (~> 0.13)
|
89
90
|
jmespath (1.2.4)
|
90
91
|
json_pure (>= 1.8.1)
|
91
92
|
json (1.8.3)
|
@@ -107,10 +108,11 @@ GEM
|
|
107
108
|
multi_json (~> 1.10)
|
108
109
|
method_source (0.8.2)
|
109
110
|
minitar (0.5.4)
|
111
|
+
mixlib-archive (0.1.0)
|
110
112
|
mixlib-authentication (1.4.1)
|
111
113
|
mixlib-log
|
112
114
|
mixlib-config (2.2.1)
|
113
|
-
mixlib-install (1.0.
|
115
|
+
mixlib-install (1.0.13)
|
114
116
|
artifactory
|
115
117
|
mixlib-shellout
|
116
118
|
mixlib-versioning
|
@@ -131,14 +133,6 @@ GEM
|
|
131
133
|
coderay (~> 1.1.0)
|
132
134
|
method_source (~> 0.8.1)
|
133
135
|
slop (~> 3.4)
|
134
|
-
r-train (0.12.1)
|
135
|
-
docker-api (~> 1.26)
|
136
|
-
json (~> 1.8)
|
137
|
-
mixlib-shellout (~> 2.0)
|
138
|
-
net-scp (~> 1.2)
|
139
|
-
net-ssh (>= 2.9, < 4.0)
|
140
|
-
winrm (~> 1.6)
|
141
|
-
winrm-fs (~> 0.3)
|
142
136
|
rainbow (2.1.0)
|
143
137
|
retryable (2.0.3)
|
144
138
|
ridley (4.5.1)
|
@@ -186,7 +180,7 @@ GEM
|
|
186
180
|
solve (2.0.3)
|
187
181
|
molinillo (~> 0.4.2)
|
188
182
|
semverse (~> 1.1)
|
189
|
-
test-kitchen (1.
|
183
|
+
test-kitchen (1.10.0)
|
190
184
|
mixlib-install (~> 1.0, >= 1.0.4)
|
191
185
|
mixlib-shellout (>= 1.2, < 3.0)
|
192
186
|
net-scp (~> 1.1)
|
@@ -196,6 +190,14 @@ GEM
|
|
196
190
|
thor (0.19.1)
|
197
191
|
timers (4.0.4)
|
198
192
|
hitimes
|
193
|
+
train (0.13.1)
|
194
|
+
docker-api (~> 1.26)
|
195
|
+
json (~> 1.8)
|
196
|
+
mixlib-shellout (~> 2.0)
|
197
|
+
net-scp (~> 1.2)
|
198
|
+
net-ssh (>= 2.9, < 4.0)
|
199
|
+
winrm (~> 1.6)
|
200
|
+
winrm-fs (~> 0.3)
|
199
201
|
varia_model (0.4.1)
|
200
202
|
buff-extensions (~> 1.0)
|
201
203
|
hashie (>= 2.0.2, < 4.0.0)
|
@@ -1,148 +1,148 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright (c) 2014 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 'chef-dk/configurable'
|
19
|
-
require 'chef-dk/command/generator_commands'
|
20
|
-
|
21
|
-
module ChefDK
|
22
|
-
module Command
|
23
|
-
module GeneratorCommands
|
24
|
-
# ## Base
|
25
|
-
#
|
26
|
-
# Base class for `chef generate` subcommands. Contains basic behaviors
|
27
|
-
# for setting up the generator context, detecting git, and launching a
|
28
|
-
# chef converge.
|
29
|
-
#
|
30
|
-
# The behavior of the generators is largely delegated to a chef cookbook.
|
31
|
-
# The default implementation is the `code_generator` cookbook in
|
32
|
-
# chef-dk/skeletons/code_generator.
|
33
|
-
class Base < Command::Base
|
34
|
-
|
35
|
-
include Configurable
|
36
|
-
|
37
|
-
attr_reader :params
|
38
|
-
|
39
|
-
options.merge!(SharedGeneratorOptions.options)
|
40
|
-
|
41
|
-
def initialize(params)
|
42
|
-
super()
|
43
|
-
@params = params
|
44
|
-
|
45
|
-
@generator_cookbook_path = nil
|
46
|
-
@generator_cookbook_name = nil
|
47
|
-
end
|
48
|
-
|
49
|
-
# An instance of ChefRunner. Calling ChefRunner#converge will trigger
|
50
|
-
# convergence and generate the desired code.
|
51
|
-
def chef_runner
|
52
|
-
@chef_runner ||= ChefRunner.new(generator_cookbook_path, ["recipe[#{generator_cookbook_name}::#{recipe}]"])
|
53
|
-
end
|
54
|
-
|
55
|
-
# Path to the directory where the code_generator cookbook is located.
|
56
|
-
def generator_cookbook_path
|
57
|
-
detect_generator_cookbook_name_and_path! unless @generator_cookbook_path
|
58
|
-
@generator_cookbook_path
|
59
|
-
end
|
60
|
-
|
61
|
-
def generator_cookbook_name
|
62
|
-
detect_generator_cookbook_name_and_path! unless @generator_cookbook_name
|
63
|
-
@generator_cookbook_name
|
64
|
-
end
|
65
|
-
|
66
|
-
# Sets git related generator_context values.
|
67
|
-
def setup_context
|
68
|
-
apply_generator_values_from_config
|
69
|
-
Generator.add_attr_to_context(:have_git, have_git?)
|
70
|
-
Generator.add_attr_to_context(:skip_git_init, false)
|
71
|
-
config.each do |k,v|
|
72
|
-
Generator.add_attr_to_context(k, v)
|
73
|
-
end
|
74
|
-
# inject the arbitrary args supplied on cmdline, default = []
|
75
|
-
config[:generator_arg].each do |k,v|
|
76
|
-
Generator.add_attr_to_context(k, v)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# Checks the `PATH` for the presence of a `git` (or `git.exe`, on
|
81
|
-
# windows) executable.
|
82
|
-
def have_git?
|
83
|
-
path = ENV["PATH"] || ""
|
84
|
-
paths = path.split(File::PATH_SEPARATOR)
|
85
|
-
paths.any? {|bin_path| File.exist?(File.join(bin_path, "git#{RbConfig::CONFIG['EXEEXT']}"))}
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
# Inspects the `config[:generator_cookbook]` option to determine the
|
91
|
-
# generator_cookbook_name and generator_cookbook_path. There are two
|
92
|
-
# supported ways this can work:
|
93
|
-
#
|
94
|
-
# * `config[:generator_cookbook]` is the full path to the generator
|
95
|
-
# cookbook. In this case, the last path component is the cookbook name,
|
96
|
-
# and the parent directory is the cookbook path
|
97
|
-
# * `config[:generator_cookbook]` is the path to a directory that
|
98
|
-
# contains a cookbook named "code_generator" (DEPRECATED). This is how
|
99
|
-
# the `--generator-cookbook` feature was originally written, so we
|
100
|
-
# support this for backwards compatibility. This way has poor UX and
|
101
|
-
# we'd like to get rid of it, so a warning is printed in this case.
|
102
|
-
def detect_generator_cookbook_name_and_path!
|
103
|
-
given_path = generator_cookbook_option
|
104
|
-
code_generator_subdir = File.join(given_path, "code_generator")
|
105
|
-
if File.directory?(code_generator_subdir)
|
106
|
-
@generator_cookbook_name = "code_generator"
|
107
|
-
@generator_cookbook_path = given_path
|
108
|
-
err("WARN: Please configure the generator cookbook by giving the full path to the desired cookbook (like '#{code_generator_subdir}')")
|
109
|
-
else
|
110
|
-
@generator_cookbook_name = File.basename(given_path)
|
111
|
-
@generator_cookbook_path = File.dirname(given_path)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def generator_cookbook_option
|
116
|
-
config[:generator_cookbook] || chefdk_config.generator_cookbook
|
117
|
-
end
|
118
|
-
|
119
|
-
# Load any values that were not defined via cli switches from Chef
|
120
|
-
# configuration
|
121
|
-
#
|
122
|
-
def apply_generator_values_from_config
|
123
|
-
config[:copyright_holder] ||= coerce_generator_copyright_holder
|
124
|
-
config[:email] ||= coerce_generator_email
|
125
|
-
config[:license] ||= coerce_generator_license
|
126
|
-
end
|
127
|
-
|
128
|
-
def coerce_generator_copyright_holder
|
129
|
-
generator_config.copyright_holder ||
|
130
|
-
knife_config.cookbook_copyright ||
|
131
|
-
"The Authors"
|
132
|
-
end
|
133
|
-
|
134
|
-
def coerce_generator_email
|
135
|
-
generator_config.email ||
|
136
|
-
knife_config.cookbook_email ||
|
137
|
-
"you@example.com"
|
138
|
-
end
|
139
|
-
|
140
|
-
def coerce_generator_license
|
141
|
-
generator_config.license ||
|
142
|
-
knife_config.cookbook_license ||
|
143
|
-
"all_rights"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 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 'chef-dk/configurable'
|
19
|
+
require 'chef-dk/command/generator_commands'
|
20
|
+
|
21
|
+
module ChefDK
|
22
|
+
module Command
|
23
|
+
module GeneratorCommands
|
24
|
+
# ## Base
|
25
|
+
#
|
26
|
+
# Base class for `chef generate` subcommands. Contains basic behaviors
|
27
|
+
# for setting up the generator context, detecting git, and launching a
|
28
|
+
# chef converge.
|
29
|
+
#
|
30
|
+
# The behavior of the generators is largely delegated to a chef cookbook.
|
31
|
+
# The default implementation is the `code_generator` cookbook in
|
32
|
+
# chef-dk/skeletons/code_generator.
|
33
|
+
class Base < Command::Base
|
34
|
+
|
35
|
+
include Configurable
|
36
|
+
|
37
|
+
attr_reader :params
|
38
|
+
|
39
|
+
options.merge!(SharedGeneratorOptions.options)
|
40
|
+
|
41
|
+
def initialize(params)
|
42
|
+
super()
|
43
|
+
@params = params
|
44
|
+
|
45
|
+
@generator_cookbook_path = nil
|
46
|
+
@generator_cookbook_name = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
# An instance of ChefRunner. Calling ChefRunner#converge will trigger
|
50
|
+
# convergence and generate the desired code.
|
51
|
+
def chef_runner
|
52
|
+
@chef_runner ||= ChefRunner.new(generator_cookbook_path, ["recipe[#{generator_cookbook_name}::#{recipe}]"])
|
53
|
+
end
|
54
|
+
|
55
|
+
# Path to the directory where the code_generator cookbook is located.
|
56
|
+
def generator_cookbook_path
|
57
|
+
detect_generator_cookbook_name_and_path! unless @generator_cookbook_path
|
58
|
+
@generator_cookbook_path
|
59
|
+
end
|
60
|
+
|
61
|
+
def generator_cookbook_name
|
62
|
+
detect_generator_cookbook_name_and_path! unless @generator_cookbook_name
|
63
|
+
@generator_cookbook_name
|
64
|
+
end
|
65
|
+
|
66
|
+
# Sets git related generator_context values.
|
67
|
+
def setup_context
|
68
|
+
apply_generator_values_from_config
|
69
|
+
Generator.add_attr_to_context(:have_git, have_git?)
|
70
|
+
Generator.add_attr_to_context(:skip_git_init, false)
|
71
|
+
config.each do |k,v|
|
72
|
+
Generator.add_attr_to_context(k, v)
|
73
|
+
end
|
74
|
+
# inject the arbitrary args supplied on cmdline, default = []
|
75
|
+
config[:generator_arg].each do |k,v|
|
76
|
+
Generator.add_attr_to_context(k, v)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Checks the `PATH` for the presence of a `git` (or `git.exe`, on
|
81
|
+
# windows) executable.
|
82
|
+
def have_git?
|
83
|
+
path = ENV["PATH"] || ""
|
84
|
+
paths = path.split(File::PATH_SEPARATOR)
|
85
|
+
paths.any? {|bin_path| File.exist?(File.join(bin_path, "git#{RbConfig::CONFIG['EXEEXT']}"))}
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
# Inspects the `config[:generator_cookbook]` option to determine the
|
91
|
+
# generator_cookbook_name and generator_cookbook_path. There are two
|
92
|
+
# supported ways this can work:
|
93
|
+
#
|
94
|
+
# * `config[:generator_cookbook]` is the full path to the generator
|
95
|
+
# cookbook. In this case, the last path component is the cookbook name,
|
96
|
+
# and the parent directory is the cookbook path
|
97
|
+
# * `config[:generator_cookbook]` is the path to a directory that
|
98
|
+
# contains a cookbook named "code_generator" (DEPRECATED). This is how
|
99
|
+
# the `--generator-cookbook` feature was originally written, so we
|
100
|
+
# support this for backwards compatibility. This way has poor UX and
|
101
|
+
# we'd like to get rid of it, so a warning is printed in this case.
|
102
|
+
def detect_generator_cookbook_name_and_path!
|
103
|
+
given_path = generator_cookbook_option
|
104
|
+
code_generator_subdir = File.join(given_path, "code_generator")
|
105
|
+
if File.directory?(code_generator_subdir)
|
106
|
+
@generator_cookbook_name = "code_generator"
|
107
|
+
@generator_cookbook_path = given_path
|
108
|
+
err("WARN: Please configure the generator cookbook by giving the full path to the desired cookbook (like '#{code_generator_subdir}')")
|
109
|
+
else
|
110
|
+
@generator_cookbook_name = File.basename(given_path)
|
111
|
+
@generator_cookbook_path = File.dirname(given_path)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def generator_cookbook_option
|
116
|
+
config[:generator_cookbook] || chefdk_config.generator_cookbook
|
117
|
+
end
|
118
|
+
|
119
|
+
# Load any values that were not defined via cli switches from Chef
|
120
|
+
# configuration
|
121
|
+
#
|
122
|
+
def apply_generator_values_from_config
|
123
|
+
config[:copyright_holder] ||= coerce_generator_copyright_holder
|
124
|
+
config[:email] ||= coerce_generator_email
|
125
|
+
config[:license] ||= coerce_generator_license
|
126
|
+
end
|
127
|
+
|
128
|
+
def coerce_generator_copyright_holder
|
129
|
+
generator_config.copyright_holder ||
|
130
|
+
knife_config.cookbook_copyright ||
|
131
|
+
"The Authors"
|
132
|
+
end
|
133
|
+
|
134
|
+
def coerce_generator_email
|
135
|
+
generator_config.email ||
|
136
|
+
knife_config.cookbook_email ||
|
137
|
+
"you@example.com"
|
138
|
+
end
|
139
|
+
|
140
|
+
def coerce_generator_license
|
141
|
+
generator_config.license ||
|
142
|
+
knife_config.cookbook_license ||
|
143
|
+
"all_rights"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|