chef 19.3.15 → 19.4.46

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -2
  3. data/chef.gemspec +5 -4
  4. data/lib/chef/application/base.rb +1 -5
  5. data/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb +1 -1
  6. data/lib/chef/cookbook_manifest.rb +18 -7
  7. data/lib/chef/cookbook_uploader.rb +1 -1
  8. data/lib/chef/cookbook_version.rb +3 -3
  9. data/lib/chef/data_bag.rb +3 -4
  10. data/lib/chef/data_collector.rb +1 -0
  11. data/lib/chef/encrypted_data_bag_item.rb +1 -1
  12. data/lib/chef/formatters/error_description.rb +8 -1
  13. data/lib/chef/http/auth_credentials.rb +1 -1
  14. data/lib/chef/http/authenticator.rb +18 -5
  15. data/lib/chef/http.rb +2 -2
  16. data/lib/chef/mixin/properties.rb +1 -1
  17. data/lib/chef/mixin/template.rb +24 -2
  18. data/lib/chef/property.rb +11 -1
  19. data/lib/chef/provider/group/dscl.rb +9 -5
  20. data/lib/chef/provider/group.rb +5 -0
  21. data/lib/chef/provider/mount/solaris.rb +10 -18
  22. data/lib/chef/provider/package/chocolatey.rb +2 -2
  23. data/lib/chef/provider/package/homebrew.rb +2 -3
  24. data/lib/chef/provider/package/portage.rb +0 -1
  25. data/lib/chef/provider/package/yum/python_helper.rb +0 -1
  26. data/lib/chef/provider/service/debian.rb +9 -9
  27. data/lib/chef/resource/apt_repository.rb +5 -1
  28. data/lib/chef/resource/archive_dll_locator.rb +70 -0
  29. data/lib/chef/resource/archive_file.rb +56 -27
  30. data/lib/chef/resource/chef_client_config.rb +187 -21
  31. data/lib/chef/resource/chef_client_hab_ca_cert.rb +10 -3
  32. data/lib/chef/resource/chef_vault_secret.rb +1 -1
  33. data/lib/chef/resource/chocolatey_installer.rb +41 -7
  34. data/lib/chef/resource/chocolatey_package.rb +1 -1
  35. data/lib/chef/resource/dnf_package.rb +1 -1
  36. data/lib/chef/resource/habitat/habitat_package.rb +1 -1
  37. data/lib/chef/resource/habitat/habitat_sup.rb +2 -2
  38. data/lib/chef/resource/habitat_config.rb +1 -1
  39. data/lib/chef/resource/habitat_service.rb +1 -1
  40. data/lib/chef/resource/helpers/path_helpers.rb +2 -2
  41. data/lib/chef/resource/homebrew_cask.rb +11 -5
  42. data/lib/chef/resource/homebrew_tap.rb +18 -0
  43. data/lib/chef/resource/launchd.rb +1 -1
  44. data/lib/chef/resource/mount.rb +2 -2
  45. data/lib/chef/resource/openssl_ec_private_key.rb +1 -1
  46. data/lib/chef/resource/openssl_ec_public_key.rb +2 -2
  47. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -1
  48. data/lib/chef/resource/openssl_rsa_public_key.rb +2 -2
  49. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  50. data/lib/chef/resource/openssl_x509_request.rb +1 -1
  51. data/lib/chef/resource/powershell_package_source.rb +1 -1
  52. data/lib/chef/resource/rhsm_register.rb +1 -1
  53. data/lib/chef/resource/service.rb +1 -1
  54. data/lib/chef/resource/sysctl.rb +22 -5
  55. data/lib/chef/resource/windows_ad_join.rb +1 -1
  56. data/lib/chef/resource/windows_certificate.rb +1 -1
  57. data/lib/chef/resource/windows_security_policy.rb +0 -1
  58. data/lib/chef/resource/windows_service.rb +1 -1
  59. data/lib/chef/resource/windows_task.rb +1 -3
  60. data/lib/chef/resource/windows_update_settings.rb +51 -30
  61. data/lib/chef/resource/yum_package.rb +1 -1
  62. data/lib/chef/resource/yum_repository.rb +2 -2
  63. data/lib/chef/resource.rb +2 -2
  64. data/lib/chef/resource_inspector.rb +1 -1
  65. data/lib/chef/role.rb +1 -1
  66. data/lib/chef/target_io/train/dir.rb +10 -1
  67. data/lib/chef/target_io/train/fileutils.rb +1 -1
  68. data/lib/chef/util/selinux.rb +2 -2
  69. data/lib/chef/version.rb +1 -1
  70. data/lib/chef/win32/api/command_line_helper.rb +2 -2
  71. data/lib/chef/win32/api/error.rb +0 -2
  72. data/lib/chef/win32/api/net.rb +2 -4
  73. data/lib/chef/win32/api.rb +4 -4
  74. data/lib/chef/win32/net.rb +0 -1
  75. data/lib/chef/win32/security/acl.rb +1 -1
  76. data/lib/chef/win32/security.rb +1 -1
  77. metadata +18 -11
