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
@@ -42,9 +42,9 @@ class Chef
42
42
 
43
43
  def mountable?
44
44
  # only check for existence of non-remote devices
45
- if device_should_exist? && !::TargetIO::File.exist?(device_real)
45
+ if device_should_exist? && !::File.exist?(device_real)
46
46
  raise Chef::Exceptions::Mount, "Device #{@new_resource.device} does not exist"
47
- elsif @new_resource.mount_point != "none" && !::TargetIO::File.exist?(@new_resource.mount_point)
47
+ elsif @new_resource.mount_point != "none" && !::File.exist?(@new_resource.mount_point)
48
48
  raise Chef::Exceptions::Mount, "Mount point #{@new_resource.mount_point} does not exist"
49
49
  end
50
50
 
@@ -54,11 +54,11 @@ class Chef
54
54
  def enabled?
55
55
  # Check to see if there is a entry in /etc/fstab. Last entry for a volume wins.
56
56
  enabled = false
57
- unless ::TargetIO::File.exist?("/etc/fstab")
57
+ unless ::File.exist?("/etc/fstab")
58
58
  logger.debug "/etc/fstab not found, treating mount as not-enabled"
59
59
  return
60
60
  end
61
- ::TargetIO::File.foreach("/etc/fstab") do |line|
61
+ ::File.foreach("/etc/fstab") do |line|
62
62
  case line
63
63
  when /^[#\s]/
64
64
  next
@@ -81,8 +81,8 @@ class Chef
81
81
  # "mount" outputs the mount points as real paths. Convert
82
82
  # the mount_point of the resource to a real path in case it
83
83
  # contains symlinks in its parents dirs.
84
- real_mount_point = if ::TargetIO::File.exist? @new_resource.mount_point
85
- ::TargetIO::File.realpath(@new_resource.mount_point)
84
+ real_mount_point = if ::File.exist? @new_resource.mount_point
85
+ ::File.realpath(@new_resource.mount_point)
86
86
  else
87
87
  @new_resource.mount_point
88
88
  end
@@ -168,7 +168,7 @@ class Chef
168
168
  # and order will remain the same.
169
169
  edit_fstab
170
170
  else
171
- ::TargetIO::File.open("/etc/fstab", "a") do |fstab|
171
+ ::File.open("/etc/fstab", "a") do |fstab|
172
172
  fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? default_mount_options : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}")
173
173
  logger.trace("#{@new_resource} is enabled at #{@new_resource.mount_point}")
174
174
  end
@@ -229,12 +229,12 @@ class Chef
229
229
  if network_device?
230
230
  # ignore trailing slash
231
231
  Regexp.escape(device_real) + "/?"
232
- elsif ::TargetIO::File.symlink?(device_real)
232
+ elsif ::File.symlink?(device_real)
233
233
  # This regular expression tries to match device_real. If that does not match it will try to match the target of device_real.
234
234
  # So given a symlink like this:
235
235
  # /dev/mapper/vgroot-tmp.vol -> /dev/dm-9
236
236
  # First it will try to match "/dev/mapper/vgroot-tmp.vol". If there is no match it will try matching for "/dev/dm-9".
237
- "(?:#{Regexp.escape(device_real)}|#{Regexp.escape(::File.expand_path(::TargetIO::File.readlink(device_real), ::File.dirname(device_real)))})"
237
+ "(?:#{Regexp.escape(device_real)}|#{Regexp.escape(::File.expand_path(::File.readlink(device_real), ::File.dirname(device_real)))})"
238
238
  else
239
239
  Regexp.escape(device_real)
240
240
  end
@@ -261,7 +261,7 @@ class Chef
261
261
  contents = []
262
262
 
263
263
  found = false
264
- ::TargetIO::File.readlines("/etc/fstab").reverse_each do |line|
264
+ ::File.readlines("/etc/fstab").reverse_each do |line|
265
265
  if !found && line =~ /^#{device_fstab_regex}\s+#{Regexp.escape(@new_resource.mount_point)}\s/
266
266
  found = true
267
267
  if remove
@@ -276,7 +276,7 @@ class Chef
276
276
  end
277
277
  end
278
278
 
279
- ::TargetIO::File.open("/etc/fstab", "w") do |fstab|
279
+ ::File.open("/etc/fstab", "w") do |fstab|
280
280
  contents.reverse_each { |line| fstab.puts line }
