chef 18.9.4 → 18.10.17

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 (182) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -5
  3. data/Rakefile +21 -5
  4. data/chef.gemspec +3 -3
  5. data/lib/chef/application/apply.rb +1 -1
  6. data/lib/chef/application/base.rb +4 -4
  7. data/lib/chef/application/exit_code.rb +1 -1
  8. data/lib/chef/chef_fs/command_line.rb +4 -4
  9. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +1 -1
  10. data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +2 -3
  11. data/lib/chef/client.rb +2 -3
  12. data/lib/chef/compliance/fetcher/chef_server.rb +1 -1
  13. data/lib/chef/compliance/reporter/cli.rb +2 -2
  14. data/lib/chef/dsl/chef_vault.rb +1 -1
  15. data/lib/chef/encrypted_data_bag_item/decryptor.rb +1 -5
  16. data/lib/chef/environment.rb +1 -1
  17. data/lib/chef/exceptions.rb +1 -1
  18. data/lib/chef/file_cache.rb +1 -5
  19. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +1 -1
  20. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  21. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -1
  22. data/lib/chef/group.rb +1 -1
  23. data/lib/chef/handler/slow_report.rb +1 -1
  24. data/lib/chef/http/authenticator.rb +9 -9
  25. data/lib/chef/mixin/api_version_request_handling.rb +1 -1
  26. data/lib/chef/mixin/powershell_type_coercions.rb +2 -2
  27. data/lib/chef/mixin/securable.rb +2 -2
  28. data/lib/chef/mixin/template.rb +1 -1
  29. data/lib/chef/mixin/versioned_api.rb +1 -1
  30. data/lib/chef/monkey_patches/net-http.rb +8 -8
  31. data/lib/chef/property.rb +1 -1
  32. data/lib/chef/provider/cron.rb +1 -1
  33. data/lib/chef/provider/directory.rb +11 -0
  34. data/lib/chef/provider/dsc_resource.rb +2 -2
  35. data/lib/chef/provider/git.rb +1 -1
  36. data/lib/chef/provider/ifconfig/debian.rb +1 -1
  37. data/lib/chef/provider/mount/linux.rb +1 -1
  38. data/lib/chef/provider/mount/windows.rb +4 -4
  39. data/lib/chef/provider/package/chocolatey.rb +78 -19
  40. data/lib/chef/provider/package/homebrew.rb +3 -3
  41. data/lib/chef/provider/package/rubygems.rb +25 -2
  42. data/lib/chef/provider/package/snap.rb +1 -1
  43. data/lib/chef/provider/package/windows/exe.rb +1 -1
  44. data/lib/chef/provider/package/windows/msi.rb +1 -1
  45. data/lib/chef/provider/package/yum/rpm_utils.rb +2 -2
  46. data/lib/chef/provider/powershell_script.rb +84 -84
  47. data/lib/chef/provider/service/debian.rb +2 -4
  48. data/lib/chef/provider/user/dscl.rb +1 -1
  49. data/lib/chef/provider/user/mac.rb +1 -1
  50. data/lib/chef/provider/windows_script.rb +1 -1
  51. data/lib/chef/resource/_rest_resource.rb +5 -5
  52. data/lib/chef/resource/alternatives.rb +41 -41
  53. data/lib/chef/resource/apt_package.rb +31 -31
  54. data/lib/chef/resource/apt_preference.rb +22 -22
  55. data/lib/chef/resource/apt_repository.rb +2 -2
  56. data/lib/chef/resource/bash.rb +129 -129
  57. data/lib/chef/resource/bff_package.rb +15 -15
  58. data/lib/chef/resource/breakpoint.rb +44 -44
  59. data/lib/chef/resource/cab_package.rb +22 -22
  60. data/lib/chef/resource/chef_client_config.rb +72 -76
  61. data/lib/chef/resource/chef_client_cron.rb +18 -18
  62. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  63. data/lib/chef/resource/chef_client_scheduled_task.rb +31 -31
  64. data/lib/chef/resource/chef_client_systemd_timer.rb +16 -16
  65. data/lib/chef/resource/chef_client_trusted_certificate.rb +28 -28
  66. data/lib/chef/resource/chef_handler.rb +107 -107
  67. data/lib/chef/resource/chocolatey_config.rb +14 -14
  68. data/lib/chef/resource/chocolatey_feature.rb +1 -1
  69. data/lib/chef/resource/chocolatey_installer.rb +29 -29
  70. data/lib/chef/resource/chocolatey_source.rb +15 -15
  71. data/lib/chef/resource/cron/_cron_shared.rb +0 -2
  72. data/lib/chef/resource/cron/cron.rb +70 -70
  73. data/lib/chef/resource/csh.rb +5 -5
  74. data/lib/chef/resource/directory.rb +6 -6
  75. data/lib/chef/resource/dpkg_package.rb +3 -3
  76. data/lib/chef/resource/group.rb +28 -28
  77. data/lib/chef/resource/habitat/habitat_package.rb +79 -79
  78. data/lib/chef/resource/habitat/habitat_sup.rb +91 -93
  79. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +10 -10
  80. data/lib/chef/resource/habitat/habitat_sup_windows.rb +3 -3
  81. data/lib/chef/resource/habitat_config.rb +12 -12
  82. data/lib/chef/resource/habitat_install.rb +17 -17
  83. data/lib/chef/resource/habitat_user_toml.rb +12 -12
  84. data/lib/chef/resource/helpers/cron_validations.rb +2 -2
  85. data/lib/chef/resource/homebrew_cask.rb +1 -1
  86. data/lib/chef/resource/homebrew_package.rb +20 -20
  87. data/lib/chef/resource/homebrew_tap.rb +1 -1
  88. data/lib/chef/resource/hostname.rb +2 -2
  89. data/lib/chef/resource/http_request.rb +2 -2
  90. data/lib/chef/resource/ifconfig.rb +34 -34
  91. data/lib/chef/resource/inspec_input.rb +37 -37
  92. data/lib/chef/resource/inspec_waiver.rb +63 -63
  93. data/lib/chef/resource/inspec_waiver_file_entry.rb +25 -25
  94. data/lib/chef/resource/ksh.rb +5 -5
  95. data/lib/chef/resource/launchd.rb +2 -2
  96. data/lib/chef/resource/link.rb +8 -8
  97. data/lib/chef/resource/locale.rb +6 -6
  98. data/lib/chef/resource/log.rb +4 -4
  99. data/lib/chef/resource/mdadm.rb +36 -36
  100. data/lib/chef/resource/mount.rb +3 -3
  101. data/lib/chef/resource/msu_package.rb +1 -1
  102. data/lib/chef/resource/ohai.rb +32 -32
  103. data/lib/chef/resource/ohai_hint.rb +24 -24
  104. data/lib/chef/resource/openssl_ec_private_key.rb +1 -1
  105. data/lib/chef/resource/openssl_x509_crl.rb +15 -15
  106. data/lib/chef/resource/openssl_x509_request.rb +1 -1
  107. data/lib/chef/resource/osx_profile.rb +54 -54
  108. data/lib/chef/resource/package.rb +6 -6
  109. data/lib/chef/resource/perl.rb +5 -5
  110. data/lib/chef/resource/plist.rb +4 -4
  111. data/lib/chef/resource/powershell_package_source.rb +11 -11
  112. data/lib/chef/resource/python.rb +4 -4
  113. data/lib/chef/resource/reboot.rb +5 -5
  114. data/lib/chef/resource/registry_key.rb +81 -81
  115. data/lib/chef/resource/remote_file.rb +72 -72
  116. data/lib/chef/resource/resource_notification.rb +4 -4
  117. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  118. data/lib/chef/resource/rhsm_register.rb +1 -1
  119. data/lib/chef/resource/scm/git.rb +79 -79
  120. data/lib/chef/resource/scm/subversion.rb +9 -9
  121. data/lib/chef/resource/script.rb +3 -3
  122. data/lib/chef/resource/selinux_boolean.rb +12 -12
  123. data/lib/chef/resource/selinux_fcontext.rb +21 -21
  124. data/lib/chef/resource/selinux_install.rb +18 -18
  125. data/lib/chef/resource/selinux_login.rb +11 -11
  126. data/lib/chef/resource/selinux_module.rb +16 -16
  127. data/lib/chef/resource/selinux_permissive.rb +9 -9
  128. data/lib/chef/resource/selinux_port.rb +16 -16
  129. data/lib/chef/resource/selinux_state.rb +28 -28
  130. data/lib/chef/resource/selinux_user.rb +14 -14
  131. data/lib/chef/resource/service.rb +5 -5
  132. data/lib/chef/resource/snap_package.rb +16 -16
  133. data/lib/chef/resource/ssh_known_hosts_entry.rb +10 -10
  134. data/lib/chef/resource/sudo.rb +68 -68
  135. data/lib/chef/resource/swap_file.rb +12 -12
  136. data/lib/chef/resource/sysctl.rb +42 -42
  137. data/lib/chef/resource/systemd_unit.rb +38 -38
  138. data/lib/chef/resource/timezone.rb +16 -16
  139. data/lib/chef/resource/user/mac_user.rb +3 -3
  140. data/lib/chef/resource/user.rb +6 -6
  141. data/lib/chef/resource/user_ulimit.rb +22 -22
  142. data/lib/chef/resource/windows_ad_join.rb +24 -24
  143. data/lib/chef/resource/windows_audit_policy.rb +34 -34
  144. data/lib/chef/resource/windows_auto_run.rb +8 -8
  145. data/lib/chef/resource/windows_certificate.rb +19 -19
  146. data/lib/chef/resource/windows_defender.rb +22 -22
  147. data/lib/chef/resource/windows_defender_exclusion.rb +17 -17
  148. data/lib/chef/resource/windows_env.rb +6 -6
  149. data/lib/chef/resource/windows_feature.rb +42 -42
  150. data/lib/chef/resource/windows_feature_dism.rb +8 -8
  151. data/lib/chef/resource/windows_feature_powershell.rb +20 -20
  152. data/lib/chef/resource/windows_firewall_profile.rb +28 -28
  153. data/lib/chef/resource/windows_firewall_rule.rb +47 -47
  154. data/lib/chef/resource/windows_font.rb +7 -7
  155. data/lib/chef/resource/windows_package.rb +59 -59
  156. data/lib/chef/resource/windows_pagefile.rb +29 -29
  157. data/lib/chef/resource/windows_path.rb +12 -12
  158. data/lib/chef/resource/windows_printer.rb +28 -28
  159. data/lib/chef/resource/windows_printer_port.rb +21 -21
  160. data/lib/chef/resource/windows_security_policy.rb +23 -23
  161. data/lib/chef/resource/windows_service.rb +107 -107
  162. data/lib/chef/resource/windows_share.rb +19 -19
  163. data/lib/chef/resource/windows_shortcut.rb +7 -7
  164. data/lib/chef/resource/windows_task.rb +104 -104
  165. data/lib/chef/resource/windows_uac.rb +14 -14
  166. data/lib/chef/resource/windows_update_settings.rb +27 -27
  167. data/lib/chef/resource/windows_user_privilege.rb +59 -59
  168. data/lib/chef/resource/windows_workgroup.rb +12 -12
  169. data/lib/chef/resource/yum_repository.rb +34 -34
  170. data/lib/chef/resource.rb +1 -1
  171. data/lib/chef/resource_collection/resource_set.rb +2 -3
  172. data/lib/chef/resource_inspector.rb +1 -2
  173. data/lib/chef/run_context.rb +2 -2
  174. data/lib/chef/runner.rb +1 -1
  175. data/lib/chef/secret_fetcher/akeyless_vault.rb +0 -1
  176. data/lib/chef/secret_fetcher/hashi_vault.rb +0 -1
  177. data/lib/chef/shell/ext.rb +20 -20
  178. data/lib/chef/shell/shell_session.rb +1 -1
  179. data/lib/chef/version.rb +1 -1
  180. data/lib/chef/version_constraint.rb +1 -1
  181. data/lib/chef/win32/file/version_info.rb +1 -1
  182. metadata +10 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a1de7dd02696d84d680c3851565ec4837ca0275cc4cc153d39bde72eea4f2be