@@ -29,8 +29,8 @@ class Chef
29
29
  # return path for any bin/chef-* names
30
30
  return path.sub(bin, ChefUtils::Dist::Infra::CLIENT) if bin =~ /^chef-[a-z-]+$/
31
31
 
32
- # Return empty string if no valid path is found
33
- ""
32
+ # Fall back to legacy path if no valid path is found
33
+ which(ChefUtils::Dist::Infra::CLIENT)
34
34
  end
35
35
 
36
36
  # once the binstubs under hab package have been fixed,
@@ -55,7 +55,13 @@ class Chef
55
55
  command "#{homebrew_bin_path(new_resource.homebrew_path)} install --cask #{new_resource.cask_name} #{new_resource.options}"
56
56
  user new_resource.owner
57
57
  cwd ::Dir.home(new_resource.owner)
58
- login true
58
+ # NOTE: intentionally not using `login true` here. Executing brew via a login
59
+ # shell can cause Homebrew's vendored (setgid) portable-ruby to fail with
60
+ # "no -I allowed while running setgid (SecurityError)" during cask installs.
61
+ # See https://github.com/chef/chef/issues/14885 for the same issue in the
62
+ # homebrew_package provider. We instead set the environment explicitly, which
63
+ # is what a login shell would otherwise have done for us.
64
+ environment "HOME" => ::Dir.home(new_resource.owner), "RUBYOPT" => nil, "TMPDIR" => nil
59
65
  end
60
66
  end
61
67
  end
@@ -68,7 +74,8 @@ class Chef
68
74
  command "#{homebrew_bin_path(new_resource.homebrew_path)} uninstall --cask #{new_resource.cask_name}"
69
75
  user new_resource.owner
70
76
  cwd ::Dir.home(new_resource.owner)
71
- login true
77
+ # See NOTE above in :install about avoiding `login true`.
78
+ environment "HOME" => ::Dir.home(new_resource.owner), "RUBYOPT" => nil, "TMPDIR" => nil
72
79
  end
73
80
  end
74
81
  end
@@ -87,9 +94,8 @@ class Chef
87
94
  shell_out!(
88
95
  "#{homebrew_bin_path(new_resource.homebrew_path)} list --cask 2>/dev/null",
89
96
  user: new_resource.owner,
90
- env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner },
91
- cwd: ::Dir.home(new_resource.owner),
92
- login: true
97
+ env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner, "RUBYOPT" => nil, "TMPDIR" => nil },
98
+ cwd: ::Dir.home(new_resource.owner)
93
99
  ).stdout.split.include?(unscoped_name)
94
100
  end
95
101
  end
@@ -59,6 +59,24 @@ class Chef
59
59
  action :tap, description: "Add a Homebrew tap." do
60
60
  unless tapped?(new_resource.tap_name)
61
61
  converge_by("tap #{new_resource.tap_name}") do
62
+ # Homebrew 6.0+ requires non-official taps to be explicitly trusted
63
+ # before their formulae/casks/commands can be loaded (see
64
+ # https://docs.brew.sh/Tap-Trust). Without this, `brew tap` on a
65
+ # third-party tap fails with "Refusing to load cask ... from
66
+ # untrusted tap"/"invalid syntax in tap!". Trust the tap before
67
+ # tapping it. `ignore_failure` covers Homebrew releases that
68
+ # predate the `trust` command (or any future release that removes
69
+ # it) -- on those, this step simply no-ops and `brew tap` behaves
70
+ # exactly as it did before this change.
71
+ execute "trust #{new_resource.tap_name}" do
72
+ command "#{homebrew_bin_path(new_resource.homebrew_path)} trust #{new_resource.tap_name}"
73
+ user new_resource.owner
74
+ default_env true
75
+ cwd ::Dir.home(new_resource.owner)
76
+ login true
77
+ ignore_failure true
78
+ end
79
+
62
80
  execute "tap #{new_resource.tap_name}" do
63
81
  command "#{homebrew_bin_path(new_resource.homebrew_path)} tap #{new_resource.tap_name} #{new_resource.url || ""}"