281
281
  end
282
282
  else
@@ -124,6 +124,11 @@ class Chef
124
124
 
125
125
  private
126
126
 
127
+ # @return [String] package name with or without anchors attached to it.
128
+ def resolve_package(pkg)
129
+ new_resource.anchor_package_regex ? "^#{pkg}$" : pkg
130
+ end
131
+
127
132
  # @return [String] version of apt-get which is installed
128
133
  def apt_version
129
134
  @apt_version ||= shell_out("apt-get --version").stdout.match(/^apt (\S+)/)[1]
@@ -174,10 +179,12 @@ class Chef
174
179
  end
175
180
 
176
181
  def resolve_package_versions(pkg)
182
+ # apt-cache considers package names as regex by default. The anchor_package_regex flag will decide whether to match name exact string or not
183
+ pkg_name = resolve_package(pkg)
177
184
  current_version = nil
178
185
  candidate_version = nil
179
186
  all_versions = []
180
- run_noninteractive("apt-cache", default_release_options, "policy", pkg).stdout.each_line do |line|
187
+ run_noninteractive("apt-cache", default_release_options, "policy", pkg_name).stdout.each_line do |line|
181
188
  case line
182
189
  when /^\s{2}Installed: (.+)$/
183
190
  current_version = ( $1 != "(none)" ) ? $1 : nil
@@ -216,7 +223,9 @@ class Chef
216
223
  end
217
224
 
218
225
  def resolve_virtual_package_name(pkg)