4
- data.tar.gz: 5e8ac13c389d7e024108b626f935d11c092a120fd857ac5200fc13fafcc1a5d2
3
+ metadata.gz: ea642da5a95174bc30b1f2010f05945c9a7847e1082f88c415bf5d9807f39227
4
+ data.tar.gz: 0edf60effa635270d37059fd3e315d77cd97f852fce7547569fae96b13ccaf4c
5
5
  SHA512:
6
- metadata.gz: cc96321c5e4d51febea1aec696accb358d3219a31e142c00b5c7255501682f98f098de20ae2e720ac9fbb4c13991a3692614262585ed4dde34ce2b2eb7830bb7
7
- data.tar.gz: 8d35f965f1f382983b098dce2a7302684cd2273523ea03b07a1a66c5183f70bda24bcabfd4056c8c9bc7ca5eeb7c698ed92e70826703e760b5927b4a06af1055
6
+ metadata.gz: 29095f460f5a93f61dfc67cb21a76bdedd4ceb154a347583424b1d07d7f23e707cafd6a28677d81b2d9753eed323fc78ae8474027d86fb3fee9f7d3910560997
7
+ data.tar.gz: f1f1869359071735d971e79faa2f2a5a0ab11ddad463c278ae1ff47a0b80db4e1c202d71ff7e10b7c6a761e45cb1c79b958ae3bbd0f02dec8901240c178cffa2
data/Gemfile CHANGED
@@ -64,11 +64,7 @@ group(:development, :test) do
64
64
  gem "fauxhai-ng" # for chef-utils gem
