chef 18.5.0 → 18.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +11 -6
  3. data/chef-universal-mingw-ucrt.gemspec +1 -1
  4. data/chef.gemspec +19 -15
  5. data/lib/chef/application/client.rb +0 -12
  6. data/lib/chef/client.rb +1 -10
  7. data/lib/chef/compliance/default_attributes.rb +2 -2
  8. data/lib/chef/compliance/runner.rb +6 -11
  9. data/lib/chef/cookbook/metadata.rb +1 -1
  10. data/lib/chef/cookbook/remote_file_vendor.rb +1 -3
  11. data/lib/chef/cookbook/synchronizer.rb +0 -5
  12. data/lib/chef/event_dispatch/dispatcher.rb +0 -1
  13. data/lib/chef/exceptions.rb +1 -1
  14. data/lib/chef/file_access_control/unix.rb +9 -9
  15. data/lib/chef/file_content_management/deploy.rb +1 -4
  16. data/lib/chef/mixin/file_class.rb +1 -3
  17. data/lib/chef/mixin/get_source_from_package.rb +1 -1
  18. data/lib/chef/mixin/{homebrew_user.rb → homebrew.rb} +13 -16
  19. data/lib/chef/mixin/openssl_helper.rb +1 -12
  20. data/lib/chef/provider/cookbook_file.rb +1 -1
  21. data/lib/chef/provider/cron.rb +1 -1
  22. data/lib/chef/provider/directory.rb +15 -15
  23. data/lib/chef/provider/file.rb +29 -42
  24. data/lib/chef/provider/git.rb +8 -8
  25. data/lib/chef/provider/group/aix.rb +1 -1
  26. data/lib/chef/provider/group/dscl.rb +1 -1
  27. data/lib/chef/provider/group/gpasswd.rb +2 -2
  28. data/lib/chef/provider/group/groupadd.rb +1 -1
  29. data/lib/chef/provider/group/groupmod.rb +2 -2
  30. data/lib/chef/provider/group/pw.rb +2 -2
  31. data/lib/chef/provider/group/solaris.rb +2 -2
  32. data/lib/chef/provider/group/usermod.rb +2 -2
  33. data/lib/chef/provider/group.rb +1 -1
  34. data/lib/chef/provider/http_request.rb +3 -2
  35. data/lib/chef/provider/ifconfig/aix.rb +1 -1
  36. data/lib/chef/provider/ifconfig/debian.rb +3 -3
  37. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  38. data/lib/chef/provider/ifconfig.rb +1 -1
  39. data/lib/chef/provider/link.rb +10 -10
  40. data/lib/chef/provider/mount/aix.rb +4 -4
  41. data/lib/chef/provider/mount/linux.rb +4 -4
  42. data/lib/chef/provider/mount/mount.rb +11 -11
  43. data/lib/chef/provider/package/apt.rb +11 -2
  44. data/lib/chef/provider/package/bff.rb +3 -3
  45. data/lib/chef/provider/package/chocolatey.rb +2 -2
  46. data/lib/chef/provider/package/dnf/dnf_helper.py +7 -0
  47. data/lib/chef/provider/package/dpkg.rb +3 -3
  48. data/lib/chef/provider/package/freebsd/base.rb +1 -1
  49. data/lib/chef/provider/package/habitat.rb +3 -5
  50. data/lib/chef/provider/package/homebrew.rb +6 -9
  51. data/lib/chef/provider/package/ips.rb +2 -2
  52. data/lib/chef/provider/package/openbsd.rb +2 -3
  53. data/lib/chef/provider/package/pacman.rb +4 -4
  54. data/lib/chef/provider/package/paludis.rb +2 -2
  55. data/lib/chef/provider/package/portage.rb +1 -1
  56. data/lib/chef/provider/package/rpm.rb +2 -2
  57. data/lib/chef/provider/package/rubygems.rb +4 -0
  58. data/lib/chef/provider/package/smartos.rb +2 -2
  59. data/lib/chef/provider/package/snap.rb +2 -2
  60. data/lib/chef/provider/package/solaris.rb +4 -4
  61. data/lib/chef/provider/package/zypper.rb +4 -4
  62. data/lib/chef/provider/package.rb +1 -1
  63. data/lib/chef/provider/registry_key.rb +6 -0
  64. data/lib/chef/provider/remote_directory.rb +5 -5
  65. data/lib/chef/provider/remote_file/http.rb +3 -2
  66. data/lib/chef/provider/remote_file.rb +1 -1
  67. data/lib/chef/provider/route.rb +9 -9
  68. data/lib/chef/provider/service/aix.rb +1 -1
  69. data/lib/chef/provider/service/aixinit.rb +4 -4
  70. data/lib/chef/provider/service/arch.rb +6 -6
  71. data/lib/chef/provider/service/debian.rb +5 -5
  72. data/lib/chef/provider/service/freebsd.rb +7 -7
  73. data/lib/chef/provider/service/gentoo.rb +5 -5
  74. data/lib/chef/provider/service/init.rb +2 -2
  75. data/lib/chef/provider/service/insserv.rb +2 -2
  76. data/lib/chef/provider/service/invokercd.rb +1 -1
  77. data/lib/chef/provider/service/openbsd.rb +7 -7
  78. data/lib/chef/provider/service/redhat.rb +3 -3
  79. data/lib/chef/provider/service/solaris.rb +2 -2
  80. data/lib/chef/provider/service/systemd.rb +2 -2
  81. data/lib/chef/provider/service/upstart.rb +2 -2
  82. data/lib/chef/provider/subversion.rb +8 -8
  83. data/lib/chef/provider/systemd_unit.rb +3 -3
  84. data/lib/chef/provider/template.rb +1 -1
  85. data/lib/chef/provider/user/aix.rb +3 -3
  86. data/lib/chef/provider/user/linux.rb +2 -7
  87. data/lib/chef/provider/user/pw.rb +3 -3
  88. data/lib/chef/provider/user/solaris.rb +7 -7
  89. data/lib/chef/provider/user/windows.rb +5 -0
  90. data/lib/chef/provider/user.rb +8 -7
  91. data/lib/chef/provider/yum_repository.rb +3 -1
  92. data/lib/chef/provider/zypper_repository.rb +1 -1
  93. data/lib/chef/providers.rb +0 -1
  94. data/lib/chef/resource/alternatives.rb +2 -2
  95. data/lib/chef/resource/apt_preference.rb +1 -1
  96. data/lib/chef/resource/apt_repository.rb +90 -15
  97. data/lib/chef/resource/apt_update.rb +3 -3
  98. data/lib/chef/resource/bff_package.rb +1 -1
  99. data/lib/chef/resource/chef_client_config.rb +3 -2
  100. data/lib/chef/resource/chef_sleep.rb +1 -1
  101. data/lib/chef/resource/cookbook_file.rb +1 -1
  102. data/lib/chef/resource/cron/cron.rb +1 -1
  103. data/lib/chef/resource/cron/cron_d.rb +1 -1
  104. data/lib/chef/resource/cron_access.rb +1 -1
  105. data/lib/chef/resource/directory.rb +1 -1
  106. data/lib/chef/resource/dpkg_package.rb +1 -1
  107. data/lib/chef/resource/file/verification/json.rb +1 -1
  108. data/lib/chef/resource/file/verification/systemd_unit.rb +1 -1
  109. data/lib/chef/resource/file/verification/yaml.rb +1 -1
  110. data/lib/chef/resource/file.rb +1 -1
  111. data/lib/chef/resource/freebsd_package.rb +2 -2
  112. data/lib/chef/resource/group.rb +1 -1
  113. data/lib/chef/resource/habitat/habitat_package.rb +1 -1
  114. data/lib/chef/resource/habitat/habitat_sup.rb +9 -9
  115. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +2 -2
  116. data/lib/chef/resource/habitat_install.rb +3 -3
  117. data/lib/chef/resource/homebrew_cask.rb +19 -30
  118. data/lib/chef/resource/homebrew_tap.rb +32 -17
  119. data/lib/chef/resource/homebrew_update.rb +4 -4
  120. data/lib/chef/resource/hostname.rb +10 -11
  121. data/lib/chef/resource/http_request.rb +1 -1
  122. data/lib/chef/resource/ifconfig.rb +1 -1
  123. data/lib/chef/resource/inspec_input.rb +1 -3
  124. data/lib/chef/resource/inspec_waiver.rb +1 -1
  125. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  126. data/lib/chef/resource/ips_package.rb +2 -2
  127. data/lib/chef/resource/kernel_module.rb +2 -2
  128. data/lib/chef/resource/link.rb +1 -1
  129. data/lib/chef/resource/locale.rb +2 -2
  130. data/lib/chef/resource/mount.rb +1 -1
  131. data/lib/chef/resource/notify_group.rb +1 -1
  132. data/lib/chef/resource/ohai.rb +1 -1
  133. data/lib/chef/resource/ohai_hint.rb +1 -1
  134. data/lib/chef/resource/openbsd_package.rb +2 -2
  135. data/lib/chef/resource/package.rb +1 -1
  136. data/lib/chef/resource/pacman_package.rb +1 -1
  137. data/lib/chef/resource/paludis_package.rb +1 -1
  138. data/lib/chef/resource/portage_package.rb +1 -1
  139. data/lib/chef/resource/reboot.rb +1 -1
  140. data/lib/chef/resource/registry_key.rb +18 -0
  141. data/lib/chef/resource/remote_directory.rb +1 -1
  142. data/lib/chef/resource/remote_file.rb +1 -1
  143. data/lib/chef/resource/rhsm_errata.rb +1 -1
  144. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  145. data/lib/chef/resource/rhsm_register.rb +1 -1
  146. data/lib/chef/resource/rhsm_repo.rb +4 -3
  147. data/lib/chef/resource/rhsm_subscription.rb +9 -8
  148. data/lib/chef/resource/route.rb +1 -1
  149. data/lib/chef/resource/rpm_package.rb +1 -1
  150. data/lib/chef/resource/scm/git.rb +1 -1
  151. data/lib/chef/resource/scm/subversion.rb +1 -1
  152. data/lib/chef/resource/selinux/common_helpers.rb +1 -1
  153. data/lib/chef/resource/selinux_boolean.rb +1 -1
  154. data/lib/chef/resource/selinux_fcontext.rb +3 -3
  155. data/lib/chef/resource/selinux_install.rb +1 -1
  156. data/lib/chef/resource/selinux_login.rb +1 -1
  157. data/lib/chef/resource/selinux_module.rb +5 -5
  158. data/lib/chef/resource/selinux_permissive.rb +2 -2
  159. data/lib/chef/resource/selinux_port.rb +2 -2
  160. data/lib/chef/resource/selinux_state.rb +2 -2
  161. data/lib/chef/resource/selinux_user.rb +1 -1
  162. data/lib/chef/resource/smartos_package.rb +2 -2
  163. data/lib/chef/resource/snap_package.rb +1 -1
  164. data/lib/chef/resource/solaris_package.rb +1 -1
  165. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  166. data/lib/chef/resource/sudo.rb +5 -5
  167. data/lib/chef/resource/support/client.erb +3 -2
  168. data/lib/chef/resource/swap_file.rb +6 -6
  169. data/lib/chef/resource/sysctl.rb +5 -5
  170. data/lib/chef/resource/systemd_unit.rb +1 -1
  171. data/lib/chef/resource/template.rb +1 -1
  172. data/lib/chef/resource/timezone.rb +5 -5
  173. data/lib/chef/resource/user/aix_user.rb +2 -2
  174. data/lib/chef/resource/user/linux_user.rb +2 -2
  175. data/lib/chef/resource/user/pw_user.rb +2 -2
  176. data/lib/chef/resource/user/solaris_user.rb +2 -2
  177. data/lib/chef/resource/user_ulimit.rb +1 -1
  178. data/lib/chef/resource/yum_repository.rb +1 -1
  179. data/lib/chef/resource/zypper_package.rb +2 -2
  180. data/lib/chef/resource/zypper_repository.rb +2 -2
  181. data/lib/chef/resource.rb +1 -0
  182. data/lib/chef/resource_inspector.rb +25 -7
  183. data/lib/chef/resource_reporter.rb +1 -0
  184. data/lib/chef/run_lock.rb +0 -3
  185. data/lib/chef/scan_access_control.rb +6 -6
  186. data/lib/chef/util/backup.rb +1 -1
  187. data/lib/chef/util/diff.rb +1 -14
  188. data/lib/chef/util/file_edit.rb +4 -4
  189. data/lib/chef/util/powershell/ps_credential.rb +10 -0
  190. data/lib/chef/version.rb +1 -1
  191. data/lib/chef/win32/registry.rb +5 -1
  192. data/lib/chef/win32/security.rb +9 -0
  193. data/lib/chef.rb +0 -2
  194. data/spec/functional/assets/yumrepo-empty/repodata/repomd.xml +6 -6
  195. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  196. data/spec/functional/resource/registry_spec.rb +276 -609
  197. data/spec/integration/client/open_ssl_spec.rb +1 -1
  198. data/spec/spec_helper.rb +1 -0
  199. data/spec/support/chef_helpers.rb +2 -2
  200. data/spec/support/platform_helpers.rb +8 -0
  201. data/spec/support/shared/functional/file_resource.rb +3 -3
  202. data/spec/tiny_server.rb +5 -2
  203. data/spec/unit/mixin/homebrew_spec.rb +118 -0
  204. data/spec/unit/provider/apt_repository_spec.rb +14 -9
  205. data/spec/unit/provider/package/chocolatey_spec.rb +1 -1
  206. data/spec/unit/provider/package/homebrew_spec.rb +4 -1
  207. data/spec/unit/provider/registry_key_spec.rb +18 -17
  208. data/spec/unit/provider/route_spec.rb +4 -6
  209. data/spec/unit/provider/user/windows_spec.rb +1 -0
  210. data/spec/unit/resource/rhsm_repo_spec.rb +0 -1
  211. data/spec/unit/resource/rhsm_subscription_spec.rb +0 -2
  212. data/spec/unit/resource_inspector_spec.rb +36 -0
  213. data/spec/unit/util/powershell/ps_credential_spec.rb +6 -0
  214. metadata +36 -44
  215. data/lib/chef/file_content_management/deploy/target_io.rb +0 -29
  216. data/lib/chef/provider/.gitkeep +0 -0
  217. data/lib/chef/provider/package/snap_tm.rb +0 -79
  218. data/lib/chef/resource/.gitkeep +0 -0
  219. data/lib/chef/target_io/dir.rb +0 -12
  220. data/lib/chef/target_io/etc.rb +0 -16
  221. data/lib/chef/target_io/file.rb +0 -12
  222. data/lib/chef/target_io/fileutils.rb +0 -12
  223. data/lib/chef/target_io/http.rb +0 -22
  224. data/lib/chef/target_io/io.rb +0 -12
  225. data/lib/chef/target_io/shadow.rb +0 -44
  226. data/lib/chef/target_io/train/dir.rb +0 -69
  227. data/lib/chef/target_io/train/etc.rb +0 -112
  228. data/lib/chef/target_io/train/file.rb +0 -219
  229. data/lib/chef/target_io/train/fileutils.rb +0 -220
  230. data/lib/chef/target_io/train/http.rb +0 -117
  231. data/lib/chef/target_io/train/io.rb +0 -13
  232. data/lib/chef/target_io/train/shadow.rb +0 -52
  233. data/lib/chef/target_io/train_compat.rb +0 -7
  234. data/lib/chef/target_io.rb +0 -9
  235. data/spec/unit/mixin/homebrew_user_spec.rb +0 -119
  236. /data/spec/functional/assets/yumrepo-empty/repodata/{01a3b489a465bcac22a43492163df43451dc6ce47d27f66de289756b91635523-filelists.sqlite.bz2 → 01a3b-filelists.sqlite.bz2} +0 -0
  237. /data/spec/functional/assets/yumrepo-empty/repodata/{401dc19bda88c82c403423fb835844d64345f7e95f5b9835888189c03834cc93-filelists.xml.gz → 401dc-filelists.xml.gz} +0 -0
  238. /data/spec/functional/assets/yumrepo-empty/repodata/{5dc1e6e73c84803f059bb3065e684e56adfc289a7e398946574d79dac6643945-primary.sqlite.bz2 → 5dc1e-primary.sqlite.bz2} +0 -0
  239. /data/spec/functional/assets/yumrepo-empty/repodata/{6bf9672d0862e8ef8b8ff05a2fd0208a922b1f5978e6589d87944c88259cb670-other.xml.gz → 6bf96-other.xml.gz} +0 -0
  240. /data/spec/functional/assets/yumrepo-empty/repodata/{7c36572015e075add2b38b900837bcdbb8a504130ddff49b2351a7fc0affa3d4-other.sqlite.bz2 → 7c365-other.sqlite.bz2} +0 -0
  241. /data/spec/functional/assets/yumrepo-empty/repodata/{dabe2ce5481d23de1f4f52bdcfee0f9af98316c9e0de2ce8123adeefa0dd08b9-primary.xml.gz → dabe2-primary.xml.gz} +0 -0