219
- showpkg = run_noninteractive("apt-cache", "showpkg", pkg).stdout
226
+ # apt-cache considers package names as regex by default. The anchor_package_regex flag will decide whether to match name exact string or not
227
+ pkg_name = resolve_package(pkg)
228
+ showpkg = run_noninteractive("apt-cache", "showpkg", pkg_name).stdout
220
229
  partitions = showpkg.rpartition(/Reverse Provides: ?#{$/}/)
221
230
  return nil if partitions[0] == "" && partitions[1] == "" # not found in output
222
231
 
@@ -25,8 +25,8 @@ class Chef
25
25
  class Package
26
26
  class Bff < Chef::Provider::Package
27
27
 
28
- provides :package, os: "aix", target_mode: true
29
- provides :bff_package, target_mode: true
28
+ provides :package, os: "aix"
29
+ provides :bff_package
30
30
 
31
31
  include Chef::Mixin::GetSourceFromPackage
32
32
 
@@ -134,7 +134,7 @@ class Chef
134
134
  end
135
135
 
136
136
  def package_source_found?
137
- @package_source_found ||= new_resource.source && ::TargetIO::File.exist?(new_resource.source)
137
+ @package_source_found ||= new_resource.source && ::File.exist?(new_resource.source)
138
138
  end
139
139
 
140
140
  end
@@ -153,7 +153,7 @@ class Chef
153
153
 
154
154
  # Choco V2 uses 'Search' for remote repositories and 'List' for local packages
155
155
  def query_command
156
- return "list" if get_choco_version.match?(/^1/)
156
+ return "list" if Gem::Dependency.new("", "< 1.4.0").match?("", get_choco_version)
157
157
 
158
158
  "search"
159
159
  end
@@ -240,7 +240,7 @@ class Chef
240
240
  @choco_exe ||= begin
241
241
  # if this check is in #define_resource_requirements, it won't get
242
242
  # run before choco.exe gets called from #load_current_resource.
243
- exe_path = ::File.join(choco_install_path, "bin", "choco.exe")
243
+ exe_path = ::File.join(choco_install_path, "choco.exe")
244
244
  raise Chef::Exceptions::MissingLibrary, CHOCO_MISSING_MSG unless ::File.exist?(exe_path)
245
245
 
246
246
  exe_path
@@ -92,6 +92,13 @@ def query(command):
92
92
  q = subj.get_best_query(sack, with_provides=True)
93
93
 
94
94
  if command['action'] == "whatinstalled":
95
+ # When attempting to figure out what is installed, we should ignore any
96
+ # excludes that are configured, otherwise the "best" query for a given
97
+ # subject may refer to a package that is installed that provides that
98
+ # subject, but we really want to know if a package by that name exists
99
+ # in any available repository
100
+ q = subj.get_best_query(sack, with_provides=True, query=sack.query(flags=hawkey.IGNORE_EXCLUDES))
101
+
95
102
  q = q.installed()
96
103
 
97
104
  if command['action'] == "whatavailable":
@@ -29,7 +29,7 @@ class Chef
29
29
  DPKG_INSTALLED = /^Status: install ok installed/.freeze
30
30
  DPKG_VERSION = /^Version: (.+)$/.freeze
31
31
 
32
- provides :dpkg_package, target_mode: true
32
+ provides :dpkg_package
33
33
 
34
34
  use_multipackage_api
35
35
  use_package_name_for_source
@@ -146,14 +146,14 @@ class Chef
146
146
  #
147
147
  # @return [Boolean] True if all sources exist
148
148
  def source_files_exist?
149
- resolved_source_array.all? { |s| s && ::TargetIO::File.exist?(s) }
149
+ resolved_source_array.all? { |s| s && ::File.exist?(s) }
150
150
  end
151
151
 
152
152
  # Helper to return all the names of the missing sources for error messages.
153
153
  #
154
154
  # @return [Array<String>] Array of missing sources
155
155
  def missing_sources
156
- resolved_source_array.select { |s| s.nil? || !::TargetIO::File.exist?(s) }
156
+ resolved_source_array.select { |s| s.nil? || !::File.exist?(s) }
157
157
  end
158
158
 
159
159
  def current_package_name_array
@@ -30,7 +30,7 @@ class Chef
30
30
 
31
31
  module PortsHelper
32
32
  def supports_ports?
33
- ::TargetIO::File.exist?("/usr/ports/Makefile")
33
+ ::File.exist?("/usr/ports/Makefile")
34
34
  end
35
35
 
36
36
  def port_dir(port)
@@ -15,6 +15,7 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  #
18
+ require_relative "../../http/simple"
18
19
  require_relative "../../json_compat"
19
20
  require_relative "../../exceptions"
20
21
  require_relative "../package"
@@ -26,7 +27,7 @@ class Chef
26
27
  class Habitat < Chef::Provider::Package
27
28
  use_multipackage_api
28
29
  use "../../resource/habitat/habitat_shared"
29
- provides :habitat_package, target_mode: true
30
+ provides :habitat_package
30
31
 
31
32
  def load_current_resource
32
33
  @current_resource = Chef::Resource::HabitatPackage.new(new_resource.name)
@@ -39,9 +40,6 @@ class Chef
39
40
  end
40
41
 
41
42
  def install_package(names, versions)
42
- # License acceptance needed outside of local Chef Client
43
- shell_out!("hab license accept") if Chef::Config.target_mode?
44
-
45
43
  names.zip(versions).map do |n, v|
46
44
  opts = ["pkg", "install", "--channel", new_resource.channel, "--url", new_resource.bldr_url]
47
45
  opts += ["--auth", new_resource.auth_token] if new_resource.auth_token
@@ -122,7 +120,7 @@ class Chef
122
120
 
123
121
  def http
124
122
  # FIXME: use SimpleJSON when the depot mime-type is fixed
125
- @http ||= TargetIO::HTTP.new(new_resource.bldr_url.to_s)
123
+ @http ||= Chef::HTTP::Simple.new(new_resource.bldr_url.to_s)
126
124
  end
127
125
 
128
126
  def candidate_versions
@@ -18,7 +18,7 @@
18
18
  #
19
19
 
20
20
  require "etc" unless defined?(Etc)
21
- require_relative "../../mixin/homebrew_user"
21
+ require_relative "../../mixin/homebrew"
22
22
 
23
23
  class Chef
24
24
  class Provider
@@ -30,7 +30,7 @@ class Chef
30
30
  provides :package, os: "darwin"
31
31
  provides :homebrew_package
32
32
 
33
- include Chef::Mixin::HomebrewUser
33
+ include Chef::Mixin::Homebrew
34
34
 
35
35
  def load_current_resource
36
36
  @current_resource = Chef::Resource::HomebrewPackage.new(new_resource.name)
@@ -63,9 +63,8 @@ class Chef
63
63
  # and which packages can be upgrades. We do this by checking if brew_info has an entry
64
64
  # via the installed_version helper.
65
65
  def upgrade_package(names, versions)
66
- # @todo when we no longer support Ruby 2.6 this can be simplified to be a .filter_map
67
- upgrade_pkgs = names.select { |x| x if installed_version(x) }.compact
68
- install_pkgs = names.select { |x| x unless installed_version(x) }.compact
66
+ upgrade_pkgs = names.filter_map { |x| x if installed_version(x) }
67
+ install_pkgs = names.filter_map { |x| x unless installed_version(x) }
69
68
 
70
69
  brew_cmd_output("upgrade", options, upgrade_pkgs) unless upgrade_pkgs.empty?
71
70
  brew_cmd_output("install", options, install_pkgs) unless install_pkgs.empty?
@@ -182,7 +181,7 @@ class Chef
182
181
  homebrew_uid = find_homebrew_uid(new_resource.respond_to?(:homebrew_user) && new_resource.homebrew_user)
183
182
  homebrew_user = Etc.getpwuid(homebrew_uid)
184
183
 
185
- logger.trace "Executing 'brew #{command.join(" ")}' as user '#{homebrew_user.name}'"
184
+ logger.trace "Executing '#{homebrew_bin_path} #{command.join(" ")}' as user '#{homebrew_user.name}'"
186
185
 
187
186
  # allow the calling method to decide if the cmd should raise or not
188
187
  # brew_info uses this when querying out available package info since a bad
@@ -190,11 +189,9 @@ class Chef
190
189
  # the package provider can magically handle that
191
190
  shell_out_cmd = options[:allow_failure] ? :shell_out : :shell_out!
192
191
 
193
- # FIXME: this 1800 second default timeout should be deprecated
194
- output = send(shell_out_cmd, "brew", *command, timeout: 1800, user: homebrew_uid, environment: { "HOME" => homebrew_user.dir, "RUBYOPT" => nil, "TMPDIR" => nil })
192
+ output = send(shell_out_cmd, homebrew_bin_path, *command, user: homebrew_uid, login: true, environment: { "HOME" => homebrew_user.dir, "RUBYOPT" => nil, "TMPDIR" => nil })
195
193
  output.stdout.chomp
196
194
  end
197
-
198
195
  end
199
196
  end
200
197
  end
@@ -26,8 +26,8 @@ class Chef
26
26
  class Package
27
27
  class Ips < Chef::Provider::Package
28
28
 
29
- provides :package, platform: %w{openindiana omnios solaris2}, target_mode: true
30
- provides :ips_package, target_mode: true
29
+ provides :package, platform: %w{openindiana omnios solaris2}
30
+ provides :ips_package
31
31
 
32
32
  attr_accessor :virtual
33
33
 
@@ -30,8 +30,8 @@ class Chef
30
30
  class Package
31
31
  class Openbsd < Chef::Provider::Package
32
32
 
33
- provides :package, os: "openbsd", target_mode: true
34
- provides :openbsd_package, target_mode: true
33
+ provides :package, os: "openbsd"
34
+ provides :openbsd_package
35
35
 
36
36
  include Chef::Mixin::ShellOut
37
37
  include Chef::Mixin::GetSourceFromPackage
@@ -129,7 +129,6 @@ class Chef
129
129
  end
130
130
  end
131
131
 
132
- # Target Mode limitation: ENV["PKG_PATH"] cannot be evaluated, as remote commands are not run in a standard shell
133
132
  def pkg_path
134
133
  ENV["PKG_PATH"] || "http://ftp.OpenBSD.org/pub/#{node["kernel"]["name"]}/#{node["kernel"]["release"]}/packages/#{node["kernel"]["machine"]}/"
135
134
  end
@@ -24,8 +24,8 @@ class Chef
24
24
  class Package
25
25
  class Pacman < Chef::Provider::Package
26
26
 
27
- provides :package, platform: "arch", target_mode: true
28
- provides :pacman_package, target_mode: true
27
+ provides :package, platform: "arch"
28
+ provides :pacman_package
29
29
 
30
30
  use_multipackage_api
31
31
  allow_nils
@@ -37,8 +37,8 @@ class Chef
37
37
 
38
38
  repos = %w{extra core community}
39
39
 
40
- if ::TargetIO::File.exist?("/etc/pacman.conf")
41
- pacman = ::TargetIO::File.read("/etc/pacman.conf")
40
+ if ::File.exist?("/etc/pacman.conf")
41
+ pacman = ::File.read("/etc/pacman.conf")
42
42
  repos = pacman.scan(/\[(.+)\]/).flatten
43
43
  end
44
44
 
@@ -24,8 +24,8 @@ class Chef
24
24
  class Package
25
25
  class Paludis < Chef::Provider::Package
26
26
 
27
- provides :package, platform: "exherbo", target_mode: true
28
- provides :paludis_package, target_mode: true
27
+ provides :package, platform: "exherbo"
28
+ provides :paludis_package
29
29
 
30
30
  def load_current_resource
31
31
  @current_resource = Chef::Resource::Package.new(new_resource.package_name)
@@ -38,7 +38,7 @@ class Chef
38
38
 
39
39
  globsafe_category = category ? Chef::Util::PathHelper.escape_glob_dir(category) : nil
40
40
  globsafe_pkg = Chef::Util::PathHelper.escape_glob_dir(pkg)
41
- possibilities = TargetIO::Dir["/var/db/pkg/#{globsafe_category || "*"}/#{globsafe_pkg}-*"].map { |d| d.sub(%r{/var/db/pkg/}, "") }
41
+ possibilities = Dir["/var/db/pkg/#{globsafe_category || "*"}/#{globsafe_pkg}-*"].map { |d| d.sub(%r{/var/db/pkg/}, "") }
42
42
  versions = possibilities.map do |entry|
43
43
  if entry =~ %r{[^/]+/#{Regexp.escape(pkg)}\-(\d[\.\d]*[a-z]?((_(alpha|beta|pre|rc|p)\d*)*)?(-r\d+)?)}
44
44
  [$&, $1]
@@ -24,7 +24,7 @@ class Chef
24
24
  class Provider
25
25
  class Package
26
26
  class Rpm < Chef::Provider::Package
27
- provides :rpm_package, target_mode: true
27
+ provides :rpm_package
28
28
 
29
29
  include Chef::Mixin::GetSourceFromPackage
30
30
 
@@ -51,7 +51,7 @@ class Chef
51
51
  current_resource.package_name(new_resource.package_name)
52
52
 
53
53
  if new_resource.source
54
- unless uri_scheme?(new_resource.source) || ::TargetIO::File.exist?(new_resource.source)
54
+ unless uri_scheme?(new_resource.source) || ::File.exist?(new_resource.source)
55
55
  @package_source_exists = false
56
56
  return
57
57
  end
@@ -136,6 +136,10 @@ class Chef
136
136
  if defined?(Gem::Format) && Gem::Package.respond_to?(:open)
137
137
  Gem::Format.from_file_by_path(file).spec
138
138
  else
139
+ # Gem::Package is getting defined as an empty class as of bundler 2.5.23
140
+ # and therefore won't autoload
141
+ # ["bundler-2.5.23/lib/bundler/rubygems_ext.rb", 457]
142
+ require "rubygems/package" if Gem::Package.method(:new).source_location.nil?
139
143
  Gem::Package.new(file).spec
140
144
  end
141
145
  end
@@ -29,8 +29,8 @@ class Chef
29
29
  class SmartOS < Chef::Provider::Package
30
30
  attr_accessor :is_virtual_package
31
31
 
32
- provides :package, platform: "smartos", target_mode: true
33
- provides :smartos_package, target_mode: true
32
+ provides :package, platform: "smartos"
33
+ provides :smartos_package
34
34
 
35
35
  def load_current_resource
36
36
  logger.trace("#{new_resource} loading current resource")
@@ -223,7 +223,7 @@ class Chef
223
223
  when "Do", "Doing", "Undoing", "Undo"
224
224
  # Continue
225
225
  when "Abort", "Hold", "Error"
226
- raise result
226
+ raise "#{result["result"]["summary"]} - #{result["result"]["status"]} - #{result["result"]["err"]}"
227
227
  when "Done"
228
228
  waiting = false
229
229
  else
@@ -330,7 +330,7 @@ class Chef
330
330
  def generate_snap_json(snap_names, action, channel, options, revision = nil)
331
331
  request = {
332
332
  "action" => action,
333
- "snaps" => Array(snap_names),
333
+ "snaps" => snap_names,
334
334
  }
335
335
  if %w{install refresh switch}.include?(action) && channel
336
336
  request["channel"] = channel
@@ -26,7 +26,7 @@ class Chef
26
26
 
27
27
  include Chef::Mixin::GetSourceFromPackage
28
28
 
29
- provides :solaris_package, target_mode: true
29
+ provides :solaris_package
30
30
 
31
31
  # def initialize(*args)
32
32
  # super
@@ -50,7 +50,7 @@ class Chef
50
50
  current_resource.package_name(new_resource.package_name)
51
51
 
52
52
  if new_resource.source
53
- @package_source_found = ::TargetIO::File.exist?(new_resource.source)
53
+ @package_source_found = ::File.exist?(new_resource.source)
54
54
  if @package_source_found
55
55
  logger.trace("#{new_resource} checking pkg status")
56
56
  shell_out("pkginfo", "-l", "-d", new_resource.source, new_resource.package_name).stdout.each_line do |line|
@@ -101,7 +101,7 @@ class Chef
101
101
  def install_package(name, version)
102
102
  logger.trace("#{new_resource} package install options: #{options}")
103
103
  if options.nil?
104
- command = if ::TargetIO::File.directory?(new_resource.source) # CHEF-4469
104
+ command = if ::File.directory?(new_resource.source) # CHEF-4469
105
105
  [ "pkgadd", "-n", "-d", new_resource.source, new_resource.package_name ]
106
106
  else
107
107
  [ "pkgadd", "-n", "-d", new_resource.source, "all" ]
@@ -109,7 +109,7 @@ class Chef
109
109
  shell_out!(command)
110
110
  logger.trace("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}")
111
111
  else
112
- command = if ::TargetIO::File.directory?(new_resource.source) # CHEF-4469
112
+ command = if ::File.directory?(new_resource.source) # CHEF-4469
113
113
  [ "pkgadd", "-n", options, "-d", new_resource.source, new_resource.package_name ]
114
114
  else
115
115
  [ "pkgadd", "-n", options, "-d", new_resource.source, "all" ]
@@ -30,8 +30,8 @@ class Chef
30
30
  use_package_name_for_source
31
31
  allow_nils
32
32
 
33
- provides :package, platform_family: "suse", target_mode: true
34
- provides :zypper_package, target_mode: true
33
+ provides :package, platform_family: "suse"
34
+ provides :zypper_package
35
35
 
36
36
  def define_resource_requirements
37
37
  super
@@ -91,7 +91,7 @@ class Chef
91
91
  # @return [Boolean] True if all sources exist
92
92
  def source_files_exist?
93
93
  if !new_resource.source.nil?
94
- resolved_source_array.all? { |s| s && ::TargetIO::File.exist?(s) }
94
+ resolved_source_array.all? { |s| s && ::File.exist?(s) }
95
95
  else
96
96
  true
97
97
  end
@@ -100,7 +100,7 @@ class Chef
100
100
  # Helper to return all the names of the missing sources for error messages.
101
101
  # @return [Array<String>] Array of missing sources
102
102
  def missing_sources
103
- resolved_source_array.select { |s| s.nil? || !::TargetIO::File.exist?(s) }
103
+ resolved_source_array.select { |s| s.nil? || !::File.exist?(s) }
104
104
  end
105
105
 
106
106
  def resolve_source_to_version
@@ -648,7 +648,7 @@ class Chef
648
648
  source_array.each_with_index.map do |source, i|
649
649
  package_name = package_name_array[i]
650
650
  # we require at least one '/' in the package_name to avoid [XXX_]package 'foo' breaking due to a random 'foo' file in cwd
651
- if use_package_name_for_source? && source.nil? && package_name.match(/#{::File::SEPARATOR}/) && ::TargetIO::File.exist?(package_name)
651
+ if use_package_name_for_source? && source.nil? && package_name.match(/#{::File::SEPARATOR}/) && ::File.exist?(package_name)
652
652
  logger.trace("No package source specified, but #{package_name} exists on filesystem, using #{package_name} as source.")
653
653
  package_name
654
654
  else
@@ -51,9 +51,14 @@ class Chef
51
51
  current_resource.recursive(new_resource.recursive)
52
52
  if registry.key_exists?(new_resource.key)
53
53
  current_registry_values = registry.get_values(new_resource.key) || []
54
+
55
+ if new_resource.only_record_changes
56
+ current_registry_values.select! { |v| new_resource.values.any? { |nv| nv[:name] == v[:name] } }
57
+ end
54
58
  current_resource.values(current_registry_values)
55
59
  end
56
60
  values_to_hash(current_resource.unscrubbed_values)
61
+
57
62
  current_resource
58
63
  end
59
64
 
@@ -122,6 +127,7 @@ class Chef
122
127
  registry.create_key(new_resource.key, new_resource.recursive)
123
128
  end
124
129
  end
130
+
125
131
  new_resource.unscrubbed_values.each do |value|
126
132
  if @name_hash.key?(value[:name].downcase)
127
133
  current_value = @name_hash[value[:name].downcase]
@@ -32,7 +32,7 @@ class Chef
32
32
  extend Forwardable
33
33
  include Chef::Mixin::FileClass
34
34
 
35
- provides :remote_directory, target_mode: true
35
+ provides :remote_directory
36
36
 
37
37
  def_delegators :new_resource, :purge, :path, :source, :cookbook, :cookbook_name
38
38
  def_delegators :new_resource, :files_rights, :files_mode, :files_group, :files_owner, :files_backup
@@ -100,7 +100,7 @@ class Chef
100
100
  #
101
101
  def purge_unmanaged_files
102
102
  if purge
103
- TargetIO::Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob_dir(path), "**", "*"), ::File::FNM_DOTMATCH).sort!.reverse!.each do |file|
103
+ Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob_dir(path), "**", "*"), ::File::FNM_DOTMATCH).sort!.reverse!.each do |file|
104
104
  # skip '.' and '..'