65
65
  end
66
66
 
67
- gem "chefstyle"
68
- # group(:chefstyle) do
69
- # # for testing new chefstyle rules
70
- # gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "main"
71
- # end
67
+ gem "cookstyle", "~> 8.6"
72
68
 
73
69
  instance_eval(ENV["GEMFILE_MOD"]) if ENV["GEMFILE_MOD"]
74
70
 
data/Rakefile CHANGED
@@ -100,12 +100,28 @@ task :register_eventlog do
100
100
  end
101
101
  end
102
102
 
103
- begin
104
- require "chefstyle"
103
+ desc "Check Linting and code style."
104
+ task :style do
105
105
  require "rubocop/rake_task"
106
- RuboCop::RakeTask.new(:style) do |task|
107
- task.options += ["--display-cop-names", "--no-color"]
106
+ require "cookstyle/chefstyle"
107
+
108
+ if RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/
109
+ # Windows-specific command, rubocop erroneously reports the CRLF in each file which is removed when your PR is uploaded to GitHub.
110
+ # This is a workaround to ignore the CRLF from the files before running cookstyle.
111
+ sh "cookstyle --chefstyle -c .rubocop.yml --except Layout/EndOfLine"
112
+ else
113
+ sh "cookstyle --chefstyle -c .rubocop.yml"
108
114
  end
109
115
  rescue LoadError
110
- puts "chefstyle/rubocop is not available. bundle install first to make sure all dependencies are installed."
116
+ puts "Rubocop or Cookstyle gems are not installed. bundle install first to make sure all dependencies are installed."
111
117
  end
