chef-cli 5.6.11 → 5.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/chef-cli.gemspec +1 -1
- data/lib/chef-cli/command/generator_commands/cookbook.rb +12 -1
- data/lib/chef-cli/cookbook_profiler/git.rb +25 -2
- data/lib/chef-cli/version.rb +1 -1
- data/spec/shared/custom_generator_cookbook.rb +30 -9
- data/spec/unit/command/generator_commands/cookbook_spec.rb +6 -0
- data/spec/unit/cookbook_profiler/git_spec.rb +2 -1
- data/spec/unit/policyfile_lock_build_spec.rb +4 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91bf4c20f2e571268b98a467e2f708ff7e87f5a6f1caddf6c1d2eaab0815e6a9
|
4
|
+
data.tar.gz: f337d8fefb2dfbc90cbb37f003b65948dffbf901918b81ddadd0c671df93547e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fbf23fb835d00f629d14c1dfd1457874db6db968e2a9095d3869359aa73c8a8fd881fb6d0f98367e382482c63e8c035984270171be31510c7353ba47882df5f
|
7
|
+
data.tar.gz: 9d7737dc9edd87a309635c13de1819b7bf366612ed7a3f629adbe1ca8b8d6a0a840a2a4cf4de5dfe71ed2e211ef792f9f2f5f58077f51dba0c3582acb4b4265f
|
data/chef-cli.gemspec
CHANGED
@@ -41,7 +41,7 @@ Gem::Specification.new do |gem|
|
|
41
41
|
|
42
42
|
gem.add_dependency "mixlib-cli", ">= 1.7", "< 3.0"
|
43
43
|
gem.add_dependency "mixlib-shellout", ">= 2.0", "< 4.0"
|
44
|
-
gem.add_dependency "ffi-yajl", ">= 1.0", "<
|
44
|
+
gem.add_dependency "ffi-yajl", ">= 1.0", "< 4.0"
|
45
45
|
gem.add_dependency "minitar", "~> 0.6"
|
46
46
|
gem.add_dependency "chef", ">= 16.0"
|
47
47
|
gem.add_dependency "solve", "< 5.0", "> 2.0"
|
@@ -180,7 +180,11 @@ module ChefCLI
|
|
180
180
|
end
|
181
181
|
|
182
182
|
def cookbook_full_path
|
183
|
-
|
183
|
+
if !cookbook_name_or_path.nil? && !cookbook_name_or_path.empty?
|
184
|
+
File.expand_path(cookbook_name_or_path, Dir.pwd)
|
185
|
+
else
|
186
|
+
""
|
187
|
+
end
|
184
188
|
end
|
185
189
|
|
186
190
|
def policy_mode?
|
@@ -205,6 +209,13 @@ module ChefCLI
|
|
205
209
|
msg("Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook for more information.")
|
206
210
|
end
|
207
211
|
|
212
|
+
if !generator_cookbook_path.empty? &&
|
213
|
+
!cookbook_full_path.empty? &&
|
214
|
+
File.identical?(Pathname.new(cookbook_full_path).parent, generator_cookbook_path)
|
215
|
+
err("The generator and the cookbook cannot be in the same directory. Please specify a cookbook directory that is different from the generator's parent.")
|
216
|
+
@params_valid = false
|
217
|
+
end
|
218
|
+
|
208
219
|
if config[:berks] && config[:policy]
|
209
220
|
err("Berkshelf and Policyfiles are mutually exclusive. Please specify only one.")
|
210
221
|
@params_valid = false
|
@@ -23,10 +23,17 @@ module ChefCLI
|
|
23
23
|
|
24
24
|
include Helpers
|
25
25
|
|
26
|
+
@@git_memo = {}
|
27
|
+
|
26
28
|
attr_reader :cookbook_path
|
27
29
|
|
30
|
+
def self.uncache
|
31
|
+
@@git_memo = {}
|
32
|
+
end
|
33
|
+
|
28
34
|
def initialize(cookbook_path)
|
29
35
|
@cookbook_path = cookbook_path
|
36
|
+
@repo_path = nil
|
30
37
|
@unborn_branch = nil
|
31
38
|
@unborn_branch_ref = nil
|
32
39
|
end
|
@@ -111,8 +118,24 @@ module ChefCLI
|
|
111
118
|
end
|
112
119
|
|
113
120
|
def git(subcommand, options = {})
|
114
|
-
|
115
|
-
|
121
|
+
# memoize commands per-repo
|
122
|
+
repo_path = get_repo_path
|
123
|
+
memo_key = [repo_path, subcommand, options]
|
124
|
+
if @@git_memo.key?(memo_key)
|
125
|
+
rv = @@git_memo[memo_key]
|
126
|
+
else
|
127
|
+
options = { cwd: cookbook_path }.merge(options)
|
128
|
+
rv = system_command("git #{subcommand}", options)
|
129
|
+
@@git_memo[memo_key] = rv
|
130
|
+
end
|
131
|
+
rv
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_repo_path
|
135
|
+
unless @repo_path
|
136
|
+
@repo_path = system_command("git rev-parse --show-toplevel", { cwd: cookbook_path }).stdout.strip
|
137
|
+
end
|
138
|
+
@repo_path
|
116
139
|
end
|
117
140
|
|
118
141
|
def detect_current_branch
|
data/lib/chef-cli/version.rb
CHANGED
@@ -24,15 +24,13 @@ shared_examples_for "custom generator cookbook" do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
it "configures the generator context" do
|
28
28
|
reset_tempdir
|
29
29
|
code_generator.read_and_validate_params
|
30
30
|
allow(code_generator.config_loader).to receive(:load)
|
31
|
-
end
|
32
31
|
|
33
|
-
it "configures the generator context" do
|
34
32
|
code_generator.setup_context
|
35
|
-
expect(generator_context.cookbook_name).to eq(generator_arg)
|
33
|
+
expect(generator_context.cookbook_name).to eq(File.basename(generator_arg))
|
36
34
|
expect(code_generator.chef_runner.cookbook_path).to eq(tempdir)
|
37
35
|
expect(code_generator.chef_runner.run_list).to eq(["recipe[a_generator_cookbook::#{generator_name}]"])
|
38
36
|
end
|
@@ -55,19 +53,33 @@ shared_examples_for "custom generator cookbook" do
|
|
55
53
|
end
|
56
54
|
|
57
55
|
before do
|
56
|
+
reset_tempdir
|
57
|
+
code_generator.read_and_validate_params
|
58
|
+
allow(code_generator.config_loader).to receive(:load)
|
58
59
|
allow(code_generator).to receive(:chefcli_config).and_return(chefcli_config)
|
59
60
|
end
|
60
61
|
|
61
62
|
it "configures the generator context" do
|
62
63
|
code_generator.setup_context
|
63
|
-
expect(generator_context.cookbook_name).to eq(generator_arg)
|
64
|
-
expect(code_generator.chef_runner.cookbook_path).to eq(
|
65
|
-
expect(code_generator.chef_runner.run_list).to eq(["recipe[
|
64
|
+
expect(generator_context.cookbook_name).to eq(File.basename(generator_arg))
|
65
|
+
expect(code_generator.chef_runner.cookbook_path).to eq(File.expand_path("lib/chef-cli/skeletons", project_root))
|
66
|
+
expect(code_generator.chef_runner.run_list).to eq(["recipe[code_generator::#{generator_name}]"])
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
70
|
context "with an invalid generator-cookbook path" do
|
70
71
|
|
72
|
+
let(:argv) { ["new_cookbook", "--generator-cookbook", "#{tempdir}/nested/a_generator_cookbook"] }
|
73
|
+
|
74
|
+
before do
|
75
|
+
reset_tempdir
|
76
|
+
FileUtils.mkdir_p("#{tempdir}/nested")
|
77
|
+
FileUtils.cp_r(default_generator_cookbook_path, "#{tempdir}/nested/")
|
78
|
+
|
79
|
+
code_generator.read_and_validate_params
|
80
|
+
allow(code_generator.config_loader).to receive(:load)
|
81
|
+
end
|
82
|
+
|
71
83
|
it "fails with an informative error" do
|
72
84
|
Dir.chdir(tempdir) do
|
73
85
|
allow(code_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
@@ -88,6 +100,10 @@ shared_examples_for "custom generator cookbook" do
|
|
88
100
|
let(:metadata_file) { File.join(generator_cookbook_path, "metadata.rb") }
|
89
101
|
|
90
102
|
before do
|
103
|
+
reset_tempdir
|
104
|
+
code_generator.read_and_validate_params
|
105
|
+
allow(code_generator.config_loader).to receive(:load)
|
106
|
+
|
91
107
|
FileUtils.cp_r(default_generator_cookbook_path, generator_cookbook_path)
|
92
108
|
|
93
109
|
# have to update metadata with the correct name
|
@@ -95,7 +111,7 @@ shared_examples_for "custom generator cookbook" do
|
|
95
111
|
end
|
96
112
|
|
97
113
|
it "creates the new files" do
|
98
|
-
expect(code_generator.chef_runner.cookbook_path).to eq(tempdir)
|
114
|
+
expect(code_generator.chef_runner.cookbook_path).to eq("#{tempdir}")
|
99
115
|
expect(code_generator.chef_runner.run_list).to eq(["recipe[a_generator_cookbook::#{generator_name}]"])
|
100
116
|
|
101
117
|
Dir.chdir(tempdir) do
|
@@ -108,11 +124,16 @@ shared_examples_for "custom generator cookbook" do
|
|
108
124
|
|
109
125
|
context "with a generator-cookbook path to a directory containing a 'code_generator' cookbook" do
|
110
126
|
|
127
|
+
let(:argv) { ["#{tempdir}/new_cookbook", "--generator-cookbook", generator_cookbook_path] }
|
128
|
+
|
111
129
|
before do
|
130
|
+
reset_tempdir
|
112
131
|
FileUtils.mkdir_p(generator_cookbook_path)
|
113
132
|
FileUtils.cp_r(default_generator_cookbook_path, generator_cookbook_path)
|
114
133
|
|
115
134
|
allow(code_generator).to receive(:stderr).and_return(stderr_io)
|
135
|
+
code_generator.read_and_validate_params
|
136
|
+
allow(code_generator.config_loader).to receive(:load)
|
116
137
|
end
|
117
138
|
|
118
139
|
it "creates the new_files (and warns about deprecated usage)" do
|
@@ -121,7 +142,7 @@ shared_examples_for "custom generator cookbook" do
|
|
121
142
|
Dir.chdir(tempdir) do
|
122
143
|
code_generator.run
|
123
144
|
end
|
124
|
-
generated_files = Dir.glob("#{tempdir}
|
145
|
+
generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
|
125
146
|
expected_cookbook_files.each do |expected_file|
|
126
147
|
expect(generated_files).to include(expected_file)
|
127
148
|
end
|
@@ -152,6 +152,12 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
152
152
|
expect(stderr_io.string).to include(message)
|
153
153
|
end
|
154
154
|
|
155
|
+
it "errors if cookbook parent folder is same as generator parent folder" do
|
156
|
+
expect(with_argv(%w{ my_cookbook -g my_generator }).run).to eq(1)
|
157
|
+
message = "The generator and the cookbook cannot be in the same directory. Please specify a cookbook directory that is different from the generator's parent."
|
158
|
+
expect(stderr_io.string).to include(message)
|
159
|
+
end
|
160
|
+
|
155
161
|
it "warns if a hyphenated cookbook name is passed" do
|
156
162
|
expect(with_argv(%w{my-cookbook}).run).to eq(0)
|
157
163
|
message = "Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook for more information."
|
@@ -50,6 +50,10 @@ describe ChefCLI::PolicyfileLock, "building a lockfile", :skip_on_windows do
|
|
50
50
|
ChefCLI::Policyfile::StorageConfig.new( cache_path: cache_path, relative_paths_root: relative_paths_root )
|
51
51
|
end
|
52
52
|
|
53
|
+
let!(:git_memo) do
|
54
|
+
ChefCLI::CookbookProfiler::Git.uncache
|
55
|
+
end
|
56
|
+
|
53
57
|
context "when a cached cookbook omits the cache key" do
|
54
58
|
|
55
59
|
let(:policyfile_lock) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.6.
|
4
|
+
version: 5.6.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-cli
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
version: '1.0'
|
60
60
|
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '4.0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -69,7 +69,7 @@ dependencies:
|
|
69
69
|
version: '1.0'
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: '
|
72
|
+
version: '4.0'
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: minitar
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|