@@ -21,7 +21,7 @@ class Chef
21
21
  class Resource
22
22
  class RhsmSubscription < Chef::Resource
23
23
 
24
- provides(:rhsm_subscription, target_mode: true) { true }
24
+ provides(:rhsm_subscription) { true }
25
25
 
26
26
  description "Use the **rhsm_subscription** resource to add or remove Red Hat Subscription Manager subscriptions from your host. This can be used when a host's activation_key does not attach all necessary subscriptions to your host."
27
27
  introduced "14.0"
@@ -50,9 +50,10 @@ class Chef
50
50
 
51
51
  action_class do
52
52
  def subscription_attached?(subscription)
53
- cmd = "subscription-manager list --consumed | grep #{subscription}"
54
- stdout = shell_out(cmd, env: { LANG: "en_US" }).stdout
55
- !stdout.match(/Pool ID:\s+#{subscription}$/).nil?
53
+ # FIXME: use shell_out
54
+ cmd = Mixlib::ShellOut.new("subscription-manager list --consumed | grep #{subscription}", env: { LANG: "en_US" })
55
+ cmd.run_command
56
+ !cmd.stdout.match(/Pool ID:\s+#{subscription}$/).nil?
56
57
  end
57
58
 
58
59
  def serials_by_pool
@@ -60,10 +61,10 @@ class Chef
60
61
  pool = nil
61
62
  serial = nil
62
63
 
63
- cmd = "subscription-manager list --consumed"
64
- stdout = shell_out(cmd, env: { LANG: "en_US" }).stdout
65
-
66
- stdout.lines.each do |line|
64
+ # FIXME: use shell_out
65
+ cmd = Mixlib::ShellOut.new("subscription-manager list --consumed", env: { LANG: "en_US" })
66
+ cmd.run_command
67
+ cmd.stdout.lines.each do |line|
67
68
  line.strip!
68
69
  key, value = line.split(/:\s+/, 2)
69
70
  next unless ["Pool ID", "Serial"].include?(key)
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class Route < Chef::Resource
25
25
 
26
- provides :route, target_mode: true
26
+ provides :route
27
27
 
28
28
  default_action :add
29
29
  allowed_actions :add, :delete
@@ -22,7 +22,7 @@ class Chef
22
22
  class Resource
23
23
  class RpmPackage < Chef::Resource::Package
24
24
 
25
- provides :rpm_package, target_mode: true
25
+ provides :rpm_package
26
26
 
27
27
  allowed_actions :install, :upgrade, :remove
28
28
 
@@ -23,7 +23,7 @@ class Chef
23
23
  class Git < Chef::Resource
24
24
  use "scm"
25
25
 
26
- provides :git, target_mode: true
26
+ provides :git
27
27
 
28
28
  description "Use the **git** resource to manage source control resources that exist in a git repository. git version 1.6.5 (or higher) is required to use all of the functionality in the git resource."
29
29
  examples <<~DOC
@@ -24,7 +24,7 @@ class Chef
24
24
  class Subversion < Chef::Resource
25
25
  use "scm"
26
26
 
27
- provides :subversion, target_mode: true
27
+ provides :subversion
28
28
 
29
29
  description "Use the **subversion** resource to manage source control resources that exist in a Subversion repository. Warning: The subversion resource has known bugs and may not work as expected. For more information see Chef GitHub issues, particularly [#4050](https://github.com/chef/chef/issues/4050) and [#4257](https://github.com/chef/chef/issues/4257)."
30
30
  examples <<~DOC
@@ -40,7 +40,7 @@ class Chef
40
40
  def selinux_activate_required?
41
41
  return false unless platform_family?("debian")
42
42
 
43
- !TargetIO::File.read("/etc/default/grub").match?("security=selinux")
43
+ !File.read("/etc/default/grub").match?("security=selinux")
44
44
  end
45
45
  end
46
46
  end
@@ -20,7 +20,7 @@ class Chef
20
20
  class SelinuxBoolean < Chef::Resource
21
21
  unified_mode true
22
22
 
23
- provides :selinux_boolean, target_mode: true
23
+ provides :selinux_boolean
24
24
 
25
25
  description "Use **selinux_boolean** resource to set SELinux boolean values."
26
26
  introduced "18.0"
@@ -20,7 +20,7 @@ class Chef
20
20
  class SelinuxFcontext < Chef::Resource
21
21
  unified_mode true
22
22
 
23
- provides :selinux_fcontext, target_mode: true
23
+ provides :selinux_fcontext
24
24
 
25
25
  description "Use the **selinux_fcontext** resource to set the SELinux context of files using the `semanage fcontext` command."
26
26
  introduced "18.0"
@@ -95,7 +95,7 @@ class Chef
95
95
  # if path is not absolute, ignore it and search everything
96
96
  common = "/" if common[0] != "/"
97
97
 
98
- if ::TargetIO::File.exist? common
98
+ if ::File.exist? common
99
99
  shell_out!("find #{common.shellescape} -ignore_readdir_race -regextype posix-egrep -regex #{spec.shellescape} -prune -print0 | xargs -0 restorecon -iRv")
100
100
  end
101
101
  end
@@ -157,4 +157,4 @@ class Chef
157
157
  end
158
158
  end
159
159
  end
160
- end
160
+ end
@@ -18,7 +18,7 @@ class Chef
18
18
  class SelinuxInstall < Chef::Resource
19
19
  unified_mode true
20
20
 
21
- provides :selinux_install, target_mode: true
21
+ provides :selinux_install
22
22
 
23
23
  description "Use **selinux_install** resource to encapsulates the set of selinux packages to install in order to manage selinux. It also ensures the directory `/etc/selinux` is created."
24
24
  introduced "18.0"
@@ -19,7 +19,7 @@ class Chef
19
19
  class SelinuxLogin < Chef::Resource
20
20
  unified_mode true
21
21
 
22
- provides :selinux_login, target_mode: true
22
+ provides :selinux_login
23
23
 
24
24
  description "Use the **selinux_login** resource to add, update, or remove SELinux user to OS login mappings."
25
25
  introduced "18.1"
@@ -18,7 +18,7 @@ class Chef
18
18
  class SelinuxModule < Chef::Resource
19
19
  unified_mode true
20
20
 
21
- provides :selinux_module, target_mode: true
21
+ provides :selinux_module
22
22
 
23
23
  description "Use **selinux_module** module resource to create an SELinux policy module from a cookbook file or content provided as a string."
24
24
  introduced "18.0"
@@ -103,7 +103,7 @@ class Chef
103
103
  notifies :run, "execute[Install SELinux module '#{selinux_module_filepath("pp")}']", :immediately
104
104
  end
105
105
 
106
- raise "Compilation must have failed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::TargetIO::File.exist?(selinux_module_filepath("pp"))
106
+ raise "Compilation must have failed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::File.exist?(selinux_module_filepath("pp"))
107
107
 
108
108
  execute "Install SELinux module '#{selinux_module_filepath("pp")}'" do
109
109
  command "semodule --install '#{selinux_module_filepath("pp")}'"
@@ -113,7 +113,7 @@ class Chef
113
113
 
114
114
  action :delete, description: "Remove module source files from `/etc/selinux/local`." do
115
115
  %w{fc if pp te}.each do |type|
116
- next unless ::TargetIO::File.exist?(selinux_module_filepath(type))
116
+ next unless ::File.exist?(selinux_module_filepath(type))
117
117
 
118
118
  file selinux_module_filepath(type) do
119
119
  action :delete
@@ -122,7 +122,7 @@ class Chef
122
122
  end
123
123
 
124
124
  action :install, description: "Install a compiled module into the system." do
125
- raise "Module must be compiled before it can be installed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::TargetIO::File.exist?(selinux_module_filepath("pp"))
125
+ raise "Module must be compiled before it can be installed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::File.exist?(selinux_module_filepath("pp"))
126
126
 
127
127
  unless list_installed_modules.include? new_resource.module_name
128
128
  converge_by "Install SELinux module #{selinux_module_filepath("pp")}" do
@@ -140,4 +140,4 @@ class Chef
140
140
  end
141
141
  end
142
142
  end
143
- end
143
+ end
@@ -18,7 +18,7 @@ class Chef
18
18
  class SelinuxPermissive < Chef::Resource
19
19
  unified_mode true
20
20
 
21
- provides :selinux_permissive, target_mode: true
21
+ provides :selinux_permissive
22
22
 
23
23
  description "Use the **selinux_permissive** resource to allow some domains to misbehave without stopping them. This is not as good as setting specific policies, but better than disabling SELinux entirely."
24
24
  introduced "18.0"
@@ -61,4 +61,4 @@ class Chef
61
61
  end
62
62
  end
63
63
  end
64
- end
64
+ end
@@ -19,7 +19,7 @@ class Chef
19
19
  class SelinuxPort < Chef::Resource
20
20
  unified_mode true
21
21
 
22
- provides :selinux_port, target_mode: true
22
+ provides :selinux_port
23
23
 
24
24
  description "Use the **selinux_port** resource to assign a network port to a specific SELinux context. For example, running a web server on a non-standard port."
25
25
  introduced "18.0"
@@ -115,4 +115,4 @@ class Chef
115
115
 
116
116
  end
117
117
  end
118
- end
118
+ end
@@ -19,7 +19,7 @@ class Chef
19
19
  class SelinuxState < Chef::Resource
20
20
  unified_mode true
21
21
 
22
- provides :selinux_state, target_mode: true
22
+ provides :selinux_state
23
23
 
24
24
  description "Use **selinux_state** resource to manages the SELinux state on the system. It does this by using the `setenforce` command and rendering the `/etc/selinux/config` file from a template."
25
25
  introduced "18.0"
@@ -163,4 +163,4 @@ class Chef
163
163
  end
164
164
  end
165
165
  end
166
- end
166
+ end
@@ -19,7 +19,7 @@ class Chef
19
19
  class SelinuxUser < Chef::Resource
20
20
  unified_mode true
21
21
 
22
- provides :selinux_user, target_mode: true
22
+ provides :selinux_user
23
23
 
24
24
  description "Use the **selinux_user** resource to add, update, or remove SELinux users."
25
25
  introduced "18.1"
@@ -22,8 +22,8 @@ class Chef
22
22
  class Resource
23
23
  class SmartosPackage < Chef::Resource::Package
24
24
 
25
- provides :smartos_package, target_mode: true
26
- provides :package, platform_family: "smartos", target_mode: true
25
+ provides :smartos_package
26
+ provides :package, platform_family: "smartos"
27
27
 
28
28
  description "Use the **smartos_package** resource to manage packages for the SmartOS platform."
29
29
 
@@ -22,7 +22,7 @@ class Chef
22
22
  class Resource
23
23
  class SnapPackage < Chef::Resource::Package
24
24
 
25
- provides :snap_package, target_mode: true
25
+ provides :snap_package
26
26
 
27
27
  description "Use the **snap_package** resource to manage snap packages on Debian and Ubuntu platforms."
28
28
  introduced "15.0"
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class SolarisPackage < Chef::Resource::Package
25
25
 
26
- provides :solaris_package, target_mode: true
26
+ provides :solaris_package
27
27
 
28
28
  description "Use the **solaris_package** resource to manage packages on the Solaris platform."
29
29
 
@@ -24,7 +24,7 @@ class Chef
24
24
  class Resource
25
25
  class SshKnownHostsEntry < Chef::Resource
26
26
 
27
- provides :ssh_known_hosts_entry, target_mode: true
27
+ provides :ssh_known_hosts_entry
28
28
 
29
29
  description "Use the **ssh_known_hosts_entry** resource to add an entry for the specified host in /etc/ssh/ssh_known_hosts or a user's known hosts file if specified."
30
30
  introduced "14.3"
@@ -25,7 +25,7 @@ class Chef
25
25
  class Resource
26
26
  class Sudo < Chef::Resource
27
27
 
28
- provides(:sudo, target_mode: true) { true }
28
+ provides(:sudo) { true }
29
29
 
30
30
  description "Use the **sudo** resource to add or remove individual sudo entries using sudoers.d files."\
31
31
  " Sudo version 1.7.2 or newer is required to use the sudo resource, as it relies on the"\
@@ -216,11 +216,11 @@ class Chef
216
216
  target = "#{new_resource.config_prefix}/sudoers.d/"
217
217
  directory(target)
218
218
 
219
- Chef::Log.warn("#{new_resource.filename} will be rendered, but will not take effect because the #{new_resource.config_prefix}/sudoers config lacks the includedir directive that loads configs from #{new_resource.config_prefix}/sudoers.d/!") if ::TargetIO::File.readlines("#{new_resource.config_prefix}/sudoers").grep(/includedir/).empty?
219
+ Chef::Log.warn("#{new_resource.filename} will be rendered, but will not take effect because the #{new_resource.config_prefix}/sudoers config lacks the includedir directive that loads configs from #{new_resource.config_prefix}/sudoers.d/!") if ::File.readlines("#{new_resource.config_prefix}/sudoers").grep(/includedir/).empty?
220
220
  file_path = "#{target}#{new_resource.filename}"
221
221
 
222
222
  if new_resource.template
223
- Chef::Log.trace("Template property provided, all other properties ignored.")
223
+ logger.trace("Template property provided, all other properties ignored.")
224
224
 
225
225
  template file_path do
226
226
  source new_resource.template
@@ -279,13 +279,13 @@ class Chef
279
279
  end
280
280
 
281
281
  def visudo_present?
282
- return true if ::TargetIO::File.exist?(new_resource.visudo_binary)
282
+ return true if ::File.exist?(new_resource.visudo_binary)
283
283
 
284
284
  Chef::Log.warn("The visudo binary cannot be found at '#{new_resource.visudo_binary}'. Skipping sudoer file validation. If visudo is on this system you can specify the path using the 'visudo_binary' property.")
285
285
  end
286
286
 
287
287
  def visudo_content(path)
288
- if ::TargetIO::File.exist?(path)
288
+ if ::File.exist?(path)
289
289
  "cat #{new_resource.config_prefix}/sudoers | #{new_resource.visudo_binary} -cf - && #{new_resource.visudo_binary} -cf %{path}"
290
290
  else
291
291
  "cat #{new_resource.config_prefix}/sudoers %{path} | #{new_resource.visudo_binary} -cf -"
@@ -16,12 +16,13 @@
16
16
  @policy_group
17
17
  @policy_name
18
18
  @rubygems_url
19
- @ssl_verify_mode
20
- @policy_persist_run_list).each do |prop| -%>
19
+ @ssl_verify_mode).each do |prop| -%>
21
20
  <% next if instance_variable_get(prop).nil? || instance_variable_get(prop).empty? -%>