118
+
119
+ # begin
120
+ # require "chefstyle"
121
+ # require "rubocop/rake_task"
122
+ # RuboCop::RakeTask.new(:style) do |task|
123
+ # task.options += ["--display-cop-names", "--no-color"]
124
+ # end
125
+ # rescue LoadError
126
+ # puts "chefstyle/rubocop is not available. bundle install first to make sure all dependencies are installed."
127
+ # end
data/chef.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # on Windows, the directory location starts with "(eval at " because it's
2
2
  # being evaled in
3
- file_directory = File.dirname(__FILE__).gsub(/\(eval at /, "")
3
+ file_directory = File.dirname(__FILE__).gsub("(eval at ", "")
4
4
  $:.unshift(File.join(file_directory, "lib"))
5
5
  vs_path = File.expand_path("chef-utils/lib/chef-utils/version_string.rb", __dir__)
6
6
 
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.add_dependency "chef-config", "= #{Chef::VERSION}"
35
35
  s.add_dependency "chef-utils", "= #{Chef::VERSION}"
36
36
  s.add_dependency "train-core", "~> 3.13", ">= 3.13.4"
37
- s.add_dependency "train-winrm", "~> 0.2.17"
37
+ s.add_dependency "train-winrm", "~> 0.4.0"
38
38
  s.add_dependency "train-rest", ">= 0.4.1" # target mode with rest APIs
39
39
 
40
40
  s.add_dependency "license-acceptance", ">= 1.0.5", "< 3"
@@ -68,7 +68,7 @@ Gem::Specification.new do |s|
68
68
  s.add_dependency "syslog-logger", "~> 1.6"
69
69
  s.add_dependency "uuidtools", ">= 2.1.5", "< 3.0" # osx_profile resource
70
70
  s.add_dependency "unf_ext", "~> 0.0.8.2" # older platforms
71
- s.add_dependency "uri", "~> 1.0.3" # This is used by net-http. We are forcing a version to get past a CVE in 1.0.2
71
+ s.add_dependency "uri", "~> 1.0.4" # This is used by net-http. We are forcing a version to get past a CVE in 1.0.2
72
72
  s.add_dependency "corefoundation", "~> 0.3.4" # macos_userdefaults resource
73
73
 
74
74
  s.add_dependency "proxifier2", "~> 1.1"
@@ -75,7 +75,7 @@ class Chef::Application::Apply < Chef::Application
75
75
  short: "-l LEVEL",
76
76
  long: "--log_level LEVEL",
77
77
  description: "Set the log level (trace, debug, info, warn, error, fatal).",
78
- proc: lambda { |l| l.to_sym }
78
+ proc: lambda(&:to_sym)
79
79
 
80
80
  option :log_location_cli,
81
81
  short: "-L LOGLOCATION",
@@ -96,7 +96,7 @@ class Chef::Application::Base < Chef::Application
96
96
  short: "-l LEVEL",
97
97
  long: "--log_level LEVEL",
98
98
  description: "Set the log level (auto, trace, debug, info, warn, error, fatal).",
99
- proc: lambda { |l| l.to_sym }
99
+ proc: lambda(&:to_sym)
100
100
 
101
101
  option :log_location_cli,
102
102
  short: "-L LOGLOCATION",
@@ -139,7 +139,7 @@ class Chef::Application::Base < Chef::Application
139
139
  short: "-i SECONDS",
140
140
  long: "--interval SECONDS",
141
141
  description: "Run #{ChefUtils::Dist::Infra::PRODUCT} periodically, in seconds.",
142
- proc: lambda { |s| s.to_i }
142
+ proc: lambda(&:to_i)
143
143
 
144
144
  option :json_attribs,
145
145
  short: "-j JSON_ATTRIBS",
@@ -157,7 +157,7 @@ class Chef::Application::Base < Chef::Application
157
157
  short: "-s SECONDS",
158
158
  long: "--splay SECONDS",
159
159
  description: "The splay time for running at intervals, in seconds.",
160
- proc: lambda { |s| s.to_i }
160
+ proc: lambda(&:to_i)
161
161
 
162
162
  option :environment,
163
163
  short: "-E ENVIRONMENT",
@@ -189,7 +189,7 @@ class Chef::Application::Base < Chef::Application
189
189
  option :run_lock_timeout,
190
190
  long: "--run-lock-timeout SECONDS",
191
191
  description: "Set maximum duration to wait for another client run to finish, default is indefinitely.",
192
- proc: lambda { |s| s.to_i }
192
+ proc: lambda(&:to_i)
193
193
 
194
194
  option :version,
195
195
  short: "-v",
@@ -141,7 +141,7 @@ class Chef
141
141
  def non_standard_exit_code_warning(exit_code)
142
142
  "#{ChefUtils::Dist::Infra::CLIENT} attempted to exit with a non-standard exit code of #{exit_code}." \
143
143
  " The #{ChefUtils::Dist::Infra::PRODUCT} Exit Codes design document (https://github.com/chef/chef/blob/main/docs/dev/design_documents/client_exit_codes.md)" \
144
- " defines the exit codes that should be used with #{ChefUtils::Dist::Infra::CLIENT}. Chef::Application::ExitCode defines" \
144
+ " defines the exit codes that should be used with #{ChefUtils::Dist::Infra::CLIENT}. Chef::Application::ExitCode defines" \
145
145
  " valid exit codes Non-standard exit codes are redefined as GENERIC_FAILURE."
146
146
  end
147
147
 
@@ -29,7 +29,7 @@ class Chef
29
29
 
30
30
  def self.diff_print(pattern, a_root, b_root, recurse_depth, output_mode, format_path = nil, diff_filter = nil, ui = nil)
31
31
  if format_path.nil?
32
- format_path = proc { |entry| entry.path_for_printing }
32
+ format_path = proc(&:path_for_printing)
33
33
  end
34
34
 
35
35
  get_content = (output_mode != :name_only && output_mode != :name_status)
@@ -119,9 +119,9 @@ class Chef
119
119
  yield result
120
120
  end
121
121
 
122
- when :both_nonexistent
123
- when :added_cannot_upload
124
- when :deleted_cannot_download
122
+ when :both_nonexistent # rubocop:disable Lint/EmptyWhen
123
+ when :added_cannot_upload # rubocop:disable Lint/EmptyWhen
124
+ when :deleted_cannot_download # rubocop:disable Lint/EmptyWhen
125
125
  when :same
126
126
  # Skip these silently
127
127
  when :error
@@ -91,7 +91,7 @@ class Chef
91
91
  end
92
92
  end
93
93
  # Create the file itself
94
- container.add_child(CookbookFile.new(parts[parts.length - 1], container, file))
94
+ container.add_child(CookbookFile.new(parts[-1], container, file))
95
95
  end
96
96
  end
97
97
  @children = @children.sort_by(&:name)
@@ -80,9 +80,8 @@ class Chef
80
80
  tmp_cl.load_cookbooks
81
81
  tmp_cl.compile_metadata
82
82
  tmp_cl.freeze_versions if options[:freeze]
83
- cookbook_for_upload = []
84
- tmp_cl.each do |cookbook_name, cookbook|
85
- cookbook_for_upload << cookbook
83
+ cookbook_for_upload = tmp_cl.map do |cookbook_name, cookbook|
84
+ cookbook
86
85
  end
87
86
 
88
87
  uploader = Chef::CookbookUploader.new(cookbook_for_upload, force: options[:force], rest: chef_rest)
data/lib/chef/client.rb CHANGED
@@ -385,7 +385,7 @@ class Chef
385
385
  # @api private
386
386
  def rest
387
387
  @rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], client_name: node_name,