64
82
  user new_resource.owner
@@ -98,7 +98,7 @@ class Chef
98
98
  end
99
99
 
100
100
  unless entry.values.all?(Integer)
101
- failed_values = entry.values.reject { |val| val.is_a?(Integer) }.join(", ")
101
+ failed_values = entry.values.grep_v(Integer).join(", ")
102
102
  error_msg = "Invalid value(s) (#{failed_values}) for start_calendar_interval item. Values must be integers!"
103
103
  raise Chef::Exceptions::ValidationFailed, error_msg
104
104
  end
@@ -26,7 +26,7 @@ class Chef
26
26
 
27
27
  provides :mount, target_mode: true
28
28
  target_mode support: :full,
29
- platforms: %i{aix bsd linux}
29
+ platforms: %i{aix bsd linux solaris}
30
30
 
31
31
  default_action :mount
32
32
  allowed_actions :mount, :umount, :unmount, :remount, :enable, :disable
@@ -36,7 +36,7 @@ class Chef
36
36
  description: "Specify a Hash of supported mount features.",
37
37
  default: lazy { { remount: false } },
38
38
  default_description: "{ remount: false }",
39
- coerce: proc { |x| x.is_a?(Array) ? x.each_with_object({}) { |i, m| m[i] = true } : x }
39
+ coerce: proc { |x| x.is_a?(Array) ? x.to_h { |i| [i, true] } : x }
40
40
 
41
41
  property :password, String,
42
42
  description: "Windows only:. Use to specify the password for username.",
@@ -60,7 +60,7 @@ class Chef
60
60
  description: "The desired curve of the generated key (if key_type is equal to 'ec'). Run openssl ecparam -list_curves to see available options.",
61
61
  default: "prime256v1"
62
62
 
63
- property :key_pass, String,
63
+ property :key_pass, String, sensitive: true,
64
64
  description: "The desired passphrase for the key."
65
65
 
66
66
  property :key_cipher, String,
@@ -56,10 +56,10 @@ class Chef
56
56
  property :private_key_path, String,
57
57
  description: "The path to the private key file."
58
58
 
59
- property :private_key_content, String,
59
+ property :private_key_content, String, sensitive: true,
60
60
  description: "The content of the private key including new lines. This property is used in place of private_key_path in instances where you want to avoid having to first write the private key to disk"
61
61
 
62
- property :private_key_pass, String,
62
+ property :private_key_pass, String, sensitive: true,
63
63
  description: "The passphrase of the provided private key."
64
64
 
65
65
  property :owner, [String, Integer],
@@ -59,7 +59,7 @@ class Chef
59
59
  description: "The desired bit length of the generated key.",
60
60
  default: 2048
61
61
 
62
- property :key_pass, String,
62
+ property :key_pass, String, sensitive: true,
63
63
  description: "The desired passphrase for the key."
64
64
 
65
65
  property :key_cipher, String,
@@ -57,10 +57,10 @@ class Chef
57
57
  property :private_key_path, String,
58
58
  description: "The path to the private key file."
59
59
 
60
- property :private_key_content, String,
60
+ property :private_key_content, String, sensitive: true,
61
61
  description: "The content of the private key, including new lines. This property is used in place of private_key_path in instances where you want to avoid having to first write the private key to disk."
62
62
 
63
- property :private_key_pass, String,
63
+ property :private_key_pass, String, sensitive: true,
64
64
  description: "The passphrase of the provided private key."
65
65
 
66
66
  property :owner, [String, Integer],
@@ -115,7 +115,7 @@ class Chef
115
115
  property :key_file, String,
116
116
  description: "The path to a certificate key file on the filesystem. If the key_file property is specified, the resource will attempt to source a key from this location. If no key file is found, the resource will generate a new key file at this location. If the key_file property is not specified, the resource will generate a key file in the same directory as the generated certificate, with the same name as the generated certificate."
117
117
 
118
- property :key_pass, String,
118
+ property :key_pass, String, sensitive: true,
119
119
  description: "The passphrase for an existing key's passphrase."
120
120
 
121
121
  property :key_type, String,
@@ -102,7 +102,7 @@ class Chef
102
102
  property :key_file, String,
103
103
  description: "The path to a certificate key file on the filesystem. If the `key_file` property is specified, the resource will attempt to source a key from this location. If no key file is found, the resource will generate a new key file at this location. If the `key_file` property is not specified, the resource will generate a key file in the same directory as the generated certificate, with the same name as the generated certificate."
104
104
 