22
21
  <%=prop.delete_prefix("@") %> <%= instance_variable_get(prop).inspect %>
23
22
  <% end -%>
23
+ <%# boolean properties are neither .nil? nor respond to .empty? so they are included below %>
24
24
  minimal_ohai <%= @minimal_ohai.inspect %>
25
+ policy_persist_run_list <%= @policy_persist_run_list.inspect %>
25
26
  <%# ohai_disabled_plugins and ohai_optional_plugins properties don't match the config value perfectly-%>
26
27
  <% %w(@ohai_disabled_plugins
27
28
  @ohai_optional_plugins).each do |prop| -%>
@@ -21,7 +21,7 @@ class Chef
21
21
  class Resource
22
22
  class SwapFile < Chef::Resource
23
23
 
24
- provides(:swap_file, target_mode: true) { true }
24
+ provides(:swap_file) { true }
25
25
 
26
26
  description "Use the **swap_file** resource to create or delete swap files on Linux systems, and optionally to manage the swappiness configuration for a host."
27
27
  introduced "14.0"
@@ -84,7 +84,7 @@ class Chef
84
84
 
85
85
  action :remove, description: "Remove a swapfile and disable swap." do
86
86
  swapoff if swap_enabled?
87
- remove_swapfile if ::TargetIO::File.exist?(new_resource.path)
87
+ remove_swapfile if ::File.exist?(new_resource.path)
88
88
  end
