chef 15.4.45 → 15.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -3
- data/Rakefile +5 -3
- data/chef.gemspec +2 -1
- data/lib/chef/application.rb +2 -2
- data/lib/chef/application/client.rb +1 -1
- data/lib/chef/application/knife.rb +1 -0
- data/lib/chef/application/solo.rb +1 -1
- data/lib/chef/chef_class.rb +1 -6
- data/lib/chef/chef_fs.rb +1 -1
- data/lib/chef/chef_fs/file_pattern.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb +2 -2
- data/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb +2 -2
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_artifact_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +7 -1
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +4 -3
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +3 -3
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +3 -3
- data/lib/chef/chef_fs/knife.rb +1 -1
- data/lib/chef/chef_fs/path_utils.rb +2 -2
- data/lib/chef/client.rb +4 -5
- data/lib/chef/config.rb +3 -2
- data/lib/chef/cookbook/chefignore.rb +16 -11
- data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
- data/lib/chef/cookbook/syntax_check.rb +5 -3
- data/lib/chef/cookbook_loader.rb +3 -3
- data/lib/chef/cookbook_uploader.rb +1 -1
- data/lib/chef/data_collector.rb +2 -2
- data/lib/chef/data_collector/run_end_message.rb +1 -0
- data/lib/chef/deprecated.rb +4 -0
- data/lib/chef/dsl/core.rb +1 -1
- data/lib/chef/dsl/platform_introspection.rb +9 -18
- data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
- data/lib/chef/file_content_management/deploy.rb +3 -3
- data/lib/chef/file_content_management/deploy/mv_windows.rb +2 -2
- data/lib/chef/file_content_management/tempfile.rb +1 -1
- data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +2 -2
- data/lib/chef/http.rb +1 -1
- data/lib/chef/http/socketless_chef_zero_client.rb +1 -1
- data/lib/chef/knife.rb +4 -3
- data/lib/chef/knife/config_get.rb +2 -1
- data/lib/chef/knife/configure.rb +1 -1
- data/lib/chef/knife/cookbook_metadata_from_file.rb +6 -0
- data/lib/chef/knife/core/generic_presenter.rb +1 -1
- data/lib/chef/knife/core/status_presenter.rb +1 -1
- data/lib/chef/knife/ssh.rb +6 -0
- data/lib/chef/local_mode.rb +1 -1
- data/lib/chef/mash.rb +21 -232
- data/lib/chef/mixin/file_class.rb +2 -2
- data/lib/chef/mixin/lazy_module_include.rb +1 -1
- data/lib/chef/mixin/path_sanity.rb +3 -39
- data/lib/chef/mixin/securable.rb +1 -1
- data/lib/chef/mixin/shell_out.rb +4 -5
- data/lib/chef/mixin/template.rb +1 -1
- data/lib/chef/mixin/user_context.rb +3 -3
- data/lib/chef/mixin/which.rb +10 -38
- data/lib/chef/mixin/windows_architecture_helper.rb +6 -6
- data/lib/chef/mixin/windows_env_helper.rb +5 -5
- data/lib/chef/node/attribute.rb +2 -2
- data/lib/chef/node_map.rb +17 -4
- data/lib/chef/platform/query_helpers.rb +4 -2
- data/lib/chef/platform/rebooter.rb +1 -1
- data/lib/chef/platform/service_helpers.rb +14 -85
- data/lib/chef/provider.rb +2 -0
- data/lib/chef/provider/file.rb +2 -2
- data/lib/chef/provider/ifconfig/redhat.rb +1 -1
- data/lib/chef/provider/link.rb +3 -3
- data/lib/chef/provider/mount/solaris.rb +1 -1
- data/lib/chef/provider/package/yum.rb +1 -1
- data/lib/chef/provider/registry_key.rb +1 -1
- data/lib/chef/provider/remote_directory.rb +3 -3
- data/lib/chef/provider/remote_file/fetcher.rb +2 -2
- data/lib/chef/provider/remote_file/local_file.rb +1 -1
- data/lib/chef/provider/script.rb +3 -3
- data/lib/chef/provider/service.rb +5 -2
- data/lib/chef/provider/service/arch.rb +1 -1
- data/lib/chef/provider/service/debian.rb +4 -4
- data/lib/chef/provider/service/init.rb +1 -1
- data/lib/chef/provider/service/insserv.rb +4 -4
- data/lib/chef/provider/service/invokercd.rb +4 -4
- data/lib/chef/provider/service/redhat.rb +4 -4
- data/lib/chef/provider/service/systemd.rb +19 -3
- data/lib/chef/provider/service/upstart.rb +3 -3
- data/lib/chef/provider/subversion.rb +1 -1
- data/lib/chef/provider/systemd_unit.rb +26 -2
- data/lib/chef/provider/windows_path.rb +3 -3
- data/lib/chef/provider/windows_task.rb +4 -4
- data/lib/chef/resource.rb +1 -0
- data/lib/chef/resource/bash.rb +2 -0
- data/lib/chef/resource/batch.rb +2 -0
- data/lib/chef/resource/breakpoint.rb +3 -1
- data/lib/chef/resource/build_essential.rb +3 -3
- data/lib/chef/resource/chef_sleep.rb +70 -0
- data/lib/chef/resource/cookbook_file.rb +2 -1
- data/lib/chef/resource/csh.rb +2 -0
- data/lib/chef/resource/directory.rb +2 -0
- data/lib/chef/resource/dmg_package.rb +1 -1
- data/lib/chef/resource/dnf_package.rb +1 -1
- data/lib/chef/resource/execute.rb +2 -0
- data/lib/chef/resource/file.rb +2 -1
- data/lib/chef/resource/git.rb +2 -0
- data/lib/chef/resource/group.rb +1 -1
- data/lib/chef/resource/homebrew_package.rb +1 -1
- data/lib/chef/resource/http_request.rb +2 -0
- data/lib/chef/resource/ifconfig.rb +3 -1
- data/lib/chef/resource/ksh.rb +2 -0
- data/lib/chef/resource/link.rb +4 -2
- data/lib/chef/resource/locale.rb +1 -1
- data/lib/chef/resource/log.rb +2 -0
- data/lib/chef/resource/ohai.rb +2 -0
- data/lib/chef/resource/perl.rb +2 -0
- data/lib/chef/resource/python.rb +2 -0
- data/lib/chef/resource/reboot.rb +2 -0
- data/lib/chef/resource/registry_key.rb +2 -0
- data/lib/chef/resource/remote_directory.rb +3 -2
- data/lib/chef/resource/remote_file.rb +1 -0
- data/lib/chef/resource/ruby.rb +2 -0
- data/lib/chef/resource/ruby_block.rb +2 -0
- data/lib/chef/resource/scm.rb +2 -0
- data/lib/chef/resource/script.rb +2 -0
- data/lib/chef/resource/service.rb +9 -1
- data/lib/chef/resource/solaris_package.rb +1 -1
- data/lib/chef/resource/subversion.rb +2 -0
- data/lib/chef/resource/sudo.rb +1 -1
- data/lib/chef/resource/systemd_unit.rb +1 -0
- data/lib/chef/resource/template.rb +2 -0
- data/lib/chef/resource/user.rb +2 -0
- data/lib/chef/resource/user/aix_user.rb +2 -0
- data/lib/chef/resource/user/linux_user.rb +2 -0
- data/lib/chef/resource/user/pw_user.rb +2 -0
- data/lib/chef/resource/user/solaris_user.rb +2 -0
- data/lib/chef/resource/user/windows_user.rb +2 -0
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
- data/lib/chef/resource/windows_ad_join.rb +1 -1
- data/lib/chef/resource/windows_env.rb +1 -1
- data/lib/chef/resource/windows_feature.rb +2 -2
- data/lib/chef/resource/windows_feature_powershell.rb +1 -1
- data/lib/chef/resource/windows_firewall_rule.rb +11 -6
- data/lib/chef/resource/windows_script.rb +3 -1
- data/lib/chef/resource/yum_package.rb +1 -1
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/run_context.rb +1 -1
- data/lib/chef/run_lock.rb +5 -5
- data/lib/chef/search/query.rb +0 -3
- data/lib/chef/train_transport.rb +3 -1
- data/lib/chef/util/powershell/ps_credential.rb +2 -2
- data/lib/chef/util/selinux.rb +1 -1
- data/lib/chef/util/windows/logon_session.rb +2 -2
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/eventlog.rb +2 -2
- data/spec/data/cookbooks/starter/chefignore +8 -0
- data/spec/data/cookbooks/starter/files/sample.txt +1 -0
- data/spec/data/cookbooks/starter/metadata.rb +2 -0
- data/spec/data/cookbooks/starter/recipes/default.rb +4 -0
- data/spec/functional/event_loggers/windows_eventlog_spec.rb +1 -1
- data/spec/functional/mixin/user_context_spec.rb +2 -2
- data/spec/functional/rebooter_spec.rb +1 -1
- data/spec/functional/resource/cookbook_file_spec.rb +2 -2
- data/spec/functional/resource/template_spec.rb +1 -1
- data/spec/functional/version_spec.rb +1 -1
- data/spec/functional/win32/crypto_spec.rb +1 -1
- data/spec/functional/win32/security_spec.rb +1 -1
- data/spec/functional/win32/service_manager_spec.rb +1 -1
- data/spec/functional/win32/sid_spec.rb +2 -2
- data/spec/functional/win32/version_info_spec.rb +1 -1
- data/spec/functional/win32/versions_spec.rb +1 -1
- data/spec/integration/knife/config_get_profile_spec.rb +2 -2
- data/spec/integration/knife/config_get_spec.rb +9 -2
- data/spec/integration/knife/config_list_profiles_spec.rb +2 -2
- data/spec/integration/knife/config_use_profile_spec.rb +2 -2
- data/spec/integration/knife/list_spec.rb +2 -2
- data/spec/integration/solo/solo_spec.rb +1 -1
- data/spec/support/matchers/leak.rb +1 -1
- data/spec/support/mock/platform.rb +1 -1
- data/spec/support/platform_helpers.rb +2 -0
- data/spec/support/shared/integration/integration_helper.rb +1 -1
- data/spec/support/shared/integration/knife_support.rb +1 -1
- data/spec/support/shared/unit/provider/file.rb +4 -4
- data/spec/unit/application/client_spec.rb +2 -2
- data/spec/unit/application/knife_spec.rb +17 -0
- data/spec/unit/application_spec.rb +1 -1
- data/spec/unit/chef_fs/file_pattern_spec.rb +2 -2
- data/spec/unit/chef_fs/path_util_spec.rb +3 -3
- data/spec/unit/client_spec.rb +2 -2
- data/spec/unit/cookbook/chefignore_spec.rb +31 -11
- data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
- data/spec/unit/cookbook/syntax_check_spec.rb +2 -2
- data/spec/unit/cookbook_loader_spec.rb +2 -2
- data/spec/unit/cookbook_uploader_spec.rb +6 -1
- data/spec/unit/data_bag_spec.rb +2 -2
- data/spec/unit/data_collector_spec.rb +7 -0
- data/spec/unit/dsl/platform_introspection_spec.rb +31 -1
- data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +1 -1
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +1 -1
- data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +7 -0
- data/spec/unit/knife/cookbook_show_spec.rb +1 -1
- data/spec/unit/knife/core/gem_glob_loader_spec.rb +1 -1
- data/spec/unit/knife/core/hashed_command_loader_spec.rb +1 -1
- data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
- data/spec/unit/knife/core/ui_spec.rb +2 -2
- data/spec/unit/knife/data_bag_from_file_spec.rb +2 -2
- data/spec/unit/knife/environment_from_file_spec.rb +2 -2
- data/spec/unit/knife/ssh_spec.rb +27 -17
- data/spec/unit/knife/status_spec.rb +1 -1
- data/spec/unit/knife/supermarket_install_spec.rb +1 -1
- data/spec/unit/mixin/path_sanity_spec.rb +3 -3
- data/spec/unit/mixin/shell_out_spec.rb +2 -3
- data/spec/unit/mixin/template_spec.rb +4 -4
- data/spec/unit/mixin/user_context_spec.rb +3 -3
- data/spec/unit/node_map_spec.rb +12 -12
- data/spec/unit/platform/query_helpers_spec.rb +9 -9
- data/spec/unit/provider/execute_spec.rb +1 -1
- data/spec/unit/provider/link_spec.rb +5 -5
- data/spec/unit/provider/package/openbsd_spec.rb +1 -1
- data/spec/unit/provider/package/smartos_spec.rb +1 -1
- data/spec/unit/provider/package/windows/exe_spec.rb +1 -1
- data/spec/unit/provider/package/windows_spec.rb +2 -2
- data/spec/unit/provider/remote_file/fetcher_spec.rb +2 -2
- data/spec/unit/provider/remote_file/local_file_spec.rb +1 -1
- data/spec/unit/provider/remote_file/network_file_spec.rb +1 -1
- data/spec/unit/provider/script_spec.rb +2 -2
- data/spec/unit/provider/service/systemd_service_spec.rb +26 -2
- data/spec/unit/provider/subversion_spec.rb +3 -3
- data/spec/unit/provider/systemd_unit_spec.rb +53 -4
- data/spec/unit/provider/user/dscl_spec.rb +1 -1
- data/spec/unit/provider_resolver_spec.rb +41 -61
- data/spec/unit/resource/chef_sleep_spec.rb +30 -0
- data/spec/unit/resource/cookbook_file_spec.rb +3 -3
- data/spec/unit/resource/remote_file_spec.rb +3 -3
- data/spec/unit/resource/windows_firewall_rule_spec.rb +69 -12
- data/spec/unit/role_spec.rb +2 -2
- data/spec/unit/shell_spec.rb +1 -1
- data/spec/unit/util/selinux_spec.rb +2 -2
- data/spec/unit/win32/error_spec.rb +1 -1
- data/spec/unit/win32/link_spec.rb +1 -1
- data/spec/unit/win32/security_spec.rb +1 -1
- data/spec/unit/windows_service_spec.rb +1 -1
- data/tasks/docs.rb +10 -2
- data/tasks/rspec.rb +8 -6
- metadata +32 -8
- data/lib/chef/mixin/train_helpers.rb +0 -60
- data/spec/unit/mash_spec.rb +0 -51
@@ -84,11 +84,13 @@ class Chef
|
|
84
84
|
# If no +cookbook_path+ is given, +Chef::Config.cookbook_path+ is used.
|
85
85
|
def self.for_cookbook(cookbook_name, cookbook_path = nil)
|
86
86
|
cookbook_path ||= Chef::Config.cookbook_path
|
87
|
-
|
88
|
-
|
87
|
+
|
88
|
+
Array(cookbook_path).each do |entry|
|
89
|
+
path = File.expand_path(File.join(entry, cookbook_name.to_s))
|
90
|
+
return new(path) if Dir.exist?(path)
|
89
91
|
end
|
90
92
|
|
91
|
-
|
93
|
+
raise ArgumentError, "Cannot find cookbook #{cookbook_name} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given"
|
92
94
|
end
|
93
95
|
|
94
96
|
# Create a new SyntaxCheck object
|
data/lib/chef/cookbook_loader.rb
CHANGED
@@ -49,8 +49,8 @@ class Chef
|
|
49
49
|
|
50
50
|
# @param repo_paths [Array<String>] the array of repo paths containing cookbook dirs
|
51
51
|
def initialize(*repo_paths)
|
52
|
-
@repo_paths = repo_paths.flatten.map { |p| File.expand_path(p) }
|
53
|
-
raise ArgumentError, "You must specify at least one cookbook repo path" if repo_paths.empty?
|
52
|
+
@repo_paths = repo_paths.flatten.compact.map { |p| File.expand_path(p) }
|
53
|
+
raise ArgumentError, "You must specify at least one cookbook repo path" if @repo_paths.empty?
|
54
54
|
end
|
55
55
|
|
56
56
|
# The primary function of this class is to build this Mash mapping cookbook names as a string to
|
@@ -171,7 +171,7 @@ class Chef
|
|
171
171
|
begin
|
172
172
|
mash = Mash.new
|
173
173
|
all_directories_in_repo_paths.each do |cookbook_path|
|
174
|
-
loader = Cookbook::CookbookVersionLoader.new(cookbook_path, chefignore(
|
174
|
+
loader = Cookbook::CookbookVersionLoader.new(cookbook_path, chefignore(cookbook_path))
|
175
175
|
cookbook_name = loader.cookbook_name
|
176
176
|
if mash.key?(cookbook_name)
|
177
177
|
raise Chef::Exceptions::CookbookMergingError, "Cookbook merging is no longer supported, the cookbook named #{cookbook_name} can only appear once in the cookbook_path"
|
@@ -139,7 +139,7 @@ class Chef
|
|
139
139
|
|
140
140
|
def validate_cookbooks
|
141
141
|
cookbooks.each do |cb|
|
142
|
-
syntax_checker = Chef::Cookbook::SyntaxCheck.
|
142
|
+
syntax_checker = Chef::Cookbook::SyntaxCheck.new(cb.root_dir)
|
143
143
|
Chef::Log.info("Validating ruby files")
|
144
144
|
exit(1) unless syntax_checker.validate_ruby_files
|
145
145
|
Chef::Log.info("Validating templates")
|
data/lib/chef/data_collector.rb
CHANGED
@@ -64,8 +64,8 @@ class Chef
|
|
64
64
|
# @param events [Chef::EventDispatch::Dispatcher] the event dispatcher
|
65
65
|
def initialize(events)
|
66
66
|
@events = events
|
67
|
-
@expanded_run_list
|
68
|
-
@deprecations
|
67
|
+
@expanded_run_list = {}
|
68
|
+
@deprecations = Set.new
|
69
69
|
end
|
70
70
|
|
71
71
|
# Hook to grab the run_status. We also make the decision to run or not run here (our
|
@@ -57,6 +57,7 @@ class Chef
|
|
57
57
|
"resources" => all_action_records(action_collection),
|
58
58
|
"run_id" => run_status&.run_id,
|
59
59
|
"run_list" => node&.run_list&.for_json || [],
|
60
|
+
"cookbooks" => ( node && node["cookbooks"] ) || {},
|
60
61
|
"policy_name" => node&.policy_name,
|
61
62
|
"policy_group" => node&.policy_group,
|
62
63
|
"start_time" => run_status.start_time.utc.iso8601,
|
data/lib/chef/deprecated.rb
CHANGED
data/lib/chef/dsl/core.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#--
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
3
|
# Author:: Christopher Walters (<cw@chef.io>)
|
4
|
-
# Copyright:: Copyright 2008-
|
4
|
+
# Copyright:: Copyright 2008-2019, Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
-
# Copyright:: Copyright 2008-
|
3
|
+
# Copyright:: Copyright 2008-2019, Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -16,13 +16,15 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
+
require "chef-utils" unless defined?(ChefUtils::CANARY)
|
20
|
+
|
19
21
|
class Chef
|
20
22
|
module DSL
|
21
|
-
|
22
23
|
# == Chef::DSL::PlatformIntrospection
|
23
24
|
# Provides the DSL for platform-dependent switch logic, such as
|
24
25
|
# #value_for_platform.
|
25
26
|
module PlatformIntrospection
|
27
|
+
include ChefUtils
|
26
28
|
|
27
29
|
# Implementation class for determining platform dependent values
|
28
30
|
class PlatformDependentValue
|
@@ -245,27 +247,16 @@ class Chef
|
|
245
247
|
end
|
246
248
|
end
|
247
249
|
|
248
|
-
# Shamelessly stolen from https://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/docker.rb
|
249
|
-
# Given a node object, returns whether the node is a docker container.
|
250
|
-
#
|
251
|
-
# === Parameters
|
252
|
-
# node:: [Chef::Node] The node to check.
|
253
|
-
#
|
254
|
-
# === Returns
|
255
|
-
# true:: if the current node is a docker container
|
256
|
-
# false:: if the current node is not a docker container
|
257
|
-
def docker?(node = run_context.nil? ? nil : run_context.node)
|
258
|
-
# Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad,
|
259
|
-
# and that makes us sad too.
|
260
|
-
!!(node && node[:virtualization] && node[:virtualization][:systems] &&
|
261
|
-
node[:virtualization][:systems][:docker] && node[:virtualization][:systems][:docker] == "guest")
|
262
|
-
end
|
263
|
-
|
264
250
|
# a simple helper to determine if we're on a windows release pre-2012 / 8
|
265
251
|
# @return [Boolean] Is the system older than Windows 8 / 2012
|
266
252
|
def older_than_win_2012_or_8?(node = run_context.nil? ? nil : run_context.node)
|
267
253
|
node["platform_version"].to_f < 6.2
|
268
254
|
end
|
255
|
+
|
256
|
+
# ^^^^^^ NOTE: PLEASE DO NOT CONTINUE TO ADD THESE KINDS OF PLATFORM_VERSION APIS WITHOUT ^^^^^^^
|
257
|
+
# ^^^^^^ GOING THROUGH THE DESIGN REVIEW PROCESS AND ADDRESS THE EXISTING CHEF-SUGAR ONES ^^^^^^^
|
258
|
+
# ^^^^^^ DO "THE HARD RIGHT THING" AND ADDRESS THE BROADER PROBLEM AND FIX IT ALL. ^^^^^^^
|
259
|
+
|
269
260
|
end
|
270
261
|
end
|
271
262
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Lamont Granquist (<lamont@chef.io>)
|
3
|
-
# Copyright:: Copyright 2013-
|
3
|
+
# Copyright:: Copyright 2013-2019, Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
require_relative "deploy/cp"
|
20
20
|
require_relative "deploy/mv_unix"
|
21
|
-
if
|
21
|
+
if ChefUtils.windows?
|
22
22
|
require_relative "deploy/mv_windows"
|
23
23
|
end
|
24
24
|
|
@@ -27,7 +27,7 @@ class Chef
|
|
27
27
|
class Deploy
|
28
28
|
def self.strategy(atomic_update)
|
29
29
|
if atomic_update
|
30
|
-
|
30
|
+
ChefUtils.windows? ? MvWindows.new : MvUnix.new
|
31
31
|
else
|
32
32
|
Cp.new
|
33
33
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Lamont Granquist (<lamont@chef.io>)
|
3
|
-
# Copyright:: Copyright 2013-
|
3
|
+
# Copyright:: Copyright 2013-2019, Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -22,7 +22,7 @@
|
|
22
22
|
#
|
23
23
|
|
24
24
|
require_relative "../../platform/query_helpers"
|
25
|
-
if
|
25
|
+
if ChefUtils.windows?
|
26
26
|
require_relative "../../win32/security"
|
27
27
|
end
|
28
28
|
|
@@ -67,7 +67,7 @@ class Chef
|
|
67
67
|
basename = ::File.basename(@new_resource.path, tempfile_extension)
|
68
68
|
# the leading "[.]chef-" here should be considered a public API and should not be changed
|
69
69
|
basename.insert 0, "chef-"
|
70
|
-
basename.insert 0, "." unless
|
70
|
+
basename.insert 0, "." unless ChefUtils.windows? # dotfile if we're not on windows
|
71
71
|
basename.scrub
|
72
72
|
end
|
73
73
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#--
|
2
2
|
# Author:: Daniel DeLeo (<dan@chef.io>)
|
3
3
|
# Author:: Tyler Cloke (<tyler@chef.io>)
|
4
|
-
# Copyright:: Copyright 2012-
|
4
|
+
# Copyright:: Copyright 2012-2019, Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -52,7 +52,7 @@ class Chef
|
|
52
52
|
error_description.section("Template Context:", "#{exception.source_location}\n#{exception.source_listing}")
|
53
53
|
end
|
54
54
|
|
55
|
-
if
|
55
|
+
if ChefUtils.windows?
|
56
56
|
require_relative "../../win32/security"
|
57
57
|
|
58
58
|
unless Chef::ReservedNames::Win32::Security.has_admin_privileges?
|
data/lib/chef/http.rb
CHANGED
data/lib/chef/knife.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
3
|
# Author:: Christopher Brown (<cb@chef.io>)
|
4
|
-
# Copyright:: Copyright 2009-
|
4
|
+
# Copyright:: Copyright 2009-2019, Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -20,6 +20,7 @@
|
|
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/path_sanity" unless defined?(ChefUtils::DSL::PathSanity)
|
23
24
|
require_relative "workstation_config_loader"
|
24
25
|
require_relative "mixin/convert_to_class_name"
|
25
26
|
require_relative "mixin/path_sanity"
|
@@ -39,7 +40,7 @@ class Chef
|
|
39
40
|
Chef::HTTP::HTTPRequest.user_agent = "#{Chef::Dist::PRODUCT} Knife#{Chef::HTTP::HTTPRequest::UA_COMMON}"
|
40
41
|
|
41
42
|
include Mixlib::CLI
|
42
|
-
include
|
43
|
+
include ChefUtils::DSL::PathSanity
|
43
44
|
extend Chef::Mixin::ConvertToClassName
|
44
45
|
extend Forwardable
|
45
46
|
|
@@ -479,7 +480,7 @@ class Chef
|
|
479
480
|
unless respond_to?(:run)
|
480
481
|
ui.error "You need to add a #run method to your knife command before you can use it"
|
481
482
|
end
|
482
|
-
enforce_path_sanity
|
483
|
+
ENV["PATH"] = sanitized_path if Chef::Config[:enforce_path_sanity]
|
483
484
|
maybe_setup_fips
|
484
485
|
Chef::LocalMode.with_server_connectivity do
|
485
486
|
run
|
@@ -47,9 +47,10 @@ class Chef
|
|
47
47
|
if wcl.config_location
|
48
48
|
loading_from("configuration", wcl.config_location)
|
49
49
|
end
|
50
|
+
|
50
51
|
if Chef::Config[:config_d_dir]
|
51
52
|
wcl.find_dot_d(Chef::Config[:config_d_dir]).each do |path|
|
52
|
-
loading_from(".d/ configuration",
|
53
|
+
loading_from(".d/ configuration", path)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
data/lib/chef/knife/configure.rb
CHANGED
@@ -120,7 +120,7 @@ class Chef
|
|
120
120
|
@admin_client_key = config[:admin_client_key] || ask_question("Please enter the location of the existing admin's private key: ", default: "#{Chef::Dist::SERVER_CONF_DIR}/admin.pem")
|
121
121
|
@admin_client_key = File.expand_path(@admin_client_key)
|
122
122
|
else
|
123
|
-
@new_client_name
|
123
|
+
@new_client_name = config[:node_name] || ask_question("Please enter an existing username or clientname for the API: ", default: Etc.getlogin)
|
124
124
|
end
|
125
125
|
|
126
126
|
@new_client_key = config[:client_key] || File.join(chef_config_path, "#{@new_client_name}.pem")
|
@@ -31,6 +31,12 @@ class Chef
|
|
31
31
|
banner "knife cookbook metadata from file FILE (options)"
|
32
32
|
|
33
33
|
def run
|
34
|
+
if @name_args.length < 1
|
35
|
+
show_usage
|
36
|
+
ui.fatal("You must specify the FILE.")
|
37
|
+
exit(1)
|
38
|
+
end
|
39
|
+
|
34
40
|
file = @name_args[0]
|
35
41
|
cookbook = File.basename(File.dirname(file))
|
36
42
|
|
@@ -191,7 +191,7 @@ class Chef
|
|
191
191
|
data =
|
192
192
|
if data.is_a?(Array)
|
193
193
|
data[attr.to_i]
|
194
|
-
elsif data.respond_to?(:[], false) && data.key?(attr)
|
194
|
+
elsif data.respond_to?(:[], false) && data.respond_to?(:key?) && data.key?(attr)
|
195
195
|
data[attr]
|
196
196
|
elsif data.respond_to?(attr.to_sym, false)
|
197
197
|
# handles -a chef_environment and other things that hang of the node and aren't really attributes
|
@@ -112,7 +112,7 @@ class Chef
|
|
112
112
|
|
113
113
|
if node["ohai_time"]
|
114
114
|
hours, minutes, seconds = time_difference_in_hms(node["ohai_time"])
|
115
|
-
hours_text
|
115
|
+
hours_text = "#{hours} hour#{hours == 1 ? " " : "s"}"
|
116
116
|
minutes_text = "#{minutes} minute#{minutes == 1 ? " " : "s"}"
|
117
117
|
seconds_text = "#{seconds} second#{seconds == 1 ? " " : "s"}"
|
118
118
|
if hours > 24
|
data/lib/chef/knife/ssh.rb
CHANGED
@@ -593,6 +593,12 @@ class Chef
|
|
593
593
|
def run
|
594
594
|
@longest = 0
|
595
595
|
|
596
|
+
if @name_args.length < 1
|
597
|
+
show_usage
|
598
|
+
ui.fatal("You must specify the SEARCH QUERY.")
|
599
|
+
exit(1)
|
600
|
+
end
|
601
|
+
|
596
602
|
configure_user
|
597
603
|
configure_password
|
598
604
|
@password = config[:ssh_password] if config[:ssh_password]
|
data/lib/chef/local_mode.rb
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
18
|
require_relative "config"
|
19
|
-
require_relative "monkey_patches/webrick-utils" if
|
19
|
+
require_relative "monkey_patches/webrick-utils" if ChefUtils.windows?
|
20
20
|
require_relative "dist"
|
21
21
|
|
22
22
|
class Chef
|
data/lib/chef/mash.rb
CHANGED
@@ -1,232 +1,21 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
11
|
-
#
|
12
|
-
#
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
# ---
|
23
|
-
# ---
|
24
|
-
|
25
|
-
# Some portions of blank.rb and mash.rb are verbatim copies of software
|
26
|
-
# licensed under the MIT license. That license is included below:
|
27
|
-
|
28
|
-
# Copyright 2005-2016, David Heinemeier Hansson
|
29
|
-
|
30
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
31
|
-
# a copy of this software and associated documentation files (the
|
32
|
-
# "Software"), to deal in the Software without restriction, including
|
33
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
34
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
36
|
-
# the following conditions:
|
37
|
-
|
38
|
-
# The above copyright notice and this permission notice shall be
|
39
|
-
# included in all copies or substantial portions of the Software.
|
40
|
-
|
41
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
42
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
44
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
45
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
46
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
47
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
48
|
-
|
49
|
-
# This class has dubious semantics and we only have it so that people can write
|
50
|
-
# params[:key] instead of params['key'].
|
51
|
-
class Mash < Hash
|
52
|
-
|
53
|
-
# @param constructor<Object>
|
54
|
-
# The default value for the mash. Defaults to an empty hash.
|
55
|
-
#
|
56
|
-
# @details [Alternatives]
|
57
|
-
# If constructor is a Hash, a new mash will be created based on the keys of
|
58
|
-
# the hash and no default value will be set.
|
59
|
-
def initialize(constructor = {})
|
60
|
-
if constructor.is_a?(Hash)
|
61
|
-
super()
|
62
|
-
update(constructor)
|
63
|
-
else
|
64
|
-
super(constructor)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# @param orig<Object> Mash being copied
|
69
|
-
#
|
70
|
-
# @return [Object] A new copied Mash
|
71
|
-
def initialize_copy(orig)
|
72
|
-
super
|
73
|
-
# Handle nested values
|
74
|
-
each do |k, v|
|
75
|
-
if v.is_a?(Mash) || v.is_a?(Array)
|
76
|
-
self[k] = v.dup
|
77
|
-
end
|
78
|
-
end
|
79
|
-
self
|
80
|
-
end
|
81
|
-
|
82
|
-
# @param key<Object> The default value for the mash. Defaults to nil.
|
83
|
-
#
|
84
|
-
# @details [Alternatives]
|
85
|
-
# If key is a Symbol and it is a key in the mash, then the default value will
|
86
|
-
# be set to the value matching the key.
|
87
|
-
def default(key = nil)
|
88
|
-
if key.is_a?(Symbol) && include?(key = key.to_s)
|
89
|
-
self[key]
|
90
|
-
else
|
91
|
-
super
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
96
|
-
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
97
|
-
|
98
|
-
# @param key<Object> The key to set.
|
99
|
-
# @param value<Object>
|
100
|
-
# The value to set the key to.
|
101
|
-
#
|
102
|
-
# @see Mash#convert_key
|
103
|
-
# @see Mash#convert_value
|
104
|
-
def []=(key, value)
|
105
|
-
regular_writer(convert_key(key), convert_value(value))
|
106
|
-
end
|
107
|
-
|
108
|
-
# internal API for use by Chef's deep merge cache
|
109
|
-
# @api private
|
110
|
-
def internal_set(key, value)
|
111
|
-
regular_writer(key, convert_value(value))
|
112
|
-
end
|
113
|
-
|
114
|
-
# @param other_hash<Hash>
|
115
|
-
# A hash to update values in the mash with. The keys and the values will be
|
116
|
-
# converted to Mash format.
|
117
|
-
#
|
118
|
-
# @return [Mash] The updated mash.
|
119
|
-
def update(other_hash)
|
120
|
-
other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
|
121
|
-
self
|
122
|
-
end
|
123
|
-
|
124
|
-
alias_method :merge!, :update
|
125
|
-
|
126
|
-
# @param key<Object> The key to check for. This will be run through convert_key.
|
127
|
-
#
|
128
|
-
# @return [Boolean] True if the key exists in the mash.
|
129
|
-
def key?(key)
|
130
|
-
super(convert_key(key))
|
131
|
-
end
|
132
|
-
|
133
|
-
# def include? def has_key? def member?
|
134
|
-
alias_method :include?, :key?
|
135
|
-
alias_method :has_key?, :key?
|
136
|
-
alias_method :member?, :key?
|
137
|
-
|
138
|
-
# @param key<Object> The key to fetch. This will be run through convert_key.
|
139
|
-
# @param *extras<Array> Default value.
|
140
|
-
#
|
141
|
-
# @return [Object] The value at key or the default value.
|
142
|
-
def fetch(key, *extras)
|
143
|
-
super(convert_key(key), *extras)
|
144
|
-
end
|
145
|
-
|
146
|
-
# @param *indices<Array>
|
147
|
-
# The keys to retrieve values for. These will be run through +convert_key+.
|
148
|
-
#
|
149
|
-
# @return [Array] The values at each of the provided keys
|
150
|
-
def values_at(*indices)
|
151
|
-
indices.collect { |key| self[convert_key(key)] }
|
152
|
-
end
|
153
|
-
|
154
|
-
# @param hash<Hash> The hash to merge with the mash.
|
155
|
-
#
|
156
|
-
# @return [Mash] A new mash with the hash values merged in.
|
157
|
-
def merge(hash)
|
158
|
-
dup.update(hash)
|
159
|
-
end
|
160
|
-
|
161
|
-
# @param key<Object>
|
162
|
-
# The key to delete from the mash.\
|
163
|
-
def delete(key)
|
164
|
-
super(convert_key(key))
|
165
|
-
end
|
166
|
-
|
167
|
-
# @param *rejected<Array[(String, Symbol)] The mash keys to exclude.
|
168
|
-
#
|
169
|
-
# @return [Mash] A new mash without the selected keys.
|
170
|
-
#
|
171
|
-
# @example
|
172
|
-
# { :one => 1, :two => 2, :three => 3 }.except(:one)
|
173
|
-
# #=> { "two" => 2, "three" => 3 }
|
174
|
-
def except(*keys)
|
175
|
-
super(*keys.map { |k| convert_key(k) })
|
176
|
-
end
|
177
|
-
|
178
|
-
# Used to provide the same interface as Hash.
|
179
|
-
#
|
180
|
-
# @return [Mash] This mash unchanged.
|
181
|
-
def stringify_keys!; self end
|
182
|
-
|
183
|
-
# @return [Hash] The mash as a Hash with symbolized keys.
|
184
|
-
def symbolize_keys
|
185
|
-
h = Hash.new(default)
|
186
|
-
each { |key, val| h[key.to_sym] = val }
|
187
|
-
h
|
188
|
-
end
|
189
|
-
|
190
|
-
# @return [Hash] The mash as a Hash with string keys.
|
191
|
-
def to_hash
|
192
|
-
Hash.new(default).merge(self)
|
193
|
-
end
|
194
|
-
|
195
|
-
# @return [Mash] Convert a Hash into a Mash
|
196
|
-
# The input Hash's default value is maintained
|
197
|
-
def self.from_hash(hash)
|
198
|
-
mash = Mash.new(hash)
|
199
|
-
mash.default = hash.default
|
200
|
-
mash
|
201
|
-
end
|
202
|
-
|
203
|
-
protected
|
204
|
-
|
205
|
-
# @param key<Object> The key to convert.
|
206
|
-
#
|
207
|
-
# @param [Object]
|
208
|
-
# The converted key. If the key was a symbol, it will be converted to a
|
209
|
-
# string.
|
210
|
-
#
|
211
|
-
# @api private
|
212
|
-
def convert_key(key)
|
213
|
-
key.is_a?(Symbol) ? key.to_s : key
|
214
|
-
end
|
215
|
-
|
216
|
-
# @param value<Object> The value to convert.
|
217
|
-
#
|
218
|
-
# @return [Object]
|
219
|
-
# The converted value. A Hash or an Array of hashes, will be converted to
|
220
|
-
# their Mash equivalents.
|
221
|
-
#
|
222
|
-
# @api private
|
223
|
-
def convert_value(value)
|
224
|
-
if value.class == Hash
|
225
|
-
Mash.from_hash(value)
|
226
|
-
elsif value.is_a?(Array)
|
227
|
-
value.collect { |e| convert_value(e) }
|
228
|
-
else
|
229
|
-
value
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2018-2019, 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-utils/mash" unless defined?(ChefUtils::Mash)
|
19
|
+
|
20
|
+
# For historical reasons we inject Mash directly into the top level class namespace
|
21
|
+
Mash = ChefUtils::Mash unless defined?(Mash)
|