105
105
  next if [".", ".."].include?(Pathname.new(file).basename.to_s)
106
106
 
@@ -110,7 +110,7 @@ class Chef
110
110
  # Skip files that we've sync'd and their parent dirs
111
111
  next if managed_files.include?(file)
112
112
 
113
- if ::TargetIO::File.directory?(file)
113
+ if ::File.directory?(file)
114
114
  if !ChefUtils.windows? && file_class.symlink?(file.dup)
115
115
  # Unix treats dir symlinks as files
116
116
  purge_file(file)
@@ -188,7 +188,7 @@ class Chef
188
188
  def create_cookbook_file(cookbook_file_relative_path)
189
189
  full_path = ::File.join(path, cookbook_file_relative_path)
190
190
 
191
- ensure_directory_exists(::TargetIO::File.dirname(full_path))
191
+ ensure_directory_exists(::File.dirname(full_path))
192
192
 
193
193
  res = cookbook_file_resource(full_path, cookbook_file_relative_path)
194
194
  res.run_action(action_for_cookbook_file)
@@ -228,7 +228,7 @@ class Chef
228
228
  #
229
229
  def ensure_directory_exists(dir)
230
230
  # doing the check here and skipping the resource should be more performant
231
- unless ::TargetIO::File.directory?(dir)
231
+ unless ::File.directory?(dir)
232
232
  res = directory_resource(dir)