89
89
 
90
90
  action_class do
@@ -129,7 +129,7 @@ class Chef
129
129
 
130
130
  def remove_swapfile
131
131
  converge_by "remove swap file #{new_resource.path}" do
132
- ::TargetIO::FileUtils.rm(new_resource.path)
132
+ ::FileUtils.rm(new_resource.path)
133
133
  end
134
134
  end
135
135
 
@@ -186,7 +186,7 @@ class Chef
186
186
  def compatible_kernel
187
187
  fallocate_location = shell_out("which fallocate").stdout
188
188
  Chef::Log.debug("#{new_resource} fallocate location is '#{fallocate_location}'")
189
- ::TargetIO::File.exist?(fallocate_location.chomp)
189
+ ::File.exist?(fallocate_location.chomp)
190
190
  end
191
191
 
192
192
  def compatible_filesystem?
@@ -205,7 +205,7 @@ class Chef
205
205
 
206
206
  def persist
207
207
  fstab = "/etc/fstab"
208
- contents = ::TargetIO::File.readlines(fstab)
208
+ contents = ::File.readlines(fstab)
209
209
  addition = "#{new_resource.path} swap swap defaults 0 0"
210
210
 
211
211
  if contents.any? { |line| line.strip == addition }
@@ -214,7 +214,7 @@ class Chef
214
214
  Chef::Log.info("#{new_resource} adding entry to #{fstab} for #{new_resource.path}")
