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
data/lib/chef/provider/file.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
3
|
# Author:: Lamont Granquist (<lamont@chef.io>)
|
4
|
-
# Copyright:: Copyright 2008-
|
4
|
+
# Copyright:: Copyright 2008-2017, 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");
|
@@ -95,7 +95,7 @@ class Chef
|
|
95
95
|
# true if we are going to be creating a new file
|
96
96
|
@needs_creating = !::File.exist?(new_resource.path) || needs_unlinking?
|
97
97
|
|
98
|
-
# Let children resources override constructing the
|
98
|
+
# Let children resources override constructing the current_resource
|
99
99
|
@current_resource ||= Chef::Resource::File.new(new_resource.name)
|
100
100
|
current_resource.path(new_resource.path)
|
101
101
|
|
@@ -120,17 +120,17 @@ class Chef
|
|
120
120
|
|
121
121
|
# Make sure the parent directory exists, otherwise fail. For why-run assume it would have been created.
|
122
122
|
requirements.assert(:create, :create_if_missing, :touch) do |a|
|
123
|
-
parent_directory = ::File.dirname(
|
123
|
+
parent_directory = ::File.dirname(new_resource.path)
|
124
124
|
a.assertion { ::File.directory?(parent_directory) }
|
125
125
|
a.failure_message(Chef::Exceptions::EnclosingDirectoryDoesNotExist, "Parent directory #{parent_directory} does not exist.")
|
126
126
|
a.whyrun("Assuming directory #{parent_directory} would have been created")
|
127
127
|
end
|
128
128
|
|
129
129
|
# Make sure the file is deletable if it exists, otherwise fail.
|
130
|
-
if ::File.exist?(
|
130
|
+
if ::File.exist?(new_resource.path)
|
131
131
|
requirements.assert(:delete) do |a|
|
132
|
-
a.assertion { ::File.writable?(
|
133
|
-
a.failure_message(Chef::Exceptions::InsufficientPermissions, "File #{
|
132
|
+
a.assertion { ::File.writable?(new_resource.path) }
|
133
|
+
a.failure_message(Chef::Exceptions::InsufficientPermissions, "File #{new_resource.path} exists but is not writable so it cannot be deleted")
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -154,33 +154,33 @@ class Chef
|
|
154
154
|
do_contents_changes
|
155
155
|
do_acl_changes
|
156
156
|
do_selinux
|
157
|
-
load_resource_attributes_from_file(
|
157
|
+
load_resource_attributes_from_file(new_resource) unless Chef::Config[:why_run]
|
158
158
|
end
|
159
159
|
|
160
160
|
def action_create_if_missing
|
161
|
-
unless ::File.exist?(
|
161
|
+
unless ::File.exist?(new_resource.path)
|
162
162
|
action_create
|
163
163
|
else
|
164
|
-
Chef::Log.debug("#{
|
164
|
+
Chef::Log.debug("#{new_resource} exists at #{new_resource.path} taking no action.")
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
168
|
def action_delete
|
169
|
-
if ::File.exists?(
|
170
|
-
converge_by("delete file #{
|
171
|
-
do_backup unless file_class.symlink?(
|
172
|
-
::File.delete(
|
173
|
-
Chef::Log.info("#{
|
169
|
+
if ::File.exists?(new_resource.path)
|
170
|
+
converge_by("delete file #{new_resource.path}") do
|
171
|
+
do_backup unless file_class.symlink?(new_resource.path)
|
172
|
+
::File.delete(new_resource.path)
|
173
|
+
Chef::Log.info("#{new_resource} deleted file at #{new_resource.path}")
|
174
174
|
end
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
178
|
def action_touch
|
179
179
|
action_create
|
180
|
-
converge_by("update utime on file #{
|
180
|
+
converge_by("update utime on file #{new_resource.path}") do
|
181
181
|
time = Time.now
|
182
|
-
::File.utime(time, time,
|
183
|
-
Chef::Log.info("#{
|
182
|
+
::File.utime(time, time, new_resource.path)
|
183
|
+
Chef::Log.info("#{new_resource} updated atime and mtime to #{time}")
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
@@ -197,8 +197,8 @@ class Chef
|
|
197
197
|
# content (for things like doing checksums in load_current_resource). Expected to
|
198
198
|
# be overridden in subclasses.
|
199
199
|
def managing_content?
|
200
|
-
return true if
|
201
|
-
return true if
|
200
|
+
return true if new_resource.checksum
|
201
|
+
return true if !new_resource.content.nil? && @action != :create_if_missing
|
202
202
|
false
|
203
203
|
end
|
204
204
|
|
@@ -228,25 +228,25 @@ class Chef
|
|
228
228
|
# assertions, which then decide whether or not to raise or issue a
|
229
229
|
# warning for whyrun mode.
|
230
230
|
def inspect_existing_fs_entry
|
231
|
-
path =
|
231
|
+
path = new_resource.path
|
232
232
|
|
233
233
|
if !l_exist?(path)
|
234
234
|
[nil, nil, nil]
|
235
235
|
elsif real_file?(path)
|
236
236
|
[nil, nil, nil]
|
237
|
-
elsif file_class.symlink?(path) &&
|
237
|
+
elsif file_class.symlink?(path) && new_resource.manage_symlink_source
|
238
238
|
verify_symlink_sanity(path)
|
239
|
-
elsif file_class.symlink?(
|
240
|
-
Chef::Log.warn("File #{path} managed by #{
|
239
|
+
elsif file_class.symlink?(new_resource.path) && new_resource.manage_symlink_source.nil?
|
240
|
+
Chef::Log.warn("File #{path} managed by #{new_resource} is really a symlink. Managing the source file instead.")
|
241
241
|
Chef::Log.warn("Disable this warning by setting `manage_symlink_source true` on the resource")
|
242
242
|
Chef::Log.warn("In a future Chef release, 'manage_symlink_source' will not be enabled by default")
|
243
243
|
verify_symlink_sanity(path)
|
244
|
-
elsif
|
244
|
+
elsif new_resource.force_unlink
|
245
245
|
[nil, nil, nil]
|
246
246
|
else
|
247
247
|
[ Chef::Exceptions::FileTypeMismatch,
|
248
|
-
"File #{path} exists, but is a #{file_type_string(
|
249
|
-
"Assuming #{file_type_string(
|
248
|
+
"File #{path} exists, but is a #{file_type_string(new_resource.path)}, set force_unlink to true to remove",
|
249
|
+
"Assuming #{file_type_string(new_resource.path)} at #{new_resource.path} would have been removed by a previous resource",
|
250
250
|
]
|
251
251
|
end
|
252
252
|
end
|
@@ -282,8 +282,8 @@ class Chef
|
|
282
282
|
|
283
283
|
def content
|
284
284
|
@content ||= begin
|
285
|
-
load_current_resource if
|
286
|
-
@content_class.new(
|
285
|
+
load_current_resource if current_resource.nil?
|
286
|
+
@content_class.new(new_resource, current_resource, @run_context)
|
287
287
|
end
|
288
288
|
end
|
289
289
|
|
@@ -312,11 +312,9 @@ class Chef
|
|
312
312
|
|
313
313
|
# like real_file? that follows (sane) symlinks
|
314
314
|
def symlink_to_real_file?(path)
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
false
|
319
|
-
end
|
315
|
+
real_file?(::File.realpath(path))
|
316
|
+
rescue Errno::ELOOP, Errno::ENOENT
|
317
|
+
false
|
320
318
|
end
|
321
319
|
|
322
320
|
# Similar to File.exist?, but also returns true in the case that the
|
@@ -358,12 +356,12 @@ class Chef
|
|
358
356
|
end
|
359
357
|
|
360
358
|
def do_unlink
|
361
|
-
if
|
359
|
+
if new_resource.force_unlink
|
362
360
|
if needs_unlinking?
|
363
361
|
# unlink things that aren't normal files
|
364
|
-
description = "unlink #{file_type_string(
|
362
|
+
description = "unlink #{file_type_string(new_resource.path)} at #{new_resource.path}"
|
365
363
|
converge_by(description) do
|
366
|
-
unlink(
|
364
|
+
unlink(new_resource.path)
|
367
365
|
end
|
368
366
|
end
|
369
367
|
end
|
@@ -371,15 +369,15 @@ class Chef
|
|
371
369
|
|
372
370
|
def do_create_file
|
373
371
|
if needs_creating?
|
374
|
-
converge_by("create new file #{
|
375
|
-
deployment_strategy.create(
|
376
|
-
Chef::Log.info("#{
|
372
|
+
converge_by("create new file #{new_resource.path}") do
|
373
|
+
deployment_strategy.create(new_resource.path)
|
374
|
+
Chef::Log.info("#{new_resource} created file #{new_resource.path}")
|
377
375
|
end
|
378
376
|
end
|
379
377
|
end
|
380
378
|
|
381
379
|
def do_backup(file = nil)
|
382
|
-
Chef::Util::Backup.new(
|
380
|
+
Chef::Util::Backup.new(new_resource, file).backup!
|
383
381
|
end
|
384
382
|
|
385
383
|
def diff
|
@@ -405,17 +403,17 @@ class Chef
|
|
405
403
|
end
|
406
404
|
|
407
405
|
# the file? on the next line suppresses the case in why-run when we have a not-file here that would have otherwise been removed
|
408
|
-
if ::File.file?(
|
409
|
-
description = [ "update content in file #{
|
410
|
-
#{short_cksum(
|
406
|
+
if ::File.file?(new_resource.path) && contents_changed?
|
407
|
+
description = [ "update content in file #{new_resource.path} from \
|
408
|
+
#{short_cksum(current_resource.checksum)} to #{short_cksum(tempfile_checksum)}" ]
|
411
409
|
|
412
410
|
# Hide the diff output if the resource is marked as a sensitive resource
|
413
|
-
if
|
414
|
-
|
411
|
+
if new_resource.sensitive
|
412
|
+
new_resource.diff("suppressed sensitive resource")
|
415
413
|
description << "suppressed sensitive resource"
|
416
414
|
else
|
417
|
-
diff.diff(
|
418
|
-
|
415
|
+
diff.diff(current_resource.path, tempfile.path)
|
416
|
+
new_resource.diff( diff.for_reporting ) unless needs_creating?
|
419
417
|
description << diff.for_output
|
420
418
|
end
|
421
419
|
|
@@ -437,7 +435,7 @@ class Chef
|
|
437
435
|
if resource_updated? && Chef::Config[:enable_selinux_file_permission_fixup]
|
438
436
|
if selinux_enabled?
|
439
437
|
converge_by("restore selinux security context") do
|
440
|
-
restore_security_context(::File.realpath(
|
438
|
+
restore_security_context(::File.realpath(new_resource.path), recursive)
|
441
439
|
end
|
442
440
|
else
|
443
441
|
Chef::Log.debug "selinux utilities can not be found. Skipping selinux permission fixup."
|
@@ -454,8 +452,8 @@ class Chef
|
|
454
452
|
end
|
455
453
|
|
456
454
|
def contents_changed?
|
457
|
-
Chef::Log.debug "calculating checksum of #{tempfile.path} to compare with #{
|
458
|
-
tempfile_checksum !=
|
455
|
+
Chef::Log.debug "calculating checksum of #{tempfile.path} to compare with #{current_resource.checksum}"
|
456
|
+
tempfile_checksum != current_resource.checksum
|
459
457
|
end
|
460
458
|
|
461
459
|
def tempfile
|
@@ -470,7 +468,7 @@ class Chef
|
|
470
468
|
# reporting won't work for Windows.
|
471
469
|
return
|
472
470
|
end
|
473
|
-
acl_scanner = ScanAccessControl.new(
|
471
|
+
acl_scanner = ScanAccessControl.new(new_resource, resource)
|
474
472
|
acl_scanner.set_all!
|
475
473
|
end
|
476
474
|
|
data/lib/chef/provider/git.rb
CHANGED
@@ -28,7 +28,7 @@ class Chef
|
|
28
28
|
extend Forwardable
|
29
29
|
provides :git
|
30
30
|
|
31
|
-
def_delegator
|
31
|
+
def_delegator :new_resource, :destination, :cwd
|
32
32
|
|
33
33
|
def whyrun_supported?
|
34
34
|
true
|
@@ -36,9 +36,9 @@ class Chef
|
|
36
36
|
|
37
37
|
def load_current_resource
|
38
38
|
@resolved_reference = nil
|
39
|
-
@current_resource = Chef::Resource::Git.new(
|
39
|
+
@current_resource = Chef::Resource::Git.new(new_resource.name)
|
40
40
|
if current_revision = find_current_revision
|
41
|
-
|
41
|
+
current_resource.revision current_revision
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -49,16 +49,16 @@ class Chef
|
|
49
49
|
a.assertion { ::File.directory?(dirname) }
|
50
50
|
a.whyrun("Directory #{dirname} does not exist, this run will fail unless it has been previously created. Assuming it would have been created.")
|
51
51
|
a.failure_message(Chef::Exceptions::MissingParentDirectory,
|
52
|
-
"Cannot clone #{
|
52
|
+
"Cannot clone #{new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist")
|
53
53
|
end
|
54
54
|
|
55
55
|
requirements.assert(:all_actions) do |a|
|
56
|
-
a.assertion { !(
|
56
|
+
a.assertion { !(new_resource.revision =~ /^origin\//) }
|
57
57
|
a.failure_message Chef::Exceptions::InvalidRemoteGitReference,
|
58
58
|
"Deploying remote branches is not supported. " +
|
59
59
|
"Specify the remote branch as a local branch for " +
|
60
60
|
"the git repository you're deploying from " +
|
61
|
-
"(ie: '#{
|
61
|
+
"(ie: '#{new_resource.revision.gsub('origin/', '')}' rather than '#{new_resource.revision}')."
|
62
62
|
end
|
63
63
|
|
64
64
|
requirements.assert(:all_actions) do |a|
|
@@ -67,22 +67,22 @@ class Chef
|
|
67
67
|
# if we can't resolve it up front.
|
68
68
|
a.assertion { !target_revision.nil? }
|
69
69
|
a.failure_message Chef::Exceptions::UnresolvableGitReference,
|
70
|
-
"Unable to parse SHA reference for '#{
|
70
|
+
"Unable to parse SHA reference for '#{new_resource.revision}' in repository '#{new_resource.repository}'. " +
|
71
71
|
"Verify your (case-sensitive) repository URL and revision.\n" +
|
72
|
-
"`git ls-remote '#{
|
72
|
+
"`git ls-remote '#{new_resource.repository}' '#{rev_search_pattern}'` output: #{@resolved_reference}"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
def action_checkout
|
77
77
|
if target_dir_non_existent_or_empty?
|
78
78
|
clone
|
79
|
-
if
|
79
|
+
if new_resource.enable_checkout
|
80
80
|
checkout
|
81
81
|
end
|
82
82
|
enable_submodules
|
83
83
|
add_remotes
|
84
84
|
else
|
85
|
-
Chef::Log.debug "#{
|
85
|
+
Chef::Log.debug "#{new_resource} checkout destination #{cwd} already exists or is a non-empty directory"
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -95,11 +95,11 @@ class Chef
|
|
95
95
|
|
96
96
|
def action_sync
|
97
97
|
if existing_git_clone?
|
98
|
-
Chef::Log.debug "#{
|
98
|
+
Chef::Log.debug "#{new_resource} current revision: #{current_resource.revision} target revision: #{target_revision}"
|
99
99
|
unless current_revision_matches_target_revision?
|
100
100
|
fetch_updates
|
101
101
|
enable_submodules
|
102
|
-
Chef::Log.info "#{
|
102
|
+
Chef::Log.info "#{new_resource} updated to revision #{target_revision}"
|
103
103
|
end
|
104
104
|
add_remotes
|
105
105
|
else
|
@@ -120,7 +120,7 @@ class Chef
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def find_current_revision
|
123
|
-
Chef::Log.debug("#{
|
123
|
+
Chef::Log.debug("#{new_resource} finding current git revision")
|
124
124
|
if ::File.exist?(::File.join(cwd, ".git"))
|
125
125
|
# 128 is returned when we're not in a git repo. this is fine
|
126
126
|
result = git("rev-parse", "HEAD", cwd: cwd, returns: [0, 128]).stdout.strip
|
@@ -129,10 +129,10 @@ class Chef
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def add_remotes
|
132
|
-
if
|
133
|
-
|
132
|
+
if new_resource.additional_remotes.length > 0
|
133
|
+
new_resource.additional_remotes.each_pair do |remote_name, remote_url|
|
134
134
|
converge_by("add remote #{remote_name} from #{remote_url}") do
|
135
|
-
Chef::Log.info "#{
|
135
|
+
Chef::Log.info "#{new_resource} adding git remote #{remote_name} = #{remote_url}"
|
136
136
|
setup_remote_tracking_branches(remote_name, remote_url)
|
137
137
|
end
|
138
138
|
end
|
@@ -140,17 +140,17 @@ class Chef
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def clone
|
143
|
-
converge_by("clone from #{
|
144
|
-
remote =
|
143
|
+
converge_by("clone from #{new_resource.repository} into #{cwd}") do
|
144
|
+
remote = new_resource.remote
|
145
145
|
|
146
146
|
clone_cmd = ["clone"]
|
147
147
|
clone_cmd << "-o #{remote}" unless remote == "origin"
|
148
|
-
clone_cmd << "--depth #{
|
149
|
-
clone_cmd << "--no-single-branch" if
|
150
|
-
clone_cmd << "\"#{
|
148
|
+
clone_cmd << "--depth #{new_resource.depth}" if new_resource.depth
|
149
|
+
clone_cmd << "--no-single-branch" if new_resource.depth && git_minor_version >= Gem::Version.new("1.7.10")
|
150
|
+
clone_cmd << "\"#{new_resource.repository}\""
|
151
151
|
clone_cmd << "\"#{cwd}\""
|
152
152
|
|
153
|
-
Chef::Log.info "#{
|
153
|
+
Chef::Log.info "#{new_resource} cloning repo #{new_resource.repository} to #{cwd}"
|
154
154
|
git clone_cmd
|
155
155
|
end
|
156
156
|
end
|
@@ -158,20 +158,20 @@ class Chef
|
|
158
158
|
def checkout
|
159
159
|
sha_ref = target_revision
|
160
160
|
|
161
|
-
converge_by("checkout ref #{sha_ref} branch #{
|
161
|
+
converge_by("checkout ref #{sha_ref} branch #{new_resource.revision}") do
|
162
162
|
# checkout into a local branch rather than a detached HEAD
|
163
|
-
git("branch", "-f",
|
164
|
-
git("checkout",
|
165
|
-
Chef::Log.info "#{
|
163
|
+
git("branch", "-f", new_resource.checkout_branch, sha_ref, cwd: cwd)
|
164
|
+
git("checkout", new_resource.checkout_branch, cwd: cwd)
|
165
|
+
Chef::Log.info "#{new_resource} checked out branch: #{new_resource.revision} onto: #{new_resource.checkout_branch} reference: #{sha_ref}"
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
169
|
def enable_submodules
|
170
|
-
if
|
171
|
-
converge_by("enable git submodules for #{
|
172
|
-
Chef::Log.info "#{
|
170
|
+
if new_resource.enable_submodules
|
171
|
+
converge_by("enable git submodules for #{new_resource}") do
|
172
|
+
Chef::Log.info "#{new_resource} synchronizing git submodules"
|
173
173
|
git("submodule", "sync", cwd: cwd)
|
174
|
-
Chef::Log.info "#{
|
174
|
+
Chef::Log.info "#{new_resource} enabling git submodules"
|
175
175
|
# the --recursive flag means we require git 1.6.5+ now, see CHEF-1827
|
176
176
|
git("submodule", "update", "--init", "--recursive", cwd: cwd)
|
177
177
|
end
|
@@ -179,19 +179,19 @@ class Chef
|
|
179
179
|
end
|
180
180
|
|
181
181
|
def fetch_updates
|
182
|
-
setup_remote_tracking_branches(
|
183
|
-
converge_by("fetch updates for #{
|
182
|
+
setup_remote_tracking_branches(new_resource.remote, new_resource.repository)
|
183
|
+
converge_by("fetch updates for #{new_resource.remote}") do
|
184
184
|
# since we're in a local branch already, just reset to specified revision rather than merge
|
185
185
|
Chef::Log.debug "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}"
|
186
|
-
git("fetch",
|
187
|
-
git("fetch",
|
186
|
+
git("fetch", new_resource.remote, cwd: cwd)
|
187
|
+
git("fetch", new_resource.remote, "--tags", cwd: cwd)
|
188
188
|
git("reset", "--hard", target_revision, cwd: cwd)
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
192
|
def setup_remote_tracking_branches(remote_name, remote_url)
|
193
193
|
converge_by("set up remote tracking branches for #{remote_url} at #{remote_name}") do
|
194
|
-
Chef::Log.debug "#{
|
194
|
+
Chef::Log.debug "#{new_resource} configuring remote tracking branches for repository #{remote_url} " + "at remote #{remote_name}"
|
195
195
|
check_remote_command = ["config", "--get", "remote.#{remote_name}.url"]
|
196
196
|
remote_status = git(check_remote_command, cwd: cwd, returns: [0, 1, 2])
|
197
197
|
case remote_status.exitstatus
|
@@ -219,13 +219,13 @@ class Chef
|
|
219
219
|
end
|
220
220
|
|
221
221
|
def current_revision_matches_target_revision?
|
222
|
-
(
|
222
|
+
(!current_resource.revision.nil?) && (target_revision.strip.to_i(16) == current_resource.revision.strip.to_i(16))
|
223
223
|
end
|
224
224
|
|
225
225
|
def target_revision
|
226
226
|
@target_revision ||= begin
|
227
|
-
if sha_hash?(
|
228
|
-
@target_revision =
|
227
|
+
if sha_hash?(new_resource.revision)
|
228
|
+
@target_revision = new_resource.revision
|
229
229
|
else
|
230
230
|
@target_revision = remote_resolve_reference
|
231
231
|
end
|
@@ -235,7 +235,7 @@ class Chef
|
|
235
235
|
alias :revision_slug :target_revision
|
236
236
|
|
237
237
|
def remote_resolve_reference
|
238
|
-
Chef::Log.debug("#{
|
238
|
+
Chef::Log.debug("#{new_resource} resolving remote reference")
|
239
239
|
# The sha pointed to by an annotated tag is identified by the
|
240
240
|
# '^{}' suffix appended to the tag. In order to resolve
|
241
241
|
# annotated tags, we have to search for "revision*" and
|
@@ -250,11 +250,11 @@ class Chef
|
|
250
250
|
# confusing. We avoid the issue by disallowing the use of
|
251
251
|
# annotated tags named 'HEAD'.
|
252
252
|
if rev_search_pattern != "HEAD"
|
253
|
-
found = find_revision(refs,
|
253
|
+
found = find_revision(refs, new_resource.revision, "^{}")
|
254
254
|
else
|
255
255
|
found = refs_search(refs, "HEAD")
|
256
256
|
end
|
257
|
-
found = find_revision(refs,
|
257
|
+
found = find_revision(refs, new_resource.revision) if found.empty?
|
258
258
|
found.size == 1 ? found.first[0] : nil
|
259
259
|
end
|
260
260
|
|
@@ -274,15 +274,15 @@ class Chef
|
|
274
274
|
end
|
275
275
|
|
276
276
|
def rev_search_pattern
|
277
|
-
if ["", "HEAD"].include?
|
277
|
+
if ["", "HEAD"].include? new_resource.revision
|
278
278
|
"HEAD"
|
279
279
|
else
|
280
|
-
|
280
|
+
new_resource.revision + "*"
|
281
281
|
end
|
282
282
|
end
|
283
283
|
|
284
284
|
def git_ls_remote(rev_pattern)
|
285
|
-
git("ls-remote", "\"#{
|
285
|
+
git("ls-remote", "\"#{new_resource.repository}\"", "\"#{rev_pattern}\"").stdout
|
286
286
|
end
|
287
287
|
|
288
288
|
def refs_search(refs, pattern)
|
@@ -293,28 +293,28 @@ class Chef
|
|
293
293
|
|
294
294
|
def run_options(run_opts = {})
|
295
295
|
env = {}
|
296
|
-
if
|
297
|
-
run_opts[:user] =
|
296
|
+
if new_resource.user
|
297
|
+
run_opts[:user] = new_resource.user
|
298
298
|
# Certain versions of `git` misbehave if git configuration is
|
299
299
|
# inaccessible in $HOME. We need to ensure $HOME matches the
|
300
300
|
# user who is executing `git` not the user running Chef.
|
301
301
|
env["HOME"] = begin
|
302
302
|
require "etc"
|
303
|
-
case
|
303
|
+
case new_resource.user
|
304
304
|
when Integer
|
305
|
-
Etc.getpwuid(
|
305
|
+
Etc.getpwuid(new_resource.user).dir
|
306
306
|
else
|
307
|
-
Etc.getpwnam(
|
307
|
+
Etc.getpwnam(new_resource.user.to_s).dir
|
308
308
|
end
|
309
309
|
rescue ArgumentError # user not found
|
310
|
-
raise Chef::Exceptions::User, "Could not determine HOME for specified user '#{
|
310
|
+
raise Chef::Exceptions::User, "Could not determine HOME for specified user '#{new_resource.user}' for resource '#{new_resource.name}'"
|
311
311
|
end
|
312
312
|
end
|
313
|
-
run_opts[:group] =
|
314
|
-
env["GIT_SSH"] =
|
315
|
-
run_opts[:log_tag] =
|
316
|
-
run_opts[:timeout] =
|
317
|
-
env.merge!(
|
313
|
+
run_opts[:group] = new_resource.group if new_resource.group
|
314
|
+
env["GIT_SSH"] = new_resource.ssh_wrapper if new_resource.ssh_wrapper
|
315
|
+
run_opts[:log_tag] = new_resource.to_s
|
316
|
+
run_opts[:timeout] = new_resource.timeout if new_resource.timeout
|
317
|
+
env.merge!(new_resource.environment) if new_resource.environment
|
318
318
|
run_opts[:environment] = env unless env.empty?
|
319
319
|
run_opts
|
320
320
|
end
|