233
233
  res.run_action(:create)
234
234
  new_resource.updated_by_last_action(true) if res.updated?
@@ -17,6 +17,7 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
+ require_relative "../../http/simple"
20
21
  require_relative "../../digester"
21
22
  require_relative "../remote_file"
22
23
  require_relative "cache_control_data"
@@ -61,7 +62,7 @@ class Chef
61
62
  end
62
63
 
63
64
  def fetch
64
- http = TargetIO::HTTP.new(uri, http_client_opts)
65
+ http = Chef::HTTP::Simple.new(uri, http_client_opts)
65
66
  orig_tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile
66
67
  if want_progress?
67
68
  tempfile = http.streaming_request_with_progress(uri, headers, orig_tempfile) do |size, total|
@@ -96,7 +97,7 @@ class Chef
96
97
  end
97
98
 
98
99
  def want_progress?
99
- !ChefConfig::Config.target_mode? && events.formatter? && (Chef::Config[:show_download_progress] || !!new_resource.show_progress)
100
+ events.formatter? && (Chef::Config[:show_download_progress] || !!new_resource.show_progress)
100
101
  end
101
102
 
102
103
  def progress_interval
@@ -22,7 +22,7 @@ require_relative "file"
22
22
  class Chef
23
23
  class Provider
24
24
  class RemoteFile < Chef::Provider::File
25
- provides :remote_file, target_mode: true
25
+ provides :remote_file
26
26
 
27
27
  def initialize(new_resource, run_context)
28
28
  @content_class = Chef::Provider::RemoteFile::Content