215
215
 
216
216
  contents << "#{addition}\n"
217
- ::TargetIO::File.open(fstab, "w") { |f| f.write(contents.join("")) }
217
+ ::File.open(fstab, "w") { |f| f.write(contents.join("")) }
218
218
  end
219
219
  end
220
220
  end
@@ -21,8 +21,8 @@ class Chef
21
21
  class Resource
22
22
  class Sysctl < Chef::Resource
23
23
 
24
- provides(:sysctl, target_mode: true) { true }
25
- provides(:sysctl_param, target_mode: true) { true }
24
+ provides(:sysctl) { true }
25
+ provides(:sysctl_param) { true }
26
26
 
27
27
  description "Use the **sysctl** resource to set or remove kernel parameters using the `sysctl` command line tool and configuration files in the system's `sysctl.d` directory. Configuration files managed by this resource are named `99-chef-KEYNAME.conf`."
28
28
  examples <<~DOC
@@ -152,7 +152,7 @@ class Chef
152
152
 
153
153
  action :remove, description: "Remove the kernel parameter and update the `sysctl` settings." do
154
154
  # only converge the resource if the file actually exists to delete
155
- if ::TargetIO::File.exist?("#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr("/", ".")}.conf")
155
+ if ::File.exist?("#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr("/", ".")}.conf")
156
156
  converge_by "removing sysctl config at #{new_resource.conf_dir}/99-chef-#{new_resource.key.tr("/", ".")}.conf" do