388
- signing_key_filename: Chef::Config[:client_key])
388
+ signing_key_filename: Chef::Config[:client_key])
389
389
  end
390
390
 
391
391
  # A rest object with validate_utf8 set to false. This will not throw exceptions
@@ -397,7 +397,7 @@ class Chef
397
397
  def rest_clean
398
398
  @rest_clean ||=
399
399
  Chef::ServerAPI.new(Chef::Config[:chef_server_url], client_name: node_name,
400
- signing_key_filename: Chef::Config[:client_key], validate_utf8: false)
400
+ signing_key_filename: Chef::Config[:client_key], validate_utf8: false)
401
401
  end
402
402
 
403
403
  #
@@ -1090,4 +1090,3 @@ end
1090
1090
  require_relative "cookbook_loader"
1091
1091
  require_relative "cookbook_version"
1092
1092
  require_relative "cookbook/synchronizer"
1093
-
@@ -125,7 +125,7 @@ class Chef
125
125
  private
126
126
 
127
127
  def chef_server_url
128
- m = %r{^#{@config['server']}/owners/(?<owner>[^/]+)/compliance/(?<id>[^/]+)/tar$}.match(@target)
128
+ m = %r{^#{@config["server"]}/owners/(?<owner>[^/]+)/compliance/(?<id>[^/]+)/tar$}.match(@target)
129
129
  "#{m[:owner]}/#{m[:id]}"
130
130
  end
131
131
  end
@@ -46,11 +46,11 @@ class Chef
46
46
  end
47
47
  if result[:message]
48
48
  if found
49
- result[:message].split(/\n/).reject(&:empty?).each do |m|
49
+ result[:message].split("\n").reject(&:empty?).each do |m|
50
50
  output << pastel.red("#{" " * 12}#{m}")
51
51
  end
52
52
  else
53
- result[:message].split(/\n/).reject(&:empty?).each do |m|
53
+ result[:message].split("\n").reject(&:empty?).each do |m|
54
54
  output << pastel.red("#{" " * 9}#{m}")
55
55
  end
56
56
  end
@@ -81,4 +81,4 @@ class Chef
81
81
  end
82
82
  end
83
83
  end
84
- end
84
+ end
@@ -177,11 +177,7 @@ class Chef::EncryptedDataBagItem
177
177
  digest = OpenSSL::Digest.new("sha256")
178
178
  raw_hmac = OpenSSL::HMAC.digest(digest, key, @encrypted_data["encrypted_data"])
179
179
 
180
- if candidate_hmac_matches?(raw_hmac)
181
- true
182
- else
183
- raise DecryptionFailure, "Error decrypting data bag value: invalid hmac. Most likely the provided key is incorrect"
184
- end
180
+ candidate_hmac_matches?(raw_hmac) || raise(DecryptionFailure, "Error decrypting data bag value: invalid hmac. Most likely the provided key is incorrect")
185
181
  end
186
182
 
187
183
  private
@@ -35,7 +35,7 @@ class Chef
35
35
  include Chef::Mixin::ParamsValidate
36
36
  include Chef::Mixin::FromFile
37
37
 
38
- COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:\s+)((?:#{Chef::VersionConstraint::OPS.join('|')})(?:\s+).+)$/.freeze
38
+ COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:\s+)((?:#{Chef::VersionConstraint::OPS.join("|")})(?:\s+).+)$/.freeze
39
39
 
40
40
  def initialize(chef_server_rest: nil)
41
41
  @name = ""
@@ -532,7 +532,7 @@ class Chef
532
532
  @resources_found = resources_found
533
533
  matches_info = @resources_found.each do |r|
534
534
  if r["Module"].nil?
535
- "Resource #{r["Name"]} was found in #{r["Module"]["Name"]}"
535
+ "Resource #{r["Name"]} was found in #{r["Module"]["Name"]}" # rubocop:disable Lint/Void
536
536
  else
537
537
  "Resource #{r["Name"]} is a binary resource"
538
538
  end
@@ -201,11 +201,7 @@ class Chef
201
201
  }
202
202
  )
203
203
  full_path = create_cache_path(path, false)
204
- if File.exist?(full_path)
205
- true
206
- else
207
- false
208
- end
204
+ File.exist?(full_path) || false
209
205
  end
210
206
 
211
207
  alias_method :has_key?, :key?
@@ -126,7 +126,7 @@ class Chef
126
126
  end
127
127
 
128
128
  def filtered_bt
129
- backtrace_lines_in_cookbooks.count > 0 ? backtrace_lines_in_cookbooks : exception.backtrace
129
+ backtrace_lines_in_cookbooks.any? ? backtrace_lines_in_cookbooks : exception.backtrace
130
130
  end
131
131
 
132
132
  def found_error_in_cookbooks?
@@ -69,7 +69,7 @@ class Chef
69
69
  describe_412_error(error_description)
70
70
  when Net::HTTPBadRequest
71
71
  describe_400_error(error_description)
72
- when Net::HTTPNotFound
72
+ when Net::HTTPNotFound # rubocop:disable Lint/EmptyWhen
73
73
  when Net::HTTPInternalServerError
74
74
  describe_500_error(error_description)
75
75
  when Net::HTTPBadGateway, Net::HTTPServiceUnavailable
@@ -64,7 +64,7 @@ class Chef
64
64
  describe_401_error(error_description)
65
65
  when Net::HTTPBadRequest
66
66
  describe_400_error(error_description)
67
- when Net::HTTPNotFound
67
+ when Net::HTTPNotFound # rubocop:disable Lint/EmptyWhen
68
68
  when Net::HTTPInternalServerError
69
69
  describe_500_error(error_description)
70
70
  when Net::HTTPBadGateway, Net::HTTPServiceUnavailable, Net::HTTPGatewayTimeOut
data/lib/chef/group.rb CHANGED
@@ -35,7 +35,7 @@ class Chef
35
35
  body_hash = {
36
36
  groupname: "#{groupname}",
37
37
  actors: {
38
- "users" => group["actors"].concat([username]),
38
+ "users" => group["actors"].push(username),
39
39
  "groups" => group["groups"],
40
40
  },
41
41
  }
@@ -54,7 +54,7 @@ class Chef
54
54
 
55
55
  def count
56
56
  num = all_resources.count
57
- num > amount ? amount : num
57
+ [num, amount].min
58
58
  end
59
59
 
60
60
  def stripped_source_line(resource)
@@ -335,15 +335,15 @@ class Chef
335
335
  def self.get_the_key_ps(client_name, password)
336
336
  store = get_cert_user
337
337
  powershell_code = <<~CODE
338
- Try {
339
- $my_pwd = ConvertTo-SecureString -String "#{password}" -Force -AsPlainText;
340
- $cert = Get-ChildItem -path cert:\\#{store}\\My -Recurse | Where-Object { $_.Subject -match "chef-#{client_name}$" } -ErrorAction Stop;
341
- $tempfile = [System.IO.Path]::GetTempPath() + "export_pfx.pfx";
342
- Export-PfxCertificate -Cert $cert -Password $my_pwd -FilePath $tempfile;
343
- }
344
- Catch {
345
- return $false
346
- }
338
+ Try {
339
+ $my_pwd = ConvertTo-SecureString -String "#{password}" -Force -AsPlainText;
340
+ $cert = Get-ChildItem -path cert:\\#{store}\\My -Recurse | Where-Object { $_.Subject -match "chef-#{client_name}$" } -ErrorAction Stop;
341
+ $tempfile = [System.IO.Path]::GetTempPath() + "export_pfx.pfx";
342
+ Export-PfxCertificate -Cert $cert -Password $my_pwd -FilePath $tempfile;
343
+ }
344
+ Catch {
345
+ return $false
346
+ }
347
347
  CODE
348
348
  end
349
349
 
@@ -42,7 +42,7 @@ class Chef
42
42
  max_server_version = Integer(header["max_version"])
43
43
 
44
44
  supported_client_versions.each do |version|
45
- if version >= min_server_version && version <= max_server_version
45
+ if version.between?(min_server_version, max_server_version)
46
46
  server_supported_client_versions.push(version)
47
47
  end
48
48
  end
@@ -72,8 +72,8 @@ class Chef
72
72
  # do we need to worry about binary data?
73
73
  if unsafe?(s)
74
74
  encoded_str = Base64.strict_encode64(s.encode("UTF-8"))
75
- "([System.Text.Encoding]::UTF8.GetString("\
76
- "[System.Convert]::FromBase64String('#{encoded_str}')"\
75
+ "([System.Text.Encoding]::UTF8.GetString(" \
76
+ "[System.Convert]::FromBase64String('#{encoded_str}')" \
77
77
  "))"
78
78
  else
79
79
  "'#{s}'"
@@ -50,9 +50,9 @@ class Chef
50
50
 
51
51
  # Windows does not support the sticky or setuid bits
52
52
  if ChefUtils.windows?
53
- Integer(m) <= 0777 && Integer(m) >= 0
53
+ Integer(m).between?(0, 0777)
54
54
  else
55
- Integer(m) <= 07777 && Integer(m) >= 0
55
+ Integer(m).between?(0, 07777)
56
56
  end
57
57
  end,
58
58
  }
@@ -238,7 +238,7 @@ class Chef
238
238
 
239
239
  def source_listing
240
240
  @source_listing ||= begin
241
- lines = @template.split(/\n/)
241
+ lines = @template.split("\n")
242
242
  if line_number
243
243
  line_index = line_number - 1
244
244
  beginning_line = line_index <= SOURCE_CONTEXT_WINDOW ? 0 : line_index - SOURCE_CONTEXT_WINDOW
@@ -48,7 +48,7 @@ class Chef
48
48
  version = klass.send(:minimum_api_version)
49
49
  # min and max versions will be nil if we've not made a request to the server yet,
50
50
  # in which case we'll just start with the highest version and see what happens
51
- ServerAPIVersions.instance.min_server_version.nil? || (version >= ServerAPIVersions.instance.min_server_version && version <= ServerAPIVersions.instance.send(type))
51
+ ServerAPIVersions.instance.min_server_version.nil? || (version.between?(ServerAPIVersions.instance.min_server_version, ServerAPIVersions.instance.send(type)))
52
52
  end
53
53
  .max_by { |a| a.send(:minimum_api_version) }
54
54
  end
@@ -37,9 +37,9 @@ if RUBY_VERSION.split(".")[0..1].join(".") == "3.1"
37
37
  if use_ssl?
38
38
  if proxy?
39
39
  plain_sock = BufferedIO.new(s, read_timeout: @read_timeout,
40
- write_timeout: @write_timeout,
41
- continue_timeout: @continue_timeout,
42
- debug_output: @debug_output)
40
+ write_timeout: @write_timeout,
41
+ continue_timeout: @continue_timeout,
42
+ debug_output: @debug_output)
43
43
  buf = "CONNECT #{conn_address}:#{@port} HTTP/#{HTTPVersion}\r\n"