105
- property :key_pass, String,
105
+ property :key_pass, String, sensitive: true,
106
106
  description: "The passphrase for an existing key's passphrase."
107
107
 
108
108
  property :key_type, String,
@@ -143,7 +143,7 @@ class Chef
143
143
  introduced: "17.6",
144
144
  description: "A username that, as part of a credential object, is used to register a repository or other package source with."
145
145
 
146
- property :password, String,
146
+ property :password, String, sensitive: true,
147
147
  introduced: "17.6",
148
148
  description: "A password that, as part of a credential object, is used to register a repository or other package source with."
149
149
 
@@ -54,7 +54,7 @@ class Chef
54
54
  property :username, String,
55
55
  description: "The username to use when registering. This property is not applicable if using an activation key. If specified, password and environment properties are also required."
56
56
 
57
- property :password, String,
57
+ property :password, String, sensitive: true,
58
58
  description: "The password to use when registering. This property is not applicable if using an activation key. If specified, username and environment are also required."
59
59
 
60
60
  property :system_name, String,
@@ -42,7 +42,7 @@ class Chef
42
42
  # this is a poor API please do not re-use this pattern
43
43
  property :supports, Hash, default: { restart: nil, reload: nil, status: nil },
44
44
  description: "A list of properties that controls how #{ChefUtils::Dist::Infra::PRODUCT} is to attempt to manage a service: :restart, :reload, :status. For :restart, the init script or other service provider can use a restart command; if :restart is not specified, the #{ChefUtils::Dist::Infra::CLIENT} attempts to stop and then start a service. For :reload, the init script or other service provider can use a reload command. For :status, the init script or other service provider can use a status command to determine if the service is running; if :status is not specified, the #{ChefUtils::Dist::Infra::CLIENT} attempts to match the service_name against the process table as a regular expression, unless a pattern is specified as a parameter property. Default value: { restart: false, reload: false, status: false } for all platforms (except for the Red Hat platform family, which defaults to { restart: false, reload: false, status: true }.)",
45
- coerce: proc { |x| x.is_a?(Array) ? x.each_with_object({}) { |i, m| m[i] = true } : x }
45
+ coerce: proc { |x| x.is_a?(Array) ? x.to_h { |i| [i, true] } : x }
46
46
 
47
47
  property :service_name, String,
48
48
  description: "An optional property to set the service name if it differs from the resource block's name.",
@@ -140,11 +140,11 @@ class Chef
140
140
  directory new_resource.conf_dir
141
141
 
142
142
  file "#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr("/", ".")}.conf" do
143
- content contruct_sysctl_content
143
+ content construct_sysctl_content
144
144
  end
145
145
 
146
146
  execute "Load sysctl values" do
147
- command "sysctl #{"-e " if new_resource.ignore_error}-p"
147
+ command sysctl_reload_command
148
148
  default_env true
149
149
  action :run
150
150
  end
@@ -161,7 +161,7 @@ class Chef
161
161
 
162
162
  execute "Load sysctl values" do
163
163
  default_env true
164
- command "sysctl -p"
164
+ command sysctl_reload_command
165
165
  action :run
166
166
  end
167
167
  end
@@ -179,12 +179,29 @@ class Chef
179
179
  shell_out!("sysctl #{"-e " if new_resource.ignore_error}-w \"#{key}=#{value}\"")
180
180
  end
181
181
 
182
+ #
183
+ # The command used to reload sysctl settings from disk.
184
+ #
185
+ # `sysctl -p` only reads /etc/sysctl.conf (or an explicit file), which
186
+ # some distros (e.g. Debian 13 "trixie") no longer ship by default, since
187
+ # they rely entirely on systemd-sysctl loading /etc/sysctl.d/*.conf.
188
+ # `sysctl --system` reloads from all of the standard locations --
189
+ # including the conf_dir this resource writes to -- and simply skips
190
+ # /etc/sysctl.conf if it doesn't exist, so it works whether or not that
191
+ # file is present.
192
+ #
193
+ # @return [String] The sysctl reload command
194
+ #
195
+ def sysctl_reload_command
196
+ "sysctl #{"-e " if new_resource.ignore_error}--system"
197
+ end
198
+
182
199
  #
183
200
  # construct a string, joining members of new_resource.comment and new_resource.value
184
201
  #
185
202
  # @return [String] The text file content
186
203
  #
187
- def contruct_sysctl_content
204
+ def construct_sysctl_content
188
205
  sysctl_lines = Array(new_resource.comment).map { |c| "# #{c.strip}" }
189
206
 
190
207
  sysctl_lines << "#{new_resource.key} = #{new_resource.value}"
