chef 12.18.31 → 12.19.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -4
- data/README.md +12 -13
- data/VERSION +1 -1
- data/acceptance/Gemfile +4 -4
- data/acceptance/Gemfile.lock +70 -69
- data/chef-universal-mingw32.gemspec +2 -3
- data/chef.gemspec +6 -6
- data/lib/chef/api_client.rb +8 -10
- data/lib/chef/api_client_v1.rb +9 -11
- data/lib/chef/application/apply.rb +8 -10
- data/lib/chef/application/client.rb +1 -1
- data/lib/chef/application/exit_code.rb +3 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/windows_service.rb +29 -30
- data/lib/chef/application/windows_service_manager.rb +1 -1
- data/lib/chef/audit/audit_event_proxy.rb +2 -2
- data/lib/chef/audit/control_group_data.rb +1 -1
- data/lib/chef/chef_class.rb +1 -0
- data/lib/chef/chef_fs/chef_fs_data_store.rb +5 -7
- data/lib/chef/chef_fs/command_line.rb +15 -16
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/user_data_handler.rb +1 -1
- data/lib/chef/chef_fs/file_pattern.rb +2 -2
- data/lib/chef/chef_fs/file_system.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +5 -6
- data/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb +8 -10
- data/lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb +8 -10
- data/lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb +10 -12
- data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +28 -30
- data/lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +27 -29
- data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +18 -24
- data/lib/chef/chef_fs/file_system/memory/memory_file.rb +1 -1
- data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +10 -12
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +10 -12
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +9 -13
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -0
- data/lib/chef/chef_fs/file_system/repository/cookbooks_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +3 -0
- data/lib/chef/chef_fs/parallelizer.rb +9 -11
- data/lib/chef/cookbook/cookbook_version_loader.rb +25 -31
- data/lib/chef/cookbook/metadata.rb +26 -26
- data/lib/chef/cookbook/syntax_check.rb +1 -1
- data/lib/chef/cookbook_version.rb +3 -3
- data/lib/chef/data_bag.rb +1 -1
- data/lib/chef/data_bag_item.rb +3 -3
- data/lib/chef/data_collector.rb +3 -4
- data/lib/chef/decorator.rb +1 -1
- data/lib/chef/deprecated.rb +30 -0
- data/lib/chef/dsl/audit.rb +2 -2
- data/lib/chef/dsl/declare_resource.rb +1 -1
- data/lib/chef/dsl/platform_introspection.rb +29 -31
- data/lib/chef/dsl/reboot_pending.rb +1 -1
- data/lib/chef/dsl/resources.rb +6 -8
- data/lib/chef/encrypted_data_bag_item.rb +2 -2
- data/lib/chef/environment.rb +9 -11
- data/lib/chef/event_loggers/windows_eventlog.rb +1 -1
- data/lib/chef/exceptions.rb +4 -1
- data/lib/chef/file_access_control/unix.rb +14 -14
- data/lib/chef/file_access_control/windows.rb +1 -1
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +4 -5
- data/lib/chef/formatters/error_mapper.rb +6 -6
- data/lib/chef/http/api_versions.rb +50 -0
- data/lib/chef/http/validate_content_length.rb +2 -2
- data/lib/chef/json_compat.rb +6 -10
- data/lib/chef/key.rb +5 -5
- data/lib/chef/knife.rb +4 -4
- data/lib/chef/knife/cookbook_site_install.rb +2 -2
- data/lib/chef/knife/core/cookbook_scm_repo.rb +2 -2
- data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
- data/lib/chef/knife/core/status_presenter.rb +1 -1
- data/lib/chef/knife/core/ui.rb +19 -25
- data/lib/chef/knife/data_bag_secret_options.rb +1 -1
- data/lib/chef/knife/deps.rb +32 -34
- data/lib/chef/knife/help.rb +1 -1
- data/lib/chef/knife/list.rb +1 -1
- data/lib/chef/knife/search.rb +2 -2
- data/lib/chef/knife/ssh.rb +37 -27
- data/lib/chef/knife/ssl_check.rb +1 -1
- data/lib/chef/knife/user_delete.rb +1 -1
- data/lib/chef/mash.rb +1 -1
- data/lib/chef/mixin/command.rb +2 -2
- data/lib/chef/mixin/create_path.rb +3 -5
- data/lib/chef/mixin/from_file.rb +2 -2
- data/lib/chef/mixin/get_source_from_package.rb +2 -2
- data/lib/chef/mixin/notifying_block.rb +7 -9
- data/lib/chef/mixin/params_validate.rb +3 -3
- data/lib/chef/mixin/securable.rb +1 -1
- data/lib/chef/mixin/shell_out.rb +23 -3
- data/lib/chef/mixin/unformatter.rb +2 -2
- data/lib/chef/mixin/uris.rb +4 -6
- data/lib/chef/mixin/versioned_api.rb +69 -0
- data/lib/chef/mixin/which.rb +25 -8
- data/lib/chef/mixin/windows_architecture_helper.rb +2 -2
- data/lib/chef/mixin/xml_escape.rb +3 -5
- data/lib/chef/monkey_patches/webrick-utils.rb +1 -1
- data/lib/chef/node.rb +8 -8
- data/lib/chef/node/attribute.rb +4 -4
- data/lib/chef/node/common_api.rb +5 -7
- data/lib/chef/org.rb +10 -12
- data/lib/chef/platform/provider_mapping.rb +7 -7
- data/lib/chef/platform/query_helpers.rb +1 -1
- data/lib/chef/policy_builder/policyfile.rb +1 -0
- data/lib/chef/property.rb +31 -0
- data/lib/chef/provider/batch.rb +1 -1
- data/lib/chef/provider/breakpoint.rb +1 -1
- data/lib/chef/provider/cookbook_file.rb +3 -3
- data/lib/chef/provider/cron.rb +38 -38
- data/lib/chef/provider/deploy.rb +81 -81
- data/lib/chef/provider/deploy/revision.rb +3 -5
- data/lib/chef/provider/directory.rb +32 -32
- data/lib/chef/provider/dsc_resource.rb +22 -6
- data/lib/chef/provider/env.rb +28 -28
- data/lib/chef/provider/env/windows.rb +1 -1
- data/lib/chef/provider/erl_call.rb +13 -13
- data/lib/chef/provider/execute.rb +5 -2
- data/lib/chef/provider/file.rb +49 -51
- data/lib/chef/provider/git.rb +55 -55
- data/lib/chef/provider/http_request.rb +36 -36
- data/lib/chef/provider/launchd.rb +2 -2
- data/lib/chef/provider/link.rb +50 -50
- data/lib/chef/provider/log.rb +2 -2
- data/lib/chef/provider/mdadm.rb +25 -25
- data/lib/chef/provider/mount/aix.rb +2 -2
- data/lib/chef/provider/mount/mount.rb +2 -2
- data/lib/chef/provider/ohai.rb +1 -1
- data/lib/chef/provider/osx_profile.rb +23 -23
- data/lib/chef/provider/package.rb +74 -56
- data/lib/chef/provider/package/aix.rb +55 -52
- data/lib/chef/provider/package/apt.rb +15 -13
- data/lib/chef/provider/package/cab.rb +49 -20
- data/lib/chef/provider/package/chocolatey.rb +9 -10
- data/lib/chef/provider/package/dnf.rb +20 -18
- data/lib/chef/provider/package/dnf/dnf_helper.py +1 -1
- data/lib/chef/provider/package/dnf/python_helper.rb +63 -26
- data/lib/chef/provider/package/dnf/version.rb +1 -1
- data/lib/chef/provider/package/dpkg.rb +8 -9
- data/lib/chef/provider/package/easy_install.rb +22 -22
- data/lib/chef/provider/package/freebsd/base.rb +10 -10
- data/lib/chef/provider/package/freebsd/pkg.rb +15 -15
- data/lib/chef/provider/package/freebsd/pkgng.rb +13 -15
- data/lib/chef/provider/package/freebsd/port.rb +7 -7
- data/lib/chef/provider/package/homebrew.rb +11 -10
- data/lib/chef/provider/package/ips.rb +18 -23
- data/lib/chef/provider/package/macports.rb +23 -23
- data/lib/chef/provider/package/msu.rb +11 -11
- data/lib/chef/provider/package/openbsd.rb +25 -22
- data/lib/chef/provider/package/pacman.rb +16 -16
- data/lib/chef/provider/package/paludis.rb +26 -27
- data/lib/chef/provider/package/portage.rb +22 -22
- data/lib/chef/provider/package/powershell.rb +17 -17
- data/lib/chef/provider/package/rpm.rb +25 -25
- data/lib/chef/provider/package/rubygems.rb +60 -60
- data/lib/chef/provider/package/smartos.rb +16 -16
- data/lib/chef/provider/package/solaris.rb +44 -44
- data/lib/chef/provider/package/windows.rb +3 -3
- data/lib/chef/provider/package/windows/exe.rb +6 -6
- data/lib/chef/provider/package/windows/msi.rb +6 -6
- data/lib/chef/provider/package/yum.rb +318 -268
- data/lib/chef/provider/package/yum/rpm_utils.rb +34 -34
- data/lib/chef/provider/package/yum/yum_cache.rb +12 -12
- data/lib/chef/provider/package/zypper.rb +11 -11
- data/lib/chef/provider/powershell_script.rb +15 -7
- data/lib/chef/provider/reboot.rb +10 -10
- data/lib/chef/provider/registry_key.rb +39 -39
- data/lib/chef/provider/remote_directory.rb +3 -3
- data/lib/chef/provider/remote_file.rb +3 -3
- data/lib/chef/provider/route.rb +1 -1
- data/lib/chef/provider/ruby_block.rb +3 -3
- data/lib/chef/provider/script.rb +42 -6
- data/lib/chef/provider/service.rb +49 -49
- data/lib/chef/provider/service/solaris.rb +1 -1
- data/lib/chef/provider/service/systemd.rb +1 -1
- data/lib/chef/provider/subversion.rb +39 -39
- data/lib/chef/provider/systemd_unit.rb +2 -0
- data/lib/chef/provider/template.rb +3 -3
- data/lib/chef/provider/user.rb +42 -42
- data/lib/chef/provider/whyrun_safe_ruby_block.rb +4 -4
- data/lib/chef/resource.rb +27 -16
- data/lib/chef/resource/apt_repository.rb +0 -1
- data/lib/chef/resource/chef_gem.rb +1 -1
- data/lib/chef/resource/dnf_package.rb +6 -3
- data/lib/chef/resource/dsc_resource.rb +9 -1
- data/lib/chef/resource/execute.rb +70 -6
- data/lib/chef/resource/file/verification/systemd_unit.rb +67 -0
- data/lib/chef/resource/freebsd_package.rb +1 -1
- data/lib/chef/resource/gem_package.rb +1 -1
- data/lib/chef/resource/launchd.rb +13 -1
- data/lib/chef/resource/package.rb +2 -2
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/yum_package.rb +12 -3
- data/lib/chef/resource/yum_repository.rb +0 -1
- data/lib/chef/resource_collection/resource_collection_serialization.rb +3 -3
- data/lib/chef/resource_collection/resource_set.rb +2 -2
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/run_context.rb +3 -3
- data/lib/chef/run_list/run_list_item.rb +1 -1
- data/lib/chef/run_list/versioned_recipe_list.rb +6 -6
- data/lib/chef/server_api.rb +2 -0
- data/lib/chef/server_api_versions.rb +40 -0
- data/lib/chef/shell.rb +1 -1
- data/lib/chef/shell/ext.rb +3 -3
- data/lib/chef/shell/shell_session.rb +1 -1
- data/lib/chef/user.rb +9 -11
- data/lib/chef/user_v1.rb +9 -11
- data/lib/chef/util/diff.rb +1 -1
- data/lib/chef/util/dsc/lcm_output_parser.rb +1 -1
- data/lib/chef/util/selinux.rb +1 -1
- data/lib/chef/util/windows/net_group.rb +18 -30
- data/lib/chef/util/windows/net_use.rb +7 -11
- data/lib/chef/util/windows/net_user.rb +11 -17
- data/lib/chef/util/windows/volume.rb +9 -15
- data/lib/chef/version.rb +1 -1
- data/lib/chef/version_class.rb +1 -1
- data/lib/chef/win32/api.rb +4 -6
- data/lib/chef/win32/api/file.rb +25 -31
- data/lib/chef/win32/api/installer.rb +2 -2
- data/lib/chef/win32/file.rb +4 -6
- data/lib/chef/win32/registry.rb +9 -9
- data/lib/chef/win32/security.rb +2 -2
- data/lib/chef/win32/security/acl.rb +2 -2
- data/lib/chef/win32/unicode.rb +2 -2
- data/lib/chef/win32/version.rb +1 -1
- data/spec/data/prefer_metadata_json/metadata.json +51 -0
- data/spec/data/prefer_metadata_json/metadata.rb +6 -0
- data/spec/data/prefer_metadata_json/recipes/default.rb +0 -0
- data/spec/functional/knife/ssh_spec.rb +5 -5
- data/spec/functional/resource/batch_spec.rb +5 -1
- data/spec/functional/resource/dsc_script_spec.rb +2 -4
- data/spec/functional/resource/execute_spec.rb +17 -0
- data/spec/functional/resource/user/dscl_spec.rb +2 -4
- data/spec/integration/client/client_spec.rb +33 -0
- data/spec/integration/recipes/recipe_dsl_spec.rb +58 -58
- data/spec/spec_helper.rb +4 -0
- data/spec/support/chef_helpers.rb +5 -7
- data/spec/support/platform_helpers.rb +6 -0
- data/spec/support/platforms/prof/gc.rb +4 -6
- data/spec/support/shared/context/client.rb +1 -1
- data/spec/support/shared/functional/execute_resource.rb +150 -0
- data/spec/support/shared/functional/windows_script.rb +74 -4
- data/spec/support/shared/unit/execute_resource.rb +37 -0
- data/spec/support/shared/unit/provider/file.rb +10 -0
- data/spec/unit/cookbook/cookbook_version_loader_spec.rb +9 -0
- data/spec/unit/cookbook/syntax_check_spec.rb +8 -2
- data/spec/unit/http/api_versions_spec.rb +69 -0
- data/spec/unit/knife/ssh_spec.rb +34 -36
- data/spec/unit/mixin/versioned_api_spec.rb +107 -0
- data/spec/unit/mixin/which.rb +160 -0
- data/spec/unit/platform_spec.rb +28 -1
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/directory_spec.rb +10 -0
- data/spec/unit/provider/dsc_resource_spec.rb +175 -0
- data/spec/unit/provider/execute_spec.rb +0 -1
- data/spec/unit/provider/launchd_spec.rb +2 -2
- data/spec/unit/provider/package/aix_spec.rb +22 -22
- data/spec/unit/provider/package/apt_spec.rb +27 -27
- data/spec/unit/provider/package/cab_spec.rb +59 -5
- data/spec/unit/provider/package/dnf/python_helper_spec.rb +29 -0
- data/spec/unit/provider/package/dpkg_spec.rb +16 -16
- data/spec/unit/provider/package/easy_install_spec.rb +18 -18
- data/spec/unit/provider/package/freebsd/pkg_spec.rb +15 -15
- data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
- data/spec/unit/provider/package/freebsd/port_spec.rb +9 -9
- data/spec/unit/provider/package/homebrew_spec.rb +9 -9
- data/spec/unit/provider/package/ips_spec.rb +37 -31
- data/spec/unit/provider/package/macports_spec.rb +10 -10
- data/spec/unit/provider/package/openbsd_spec.rb +10 -10
- data/spec/unit/provider/package/pacman_spec.rb +6 -6
- data/spec/unit/provider/package/paludis_spec.rb +7 -7
- data/spec/unit/provider/package/portage_spec.rb +6 -7
- data/spec/unit/provider/package/rpm_spec.rb +23 -23
- data/spec/unit/provider/package/rubygems_spec.rb +38 -38
- data/spec/unit/provider/package/solaris_spec.rb +15 -15
- data/spec/unit/provider/package/windows_spec.rb +2 -1
- data/spec/unit/provider/package/yum_spec.rb +51 -43
- data/spec/unit/provider/package/zypper_spec.rb +34 -34
- data/spec/unit/provider/package_spec.rb +8 -0
- data/spec/unit/provider/remote_file/sftp_spec.rb +3 -3
- data/spec/unit/provider/route_spec.rb +7 -1
- data/spec/unit/provider/script_spec.rb +49 -6
- data/spec/unit/resource/dsc_resource_spec.rb +6 -0
- data/spec/unit/resource/execute_spec.rb +214 -0
- data/spec/unit/resource/file/verification/systemd_unit_spec.rb +103 -0
- data/spec/unit/resource/freebsd_package_spec.rb +2 -2
- data/spec/unit/resource/package_spec.rb +5 -0
- data/spec/unit/resource/yum_package_spec.rb +42 -1
- data/spec/unit/resource_reporter_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +18 -0
- data/spec/unit/server_api_versions_spec.rb +44 -0
- data/spec/unit/util/selinux_spec.rb +3 -14
- data/spec/unit/win32/error_spec.rb +67 -0
- data/spec/unit/win32/security_spec.rb +66 -0
- data/tasks/changelog.rb +1 -1
- data/tasks/dependencies.rb +20 -4
- metadata +39 -18
- data/lib/chef/monkey_patches/net-ssh-multi.rb +0 -141
@@ -102,8 +102,8 @@ class Chef
|
|
102
102
|
when Hash
|
103
103
|
validation.each do |check, carg|
|
104
104
|
check_method = "_pv_#{check}"
|
105
|
-
if
|
106
|
-
|
105
|
+
if respond_to?(check_method, true)
|
106
|
+
send(check_method, opts, key, carg)
|
107
107
|
else
|
108
108
|
raise ArgumentError, "Validation map has unknown check: #{check}"
|
109
109
|
end
|
@@ -333,7 +333,7 @@ class Chef
|
|
333
333
|
if is_name_property
|
334
334
|
if opts[key].nil?
|
335
335
|
raise CannotValidateStaticallyError, "name_property cannot be evaluated without a resource." if self == Chef::Mixin::ParamsValidate
|
336
|
-
opts[key] =
|
336
|
+
opts[key] = instance_variable_get(:"@name")
|
337
337
|
end
|
338
338
|
end
|
339
339
|
end
|
data/lib/chef/mixin/securable.rb
CHANGED
@@ -110,7 +110,7 @@ class Chef
|
|
110
110
|
# equivalent to something like:
|
111
111
|
# def rights(permissions=nil, principals=nil, args_hash=nil)
|
112
112
|
define_method(name) do |permissions = nil, principals = nil, args_hash = nil|
|
113
|
-
rights =
|
113
|
+
rights = instance_variable_get("@#{name}".to_sym)
|
114
114
|
unless permissions.nil?
|
115
115
|
input = {
|
116
116
|
:permissions => permissions,
|
data/lib/chef/mixin/shell_out.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# Author:: Daniel DeLeo (<dan@chef.io>)
|
3
|
-
# Copyright:: Copyright 2010-
|
3
|
+
# Copyright:: Copyright 2010-2017, 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,6 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
18
|
require "mixlib/shellout"
|
19
|
+
require "chef/deprecated"
|
19
20
|
|
20
21
|
class Chef
|
21
22
|
module Mixin
|
@@ -75,6 +76,24 @@ class Chef
|
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
79
|
+
# helper sugar for resources that support passing timeouts to shell_out
|
80
|
+
|
81
|
+
def shell_out_compact_timeout(*args, **options)
|
82
|
+
raise "object is not a resource that supports timeouts" unless respond_to?(:new_resource) && new_resource.respond_to?(:timeout)
|
83
|
+
options_dup = options.dup
|
84
|
+
options_dup[:timeout] = new_resource.timeout if new_resource.timeout
|
85
|
+
options_dup[:timeout] = 900 unless options_dup.key?(:timeout)
|
86
|
+
shell_out_compact(*args, **options_dup)
|
87
|
+
end
|
88
|
+
|
89
|
+
def shell_out_compact_timeout!(*args, **options)
|
90
|
+
raise "object is not a resource that supports timeouts" unless respond_to?(:new_resource) && new_resource.respond_to?(:timeout)
|
91
|
+
options_dup = options.dup
|
92
|
+
options_dup[:timeout] = new_resource.timeout if new_resource.timeout
|
93
|
+
options_dup[:timeout] = 900 unless options_dup.key?(:timeout)
|
94
|
+
shell_out_compact!(*args, **options_dup)
|
95
|
+
end
|
96
|
+
|
78
97
|
# shell_out! runs a command on the system and will raise an error if the command fails, which is what you want
|
79
98
|
# for debugging, shell_out and shell_out! both will display command output to the tty when the log level is debug
|
80
99
|
# Generally speaking, 'extend Chef::Mixin::ShellOut' in your recipes and include 'Chef::Mixin::ShellOut' in your LWRPs
|
@@ -129,7 +148,7 @@ class Chef
|
|
129
148
|
my_options[new_option] = value
|
130
149
|
end
|
131
150
|
|
132
|
-
|
151
|
+
my_command_args
|
133
152
|
end
|
134
153
|
|
135
154
|
# Helper for sublcasses to convert an array of string args into a string. It
|
@@ -139,7 +158,8 @@ class Chef
|
|
139
158
|
# @param args [String] variable number of string arguments
|
140
159
|
# @return [String] nicely concatenated string or empty string
|
141
160
|
def a_to_s(*args)
|
142
|
-
#
|
161
|
+
# can't quite deprecate this yet
|
162
|
+
#Chef.deprecated(:package_misc, "a_to_s is deprecated use shell_out_compact or shell_out_compact_timeout instead")
|
143
163
|
args.flatten.reject { |i| i.nil? || i == "" }.map(&:to_s).join(" ")
|
144
164
|
end
|
145
165
|
|
@@ -22,9 +22,9 @@ class Chef
|
|
22
22
|
|
23
23
|
def write(message)
|
24
24
|
data = message.match(/(\[.+?\] )?([\w]+):(.*)$/)
|
25
|
-
|
25
|
+
send(data[2].downcase.chomp.to_sym, data[3].strip)
|
26
26
|
rescue NoMethodError
|
27
|
-
|
27
|
+
send(:info, message)
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
data/lib/chef/mixin/uris.rb
CHANGED
@@ -31,12 +31,10 @@ class Chef
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def as_uri(source)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
URI.parse(Addressable::URI.encode(source))
|
39
|
-
end
|
34
|
+
URI.parse(source)
|
35
|
+
rescue URI::InvalidURIError
|
36
|
+
Chef::Log.warn("#{source} was an invalid URI. Trying to escape invalid characters")
|
37
|
+
URI.parse(Addressable::URI.encode(source))
|
40
38
|
end
|
41
39
|
|
42
40
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright:: Copyright 2017, 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
|
+
class Chef
|
19
|
+
module Mixin
|
20
|
+
module VersionedAPI
|
21
|
+
|
22
|
+
def minimum_api_version(version = nil)
|
23
|
+
if version
|
24
|
+
@minimum_api_version = version
|
25
|
+
else
|
26
|
+
@minimum_api_version
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
module VersionedAPIFactory
|
33
|
+
|
34
|
+
def versioned_interfaces
|
35
|
+
@versioned_interfaces ||= []
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_versioned_api_class(klass)
|
39
|
+
versioned_interfaces << klass
|
40
|
+
end
|
41
|
+
|
42
|
+
def versioned_api_class
|
43
|
+
versioned_interfaces.select do |klass|
|
44
|
+
version = klass.send(:minimum_api_version)
|
45
|
+
# min and max versions will be nil if we've not made a request to the server yet,
|
46
|
+
# in which case we'll just start with the highest version and see what happens
|
47
|
+
ServerAPIVersions.instance.min_server_version.nil? || (version >= ServerAPIVersions.instance.min_server_version && version <= ServerAPIVersions.instance.max_server_version)
|
48
|
+
end
|
49
|
+
.sort { |a, b| a.send(:minimum_api_version) <=> b.send(:minimum_api_version) }
|
50
|
+
.last
|
51
|
+
end
|
52
|
+
|
53
|
+
def def_versioned_delegator(method)
|
54
|
+
line_no = __LINE__; str = %{
|
55
|
+
def self.#{method}(*args, &block)
|
56
|
+
versioned_api_class.__send__(:#{method}, *args, &block)
|
57
|
+
end
|
58
|
+
}
|
59
|
+
module_eval(str, __FILE__, line_no)
|
60
|
+
end
|
61
|
+
|
62
|
+
def new(*args)
|
63
|
+
object = versioned_api_class.allocate
|
64
|
+
object.send(:initialize, *args)
|
65
|
+
object
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/chef/mixin/which.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# Author:: Lamont Granquist <lamont@chef.io>
|
3
|
-
# Copyright:: Copyright 2010-
|
3
|
+
# Copyright:: Copyright 2010-2017, 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,15 +18,32 @@
|
|
18
18
|
class Chef
|
19
19
|
module Mixin
|
20
20
|
module Which
|
21
|
-
def which(
|
21
|
+
def which(*cmds, extra_path: nil, &block)
|
22
|
+
where(*cmds, extra_path: extra_path, &block).first || false
|
23
|
+
end
|
24
|
+
|
25
|
+
def where(*cmds, extra_path: nil, &block)
|
22
26
|
# NOTE: unnecessarily duplicates function of path_sanity
|
23
27
|
extra_path ||= [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ]
|
24
|
-
paths =
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
paths = env_path.split(File::PATH_SEPARATOR) + extra_path
|
29
|
+
cmds.map do |cmd|
|
30
|
+
paths.map do |path|
|
31
|
+
filename = Chef.path_to(File.join(path, cmd))
|
32
|
+
filename if valid_executable?(filename, &block)
|
33
|
+
end.compact
|
34
|
+
end.flatten
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# for test stubbing
|
40
|
+
def env_path
|
41
|
+
ENV["PATH"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def valid_executable?(filename, &block)
|
45
|
+
return false unless File.executable?(filename) && !File.directory?(filename)
|
46
|
+
block ? yield(filename) : true
|
30
47
|
end
|
31
48
|
end
|
32
49
|
end
|
@@ -74,11 +74,11 @@ class Chef
|
|
74
74
|
|
75
75
|
def node_supports_windows_architecture?(node, desired_architecture)
|
76
76
|
assert_valid_windows_architecture!(desired_architecture)
|
77
|
-
|
77
|
+
( node_windows_architecture(node) == :x86_64 ) || ( desired_architecture == :i386 )
|
78
78
|
end
|
79
79
|
|
80
80
|
def valid_windows_architecture?(architecture)
|
81
|
-
|
81
|
+
( architecture == :x86_64 ) || ( architecture == :i386 )
|
82
82
|
end
|
83
83
|
|
84
84
|
def assert_valid_windows_architecture!(architecture)
|
@@ -103,11 +103,9 @@ class Chef
|
|
103
103
|
(0xE000..0xFFFD), (0x10000..0x10FFFF)]
|
104
104
|
|
105
105
|
def xml_escape(unescaped_str)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
unescaped_str.unpack("C*").map { |char| xml_escape_char!(char) }.join
|
110
|
-
end
|
106
|
+
unescaped_str.unpack("U*").map { |char| xml_escape_char!(char) }.join
|
107
|
+
rescue
|
108
|
+
unescaped_str.unpack("C*").map { |char| xml_escape_char!(char) }.join
|
111
109
|
end
|
112
110
|
|
113
111
|
private
|
data/lib/chef/node.rb
CHANGED
@@ -333,8 +333,8 @@ class Chef
|
|
333
333
|
|
334
334
|
platform, version = Chef::Platform.find_platform_and_version(self)
|
335
335
|
Chef::Log.debug("Platform is #{platform} version #{version}")
|
336
|
-
|
337
|
-
|
336
|
+
automatic[:platform] = platform
|
337
|
+
automatic[:platform_version] = version
|
338
338
|
end
|
339
339
|
|
340
340
|
# Consumes the combined run_list and other attributes in +attrs+
|
@@ -343,7 +343,7 @@ class Chef
|
|
343
343
|
normal_attrs_to_merge = consume_chef_environment(normal_attrs_to_merge)
|
344
344
|
Chef::Log.debug("Applying attributes from json file")
|
345
345
|
self.normal_attrs = Chef::Mixin::DeepMerge.merge(normal_attrs, normal_attrs_to_merge)
|
346
|
-
|
346
|
+
tags # make sure they're defined
|
347
347
|
end
|
348
348
|
|
349
349
|
# Lazy initializer for tags attribute
|
@@ -394,8 +394,8 @@ class Chef
|
|
394
394
|
# Clear defaults and overrides, so that any deleted attributes
|
395
395
|
# between runs are still gone.
|
396
396
|
def reset_defaults_and_overrides
|
397
|
-
|
398
|
-
|
397
|
+
default.clear
|
398
|
+
override.clear
|
399
399
|
end
|
400
400
|
|
401
401
|
# Expands the node's run list and sets the default and override
|
@@ -414,7 +414,7 @@ class Chef
|
|
414
414
|
expansion = run_list.expand(chef_environment, data_source)
|
415
415
|
raise Chef::Exceptions::MissingRole, expansion if expansion.errors?
|
416
416
|
|
417
|
-
|
417
|
+
tags # make sure they're defined
|
418
418
|
|
419
419
|
automatic_attrs[:recipes] = expansion.recipes.with_duplicate_names
|
420
420
|
automatic_attrs[:expanded_run_list] = expansion.recipes.with_fully_qualified_names_and_version_constraints
|
@@ -632,14 +632,14 @@ class Chef
|
|
632
632
|
|
633
633
|
def ==(other)
|
634
634
|
if other.kind_of?(self.class)
|
635
|
-
|
635
|
+
name == other.name
|
636
636
|
else
|
637
637
|
false
|
638
638
|
end
|
639
639
|
end
|
640
640
|
|
641
641
|
def <=>(other)
|
642
|
-
|
642
|
+
name <=> other.name
|
643
643
|
end
|
644
644
|
|
645
645
|
private
|
data/lib/chef/node/attribute.rb
CHANGED
@@ -454,19 +454,19 @@ class Chef
|
|
454
454
|
end
|
455
455
|
|
456
456
|
def write(level, *args, &block)
|
457
|
-
|
457
|
+
send(level).write(*args, &block)
|
458
458
|
end
|
459
459
|
|
460
460
|
def write!(level, *args, &block)
|
461
|
-
|
461
|
+
send(level).write!(*args, &block)
|
462
462
|
end
|
463
463
|
|
464
464
|
def unlink(level, *path)
|
465
|
-
|
465
|
+
send(level).unlink(*path)
|
466
466
|
end
|
467
467
|
|
468
468
|
def unlink!(level, *path)
|
469
|
-
|
469
|
+
send(level).unlink!(*path)
|
470
470
|
end
|
471
471
|
|
472
472
|
alias :attribute? :has_key?
|
data/lib/chef/node/common_api.rb
CHANGED
@@ -24,7 +24,7 @@ class Chef
|
|
24
24
|
# method-style access to attributes
|
25
25
|
|
26
26
|
def valid_container?(obj, key)
|
27
|
-
|
27
|
+
obj.is_a?(Hash) || (obj.is_a?(Array) && key.is_a?(Integer))
|
28
28
|
end
|
29
29
|
|
30
30
|
private :valid_container?
|
@@ -85,16 +85,14 @@ class Chef
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
true
|
89
89
|
end
|
90
90
|
|
91
91
|
# this is a safe non-autovivifying reader that returns nil if the attribute does not exist
|
92
92
|
def read(*path)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
nil
|
97
|
-
end
|
93
|
+
read!(*path)
|
94
|
+
rescue Chef::Exceptions::NoSuchAttribute
|
95
|
+
nil
|
98
96
|
end
|
99
97
|
|
100
98
|
# non-autovivifying reader that throws an exception if the attribute does not exist
|
data/lib/chef/org.rb
CHANGED
@@ -73,15 +73,15 @@ class Chef
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def create
|
76
|
-
payload = { :name =>
|
76
|
+
payload = { :name => name, :full_name => full_name }
|
77
77
|
new_org = chef_rest.post("organizations", payload)
|
78
|
-
Chef::Org.from_hash(
|
78
|
+
Chef::Org.from_hash(to_hash.merge(new_org))
|
79
79
|
end
|
80
80
|
|
81
81
|
def update
|
82
|
-
payload = { :name =>
|
82
|
+
payload = { :name => name, :full_name => full_name }
|
83
83
|
new_org = chef_rest.put("organizations/#{name}", payload)
|
84
|
-
Chef::Org.from_hash(
|
84
|
+
Chef::Org.from_hash(to_hash.merge(new_org))
|
85
85
|
end
|
86
86
|
|
87
87
|
def destroy
|
@@ -89,14 +89,12 @@ class Chef
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def save
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
raise e
|
99
|
-
end
|
92
|
+
create
|
93
|
+
rescue Net::HTTPServerException => e
|
94
|
+
if e.response.code == "409"
|
95
|
+
update
|
96
|
+
else
|
97
|
+
raise e
|
100
98
|
end
|
101
99
|
end
|
102
100
|
|
@@ -35,7 +35,7 @@ class Chef
|
|
35
35
|
include Chef::Mixin::ParamsValidate
|
36
36
|
|
37
37
|
def find(name, version)
|
38
|
-
Chef.deprecated(:chef_platform_methods, "#{self.
|
38
|
+
Chef.deprecated(:chef_platform_methods, "#{self.name}.find is deprecated")
|
39
39
|
provider_map = platforms[:default].clone
|
40
40
|
|
41
41
|
name_sym = name
|
@@ -87,11 +87,11 @@ class Chef
|
|
87
87
|
|
88
88
|
raise ArgumentError, "Cannot find a version for #{node}" unless version
|
89
89
|
|
90
|
-
|
90
|
+
[platform, version]
|
91
91
|
end
|
92
92
|
|
93
93
|
def provider_for_resource(resource, action = :nothing)
|
94
|
-
Chef.deprecated(:chef_platform_methods, "#{
|
94
|
+
Chef.deprecated(:chef_platform_methods, "#{name}.provider_for_resource is deprecated")
|
95
95
|
node = resource.run_context && resource.run_context.node
|
96
96
|
raise ArgumentError, "Cannot find the provider for a resource with no run context set" unless node
|
97
97
|
provider = find_provider_for_node(node, resource).new(resource, resource.run_context)
|
@@ -100,17 +100,17 @@ class Chef
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def provider_for_node(node, resource_type)
|
103
|
-
raise NotImplementedError, "#{
|
103
|
+
raise NotImplementedError, "#{name} no longer supports #provider_for_node"
|
104
104
|
end
|
105
105
|
|
106
106
|
def find_provider_for_node(node, resource_type)
|
107
|
-
Chef.deprecated(:chef_platform_methods, "#{
|
107
|
+
Chef.deprecated(:chef_platform_methods, "#{name}.find_provider_for_node is deprecated")
|
108
108
|
platform, version = find_platform_and_version(node)
|
109
109
|
find_provider(platform, version, resource_type)
|
110
110
|
end
|
111
111
|
|
112
112
|
def set(args)
|
113
|
-
Chef.deprecated(:chef_platform_methods, "#{
|
113
|
+
Chef.deprecated(:chef_platform_methods, "#{name}.set is deprecated")
|
114
114
|
validate(
|
115
115
|
args,
|
116
116
|
{
|
@@ -176,7 +176,7 @@ class Chef
|
|
176
176
|
end
|
177
177
|
|
178
178
|
def find_provider(platform, version, resource_type)
|
179
|
-
Chef.deprecated(:chef_platform_methods, "#{
|
179
|
+
Chef.deprecated(:chef_platform_methods, "#{name}.find_provider is deprecated")
|
180
180
|
provider_klass = explicit_provider(platform, version, resource_type) ||
|
181
181
|
platform_provider(platform, version, resource_type) ||
|
182
182
|
resource_matching_provider(platform, version, resource_type)
|