157
157
  file "#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr("/", ".")}.conf" do
158
158
  action :delete
@@ -216,9 +216,9 @@ class Chef
216
216
  # return the value. Raise in case this conf file needs to be created
217
217
  # or updated
218
218
  def get_sysctld_value(key)
219
- raise unless ::TargetIO::File.exist?("/etc/sysctl.d/99-chef-#{key.tr("/", ".")}.conf")
219
+ raise unless ::File.exist?("/etc/sysctl.d/99-chef-#{key.tr("/", ".")}.conf")
220
220
 
221
- k, v = ::Target_IO::File.read("/etc/sysctl.d/99-chef-#{key.tr("/", ".")}.conf").match(/(.*) = (.*)/).captures
221
+ k, v = ::File.read("/etc/sysctl.d/99-chef-#{key.tr("/", ".")}.conf").match(/(.*) = (.*)/).captures
222
222
  raise "Unknown sysctl key!" if k.nil?
223
223
  raise "Unknown sysctl value!" if v.nil?
224
224
 
@@ -24,7 +24,7 @@ class Chef
24
24
  class Resource
25
25
  class SystemdUnit < Chef::Resource
26
26
 
27
- provides(:systemd_unit, target_mode: true) { true }
27
+ provides(:systemd_unit) { true }
28
28
 