@@ -219,7 +236,7 @@ class Chef
219
236
  def get_sysctld_value(key)
220
237
  raise unless ::TargetIO::File.exist?("/etc/sysctl.d/99-chef-#{key.tr("/", ".")}.conf")
221
238
 
222
- k, v = ::Target_IO::File.read("/etc/sysctl.d/99-chef-#{key.tr("/", ".")}.conf").match(/(.*) = (.*)/).captures
239
+ k, v = ::TargetIO::File.read("/etc/sysctl.d/99-chef-#{key.tr("/", ".")}.conf").match(/(.*) = (.*)/).captures
223
240
  raise "Unknown sysctl key!" if k.nil?
224
241
  raise "Unknown sysctl value!" if v.nil?
225
242
 
@@ -65,7 +65,7 @@ class Chef
65
65
  description: "The domain user that will be used to join the domain.",
66
66
  required: true
67
67
 
68
- property :domain_password, String,
68
+ property :domain_password, String, sensitive: true,
69
69
  description: "The password for the domain user. Note that this resource is set to hide sensitive information by default. ",
70
70
  required: true
71
71
 
@@ -65,7 +65,7 @@ class Chef
65
65
  description: "The source file (for `create` and `acl_add`), thumbprint (for `delete`, `export`, and `acl_add`), or subject (for `delete` or `export`) if it differs from the resource block's name.",
66
66
  name_property: true
67
67
 
68
- property :pfx_password, String,
68
+ property :pfx_password, String, sensitive: true,
69
69
  description: "The password to access the object with if it is a PFX file."
70
70
 
71
71
  property :private_key_acl, Array,
@@ -137,7 +137,6 @@ class Chef
137
137
  def load_security_options
138
138
  powershell_code = <<-CODE
139
139
  C:\\Windows\\System32\\secedit /export /cfg $env:TEMP\\secopts_export.inf | Out-Null
140
- # cspell:disable-next-line
141
140
  $security_options_data = (Get-Content $env:TEMP\\secopts_export.inf | Select-String -Pattern "^[CEFLMNPR].* =.*$" | Out-String)
142
141
  Remove-Item $env:TEMP\\secopts_export.inf -force
143
142
  $security_options_hash = ($security_options_data -Replace '"'| ConvertFrom-StringData)
@@ -228,7 +228,7 @@ class Chef
228
228
  default: "localsystem",
229
229
  coerce: proc(&:downcase)
230
230
 
231
- property :run_as_password, String,
231
+ property :run_as_password, String, sensitive: true,
232
232
  description: "The password for the user specified by `run_as_user`.",
233
233
  default: ""
234
234
  end
@@ -164,7 +164,7 @@ class Chef
164
164
  default: lazy { Chef::ReservedNames::Win32::Security::SID.LocalSystem.account_simple_name if ChefUtils.windows_ruby? },
165
165
  default_description: "The localized SYSTEM user for the node."
166
166
 
167
- property :password, String,
167
+ property :password, String, sensitive: true,
168
168
  description: "The user's password. The user property must be set if using this property."
169
169
 
170
170
  property :run_level, Symbol, equal_to: %i{highest limited},
@@ -523,7 +523,6 @@ class Chef
523
523
  6 => ::Win32::TaskScheduler::TASK_SIXTH,
524
524
  7 => ::Win32::TaskScheduler::TASK_SEVENTH,
525
525
  8 => ::Win32::TaskScheduler::TASK_EIGHTH,
526
- # cspell:disable-next-line
527
526
  9 => ::Win32::TaskScheduler::TASK_NINETH,
528
527
  10 => ::Win32::TaskScheduler::TASK_TENTH,
529
528
  11 => ::Win32::TaskScheduler::TASK_ELEVENTH,
@@ -545,7 +544,6 @@ class Chef
545
544
  27 => ::Win32::TaskScheduler::TASK_TWENTY_SEVENTH,
546
545
  28 => ::Win32::TaskScheduler::TASK_TWENTY_EIGHTH,
547
546
  29 => ::Win32::TaskScheduler::TASK_TWENTY_NINTH,
548
- # cspell:disable-next-line
549
547
  30 => ::Win32::TaskScheduler::TASK_THIRTYETH,
550
548
  31 => ::Win32::TaskScheduler::TASK_THIRTY_FIRST,
551
549
  }.freeze
@@ -144,38 +144,25 @@ class Chef
144
144
  action :set, description: "Set Windows Update settings." do
145
145
  actual_day = convert_day(new_resource.scheduled_install_day)