44
44
  buf << "Host: #{@address}:#{@port}\r\n"
45
45
  if proxy_user
@@ -65,8 +65,8 @@ if RUBY_VERSION.split(".")[0..1].join(".") == "3.1"
65
65
  @ssl_context.set_params(ssl_parameters)
66
66
  unless @ssl_context.session_cache_mode.nil? # a dummy method on JRuby
67
67
  @ssl_context.session_cache_mode =
68
- OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |
69
- OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE
68
+ OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |
69
+ OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE
70
70
  end
71
71
  if @ssl_context.respond_to?(:session_new_cb) # not implemented under JRuby
72
72
  @ssl_context.session_new_cb = proc { |sock, sess| @ssl_session = sess }
@@ -108,9 +108,9 @@ if RUBY_VERSION.split(".")[0..1].join(".") == "3.1"
108
108
  Chef::Log.debug("SSL established, protocol: #{s.ssl_version}, cipher: #{s.cipher[0]}")
109
109
  end
110
110
  @socket = BufferedIO.new(s, read_timeout: @read_timeout,
111
- write_timeout: @write_timeout,
112
- continue_timeout: @continue_timeout,
113
- debug_output: @debug_output)
111
+ write_timeout: @write_timeout,
112
+ continue_timeout: @continue_timeout,
113
+ debug_output: @debug_output)
114
114
  @last_communicated = nil