29
29
  description "Use the **systemd_unit** resource to create, manage, and run [systemd units](https://www.freedesktop.org/software/systemd/man/systemd.html#Concepts)."
30
30
  introduced "12.11"
@@ -35,7 +35,7 @@ class Chef
35
35
  # template resource follow the same file specificity rules as the remote_file and file resources.
36
36
  class Template < Chef::Resource::File
37
37
 
38
- provides :template, target_mode: true
38
+ provides :template
39
39
 
40
40
  include Chef::Mixin::Securable
41
41
 
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class Timezone < Chef::Resource
25
25
 
26
- provides :timezone, target_mode: true
26
+ provides :timezone
27
27
 
28
28
  description "Use the **timezone** resource to change the system timezone on Windows, Linux, and macOS hosts. Timezones are specified in tz database format, with a complete list of available TZ values for Linux and macOS here: <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>. On Windows systems run `tzutil /l` for a complete list of valid timezones."
29
29
  introduced "14.6"
@@ -96,10 +96,10 @@ class Chef
96
96
  # @since 16.5
97
97
  # @return [String] timezone id
98
98
  def current_rhel_tz
99
- return nil unless ::TargetIO::File.exist?("/etc/sysconfig/clock")
99
+ return nil unless ::File.exist?("/etc/sysconfig/clock")
100
100
 
101
101
  # https://rubular.com/r/aoj01L3bKBM7wh
102
- /ZONE="(.*)"/.match(::TargetIO::File.read("/etc/sysconfig/clock"))[1]
102
+ /ZONE="(.*)"/.match(::File.read("/etc/sysconfig/clock"))[1]
103
103
  end
104
104
 
105
105
  load_current_value do
@@ -155,13 +155,13 @@ class Chef
155
155
  execute "tzdata-update" do
156
156
  command "/usr/sbin/tzdata-update"
157
157
  action :nothing
158
- only_if { ::TargetIO::File.executable?("/usr/sbin/tzdata-update") }
158
+ only_if { ::File.executable?("/usr/sbin/tzdata-update") }
159
159
  subscribes :run, "file[/etc/sysconfig/clock]", :immediately
160
160
  end
161
161
 
162
162
  link "/etc/localtime" do
163
163
  to "/usr/share/zoneinfo/#{new_resource.timezone}"
164
- not_if { ::TargetIO::File.executable?("/usr/sbin/tzdata-update") }
164
+ not_if { ::File.executable?("/usr/sbin/tzdata-update") }
165
165
  end
166
166
  when "mac_os_x"
167
167
  shell_out!(["sudo", "systemsetup", "-settimezone", new_resource.timezone])
@@ -22,8 +22,8 @@ class Chef
22
22
  class User
23
23
  class AixUser < Chef::Resource::User
24
24
 
25
- provides :aix_user, target_mode: true
26
- provides :user, os: "aix", target_mode: true
25
+ provides :aix_user
26
+ provides :user, os: "aix"
27
27
  end
28
28
  end
29
29
  end
@@ -22,8 +22,8 @@ class Chef
22
22
  class User
23
23
  class LinuxUser < Chef::Resource::User
24
24
 
25
- provides :linux_user, target_mode: true
26
- provides :user, os: "linux", target_mode: true
25
+ provides :linux_user
26
+ provides :user, os: "linux"
27
27
 
28
28
  end
29
29
  end