146
146
 
147
+ windows_update_values = [{
148
+ name: "DisableOSUpgrade",
149
+ type: :dword,
150
+ data: new_resource.disable_os_upgrades ? 1 : 0,
151
+ },
152
+ {
153
+ name: "ElevateNonAdmins",
154
+ type: :dword,
155
+ data: new_resource.elevate_non_admins ? 1 : 0,
156
+ },
157
+ {
158
+ name: "TargetGroupEnabled",
159
+ type: :dword,
160
+ data: new_resource.target_wsus_group_name ? 1 : 0,
161
+ }] + wsus_registry_values
162
+
147
163
  registry_key "HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate" do
148
164
  recursive true
149
- values [{
150
- name: "DisableOSUpgrade",
151
- type: :dword,
152
- data: new_resource.disable_os_upgrades ? 1 : 0,
153
- },
154
- {
155
- name: "ElevateNonAdmins",
156
- type: :dword,
157
- data: new_resource.elevate_non_admins ? 1 : 0,
158
- },
159
- {
160
- name: "TargetGroupEnabled",
161
- type: :dword,
162
- data: new_resource.target_wsus_group_name ? 1 : 0,
163
- },
164
- {
165
- name: "TargetGroup",
166
- type: :string,
167
- data: new_resource.target_wsus_group_name,
168
- },
169
- {
170
- name: "WUServer",
171
- type: :string,
172
- data: new_resource.wsus_server_url,
173
- },
174
- {
175
- name: "WUStatusServer",
176
- type: :string,
177
- data: new_resource.wsus_server_url, # status server and server need to be the same. Why? Ask Microsoft
178
- }]
165
+ values windows_update_values
179
166
  action :create
180
167
  end
181
168
 
@@ -250,6 +237,40 @@ class Chef
250
237
  DAYS.index(day)
251
238
  end
252
239
 
240
+ # The WSUS registry values are only meaningful once a WSUS server or
241
+ # target group has been configured. Emitting them with nil data makes
242
+ # registry_key rewrite them on every run, so leave them out entirely
243
+ # when the matching property is unset.
244
+ #
245
+ # @return [Array<Hash>]
246
+ def wsus_registry_values
247
+ values = []
248
+
249
+ if new_resource.target_wsus_group_name
250
+ values << {
251
+ name: "TargetGroup",
252
+ type: :string,
253
+ data: new_resource.target_wsus_group_name,
254
+ }
255
+ end
256
+
257
+ if new_resource.wsus_server_url
258
+ values << {
259
+ name: "WUServer",
260
+ type: :string,
261
+ data: new_resource.wsus_server_url,
262
+ }
263
+ values << {
264
+ name: "WUStatusServer",
265
+ type: :string,
266
+ # status server and server need to be the same. Why? Ask Microsoft
267
+ data: new_resource.wsus_server_url,
268
+ }
269
+ end
270
+
271
+ values
272
+ end
273
+
253
274
  # support the old name as well
254
275
  alias_method :action_enable, :action_set
255
276
  end
@@ -139,7 +139,7 @@ class Chef
139
139
  if v.is_a?(Hash)
140
140
  v
141
141
  elsif v.is_a?(Array)
142
- v.each_with_object({}) { |arg, obj| obj[arg] = true }
142
+ v.to_h { |arg| [arg, true] }
143
143
  elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
144
144
  { before: v, after: v }
145
145
  elsif v == :before
@@ -147,14 +147,14 @@ class Chef
147
147
  property :options, Hash,
148
148
  description: "Specifies the repository options."
149
149
 
150
- property :password, String,
150
+ property :password, String, sensitive: true,
151
151
  description: "Password to use with the username for basic authentication."
152
152
 
153
153
  property :priority, String, regex: /^(\d?[1-9]|[0-9][0-9])$/,
154
154
  description: "Assigns a priority to a repository where the priority value is between `1` and `99` inclusive. Priorities are used to enforce ordered protection of repositories. Packages from repositories with a lower priority (higher numerical value) will never be used to upgrade packages that were installed from a repository with a higher priority (lower numerical value). The repositories with the lowest numerical priority number have the highest priority.",
155
155
  validation_message: "The priority property must be a numeric value from 1-99!"
156
156
 
157
- property :proxy_password, String,
157
+ property :proxy_password, String, sensitive: true,
158
158
  description: "Password for this proxy."
159
159
 
160
160
  property :proxy_username, String,
data/lib/chef/resource.rb CHANGED
@@ -625,10 +625,10 @@ class Chef
625
625
  end
626
626
 