115
115
  on_connect
116
116
  rescue => exception
data/lib/chef/property.rb CHANGED
@@ -698,7 +698,7 @@ class Chef
698
698
  # Weeding out class methods avoids unnecessary deprecations such Chef::Resource
699
699
  # defining a `name` property when there's an already-existing `name` method
700
700
  # for a Module.
701
- return false unless declared_in.instance_methods.include?(name)
701
+ return false unless declared_in.method_defined?(name)
702
702
 
703
703
  # Only emit deprecations for some well-known classes. This will still
704
704
  # allow more advanced users to subclass their own custom resources and
@@ -27,7 +27,7 @@ class Chef
27
27
  SPECIAL_TIME_VALUES = %i{reboot yearly annually monthly weekly daily midnight hourly}.freeze
28
28
  CRON_ATTRIBUTES = %i{minute hour day month weekday time command mailto path shell home environment}.freeze
29
29
  CRON_PATTERN = %r{\A([-0-9*,/]+)\s([-0-9*,/]+)\s([-0-9*,/]+)\s([-0-9*,/]+|[a-zA-Z]{3})\s([-0-9*,/]+|[a-zA-Z]{3})\s(.*)}.freeze
30
- SPECIAL_PATTERN = /\A(@(#{SPECIAL_TIME_VALUES.join('|')}))\s(.*)/.freeze
30
+ SPECIAL_PATTERN = /\A(@(#{SPECIAL_TIME_VALUES.join("|")}))\s(.*)/.freeze
31
31
  ENV_PATTERN = /\A(\S+)=(\S*)/.freeze
32
32
  ENVIRONMENT_PROPERTIES = %w{MAILTO PATH SHELL HOME}.freeze
33
33
 
@@ -65,6 +65,17 @@ class Chef
65
65
  a.whyrun("Assuming directory #{parent_directory} would have been created")
66
66
  end
67
67
 
68
+ requirements.assert(:create) do |a|
69
+ a.assertion do
70
+ if ::File.exist?(new_resource.path)
71
+ ::File.directory?(new_resource.path)
72
+ else
73
+ true
74
+ end
75
+ end
76
+ a.failure_message(Chef::Exceptions::FileTypeMismatch, "Cannot create #{new_resource} at #{new_resource.path} because a file already exists at that path")
77
+ end
78
+
68
79
  requirements.assert(:create) do |a|
69
80
  parent_directory = ::File.dirname(new_resource.path)
70
81
  a.assertion do
@@ -114,7 +114,7 @@ class Chef
114
114
  r = case found.length
115
115
  when 0
116
116
  raise Chef::Exceptions::ResourceNotFound,
117
- "Could not find #{dsc_resource_name}. Check to make "\
117
+ "Could not find #{dsc_resource_name}. Check to make " \
118
118
  "sure that it shows up when running Get-DscResource"
119
119
  when 1
120
120
  if found[0]["Module"].nil?
@@ -162,7 +162,7 @@ class Chef
162
162
 
163
163
  def invoke_resource(method)
164
164
  properties = translate_type(new_resource.properties)
165
- switches = "-Method #{method} -Name #{new_resource.resource}"\
165
+ switches = "-Method #{method} -Name #{new_resource.resource}" \
166
166
  " -Property #{properties} -Module #{module_info_object} -Verbose"
167
167
  Timeout.timeout(new_resource.timeout) {
168
168
  powershell_exec!("Invoke-DscResource #{switches}")
@@ -61,7 +61,7 @@ class Chef
61
61
  a.assertion { ::File.directory?(dirname) }
62
62
  a.whyrun("Directory #{dirname} does not exist, this run will fail unless it has been previously created. Assuming it would have been created.")
63
63
  a.failure_message(Chef::Exceptions::MissingParentDirectory,
64
- "Cannot clone #{new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist")
64
+ "Cannot clone #{new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist")
65
65
  end
66
66
 
67
67
  requirements.assert(:all_actions) do |a|
@@ -87,7 +87,7 @@ iface <%= new_resource.device %> <%= new_resource.family %> static
87
87
  directory INTERFACES_DOT_D_DIR
88
88
 
89
89
  # roll our own file_edit resource, this will not get reported until we have a file_edit resource
90
- interfaces_dot_d_for_regexp = INTERFACES_DOT_D_DIR.gsub(/\./, "\\.") # escape dots for the regexp
90
+ interfaces_dot_d_for_regexp = INTERFACES_DOT_D_DIR.gsub(".", "\\.") # escape dots for the regexp
91
91
  regexp = %r{^\s*source\s+#{interfaces_dot_d_for_regexp}/\*\s*$}
92
92
 
93
93
  return if ::File.exist?(INTERFACES_FILE) && regexp.match(IO.read(INTERFACES_FILE))
@@ -83,4 +83,4 @@ class Chef
83
83
  end
84
84
  end
85
85
  end
86
- end
86
+ end
@@ -30,7 +30,7 @@ class Chef
30
30
  provides :mount, os: "windows"
31
31
 
32
32
  def is_volume(name)
33
- /^\\\\\?\\Volume\{[\w-]+\}\\$/.match?(name) ? true : false
33
+ /^\\\\\?\\Volume\{[\w-]+\}\\$/.match?(name) || false
34
34
  end
35
35
 
36
36
  def initialize(new_resource, run_context)
@@ -62,9 +62,9 @@ class Chef
62
62
  def mount_fs
63
63
  unless @current_resource.mounted
64
64
  @mount.add(remote: @new_resource.device,
65
- username: @new_resource.username,
66
- domainname: @new_resource.domain,
67
- password: @new_resource.password)
65
+ username: @new_resource.username,
66
+ domainname: @new_resource.domain,
67
+ password: @new_resource.password)
68
68
  logger.trace("#{@new_resource} is mounted at #{@new_resource.mount_point}")
69
69
  else
70
70
  logger.debug("#{@new_resource} is already mounted at #{@new_resource.mount_point}")