@@ -22,8 +22,8 @@ class Chef
22
22
  class User
23
23
  class PwUser < Chef::Resource::User
24
24
 
25
- provides :pw_user, target_mode: true
26
- provides :user, os: "freebsd", target_mode: true
25
+ provides :pw_user
26
+ provides :user, os: "freebsd"
27
27
  end
28
28
  end
29
29
  end
@@ -22,8 +22,8 @@ class Chef
22
22
  class User
23
23
  class SolarisUser < Chef::Resource::User
24
24
 
25
- provides :solaris_user, target_mode: true
26
- provides :user, os: %w{omnios solaris2}, target_mode: true
25
+ provides :solaris_user
26
+ provides :user, os: %w{omnios solaris2}
27
27
  end
28
28
  end
29
29
  end
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class UserUlimit < Chef::Resource
25
25
 
26
- provides :user_ulimit, target_mode: true
26
+ provides :user_ulimit
27
27
 
28
28
  description "Use the **user_ulimit** resource to create individual ulimit files that are installed into the `/etc/security/limits.d/` directory."
29
29
  introduced "16.0"
@@ -22,7 +22,7 @@ class Chef
22
22
  class Resource
23
23
  class YumRepository < Chef::Resource
24
24
 
25
- provides(:yum_repository, target_mode: true) { true }
25
+ provides(:yum_repository) { true }
26
26
 
27
27
  description "Use the **yum_repository** resource to manage a Yum repository configuration file located at `/etc/yum.repos.d/repositoryid.repo` on the local machine. This configuration file specifies which repositories to reference, how to handle cached data, etc."
28
28
  introduced "12.14"
@@ -22,8 +22,8 @@ class Chef
22
22
  class Resource
23
23
  class ZypperPackage < Chef::Resource::Package
24
24
 
25
- provides :zypper_package, target_mode: true
26
- provides :package, platform_family: "suse", target_mode: true
25
+ provides :zypper_package
26
+ provides :package, platform_family: "suse"
27
27
 
28
28
  description "Use the **zypper_package** resource to install, upgrade, and remove packages with Zypper for the SUSE Enterprise and openSUSE platforms."
29
29
  examples <<~DOC
@@ -22,8 +22,8 @@ class Chef
22
22
  class Resource
23
23
  class ZypperRepository < Chef::Resource
24
24
 
25
- provides(:zypper_repository, target_mode: true) { true }
26
- provides(:zypper_repo, target_mode: true) { true } # legacy cookbook compatibility
25
+ provides(:zypper_repository) { true }
26
+ provides(:zypper_repo) { true } # legacy cookbook compatibility
27
27
 
28
28
  description "Use the **zypper_repository** resource to create Zypper package repositories on SUSE Enterprise Linux and openSUSE systems. This resource maintains full compatibility with the **zypper_repository** resource in the existing **zypper** cookbook."
29
29
  introduced "13.3"
data/lib/chef/resource.rb CHANGED
@@ -620,6 +620,7 @@ class Chef
620
620
  # Reporting endpoint doesn't accept a negative resource duration so set it to 0.
621
621
  # A negative value can occur when a resource changes the system time backwards
622
622
  @elapsed_time = 0 if @elapsed_time < 0
623
+
623
624
  events.resource_completed(self)
624
625
  end
625
626
 
@@ -79,19 +79,37 @@ class Chef
79
79
  Array(equal_to).map(&:inspect)
80
80
  end
81
81
 
82
+ def self.load_from_resources(resources, complete)
83
+ resources.each_with_object({}) do |r, res|
84
+ pth = r["full_path"]
85
+ # Here we do some magic to extract resources from files where there are multiple resources
86
+ # in a file - to do this, we load the file, and take the delta of which resources
87
+ # exist in object space
88
+ existing_classes = []
89
+ ObjectSpace.each_object(Class).select { |k| k < Chef::Resource }.each { |klass| existing_classes << klass }
90
+ # Load the set of resources from this file
91
+ Chef::Resource::LWRPBase.build_from_file(name, pth, Chef::RunContext.new(Chef::Node.new, nil, nil))
92
+ # Finally, process every new class added to the object space by that
93
+ ObjectSpace.each_object(Class).select { |k| k < Chef::Resource }.each do |klass|
94
+ unless existing_classes.include?(klass)
95
+ # Skip over anything which creates resources that start with exactly this - that happens
96
+ # because if there is no non-classed resource in here, LWRPBase.build_from_file builds a
97
+ # dummy object from it - we don't need that polluting out output!
98
+ next if klass.resource_name.start_with?("Chef__ResourceInspector")
99
+
100
+ res[klass.resource_name] = extract_resource(klass, complete)
101
+ end
102
+ end
103
+ end
104
+ end
105
+
82
106
  def self.extract_cookbook(path, complete)
83
107
  path = File.expand_path(path)
84
108
  dir, name = File.split(path)
85
109
  Chef::Cookbook::FileVendor.fetch_from_disk(path)
86
110
  loader = Chef::CookbookLoader.new(dir)
87
111
  cookbook = loader.load_cookbook(name)
88
- resources = cookbook.files_for(:resources)
89
-
90
- resources.each_with_object({}) do |r, res|
91
- pth = r["full_path"]
92
- cur = Chef::Resource::LWRPBase.build_from_file(name, pth, Chef::RunContext.new(Chef::Node.new, nil, nil))
93
- res[cur.resource_name] = extract_resource(cur, complete)
94
- end
112
+ load_from_resources(cookbook.files_for(:resources), complete)
95
113
  end
96
114
 
97
115
  # If we're given no resources, dump all of Chef's built ins
@@ -190,6 +190,7 @@ class Chef
190
190
  def prepare_run_data
191
191
  run_data = {}
192
192
  run_data["action"] = "end"
193
+
193
194
  run_data["resources"] = updated_resources.map do |action_record|
194
195
  for_json(action_record)
195
196
  end