627
627
  def with_umask
628
- old_value = ::File.umask(umask.oct) if umask
628
+ old_value = ::File.umask((umask.respond_to?(:oct) ? umask.oct : umask.to_i) & 0777) if umask
629
629
  yield
630
630
  ensure
631
- ::File.umask(old_value) if umask
631
+ ::File.umask(old_value) if old_value
632
632
  end
633
633
 
634
634
  #
@@ -122,7 +122,7 @@ class Chef
122
122
  # @return [String] JSON formatting of all resources
123
123
  def self.inspect(arguments = [], complete: false)
124
124
  output = if arguments.empty?
125
- ObjectSpace.each_object(Class).select { |k| k < Chef::Resource }.each_with_object({}) { |klass, acc| acc[klass.resource_name] = extract_resource(klass) }
125
+ ObjectSpace.each_object(Class).select { |k| k < Chef::Resource }.to_h { |klass| [klass.resource_name, extract_resource(klass)] }
126
126
  else
127
127
  Array(arguments).each_with_object({}) do |arg, acc|
128
128
  if File.directory?(arg)
data/lib/chef/role.rb CHANGED
@@ -141,7 +141,7 @@ class Chef
141
141
  "override_attributes" => @override_attributes,
142
142
  "chef_type" => "role",
143
143
 
144
- # Render to_json correctly for run_list items (both run_list and evn_run_lists)
144
+ # Render to_json correctly for run_list items (both run_list and env_run_lists)
145
145
  # so malformed json does not result
146
146
  "run_list" => run_list.run_list.map(&:to_s),
147
147
  "env_run_lists" => env_run_lists_without_default.inject({}) do |accumulator, (k, v)|
@@ -73,8 +73,17 @@ module TargetIO
73
73
  path
74
74
  end
75
75
 
76
+ # Resolve the temp directory on the *target*, not the local host running
77
+ # chef-client. Using ::Dir.tmpdir here would return the host's tmp dir
78
+ # (e.g. macOS's /var/folders/...), which does not exist on the remote
79
+ # target and causes staging operations (mkdir/cp over the transport) to
80
+ # silently fail when host and target have different tmp dir conventions.
76
81
  def tmpdir
77
- ::Dir.tmpdir
82
+ result = run_command(%q{printf '%s' "${TMPDIR:-${TMP:-${TEMP:-/tmp}}}"})
83
+ dir = result.stdout.to_s.strip
84
+ dir.empty? ? "/tmp" : dir
85
+ rescue StandardError
86
+ "/tmp"
78
87
  end
79
88
 
80
89
  def unlink(dir_name)
@@ -16,7 +16,7 @@ module TargetIO
16
16
  end
17
17
 
18
18
  def chmod_R(mode, list, noop: nil, verbose: nil, force: nil)
19
- cmd = sprintf("chmod -R%s %s %s", (force ? "f" : ""), mode_to_s(mode), Array(list).join(" "))
19
+ cmd = sprintf("chmod -R%s %s %s", (force ? "f" : ""), __mode_to_s(mode), Array(list).join(" "))
20
20
 
21
21
  Chef::Log.debug cmd if verbose
22
22
  return if noop
@@ -48,8 +48,8 @@ class Chef
48
48
 
49
49
  def restore_security_context(file_path, recursive = false)
50
50
  if restorecon_path
51
- restorecon_flags = [ "-R" ]
52
- restorecon_flags << "-r" if recursive
51
+ restorecon_flags = []
52
+ restorecon_flags << "-R" if recursive
53
53
  restorecon_flags << file_path
54
54
  Chef::Log.trace("Restoring selinux security content with #{restorecon_path}")
55
55
  shell_out!(restorecon_path, restorecon_flags)
data/lib/chef/version.rb CHANGED
@@ -23,7 +23,7 @@ require_relative "version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("..", __dir__)
26
- VERSION = Chef::VersionString.new("19.3.15")
26
+ VERSION = Chef::VersionString.new("19.4.46")
27
27
  end
28
28
 
29
29
  #
