chef 16.2.73 → 16.3.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/Rakefile +1 -1
- data/chef-universal-mingw32.gemspec +2 -2
- data/chef.gemspec +2 -1
- data/lib/chef/application.rb +12 -0
- data/lib/chef/{whitelist.rb → attribute_allowlist.rb} +11 -11
- data/lib/chef/{blacklist.rb → attribute_blocklist.rb} +9 -9
- data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +1 -2
- data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +1 -5
- data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -0
- data/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb +1 -1
- data/lib/chef/client.rb +3 -3
- data/lib/chef/cookbook/remote_file_vendor.rb +1 -3
- data/lib/chef/cookbook/syntax_check.rb +1 -2
- data/lib/chef/cookbook_loader.rb +15 -29
- data/lib/chef/data_bag.rb +1 -2
- data/lib/chef/deprecated.rb +8 -0
- data/lib/chef/dsl/platform_introspection.rb +2 -0
- data/lib/chef/environment.rb +1 -2
- data/lib/chef/exceptions.rb +3 -0
- data/lib/chef/http/authenticator.rb +1 -1
- data/lib/chef/knife.rb +4 -4
- data/lib/chef/knife/bootstrap.rb +4 -10
- data/lib/chef/knife/bootstrap/train_connector.rb +1 -0
- data/lib/chef/knife/config_get.rb +1 -0
- data/lib/chef/knife/config_list_profiles.rb +4 -1
- data/lib/chef/knife/configure.rb +1 -1
- data/lib/chef/knife/cookbook_upload.rb +5 -10
- data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
- data/lib/chef/knife/core/hashed_command_loader.rb +1 -0
- data/lib/chef/knife/core/subcommand_loader.rb +20 -1
- data/lib/chef/knife/core/ui.rb +8 -2
- data/lib/chef/knife/core/windows_bootstrap_context.rb +1 -2
- data/lib/chef/knife/rehash.rb +3 -21
- data/lib/chef/knife/ssh.rb +5 -1
- data/lib/chef/log.rb +7 -2
- data/lib/chef/mixin/chef_utils_wiring.rb +40 -0
- data/{spec/unit/log_spec.rb → lib/chef/mixin/default_paths.rb} +13 -5
- data/lib/chef/mixin/openssl_helper.rb +27 -5
- data/lib/chef/mixin/path_sanity.rb +5 -4
- data/lib/chef/mixin/shell_out.rb +4 -188
- data/lib/chef/mixin/template.rb +1 -0
- data/lib/chef/mixin/which.rb +6 -3
- data/lib/chef/mixins.rb +1 -0
- data/lib/chef/node.rb +36 -12
- data/lib/chef/node_map.rb +21 -18
- data/lib/chef/platform/service_helpers.rb +31 -28
- data/lib/chef/provider/git.rb +12 -4
- data/lib/chef/provider/mount/solaris.rb +0 -1
- data/lib/chef/provider/package/snap.rb +2 -3
- data/lib/chef/provider/package/windows.rb +9 -4
- data/lib/chef/provider/package/zypper.rb +0 -1
- data/lib/chef/provider/service.rb +2 -2
- data/lib/chef/provider/yum_repository.rb +1 -1
- data/lib/chef/provider/zypper_repository.rb +1 -1
- data/lib/chef/resource.rb +2 -0
- data/lib/chef/resource/build_essential.rb +2 -2
- data/lib/chef/resource/chef_client_scheduled_task.rb +1 -1
- data/lib/chef/resource/chocolatey_feature.rb +1 -2
- data/lib/chef/resource/cron/cron_d.rb +1 -1
- data/lib/chef/resource/cron_access.rb +2 -2
- data/lib/chef/resource/execute.rb +2 -2
- data/lib/chef/resource/lwrp_base.rb +1 -0
- data/lib/chef/resource/macos_userdefaults.rb +176 -61
- data/lib/chef/resource/openssl_x509_certificate.rb +11 -14
- data/lib/chef/resource/openssl_x509_crl.rb +1 -2
- data/lib/chef/resource/service.rb +2 -2
- data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
- data/lib/chef/resource/sudo.rb +1 -1
- data/lib/chef/resource/user_ulimit.rb +1 -1
- data/lib/chef/resource/windows_dns_record.rb +17 -0
- data/lib/chef/resource/windows_firewall_profile.rb +197 -0
- data/lib/chef/resource/windows_security_policy.rb +49 -20
- data/lib/chef/resource_inspector.rb +7 -1
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/role.rb +1 -2
- data/lib/chef/shell/shell_session.rb +2 -0
- data/lib/chef/util/diff.rb +0 -1
- data/lib/chef/version.rb +2 -2
- data/lib/chef/win32/registry.rb +1 -2
- data/spec/functional/knife/ssh_spec.rb +5 -16
- data/spec/functional/resource/aix_service_spec.rb +0 -2
- data/spec/functional/resource/aixinit_service_spec.rb +0 -1
- data/spec/functional/resource/apt_package_spec.rb +0 -1
- data/spec/functional/resource/cron_spec.rb +0 -1
- data/spec/functional/resource/git_spec.rb +23 -1
- data/spec/functional/resource/group_spec.rb +6 -2
- data/spec/functional/resource/insserv_spec.rb +0 -1
- data/spec/functional/resource/remote_file_spec.rb +1 -7
- data/spec/functional/resource/windows_user_privilege_spec.rb +1 -1
- data/spec/functional/run_lock_spec.rb +2 -1
- data/spec/functional/shell_spec.rb +5 -5
- data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
- data/spec/functional/version_spec.rb +1 -1
- data/spec/integration/knife/config_list_profiles_spec.rb +30 -2
- data/spec/integration/knife/cookbook_upload_spec.rb +27 -0
- data/spec/integration/recipes/accumulator_spec.rb +1 -1
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
- data/spec/integration/recipes/lwrp_spec.rb +1 -1
- data/spec/integration/recipes/notifies_spec.rb +1 -1
- data/spec/integration/recipes/notifying_block_spec.rb +1 -1
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +2 -0
- data/spec/integration/recipes/resource_load_spec.rb +2 -0
- data/spec/integration/recipes/unified_mode_spec.rb +1 -1
- data/spec/integration/recipes/use_partial_spec.rb +1 -1
- data/spec/scripts/ssl-serve.rb +1 -1
- data/spec/spec_helper.rb +10 -4
- data/spec/support/chef_helpers.rb +1 -20
- data/spec/support/platform_helpers.rb +0 -2
- data/spec/support/shared/functional/file_resource.rb +0 -1
- data/spec/support/shared/integration/knife_support.rb +2 -9
- data/spec/support/shared/unit/application_dot_d.rb +0 -1
- data/spec/unit/application_spec.rb +4 -2
- data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +2 -4
- data/spec/unit/chef_fs/{parallelizer.rb → parallelizer_spec.rb} +1 -1
- data/spec/unit/cookbook/gem_installer_spec.rb +2 -1
- data/spec/unit/data_collector_spec.rb +1 -1
- data/spec/unit/dsl/platform_introspection_spec.rb +1 -0
- data/spec/unit/event_dispatch/dispatcher_spec.rb +3 -0
- data/spec/unit/json_compat_spec.rb +1 -1
- data/spec/unit/knife/bootstrap_spec.rb +2 -6
- data/spec/unit/knife/cookbook_upload_spec.rb +7 -10
- data/spec/unit/log/syslog_spec.rb +6 -10
- data/spec/unit/log/winevt_spec.rb +21 -13
- data/spec/unit/lwrp_spec.rb +4 -4
- data/spec/unit/mixin/{path_sanity_spec.rb → default_paths_spec.rb} +14 -14
- data/spec/unit/mixin/powershell_exec_spec.rb +1 -1
- data/spec/unit/mixin/securable_spec.rb +0 -1
- data/spec/unit/mixin/shell_out_spec.rb +25 -26
- data/spec/unit/mixin/which.rb +8 -0
- data/spec/unit/node_spec.rb +98 -11
- data/spec/unit/property_spec.rb +5 -5
- data/spec/unit/provider/execute_spec.rb +0 -7
- data/spec/unit/provider/ifconfig_spec.rb +0 -1
- data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
- data/spec/unit/provider/package/rubygems_spec.rb +5 -10
- data/spec/unit/provider/package/smartos_spec.rb +1 -1
- data/spec/unit/provider/package/windows_spec.rb +30 -53
- data/spec/unit/provider/service/redhat_spec.rb +1 -1
- data/spec/unit/provider/service/windows_spec.rb +2 -6
- data/spec/unit/provider/systemd_unit_spec.rb +28 -24
- data/spec/unit/provider_spec.rb +1 -0
- data/spec/unit/resource/execute_spec.rb +10 -0
- data/spec/unit/resource/macos_user_defaults_spec.rb +103 -2
- data/spec/unit/resource/windows_firewall_profile_spec.rb +77 -0
- data/spec/unit/resource/windows_package_spec.rb +1 -0
- data/spec/unit/resource_reporter_spec.rb +1 -1
- data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
- data/spec/unit/run_lock_spec.rb +1 -1
- data/spec/unit/scan_access_control_spec.rb +1 -1
- data/spec/unit/util/diff_spec.rb +1 -15
- data/spec/unit/win32/security_spec.rb +4 -3
- metadata +30 -13
data/lib/chef/exceptions.rb
CHANGED
@@ -198,6 +198,7 @@ class Chef
|
|
198
198
|
class MetadataNotFound < StandardError
|
199
199
|
attr_reader :install_path
|
200
200
|
attr_reader :cookbook_name
|
201
|
+
|
201
202
|
def initialize(install_path, cookbook_name)
|
202
203
|
@install_path = install_path
|
203
204
|
@cookbook_name = cookbook_name
|
@@ -448,6 +449,7 @@ class Chef
|
|
448
449
|
# to correctly populate the backtrace with the wrapped backtraces.
|
449
450
|
class RunFailedWrappingError < RuntimeError
|
450
451
|
attr_reader :wrapped_errors
|
452
|
+
|
451
453
|
def initialize(*errors)
|
452
454
|
errors = errors.select { |e| !e.nil? }
|
453
455
|
output = "Found #{errors.size} errors, they are stored in the backtrace"
|
@@ -488,6 +490,7 @@ class Chef
|
|
488
490
|
|
489
491
|
class MultipleDscResourcesFound < RuntimeError
|
490
492
|
attr_reader :resources_found
|
493
|
+
|
491
494
|
def initialize(resources_found)
|
492
495
|
@resources_found = resources_found
|
493
496
|
matches_info = @resources_found.each do |r|
|
data/lib/chef/knife.rb
CHANGED
@@ -20,10 +20,10 @@
|
|
20
20
|
require "forwardable" unless defined?(Forwardable)
|
21
21
|
require_relative "version"
|
22
22
|
require "mixlib/cli" unless defined?(Mixlib::CLI)
|
23
|
-
require "chef-utils/dsl/
|
23
|
+
require "chef-utils/dsl/default_paths" unless defined?(ChefUtils::DSL::DefaultPaths)
|
24
24
|
require_relative "workstation_config_loader"
|
25
25
|
require_relative "mixin/convert_to_class_name"
|
26
|
-
require_relative "mixin/
|
26
|
+
require_relative "mixin/default_paths"
|
27
27
|
require_relative "knife/core/subcommand_loader"
|
28
28
|
require_relative "knife/core/ui"
|
29
29
|
require_relative "local_mode"
|
@@ -40,7 +40,7 @@ class Chef
|
|
40
40
|
Chef::HTTP::HTTPRequest.user_agent = "#{Chef::Dist::PRODUCT} Knife#{Chef::HTTP::HTTPRequest::UA_COMMON}"
|
41
41
|
|
42
42
|
include Mixlib::CLI
|
43
|
-
include ChefUtils::DSL::
|
43
|
+
include ChefUtils::DSL::DefaultPaths
|
44
44
|
extend Chef::Mixin::ConvertToClassName
|
45
45
|
extend Forwardable
|
46
46
|
|
@@ -484,7 +484,7 @@ class Chef
|
|
484
484
|
unless respond_to?(:run)
|
485
485
|
ui.error "You need to add a #run method to your knife command before you can use it"
|
486
486
|
end
|
487
|
-
ENV["PATH"] =
|
487
|
+
ENV["PATH"] = default_paths if Chef::Config[:enforce_default_paths] || Chef::Config[:enforce_path_sanity]
|
488
488
|
maybe_setup_fips
|
489
489
|
Chef::LocalMode.with_server_connectivity do
|
490
490
|
run
|
data/lib/chef/knife/bootstrap.rb
CHANGED
@@ -538,7 +538,7 @@ class Chef
|
|
538
538
|
end
|
539
539
|
|
540
540
|
def run
|
541
|
-
check_license
|
541
|
+
check_license if ChefConfig::Dist::ENFORCE_LICENSE
|
542
542
|
|
543
543
|
plugin_setup!
|
544
544
|
validate_name_args!
|
@@ -630,9 +630,7 @@ class Chef
|
|
630
630
|
raise
|
631
631
|
else
|
632
632
|
ui.warn("Failed to authenticate #{opts[:user]} to #{server_name} - trying password auth")
|
633
|
-
password = ui.ask("Enter password for #{opts[:user]}@#{server_name}:"
|
634
|
-
q.echo = false
|
635
|
-
end
|
633
|
+
password = ui.ask("Enter password for #{opts[:user]}@#{server_name}:", echo: false)
|
636
634
|
end
|
637
635
|
|
638
636
|
opts.merge! force_ssh_password_opts(password)
|
@@ -646,9 +644,7 @@ class Chef
|
|
646
644
|
raise
|
647
645
|
else
|
648
646
|
ui.warn("Failed to authenticate #{opts[:user]} to #{server_name} - trying password auth")
|
649
|
-
password = ui.ask("Enter password for #{opts[:user]}@#{server_name}:"
|
650
|
-
q.echo = false
|
651
|
-
end
|
647
|
+
password = ui.ask("Enter password for #{opts[:user]}@#{server_name}:", echo: false)
|
652
648
|
end
|
653
649
|
|
654
650
|
opts.merge! force_winrm_password_opts(password)
|
@@ -681,9 +677,7 @@ class Chef
|
|
681
677
|
retry
|
682
678
|
elsif config[:use_sudo_password] && (e.reason == :sudo_password_required || e.reason == :bad_sudo_password) && limit < 3
|
683
679
|
ui.warn("Failed to authenticate #{conn_options[:user]} to #{server_name} - #{e.message} \n sudo: #{limit} incorrect password attempt")
|
684
|
-
sudo_password = ui.ask("Enter sudo password for #{conn_options[:user]}@#{server_name}:"
|
685
|
-
q.echo = false
|
686
|
-
end
|
680
|
+
sudo_password = ui.ask("Enter sudo password for #{conn_options[:user]}@#{server_name}:", echo: false)
|
687
681
|
limit += 1
|
688
682
|
conn_options[:sudo_password] = sudo_password
|
689
683
|
|
@@ -62,6 +62,7 @@ class Chef
|
|
62
62
|
config_data.delete(:color)
|
63
63
|
# Only keep these if true, false is much less important because it's the default.
|
64
64
|
config_data.delete(:local_mode) unless config_data[:local_mode]
|
65
|
+
config_data.delete(:enforce_default_paths) unless config_data[:enforce_default_paths]
|
65
66
|
config_data.delete(:enforce_path_sanity) unless config_data[:enforce_path_sanity]
|
66
67
|
end
|
67
68
|
|
@@ -32,6 +32,10 @@ class Chef
|
|
32
32
|
description: "Ignore the current config.rb/knife.rb configuration.",
|
33
33
|
default: false
|
34
34
|
|
35
|
+
def configure_chef
|
36
|
+
apply_computed_config
|
37
|
+
end
|
38
|
+
|
35
39
|
def run
|
36
40
|
credentials_data = self.class.config_loader.parse_credentials_file
|
37
41
|
if credentials_data.nil? || credentials_data.empty?
|
@@ -72,7 +76,6 @@ class Chef
|
|
72
76
|
# Try to reset the config.
|
73
77
|
unless config[:ignore_knife_rb]
|
74
78
|
Chef::Config.reset
|
75
|
-
Chef::WorkstationConfigLoader.new(config[:config_file], Chef::Log, profile: config[:profile]).load
|
76
79
|
apply_computed_config
|
77
80
|
end
|
78
81
|
|
data/lib/chef/knife/configure.rb
CHANGED
@@ -92,7 +92,7 @@ class Chef
|
|
92
92
|
user_create = Chef::Knife::UserCreate.new
|
93
93
|
user_create.name_args = [ new_client_name ]
|
94
94
|
user_create.config[:user_password] = config[:user_password] ||
|
95
|
-
ui.ask("Please enter a password for the new user: "
|
95
|
+
ui.ask("Please enter a password for the new user: ", echo: false)
|
96
96
|
user_create.config[:admin] = true
|
97
97
|
user_create.config[:file] = new_client_key
|
98
98
|
user_create.config[:yes] = true
|
@@ -34,10 +34,10 @@ class Chef
|
|
34
34
|
banner "knife cookbook upload [COOKBOOKS...] (options)"
|
35
35
|
|
36
36
|
option :cookbook_path,
|
37
|
-
short: "-o PATH:PATH",
|
38
|
-
long: "--cookbook-path PATH:PATH",
|
39
|
-
description: "A
|
40
|
-
proc: lambda { |o| o.split(
|
37
|
+
short: "-o 'PATH:PATH'",
|
38
|
+
long: "--cookbook-path 'PATH:PATH'",
|
39
|
+
description: "A delimited path to search for cookbooks. On Unix the delimiter is ':', on Windows it is ';'.",
|
40
|
+
proc: lambda { |o| o.split(File::PATH_SEPARATOR) }
|
41
41
|
|
42
42
|
option :freeze,
|
43
43
|
long: "--freeze",
|
@@ -107,8 +107,7 @@ class Chef
|
|
107
107
|
cookbook_path = config[:cookbook_path].respond_to?(:join) ? config[:cookbook_path].join(", ") : config[:cookbook_path]
|
108
108
|
ui.warn("Could not find any cookbooks in your cookbook path: '#{File.expand_path(cookbook_path)}'. Use --cookbook-path to specify the desired path.")
|
109
109
|
else
|
110
|
-
|
111
|
-
tmp_cl = Chef::CookbookLoader.copy_to_tmp_dir_from_array(cookbooks)
|
110
|
+
Chef::CookbookLoader.copy_to_tmp_dir_from_array(cookbooks) do |tmp_cl|
|
112
111
|
tmp_cl.load_cookbooks
|
113
112
|
tmp_cl.compile_metadata
|
114
113
|
tmp_cl.freeze_versions if config[:freeze]
|
@@ -127,7 +126,6 @@ class Chef
|
|
127
126
|
ui.error("Uploading of some of the cookbooks must be failed. Remove cookbook whose version is frozen from your cookbooks repo OR use --force option.")
|
128
127
|
upload_failures += 1
|
129
128
|
rescue SystemExit => e
|
130
|
-
tmp_cl.unlink!
|
131
129
|
raise exit e.status
|
132
130
|
end
|
133
131
|
ui.info("Uploaded all cookbooks.") if upload_failures == 0
|
@@ -146,7 +144,6 @@ class Chef
|
|
146
144
|
ui.warn("Not updating version constraints for #{cookbook_name} in the environment as the cookbook is frozen.")
|
147
145
|
upload_failures += 1
|
148
146
|
rescue SystemExit => e
|
149
|
-
tmp_cl.unlink!
|
150
147
|
raise exit e.status
|
151
148
|
end
|
152
149
|
end
|
@@ -164,8 +161,6 @@ class Chef
|
|
164
161
|
unless version_constraints_to_update.empty?
|
165
162
|
update_version_constraints(version_constraints_to_update) if config[:environment]
|
166
163
|
end
|
167
|
-
ensure
|
168
|
-
tmp_cl.unlink!
|
169
164
|
end
|
170
165
|
end
|
171
166
|
end
|
@@ -47,7 +47,7 @@ class Chef
|
|
47
47
|
|
48
48
|
def find_subcommands_via_dirglob
|
49
49
|
# The "require paths" of the core knife subcommands bundled with chef
|
50
|
-
files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("
|
50
|
+
files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../knife", __dir__)), "*.rb")]
|
51
51
|
subcommand_files = {}
|
52
52
|
files.each do |knife_file|
|
53
53
|
rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1]
|
@@ -75,6 +75,25 @@ class Chef
|
|
75
75
|
Chef::Util::PathHelper.home(".chef", "plugin_manifest.json")
|
76
76
|
end
|
77
77
|
|
78
|
+
def self.generate_hash
|
79
|
+
output = if plugin_manifest?
|
80
|
+
plugin_manifest
|
81
|
+
else
|
82
|
+
{ Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY => {} }
|
83
|
+
end
|
84
|
+
output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]["plugins_paths"] = Chef::Knife.subcommand_files
|
85
|
+
output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]["plugins_by_category"] = Chef::Knife.subcommands_by_category
|
86
|
+
output
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.write_hash(data)
|
90
|
+
plugin_manifest_dir = File.expand_path("..", plugin_manifest_path)
|
91
|
+
FileUtils.mkdir_p(plugin_manifest_dir) unless File.directory?(plugin_manifest_dir)
|
92
|
+
File.open(plugin_manifest_path, "w") do |f|
|
93
|
+
f.write(Chef::JSONCompat.to_json_pretty(data))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
78
97
|
def initialize(chef_config_dir)
|
79
98
|
@chef_config_dir = chef_config_dir
|
80
99
|
end
|
@@ -125,7 +144,7 @@ class Chef
|
|
125
144
|
#
|
126
145
|
def find_subcommands_via_dirglob
|
127
146
|
# The "require paths" of the core knife subcommands bundled with chef
|
128
|
-
files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("
|
147
|
+
files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../knife", __dir__)), "*.rb")]
|
129
148
|
subcommand_files = {}
|
130
149
|
files.each do |knife_file|
|
131
150
|
rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1]
|
data/lib/chef/knife/core/ui.rb
CHANGED
@@ -61,6 +61,12 @@ class Chef
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
# Creates a new object of class TTY::Prompt
|
65
|
+
# with interrupt as exit so that it can be terminated with status code.
|
66
|
+
def prompt
|
67
|
+
@prompt ||= TTY::Prompt.new(interrupt: :exit)
|
68
|
+
end
|
69
|
+
|
64
70
|
# pastel.decorate is a lightweight replacement for highline.color
|
65
71
|
def pastel
|
66
72
|
@pastel ||= begin
|
@@ -163,8 +169,8 @@ class Chef
|
|
163
169
|
Chef::Config[:color] && stdout.tty?
|
164
170
|
end
|
165
171
|
|
166
|
-
def ask(*args, &block)
|
167
|
-
|
172
|
+
def ask(*args, **options, &block)
|
173
|
+
prompt.ask(*args, **options, &block)
|
168
174
|
end
|
169
175
|
|
170
176
|
def list(*args)
|
@@ -52,8 +52,7 @@ class Chef
|
|
52
52
|
# will be interpreted by ruby later and do the right thing.
|
53
53
|
def cleanpath(path)
|
54
54
|
path = Pathname.new(path).cleanpath.to_s
|
55
|
-
path
|
56
|
-
path
|
55
|
+
path.gsub(File::SEPARATOR, '\\')
|
57
56
|
end
|
58
57
|
|
59
58
|
def validation_key
|
data/lib/chef/knife/rehash.rb
CHANGED
@@ -34,7 +34,9 @@ class Chef
|
|
34
34
|
else
|
35
35
|
reload_plugins
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
|
+
ui.msg "Knife subcommands are cached in #{Chef::Knife::SubcommandLoader.plugin_manifest_path}. Delete this file to disable the caching."
|
39
|
+
Chef::Knife::SubcommandLoader.write_hash(Chef::Knife::SubcommandLoader.generate_hash)
|
38
40
|
end
|
39
41
|
|
40
42
|
def reload_plugins
|
@@ -43,26 +45,6 @@ class Chef
|
|
43
45
|
# loaded plugins and `load_commands` shouldn't have an effect.
|
44
46
|
Chef::Knife.subcommand_loader.load_commands
|
45
47
|
end
|
46
|
-
|
47
|
-
def generate_hash
|
48
|
-
output = if Chef::Knife::SubcommandLoader.plugin_manifest?
|
49
|
-
Chef::Knife::SubcommandLoader.plugin_manifest
|
50
|
-
else
|
51
|
-
{ Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY => {} }
|
52
|
-
end
|
53
|
-
output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]["plugins_paths"] = Chef::Knife.subcommand_files
|
54
|
-
output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]["plugins_by_category"] = Chef::Knife.subcommands_by_category
|
55
|
-
output
|
56
|
-
end
|
57
|
-
|
58
|
-
def write_hash(data)
|
59
|
-
plugin_manifest_dir = File.expand_path("..", Chef::Knife::SubcommandLoader.plugin_manifest_path)
|
60
|
-
FileUtils.mkdir_p(plugin_manifest_dir) unless File.directory?(plugin_manifest_dir)
|
61
|
-
File.open(Chef::Knife::SubcommandLoader.plugin_manifest_path, "w") do |f|
|
62
|
-
f.write(Chef::JSONCompat.to_json_pretty(data))
|
63
|
-
ui.msg "Knife subcommands are cached in #{Chef::Knife::SubcommandLoader.plugin_manifest_path}. Delete this file to disable the caching."
|
64
|
-
end
|
65
|
-
end
|
66
48
|
end
|
67
49
|
end
|
68
50
|
end
|
data/lib/chef/knife/ssh.rb
CHANGED
@@ -296,6 +296,10 @@ class Chef
|
|
296
296
|
opts[:keepalive] = true
|
297
297
|
opts[:keepalive_interval] = ssh_config[:keepalive_interval]
|
298
298
|
end
|
299
|
+
# maintain support for legacy key types / ciphers / key exchange algorithms.
|
300
|
+
# most importantly this adds back support for DSS host keys
|
301
|
+
# See https://github.com/net-ssh/net-ssh/pull/709
|
302
|
+
opts[:append_all_supported_algorithms] = true
|
299
303
|
end
|
300
304
|
end
|
301
305
|
|
@@ -384,7 +388,7 @@ class Chef
|
|
384
388
|
end
|
385
389
|
|
386
390
|
def prompt_for_password(prompt = "Enter your password: ")
|
387
|
-
ui.ask(prompt
|
391
|
+
ui.ask(prompt, echo: false)
|
388
392
|
end
|
389
393
|
|
390
394
|
# Present the prompt and read a single line from the console. It also
|
data/lib/chef/log.rb
CHANGED
@@ -28,8 +28,13 @@ class Chef
|
|
28
28
|
class Log
|
29
29
|
extend Mixlib::Log
|
30
30
|
|
31
|
+
def self.setup!
|
32
|
+
init(MonoLogger.new(STDOUT))
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
31
36
|
# Force initialization of the primary log device (@logger)
|
32
|
-
|
37
|
+
setup!
|
33
38
|
|
34
39
|
class Formatter
|
35
40
|
def self.show_time=(*args)
|
@@ -47,7 +52,7 @@ class Chef
|
|
47
52
|
def self.caller_location
|
48
53
|
# Pick the first caller that is *not* part of the Chef gem, that's the
|
49
54
|
# thing the user wrote. Or failing that, the most recent caller.
|
50
|
-
chef_gem_path = File.expand_path("
|
55
|
+
chef_gem_path = File.expand_path("..", __dir__)
|
51
56
|
caller(0..20).find { |c| !c.start_with?(chef_gem_path) } || caller(0..1)[0]
|
52
57
|
end
|
53
58
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright:: Copyright (c) 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
|
+
require_relative "../log"
|
18
|
+
require_relative "../config"
|
19
|
+
require_relative "../chef_class"
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
module Mixin
|
23
|
+
# Common Dependency Injection wiring for ChefUtils-related modules
|
24
|
+
module ChefUtilsWiring
|
25
|
+
private
|
26
|
+
|
27
|
+
def __config
|
28
|
+
Chef::Config
|
29
|
+
end
|
30
|
+
|
31
|
+
def __log
|
32
|
+
Chef::Log
|
33
|
+
end
|
34
|
+
|
35
|
+
def __transport_connection
|
36
|
+
Chef.run_context&.transport_connection
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Adam Jacob (<adam@chef.io>)
|
3
2
|
# Copyright:: Copyright (c) Chef Software Inc.
|
4
3
|
# License:: Apache License, Version 2.0
|
5
4
|
#
|
@@ -16,9 +15,18 @@
|
|
16
15
|
# limitations under the License.
|
17
16
|
#
|
18
17
|
|
19
|
-
require "
|
20
|
-
require "logger"
|
21
|
-
require "spec_helper"
|
18
|
+
require "chef-utils/dsl/default_paths" unless defined?(ChefUtils::DSL::DefaultPaths)
|
22
19
|
|
23
|
-
|
20
|
+
class Chef
|
21
|
+
module Mixin
|
22
|
+
module DefaultPaths
|
23
|
+
include ChefUtils::DSL::DefaultPaths
|
24
|
+
|
25
|
+
def enforce_default_paths(env = ENV)
|
26
|
+
if Chef::Config[:enforce_default_paths] || Chef::Config[:enforce_path_sanity]
|
27
|
+
env["PATH"] = default_paths(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
24
32
|
end
|
@@ -282,7 +282,9 @@ class Chef
|
|
282
282
|
ef.issuer_certificate = info["issuer"]
|
283
283
|
end
|
284
284
|
ef.subject_certificate = cert
|
285
|
-
|
285
|
+
if openssl_config = __openssl_config
|
286
|
+
ef.config = openssl_config
|
287
|
+
end
|
286
288
|
|
287
289
|
cert.extensions = extension
|
288
290
|
cert.add_extension ef.create_extension("subjectKeyIdentifier", "hash")
|
@@ -313,7 +315,9 @@ class Chef
|
|
313
315
|
crl.last_update = Time.now
|
314
316
|
crl.next_update = Time.now + 3600 * 24 * info["validity"]
|
315
317
|
|
316
|
-
|
318
|
+
if openssl_config = __openssl_config
|
319
|
+
ef.config = openssl_config
|
320
|
+
end
|
317
321
|
ef.issuer_certificate = info["issuer"]
|
318
322
|
|
319
323
|
crl.add_extension ::OpenSSL::X509::Extension.new("crlNumber", ::OpenSSL::ASN1::Integer(1))
|
@@ -369,8 +373,7 @@ class Chef
|
|
369
373
|
revoked.add_extension(ext)
|
370
374
|
crl.add_revoked(revoked)
|
371
375
|
|
372
|
-
|
373
|
-
crl
|
376
|
+
renew_x509_crl(crl, ca_private_key, info)
|
374
377
|
end
|
375
378
|
|
376
379
|
# renew a X509 crl given
|
@@ -391,7 +394,9 @@ class Chef
|
|
391
394
|
crl.next_update = crl.last_update + 3600 * 24 * info["validity"]
|
392
395
|
|
393
396
|
ef = ::OpenSSL::X509::ExtensionFactory.new
|
394
|
-
|
397
|
+
if openssl_config = __openssl_config
|
398
|
+
ef.config = openssl_config
|
399
|
+
end
|
395
400
|
ef.issuer_certificate = info["issuer"]
|
396
401
|
|
397
402
|
crl.extensions = [ ::OpenSSL::X509::Extension.new("crlNumber",
|
@@ -422,6 +427,23 @@ class Chef
|
|
422
427
|
|
423
428
|
resp
|
424
429
|
end
|
430
|
+
|
431
|
+
private
|
432
|
+
|
433
|
+
def __openssl_config
|
434
|
+
path = if File.exist?(::OpenSSL::Config::DEFAULT_CONFIG_FILE)
|
435
|
+
OpenSSL::Config::DEFAULT_CONFIG_FILE
|
436
|
+
else
|
437
|
+
Dir[File.join(RbConfig::CONFIG["prefix"], "**", "openssl.cnf")].first
|
438
|
+
end
|
439
|
+
|
440
|
+
if File.exist?(path)
|
441
|
+
::OpenSSL::Config.load(path)
|
442
|
+
else
|
443
|
+
Chef::Log.warn("Couldn't find OpenSSL config file")
|
444
|
+
nil
|
445
|
+
end
|
446
|
+
end
|
425
447
|
end
|
426
448
|
end
|
427
449
|
end
|