chef-cli 2.0.0 → 3.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -11
- data/chef-cli.gemspec +5 -5
- data/lib/chef-cli/cli.rb +12 -6
- data/lib/chef-cli/command/clean_policy_cookbooks.rb +1 -1
- data/lib/chef-cli/command/clean_policy_revisions.rb +1 -1
- data/lib/chef-cli/command/delete_policy.rb +1 -1
- data/lib/chef-cli/command/delete_policy_group.rb +1 -1
- data/lib/chef-cli/command/describe_cookbook.rb +1 -1
- data/lib/chef-cli/command/export.rb +1 -1
- data/lib/chef-cli/command/generator_commands/cookbook.rb +1 -1
- data/lib/chef-cli/command/generator_commands/policyfile.rb +2 -2
- data/lib/chef-cli/command/install.rb +2 -2
- data/lib/chef-cli/command/push.rb +1 -1
- data/lib/chef-cli/command/push_archive.rb +1 -1
- data/lib/chef-cli/command/show_policy.rb +1 -1
- data/lib/chef-cli/command/undelete.rb +1 -1
- data/lib/chef-cli/command/update.rb +1 -1
- data/lib/chef-cli/dist.rb +8 -0
- data/lib/chef-cli/generator.rb +1 -1
- data/lib/chef-cli/helpers.rb +2 -2
- data/lib/chef-cli/policyfile/cookbook_location_specification.rb +2 -1
- data/lib/chef-cli/policyfile/lock_fetcher_mixin.rb +2 -2
- data/lib/chef-cli/policyfile/uploader.rb +2 -2
- data/lib/chef-cli/policyfile_services/export_repo.rb +5 -0
- data/lib/chef-cli/policyfile_services/install.rb +2 -0
- data/lib/chef-cli/policyfile_services/rm_policy.rb +1 -1
- data/lib/chef-cli/policyfile_services/update_attributes.rb +2 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/README.md +3 -3
- data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/kitchen.yml +2 -2
- data/lib/chef-cli/skeletons/code_generator/files/default/chefignore +4 -8
- data/lib/chef-cli/skeletons/code_generator/files/default/cookbook_readmes/README-policy.md +1 -1
- data/lib/chef-cli/skeletons/code_generator/files/default/cookbook_readmes/README.md +2 -2
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/README.md +1 -1
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/README.md +2 -2
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/attributes/default.rb +1 -1
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +1 -1
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/data_bags/README.md +4 -4
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/environments/README.md +2 -2
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/roles/README.md +2 -2
- data/lib/chef-cli/skeletons/code_generator/metadata.rb +1 -1
- data/lib/chef-cli/skeletons/code_generator/recipes/build_cookbook.rb +2 -2
- data/lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb +1 -1
- data/lib/chef-cli/skeletons/code_generator/recipes/repo.rb +1 -1
- data/lib/chef-cli/skeletons/code_generator/templates/default/CHANGELOG.md.erb +1 -2
- data/lib/chef-cli/skeletons/code_generator/templates/default/Policyfile.rb.erb +1 -1
- data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb +1 -1
- data/lib/chef-cli/skeletons/code_generator/templates/default/helpers.rb.erb +2 -2
- data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb +4 -4
- data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb +4 -4
- data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb +4 -4
- data/lib/chef-cli/skeletons/code_generator/templates/default/metadata.rb.erb +1 -1
- data/lib/chef-cli/skeletons/code_generator/templates/default/recipe_spec.rb.erb +4 -4
- data/lib/chef-cli/skeletons/code_generator/templates/default/resource.rb.erb +1 -1
- data/lib/chef-cli/version.rb +1 -1
- data/lib/kitchen/provisioner/chef_zero_capture.rb +90 -0
- data/spec/unit/command/generator_commands/build_cookbook_spec.rb +1 -1
- data/spec/unit/command/generator_commands/cookbook_spec.rb +12 -12
- data/spec/unit/command/generator_commands/policyfile_spec.rb +1 -1
- data/spec/unit/command/generator_commands/repo_spec.rb +5 -5
- data/spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb +84 -0
- data/spec/unit/policyfile/cookbook_location_specification_spec.rb +5 -0
- data/spec/unit/policyfile/uploader_spec.rb +2 -2
- data/spec/unit/policyfile_lock_build_spec.rb +1 -1
- data/spec/unit/policyfile_services/clean_policies_spec.rb +2 -0
- data/spec/unit/policyfile_services/update_attributes_spec.rb +1 -1
- data/spec/unit/service_exception_inspectors/http_spec.rb +1 -1
- metadata +20 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fc888d7c983f9da1ef82774b394d549bc13117d8525d5a9013840864baf5c11
|
4
|
+
data.tar.gz: 67b55563d7c9e4ee3ce36d5bdb30fa61f63f4712debc20c25f4c97b95cce1515
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ce7bfb0348f1b680cdddf6add8944ecaa31ea46a8f18b4e3f2360503bb73c01e9108b5f37bcf671429c4ea7328edf39af44d0219449380486f3e8e2eeb0e625
|
7
|
+
data.tar.gz: c3940d5992bd129b359184cdbda5503ce21f3b04f12d0283882cee32c553a0e659f15db1effeac396e35007067f94330c3a562e63726f848984d7e7d1e09a399
|
data/Gemfile
CHANGED
@@ -9,27 +9,22 @@ group :docs do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
group :test do
|
12
|
-
# For ruby 2.4 testing we need to use ohai 14
|
13
|
-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5")
|
14
|
-
gem "ohai", "~> 14"
|
15
|
-
end
|
16
12
|
gem "rake"
|
17
13
|
gem "rspec", "~> 3.8"
|
18
14
|
gem "rspec-expectations", "~> 3.8"
|
19
15
|
gem "rspec-mocks", "~> 3.8"
|
20
16
|
gem "cookstyle"
|
21
17
|
gem "chefstyle"
|
18
|
+
gem "test-kitchen", "> 2.5"
|
19
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6")
|
20
|
+
gem "chef-zero", "~> 14"
|
21
|
+
gem "chef", "~> 15"
|
22
|
+
end
|
22
23
|
end
|
23
24
|
|
24
25
|
group :development do
|
25
26
|
gem "pry"
|
26
27
|
gem "pry-byebug"
|
27
|
-
gem "pry-stack_explorer"
|
28
|
+
gem "pry-stack_explorer", "~> 0.4.0"
|
28
29
|
gem "rb-readline"
|
29
30
|
end
|
30
|
-
|
31
|
-
instance_eval(ENV["GEMFILE_MOD"]) if ENV["GEMFILE_MOD"]
|
32
|
-
|
33
|
-
# If you want to load debugging tools into the bundle exec sandbox,
|
34
|
-
# add these additional dependencies into Gemfile.local
|
35
|
-
eval_gemfile(__FILE__ + ".local") if File.exist?(__FILE__ + ".local")
|
data/chef-cli.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright (c)
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |gem|
|
|
29
29
|
gem.license = "Apache-2.0"
|
30
30
|
gem.homepage = "https://www.chef.io/"
|
31
31
|
|
32
|
-
gem.required_ruby_version = ">= 2.
|
32
|
+
gem.required_ruby_version = ">= 2.5"
|
33
33
|
|
34
34
|
gem.files = %w{Rakefile LICENSE} +
|
35
35
|
Dir.glob("Gemfile*") + # Includes Gemfile and locks
|
@@ -43,11 +43,11 @@ Gem::Specification.new do |gem|
|
|
43
43
|
gem.add_dependency "mixlib-shellout", ">= 2.0", "< 4.0"
|
44
44
|
gem.add_dependency "ffi-yajl", ">= 1.0", "< 3.0"
|
45
45
|
gem.add_dependency "minitar", "~> 0.6"
|
46
|
-
gem.add_dependency "chef", ">=
|
46
|
+
gem.add_dependency "chef", ">= 15.0"
|
47
47
|
gem.add_dependency "solve", "< 5.0", "> 2.0"
|
48
|
-
gem.add_dependency "addressable", ">= 2.3.5", "< 2.
|
48
|
+
gem.add_dependency "addressable", ">= 2.3.5", "< 2.8"
|
49
49
|
gem.add_dependency "cookbook-omnifetch", "~> 0.5"
|
50
50
|
gem.add_dependency "diff-lcs", "~> 1.0"
|
51
|
-
gem.add_dependency "paint", "
|
51
|
+
gem.add_dependency "paint", ">= 1", "< 3"
|
52
52
|
gem.add_dependency "license-acceptance", "~> 1.0", ">= 1.0.11"
|
53
53
|
end
|
data/lib/chef-cli/cli.rb
CHANGED
@@ -34,9 +34,9 @@ module ChefCLI
|
|
34
34
|
|
35
35
|
banner(<<~BANNER)
|
36
36
|
Usage:
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
#{ChefCLI::Dist::EXEC} -h/--help
|
38
|
+
#{ChefCLI::Dist::EXEC} -v/--version
|
39
|
+
#{ChefCLI::Dist::EXEC} command [arguments...] [options...]
|
40
40
|
BANNER
|
41
41
|
|
42
42
|
option :version,
|
@@ -105,9 +105,9 @@ module ChefCLI
|
|
105
105
|
|
106
106
|
def show_version_via_version_manifest
|
107
107
|
msg("#{ChefCLI::Dist::PRODUCT} version: #{manifest_field("build_version")}")
|
108
|
-
{ "#{ChefCLI::Dist::INFRA_CLIENT_PRODUCT}": "
|
108
|
+
{ "#{ChefCLI::Dist::INFRA_CLIENT_PRODUCT}": "#{ChefCLI::Dist::INFRA_CLIENT_GEM}",
|
109
109
|
"#{ChefCLI::Dist::INSPEC_PRODUCT}": "#{ChefCLI::Dist::INSPEC_CLI}",
|
110
|
-
"
|
110
|
+
"#{ChefCLI::Dist::CLI_PRODUCT}": "#{ChefCLI::Dist::CLI_GEM}",
|
111
111
|
"Test Kitchen": "test-kitchen",
|
112
112
|
"Cookstyle": "cookstyle",
|
113
113
|
}.each do |name, gem|
|
@@ -122,7 +122,13 @@ module ChefCLI
|
|
122
122
|
"Test Kitchen": "kitchen",
|
123
123
|
"Cookstyle": "cookstyle",
|
124
124
|
}.each do |name, cli|
|
125
|
-
|
125
|
+
# @todo when Ruby 2.5/2.6 support goes away this if statement can go away
|
126
|
+
if Gem::Version.new(Bundler::VERSION) >= Gem::Version.new("2")
|
127
|
+
result = Bundler.with_unbundled_env { shell_out("#{cli} --version") }
|
128
|
+
else
|
129
|
+
result = Bundler.with_clean_env { shell_out("#{cli} --version") }
|
130
|
+
end
|
131
|
+
|
126
132
|
if result.exitstatus != 0
|
127
133
|
msg("#{name} version: ERROR")
|
128
134
|
else
|
@@ -216,7 +216,7 @@ module ChefCLI
|
|
216
216
|
if !@cookbook_name_or_path
|
217
217
|
@params_valid = false
|
218
218
|
elsif /-/ =~ File.basename(@cookbook_name_or_path)
|
219
|
-
msg("Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/ctl_chef
|
219
|
+
msg("Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/ctl_chef/#chef-generate-cookbook for more information.")
|
220
220
|
end
|
221
221
|
|
222
222
|
if config[:berks] && config[:policy]
|
@@ -76,7 +76,7 @@ module ChefCLI
|
|
76
76
|
if chef_repo_mode?
|
77
77
|
err("ERROR: You must give a policy name when generating a policy in a chef-repo.")
|
78
78
|
@params_valid = false
|
79
|
-
|
79
|
+
false
|
80
80
|
else
|
81
81
|
use_default_policy_settings
|
82
82
|
end
|
@@ -85,7 +85,7 @@ module ChefCLI
|
|
85
85
|
else
|
86
86
|
@params_valid = false
|
87
87
|
err("ERROR: too many arguments")
|
88
|
-
|
88
|
+
false
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -40,7 +40,7 @@ module ChefCLI
|
|
40
40
|
|
41
41
|
See our detailed README for more information:
|
42
42
|
|
43
|
-
https://docs.chef.io/policyfile
|
43
|
+
https://docs.chef.io/policyfile/
|
44
44
|
|
45
45
|
Options:
|
46
46
|
|
@@ -110,7 +110,7 @@ module ChefCLI
|
|
110
110
|
remaining_args = parse_options(params)
|
111
111
|
if remaining_args.size > 1
|
112
112
|
ui.err(opt_parser)
|
113
|
-
|
113
|
+
false
|
114
114
|
else
|
115
115
|
@policyfile_relative_path = remaining_args.first
|
116
116
|
true
|
data/lib/chef-cli/dist.rb
CHANGED
@@ -4,6 +4,11 @@ module ChefCLI
|
|
4
4
|
|
5
5
|
# The full marketing name of the product
|
6
6
|
PRODUCT = "Chef Workstation".freeze
|
7
|
+
PRODUCT_PKG_HOME = "chef-workstation".freeze
|
8
|
+
|
9
|
+
# the name of the chef-cli gem
|
10
|
+
CLI_PRODUCT = "Chef CLI".freeze
|
11
|
+
CLI_GEM = "chef-cli".freeze
|
7
12
|
|
8
13
|
# the name of the overall infra product
|
9
14
|
INFRA_PRODUCT = "Chef Infra".freeze
|
@@ -14,6 +19,9 @@ module ChefCLI
|
|
14
19
|
# The client's alias (chef-client)
|
15
20
|
INFRA_CLIENT_CLI = "chef-client".freeze
|
16
21
|
|
22
|
+
# The client's gem
|
23
|
+
INFRA_CLIENT_GEM = "chef".freeze
|
24
|
+
|
17
25
|
INSPEC_PRODUCT = "Chef InSpec".freeze
|
18
26
|
INSPEC_CLI = "inspec".freeze
|
19
27
|
|
data/lib/chef-cli/generator.rb
CHANGED
@@ -150,7 +150,7 @@ module ChefCLI
|
|
150
150
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
151
151
|
EOH
|
152
152
|
else
|
153
|
-
raise ArgumentError, "Invalid generator.license setting: #{license}.
|
153
|
+
raise ArgumentError, "Invalid generator.license setting: #{license}. See available licenses at https://docs.chef.io/ctl_chef/#chef-generate-cookbook"
|
154
154
|
end
|
155
155
|
if comment
|
156
156
|
# Ensure there's no trailing whitespace
|
data/lib/chef-cli/helpers.rb
CHANGED
@@ -141,9 +141,9 @@ module ChefCLI
|
|
141
141
|
|
142
142
|
def default_package_home
|
143
143
|
if Chef::Platform.windows?
|
144
|
-
File.join(ENV["LOCALAPPDATA"], "
|
144
|
+
File.join(ENV["LOCALAPPDATA"], "#{ChefCLI::Dist::PRODUCT_PKG_HOME}")
|
145
145
|
else
|
146
|
-
File.expand_path("
|
146
|
+
File.expand_path("~/.#{ChefCLI::Dist::PRODUCT_PKG_HOME}")
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -125,7 +125,8 @@ module ChefCLI
|
|
125
125
|
|
126
126
|
def cookbook_has_recipe?(recipe_name)
|
127
127
|
expected_path = cookbook_path.join("recipes/#{recipe_name}.rb")
|
128
|
-
|
128
|
+
expected_path_yml = cookbook_path.join("recipes/#{recipe_name}.yml")
|
129
|
+
expected_path.exist? || expected_path_yml.exist?
|
129
130
|
end
|
130
131
|
|
131
132
|
def cached_cookbook
|
@@ -24,9 +24,9 @@ module ChefCLI
|
|
24
24
|
expected_id = source_options[:policy_revision_id]
|
25
25
|
if expected_id
|
26
26
|
if included_id.eql?(expected_id) # are they the same?
|
27
|
-
|
27
|
+
nil
|
28
28
|
elsif included_id[0, 10].eql?(expected_id) # did they use the 10 char substring
|
29
|
-
|
29
|
+
nil
|
30
30
|
else
|
31
31
|
raise ChefCLI::InvalidLockfile, "Expected policy_revision_id '#{expected_id}' does not match included_policy '#{included_id}'."
|
32
32
|
end
|
@@ -79,7 +79,7 @@ module ChefCLI
|
|
79
79
|
|
80
80
|
def data_bag_create
|
81
81
|
http_client.post("data", { "name" => COMPAT_MODE_DATA_BAG_NAME })
|
82
|
-
rescue Net::
|
82
|
+
rescue Net::HTTPClientException => e
|
83
83
|
raise e unless e.response.code == "409"
|
84
84
|
end
|
85
85
|
|
@@ -214,7 +214,7 @@ module ChefCLI
|
|
214
214
|
|
215
215
|
def upload_lockfile_as_data_bag_item(policy_id, data_item)
|
216
216
|
http_client.put("data/#{COMPAT_MODE_DATA_BAG_NAME}/#{policy_id}", data_item)
|
217
|
-
rescue Net::
|
217
|
+
rescue Net::HTTPClientException => e
|
218
218
|
raise e unless e.response.code == "404"
|
219
219
|
|
220
220
|
http_client.post("data/#{COMPAT_MODE_DATA_BAG_NAME}", data_item)
|
@@ -44,12 +44,14 @@ module ChefCLI
|
|
44
44
|
attr_reader :storage_config
|
45
45
|
attr_reader :root_dir
|
46
46
|
attr_reader :export_dir
|
47
|
+
attr_reader :ui
|
47
48
|
|
48
49
|
def initialize(policyfile: nil, export_dir: nil, root_dir: nil, archive: false, force: false)
|
49
50
|
@root_dir = root_dir
|
50
51
|
@export_dir = File.expand_path(export_dir)
|
51
52
|
@archive = archive
|
52
53
|
@force_export = force
|
54
|
+
@ui = UI.new
|
53
55
|
|
54
56
|
@policy_data = nil
|
55
57
|
@policyfile_lock = nil
|
@@ -162,6 +164,9 @@ module ChefCLI
|
|
162
164
|
FileUtils.mkdir(export_path) unless File.directory?(export_path)
|
163
165
|
copy_unignored_cookbook_files(lock, export_path)
|
164
166
|
FileUtils.rm_f(metadata_rb_path)
|
167
|
+
if lock.cookbook_version.nil?
|
168
|
+
ui.msg "Unable to get the cookbook version/metadata for #{lock}"
|
169
|
+
end
|
165
170
|
metadata = lock.cookbook_version.metadata
|
166
171
|
|
167
172
|
metadata_json_path = File.join(export_path, "metadata.json")
|
@@ -147,8 +147,10 @@ module ChefCLI
|
|
147
147
|
end
|
148
148
|
|
149
149
|
def prepare_constraints_for_policies
|
150
|
+
# Ensure we recompute policies from their (possibly updated) source
|
150
151
|
Policyfile::LockApplier
|
151
152
|
.new(policyfile_lock, policyfile_compiler)
|
153
|
+
.with_unlocked_policies(:all)
|
152
154
|
.apply!
|
153
155
|
end
|
154
156
|
|
@@ -134,7 +134,7 @@ module ChefCLI
|
|
134
134
|
def fetch_policy_revision_data
|
135
135
|
@policy_revision_data = http_client.get("/policies/#{policy_name}")
|
136
136
|
@policy_exists = true
|
137
|
-
rescue Net::
|
137
|
+
rescue Net::HTTPClientException => e
|
138
138
|
raise unless e.response.code == "404"
|
139
139
|
|
140
140
|
@policy_exists = false
|
@@ -102,7 +102,9 @@ module ChefCLI
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def prepare_constraints
|
105
|
+
# Ensure we recompute policies from their (possibly updated) source
|
105
106
|
Policyfile::LockApplier.new(policyfile_lock, policyfile_compiler)
|
107
|
+
.with_unlocked_policies(:all)
|
106
108
|
.apply!
|
107
109
|
end
|
108
110
|
end
|
@@ -101,7 +101,7 @@ cd .delivery/build_cookbook
|
|
101
101
|
kitchen converge
|
102
102
|
```
|
103
103
|
|
104
|
-
This will take
|
104
|
+
This will take a while because it will now pass on the first VM and then create the second VM. We should have warned you this was a good time for a coffee break.
|
105
105
|
|
106
106
|
```
|
107
107
|
Recipe: test::default
|
@@ -115,7 +115,7 @@ Recipe: test::default
|
|
115
115
|
Running handlers:
|
116
116
|
Running handlers complete
|
117
117
|
Chef Infra Client finished, 3/32 resources updated in 54.665445968 seconds
|
118
|
-
Finished converging <default-centos-
|
118
|
+
Finished converging <default-centos-8> (1m26.83s).
|
119
119
|
```
|
120
120
|
|
121
121
|
Victory is ours! Our verify phase passed on the build nodes.
|
@@ -129,7 +129,7 @@ delivery review
|
|
129
129
|
|
130
130
|
## FAQ
|
131
131
|
|
132
|
-
### Why don't I just run rspec and
|
132
|
+
### Why don't I just run rspec and cookstyle on my local system?
|
133
133
|
|
134
134
|
An objection to the Test Kitchen approach is that it is much faster to run the unit, lint, and syntax commands for the project on the local system. That is totally true, and also totally valid. Do that for the really fast feedback loop. However, the dance we do with Test Kitchen brings a much higher degree of confidence in the changes we're making, that everything will run on the build nodes in Chef Workflow. We strongly encourage this approach before actually pushing the changes to Workflow.
|
135
135
|
|