@@ -73,8 +73,8 @@ HLOCAL LocalFree(
73
73
  result = command_line_to_argv_w(argv, argc)
74
74
  str_ptr = result.read_pointer
75
75
  offset = 0
76
- number_of_agrs = argc.read_int
77
- number_of_agrs.times do
76
+ number_of_args = argc.read_int
77
+ number_of_args.times do
78
78
  new_str_pointer = str_ptr.+(offset)
79
79
  argument = new_str_pointer.read_wstring
80
80
  arguments_list << argument
@@ -90,7 +90,6 @@ class Chef
90
90
  ERROR_TOO_MANY_NAMES = 68
91
91
  ERROR_TOO_MANY_SESS = 69
92
92
  ERROR_SHARING_PAUSED = 70
93
- # cspell:disable-next-line
94
93
  ERROR_REQ_NOT_ACCEP = 71
95
94
  ERROR_REDIR_PAUSED = 72
96
95
 
@@ -877,7 +876,6 @@ class Chef
877
876
 
878
877
  # Flags for LoadLibraryEx
879
878
 
880
- # cspell:disable-next-line
881
879
  DONT_RESOLVE_DLL_REFERENCES = 0x00000001
882
880
  LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010
883
881
  LOAD_LIBRARY_AS_DATAFILE = 0x00000002
@@ -39,7 +39,6 @@ class Chef
39
39
  UF_ACCOUNTDISABLE = 0x000002
40
40
  UF_PASSWD_CANT_CHANGE = 0x000040
41
41
  UF_NORMAL_ACCOUNT = 0x000200
42
- # cspell:disable-next-line
43
42
  UF_DONT_EXPIRE_PASSWD = 0x010000
44
43
 
45
44
  USE_NOFORCE = 0
@@ -84,9 +83,8 @@ class Chef
84
83
  end
85
84
 
86
85
  def as_ruby
87
- members.inject({}) do |memo, key|
88
- memo[key] = get(key)
89
- memo
86
+ members.to_h do |key|
87
+ [key, get(key)]
90
88
  end
91
89
  end
92
90
  end
@@ -125,11 +125,11 @@ class Chef
125
125
  # perform pointer arithmetic. BaseTsd.h:
126
126
  # if defined(_WIN64) host.typedef __int64 LONG_PTR; #else host.typedef long LONG_PTR;
127
127
  if win64
128
- host.typedef :int64, :LONG_PTR # Signed long type for pointer precision. Use when casting a pointer to a long to
129
- host.typedef :int64, :LPARAM # Message parameter. WinDef.h as follows: #host.typedef LONG_PTR LPARAM;
128
+ host.typedef :int64, :LONG_PTR # Signed long type for pointer precision. Use when casting a pointer to a long to
129
+ host.typedef :int64, :LPARAM # Message parameter. WinDef.h as follows: #host.typedef LONG_PTR LPARAM;
130
130
  else
131
- host.typedef :long, :LONG_PTR # Signed long type for pointer precision. Use when casting a pointer to a long to
132
- host.typedef :long, :LPARAM # Message parameter. WinDef.h as follows: #host.typedef LONG_PTR LPARAM;
131
+ host.typedef :long, :LONG_PTR # Signed long type for pointer precision. Use when casting a pointer to a long to
132
+ host.typedef :long, :LPARAM # Message parameter. WinDef.h as follows: #host.typedef LONG_PTR LPARAM;
133
133
  end
134
134
  host.typedef :pointer, :LPBOOL # Pointer to a BOOL. WinDef.h as follows: #host.typedef BOOL far *LPBOOL;
135
135
  host.typedef :pointer, :LPBYTE # Pointer to a BYTE. WinDef.h as follows: #host.typedef BYTE far *LPBYTE;
@@ -40,7 +40,6 @@ class Chef
40
40
  usri3_priv: 0,
41
41
  usri3_home_dir: nil,
42
42
  usri3_comment: nil,
43
- # cspell:disable-next-line
44
43
  usri3_flags: UF_SCRIPT | UF_DONT_EXPIRE_PASSWD | UF_NORMAL_ACCOUNT,
45
44
  usri3_script_path: nil,
46
45
  usri3_auth_flags: 0,
@@ -89,7 +89,7 @@ class Chef
89
89
  end
90
90
 
91
91
  def to_s
92
- "[#{collect(&:to_s).join(", ")}]"
92
+ "[#{collect(&:to_s).join(", ")}]" # rubocop:disable Style/MapJoin
93
93
  end
94
94
 
95
95
  def self.align_dword(size)
@@ -621,7 +621,7 @@ class Chef
621
621
  result.read_long
622
622
  end
623
623
 
624
- def set_security_descriptor_dacl(security_descriptor, acl, defaulted = false, present = nil)
624
+ def self.set_security_descriptor_dacl(security_descriptor, acl, defaulted = false, present = nil)
625
625
  security_descriptor = security_descriptor.pointer if security_descriptor.respond_to?(:pointer)
626
626
  acl = acl.pointer if acl.respond_to?(:pointer)
627
627
  present = !security_descriptor.null? if present.nil?