chef 18.9.4 → 18.11.11

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 (205) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -12
  3. data/README.md +0 -1
  4. data/Rakefile +21 -5
  5. data/chef-universal-mingw-ucrt.gemspec +4 -2
  6. data/chef.gemspec +17 -14
  7. data/lib/chef/application/apply.rb +1 -1
  8. data/lib/chef/application/base.rb +4 -4
  9. data/lib/chef/application/exit_code.rb +1 -1
  10. data/lib/chef/chef_fs/command_line.rb +4 -4
  11. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +1 -1
  12. data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +2 -3
  13. data/lib/chef/client.rb +2 -3
  14. data/lib/chef/compliance/fetcher/chef_server.rb +1 -1
  15. data/lib/chef/compliance/reporter/cli.rb +2 -2
  16. data/lib/chef/compliance/runner.rb +19 -1
  17. data/lib/chef/dsl/chef_vault.rb +1 -1
  18. data/lib/chef/dsl/rest_resource.rb +223 -16
  19. data/lib/chef/encrypted_data_bag_item/decryptor.rb +1 -5
  20. data/lib/chef/environment.rb +1 -1
  21. data/lib/chef/exceptions.rb +1 -1
  22. data/lib/chef/file_cache.rb +1 -5
  23. data/lib/chef/formatters/error_description.rb +8 -1
  24. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +1 -1
  25. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  26. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -1
  27. data/lib/chef/group.rb +1 -1
  28. data/lib/chef/handler/slow_report.rb +1 -1
  29. data/lib/chef/http/authenticator.rb +25 -12
  30. data/lib/chef/mixin/api_version_request_handling.rb +1 -1
  31. data/lib/chef/mixin/powershell_type_coercions.rb +2 -2
  32. data/lib/chef/mixin/securable.rb +2 -2
  33. data/lib/chef/mixin/template.rb +25 -3
  34. data/lib/chef/mixin/versioned_api.rb +1 -1
  35. data/lib/chef/monkey_patches/net-http.rb +8 -8
  36. data/lib/chef/monkey_patches/reline-windows.rb +116 -0
  37. data/lib/chef/property.rb +1 -1
  38. data/lib/chef/provider/cron.rb +1 -1
  39. data/lib/chef/provider/directory.rb +11 -0
  40. data/lib/chef/provider/dsc_resource.rb +2 -2
  41. data/lib/chef/provider/file/content.rb +3 -2
  42. data/lib/chef/provider/file.rb +1 -1
  43. data/lib/chef/provider/git.rb +1 -1
  44. data/lib/chef/provider/ifconfig/debian.rb +1 -1
  45. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  46. data/lib/chef/provider/mount/linux.rb +1 -1
  47. data/lib/chef/provider/mount/windows.rb +4 -4
  48. data/lib/chef/provider/package/chocolatey.rb +78 -19
  49. data/lib/chef/provider/package/dnf/dnf_helper.py +355 -65
  50. data/lib/chef/provider/package/dnf/python_helper.rb +7 -4
  51. data/lib/chef/provider/package/dnf.rb +25 -6
  52. data/lib/chef/provider/package/homebrew.rb +3 -3
  53. data/lib/chef/provider/package/rubygems.rb +25 -2
  54. data/lib/chef/provider/package/snap.rb +1 -1
  55. data/lib/chef/provider/package/windows/exe.rb +1 -1
  56. data/lib/chef/provider/package/windows/msi.rb +1 -1
  57. data/lib/chef/provider/package/yum/rpm_utils.rb +2 -2
  58. data/lib/chef/provider/package/yum.rb +1 -1
  59. data/lib/chef/provider/powershell_script.rb +84 -84
  60. data/lib/chef/provider/service/debian.rb +2 -4
  61. data/lib/chef/provider/user/dscl.rb +1 -1
  62. data/lib/chef/provider/user/mac.rb +1 -1
  63. data/lib/chef/provider/windows_script.rb +1 -1
  64. data/lib/chef/resource/_rest_resource.rb +9 -7
  65. data/lib/chef/resource/alternatives.rb +41 -41
  66. data/lib/chef/resource/apt_package.rb +31 -31
  67. data/lib/chef/resource/apt_preference.rb +22 -22
  68. data/lib/chef/resource/apt_repository.rb +2 -2
  69. data/lib/chef/resource/archive_file.rb +52 -18
  70. data/lib/chef/resource/bash.rb +129 -129
  71. data/lib/chef/resource/bff_package.rb +15 -15
  72. data/lib/chef/resource/breakpoint.rb +44 -44
  73. data/lib/chef/resource/cab_package.rb +22 -22
  74. data/lib/chef/resource/chef_client_config.rb +251 -89
  75. data/lib/chef/resource/chef_client_cron.rb +18 -18
  76. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  77. data/lib/chef/resource/chef_client_scheduled_task.rb +31 -31
  78. data/lib/chef/resource/chef_client_systemd_timer.rb +16 -16
  79. data/lib/chef/resource/chef_client_trusted_certificate.rb +28 -28
  80. data/lib/chef/resource/chef_handler.rb +107 -107
  81. data/lib/chef/resource/chef_vault_secret.rb +1 -1
  82. data/lib/chef/resource/chocolatey_config.rb +14 -14
  83. data/lib/chef/resource/chocolatey_feature.rb +1 -1
  84. data/lib/chef/resource/chocolatey_installer.rb +60 -42
  85. data/lib/chef/resource/chocolatey_package.rb +1 -1
  86. data/lib/chef/resource/chocolatey_source.rb +15 -15
  87. data/lib/chef/resource/cron/_cron_shared.rb +0 -2
  88. data/lib/chef/resource/cron/cron.rb +70 -70
  89. data/lib/chef/resource/csh.rb +5 -5
  90. data/lib/chef/resource/directory.rb +6 -6
  91. data/lib/chef/resource/dpkg_package.rb +3 -3
  92. data/lib/chef/resource/group.rb +28 -28
  93. data/lib/chef/resource/habitat/habitat_package.rb +80 -80
  94. data/lib/chef/resource/habitat/habitat_sup.rb +93 -95
  95. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +10 -10
  96. data/lib/chef/resource/habitat/habitat_sup_windows.rb +3 -3
  97. data/lib/chef/resource/habitat_config.rb +13 -13
  98. data/lib/chef/resource/habitat_install.rb +17 -17
  99. data/lib/chef/resource/habitat_service.rb +1 -1
  100. data/lib/chef/resource/habitat_user_toml.rb +12 -12
  101. data/lib/chef/resource/helpers/cron_validations.rb +2 -2
  102. data/lib/chef/resource/homebrew_cask.rb +1 -1
  103. data/lib/chef/resource/homebrew_package.rb +20 -20
  104. data/lib/chef/resource/homebrew_tap.rb +1 -1
  105. data/lib/chef/resource/hostname.rb +2 -2
  106. data/lib/chef/resource/http_request.rb +2 -2
  107. data/lib/chef/resource/ifconfig.rb +34 -34
  108. data/lib/chef/resource/inspec_input.rb +37 -37
  109. data/lib/chef/resource/inspec_waiver.rb +63 -63
  110. data/lib/chef/resource/inspec_waiver_file_entry.rb +25 -25
  111. data/lib/chef/resource/ksh.rb +5 -5
  112. data/lib/chef/resource/launchd.rb +2 -2
  113. data/lib/chef/resource/link.rb +8 -8
  114. data/lib/chef/resource/locale.rb +6 -6
  115. data/lib/chef/resource/log.rb +4 -4
  116. data/lib/chef/resource/mdadm.rb +36 -36
  117. data/lib/chef/resource/mount.rb +3 -3
  118. data/lib/chef/resource/msu_package.rb +1 -1
  119. data/lib/chef/resource/ohai.rb +32 -32
  120. data/lib/chef/resource/ohai_hint.rb +24 -24
  121. data/lib/chef/resource/openssl_ec_private_key.rb +2 -2
  122. data/lib/chef/resource/openssl_ec_public_key.rb +2 -2
  123. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -1
  124. data/lib/chef/resource/openssl_rsa_public_key.rb +2 -2
  125. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  126. data/lib/chef/resource/openssl_x509_crl.rb +15 -15
  127. data/lib/chef/resource/openssl_x509_request.rb +2 -2
  128. data/lib/chef/resource/osx_profile.rb +54 -54
  129. data/lib/chef/resource/package.rb +6 -6
  130. data/lib/chef/resource/perl.rb +5 -5
  131. data/lib/chef/resource/plist.rb +4 -4
  132. data/lib/chef/resource/powershell_package_source.rb +12 -12
  133. data/lib/chef/resource/python.rb +4 -4
  134. data/lib/chef/resource/reboot.rb +5 -5
  135. data/lib/chef/resource/registry_key.rb +81 -81
  136. data/lib/chef/resource/remote_file.rb +72 -72
  137. data/lib/chef/resource/resource_notification.rb +4 -4
  138. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  139. data/lib/chef/resource/rhsm_register.rb +2 -2
  140. data/lib/chef/resource/scm/git.rb +79 -79
  141. data/lib/chef/resource/scm/subversion.rb +9 -9
  142. data/lib/chef/resource/script.rb +3 -3
  143. data/lib/chef/resource/selinux_boolean.rb +12 -12
  144. data/lib/chef/resource/selinux_fcontext.rb +21 -21
  145. data/lib/chef/resource/selinux_install.rb +18 -18
  146. data/lib/chef/resource/selinux_login.rb +11 -11
  147. data/lib/chef/resource/selinux_module.rb +16 -16
  148. data/lib/chef/resource/selinux_permissive.rb +9 -9
  149. data/lib/chef/resource/selinux_port.rb +16 -16
  150. data/lib/chef/resource/selinux_state.rb +28 -28
  151. data/lib/chef/resource/selinux_user.rb +14 -14
  152. data/lib/chef/resource/service.rb +5 -5
  153. data/lib/chef/resource/snap_package.rb +16 -16
  154. data/lib/chef/resource/ssh_known_hosts_entry.rb +10 -10
  155. data/lib/chef/resource/sudo.rb +68 -68
  156. data/lib/chef/resource/swap_file.rb +12 -12
  157. data/lib/chef/resource/sysctl.rb +42 -42
  158. data/lib/chef/resource/systemd_unit.rb +38 -38
  159. data/lib/chef/resource/timezone.rb +16 -16
  160. data/lib/chef/resource/user/mac_user.rb +3 -3
  161. data/lib/chef/resource/user.rb +6 -6
  162. data/lib/chef/resource/user_ulimit.rb +22 -22
  163. data/lib/chef/resource/windows_ad_join.rb +25 -25
  164. data/lib/chef/resource/windows_audit_policy.rb +34 -34
  165. data/lib/chef/resource/windows_auto_run.rb +8 -8
  166. data/lib/chef/resource/windows_certificate.rb +20 -20
  167. data/lib/chef/resource/windows_defender.rb +22 -22
  168. data/lib/chef/resource/windows_defender_exclusion.rb +17 -17
  169. data/lib/chef/resource/windows_env.rb +6 -6
  170. data/lib/chef/resource/windows_feature.rb +42 -42
  171. data/lib/chef/resource/windows_feature_dism.rb +8 -8
  172. data/lib/chef/resource/windows_feature_powershell.rb +20 -20
  173. data/lib/chef/resource/windows_firewall_profile.rb +28 -28
  174. data/lib/chef/resource/windows_firewall_rule.rb +47 -47
  175. data/lib/chef/resource/windows_font.rb +7 -7
  176. data/lib/chef/resource/windows_package.rb +59 -59
  177. data/lib/chef/resource/windows_pagefile.rb +29 -29
  178. data/lib/chef/resource/windows_path.rb +12 -12
  179. data/lib/chef/resource/windows_printer.rb +28 -28
  180. data/lib/chef/resource/windows_printer_port.rb +21 -21
  181. data/lib/chef/resource/windows_security_policy.rb +23 -23
  182. data/lib/chef/resource/windows_service.rb +108 -108
  183. data/lib/chef/resource/windows_share.rb +19 -19
  184. data/lib/chef/resource/windows_shortcut.rb +7 -7
  185. data/lib/chef/resource/windows_task.rb +105 -105
  186. data/lib/chef/resource/windows_uac.rb +14 -14
  187. data/lib/chef/resource/windows_update_settings.rb +27 -27
  188. data/lib/chef/resource/windows_user_privilege.rb +59 -59
  189. data/lib/chef/resource/windows_workgroup.rb +12 -12
  190. data/lib/chef/resource/yum_package.rb +1 -1
  191. data/lib/chef/resource/yum_repository.rb +36 -36
  192. data/lib/chef/resource.rb +1 -1
  193. data/lib/chef/resource_collection/resource_set.rb +2 -3
  194. data/lib/chef/resource_inspector.rb +1 -2
  195. data/lib/chef/run_context.rb +2 -2
  196. data/lib/chef/runner.rb +1 -1
  197. data/lib/chef/secret_fetcher/akeyless_vault.rb +0 -1
  198. data/lib/chef/secret_fetcher/hashi_vault.rb +0 -1
  199. data/lib/chef/shell/ext.rb +20 -20
  200. data/lib/chef/shell/shell_session.rb +1 -1
  201. data/lib/chef/shell.rb +7 -0
  202. data/lib/chef/version.rb +1 -1
  203. data/lib/chef/version_constraint.rb +1 -1
  204. data/lib/chef/win32/file/version_info.rb +1 -1
  205. metadata +63 -38
@@ -27,149 +27,149 @@ class Chef
27
27
  description "Use the **chef_handler** resource to enable handlers during a #{ChefUtils::Dist::Infra::PRODUCT} run. The resource allows arguments to be passed to #{ChefUtils::Dist::Infra::PRODUCT}, which then applies the conditions defined by the custom handler to the node attribute data collected during a #{ChefUtils::Dist::Infra::PRODUCT} run, and then processes the handler based on that data.\nThe **chef_handler** resource is typically defined early in a node's run-list (often being the first item). This ensures that all of the handlers will be available for the entire #{ChefUtils::Dist::Infra::PRODUCT} run."
28
28
  introduced "14.0"
29
29
  examples <<~'DOC'
30
- **Enable the 'MyHandler' handler**
30
+ **Enable the 'MyHandler' handler**
31
31
 
32
- The following example shows how to enable a fictional 'MyHandler' handler which is located on disk at `/etc/chef/my_handler.rb`. The handler will be configured to run with Chef Infra Client and will be passed values to the handler's initializer method:
32
+ The following example shows how to enable a fictional 'MyHandler' handler which is located on disk at `/etc/chef/my_handler.rb`. The handler will be configured to run with Chef Infra Client and will be passed values to the handler's initializer method:
33
33
 
34
- ```ruby
35
- chef_handler 'MyHandler' do
36
- source '/etc/chef/my_handler.rb' # the file should already be at this path
37
- arguments path: '/var/chef/reports'
38
- action :enable
39
- end
40
- ```
34
+ ```ruby
35
+ chef_handler 'MyHandler' do
36
+ source '/etc/chef/my_handler.rb' # the file should already be at this path
37
+ arguments path: '/var/chef/reports'
38
+ action :enable
39
+ end
40
+ ```
41
41
 
42
- **Enable handlers during the compile phase**
42
+ **Enable handlers during the compile phase**
43
43
 
44
- ```ruby
45
- chef_handler 'Chef::Handler::JsonFile' do
46
- source 'chef/handler/json_file'
47
- arguments path: '/var/chef/reports'
48
- action :enable
49
- compile_time true
50
- end
51
- ```
44
+ ```ruby
45
+ chef_handler 'Chef::Handler::JsonFile' do
46
+ source 'chef/handler/json_file'
47
+ arguments path: '/var/chef/reports'
48
+ action :enable
49
+ compile_time true
50
+ end
51
+ ```
52
52
 
53
- **Handle only exceptions**
53
+ **Handle only exceptions**
54
54
 
55
- ```ruby
56
- chef_handler 'Chef::Handler::JsonFile' do
57
- source 'chef/handler/json_file'
58
- arguments path: '/var/chef/reports'
59
- type exception: true
60
- action :enable
61
- end
62
- ```
55
+ ```ruby
56
+ chef_handler 'Chef::Handler::JsonFile' do
57
+ source 'chef/handler/json_file'
58
+ arguments path: '/var/chef/reports'
59
+ type exception: true
60
+ action :enable
61
+ end
62
+ ```
63
63
 
64
- **Cookbook Versions (a custom handler)**
64
+ **Cookbook Versions (a custom handler)**
65
65
 
66
- [@juliandunn](https://github.com/juliandunn) created a custom report handler that logs all of the cookbooks and cookbook versions that were used during a Chef Infra Client run, and then reports after the run is complete.
66
+ [@juliandunn](https://github.com/juliandunn) created a custom report handler that logs all of the cookbooks and cookbook versions that were used during a Chef Infra Client run, and then reports after the run is complete.
67
67
 
68
- cookbook_versions.rb:
68
+ cookbook_versions.rb:
69
69
 
70
- The following custom handler defines how cookbooks and cookbook versions that are used during a Chef Infra Client run will be compiled into a report using the `Chef::Log` class in Chef Infra Client:
70
+ The following custom handler defines how cookbooks and cookbook versions that are used during a Chef Infra Client run will be compiled into a report using the `Chef::Log` class in Chef Infra Client:
71
71
 
72
- ```ruby
73
- require 'chef/log'
72
+ ```ruby
73
+ require 'chef/log'
74
74
 
75
- module Chef
76
- class CookbookVersionsHandler < Chef::Handler
77
- def report
78
- cookbooks = run_context.cookbook_collection
79
- Chef::Log.info('Cookbooks and versions run: #{cookbooks.map {|x| x.name.to_s + ' ' + x.version }}')
75
+ module Chef
76
+ class CookbookVersionsHandler < Chef::Handler
77
+ def report
78
+ cookbooks = run_context.cookbook_collection
79
+ Chef::Log.info('Cookbooks and versions run: #{cookbooks.map {|x| x.name.to_s + ' ' + x.version }}')
80
+ end
80
81
  end
81
82
  end
82
- end
83
- ```
83
+ ```
84
84
 
85
- default.rb:
85
+ default.rb:
86
86
 
87
- The following recipe is added to the run-list for every node on which a list of cookbooks and versions will be generated as report output after every Chef Infra Client run.
87
+ The following recipe is added to the run-list for every node on which a list of cookbooks and versions will be generated as report output after every Chef Infra Client run.
88
88
 
89
- ```ruby
90
- cookbook_file '/etc/chef/cookbook_versions.rb' do
91
- source 'cookbook_versions.rb'
92
- action :create
93
- end
89
+ ```ruby
90
+ cookbook_file '/etc/chef/cookbook_versions.rb' do
91
+ source 'cookbook_versions.rb'
92
+ action :create
93
+ end
94
94
 
95
- chef_handler 'Chef::CookbookVersionsHandler' do
96
- source '/etc/chef/cookbook_versions.rb'
97
- type report: true
98
- action :enable
99
- end
100
- ```
95
+ chef_handler 'Chef::CookbookVersionsHandler' do
96
+ source '/etc/chef/cookbook_versions.rb'
97
+ type report: true
98
+ action :enable
99
+ end
100
+ ```
101
101
 
102
- This recipe will generate report output similar to the following:
102
+ This recipe will generate report output similar to the following:
103
103
 
104
- ```
105
- [2013-11-26T03:11:06+00:00] INFO: Chef Infra Client Run complete in 0.300029878 seconds
106
- [2013-11-26T03:11:06+00:00] INFO: Running report handlers
107
- [2013-11-26T03:11:06+00:00] INFO: Cookbooks and versions run: ["cookbook_versions_handler 1.0.0"]
108
- [2013-11-26T03:11:06+00:00] INFO: Report handlers complete
109
- ```
104
+ ```
105
+ [2013-11-26T03:11:06+00:00] INFO: Chef Infra Client Run complete in 0.300029878 seconds
106
+ [2013-11-26T03:11:06+00:00] INFO: Running report handlers
107
+ [2013-11-26T03:11:06+00:00] INFO: Cookbooks and versions run: ["cookbook_versions_handler 1.0.0"]
108
+ [2013-11-26T03:11:06+00:00] INFO: Report handlers complete
109
+ ```
110
110
 
111
- **JsonFile Handler**
111
+ **JsonFile Handler**
112
112
 
113
- The JsonFile handler is available from the `chef_handler` cookbook and can be used with exceptions and reports. It serializes run status data to a JSON file. This handler may be enabled in one of the following ways.
113
+ The JsonFile handler is available from the `chef_handler` cookbook and can be used with exceptions and reports. It serializes run status data to a JSON file. This handler may be enabled in one of the following ways.
114
114
 
115
- By adding the following lines of Ruby code to either the client.rb file or the solo.rb file, depending on how Chef Infra Client is being run:
115
+ By adding the following lines of Ruby code to either the client.rb file or the solo.rb file, depending on how Chef Infra Client is being run:
116
116
 
117
- ```ruby
118
- require 'chef/handler/json_file'
119
- report_handlers << Chef::Handler::JsonFile.new(path: '/var/chef/reports')
120
- exception_handlers << Chef::Handler::JsonFile.new(path: '/var/chef/reports')
121
- ```
117
+ ```ruby
118
+ require 'chef/handler/json_file'
119
+ report_handlers << Chef::Handler::JsonFile.new(path: '/var/chef/reports')
120
+ exception_handlers << Chef::Handler::JsonFile.new(path: '/var/chef/reports')
121
+ ```
122
122
 
123
- By using the `chef_handler` resource in a recipe, similar to the following:
123
+ By using the `chef_handler` resource in a recipe, similar to the following:
124
124
 
125
- ```ruby
126
- chef_handler 'Chef::Handler::JsonFile' do
127
- source 'chef/handler/json_file'
128
- arguments path: '/var/chef/reports'
129
- action :enable
130
- end
131
- ```
125
+ ```ruby
126
+ chef_handler 'Chef::Handler::JsonFile' do
127
+ source 'chef/handler/json_file'
128
+ arguments path: '/var/chef/reports'
129
+ action :enable
130
+ end
131
+ ```
132
132
 
133
- After it has run, the run status data can be loaded and inspected via Interactive Ruby (IRb):
133
+ After it has run, the run status data can be loaded and inspected via Interactive Ruby (IRb):
134
134
 
135
- ```
136
- irb(main):002:0> require 'json' => true
137
- irb(main):003:0> require 'chef' => true
138
- irb(main):004:0> r = JSON.parse(IO.read('/var/chef/reports/chef-run-report-20110322060731.json')) => ... output truncated
139
- irb(main):005:0> r.keys => ['end_time', 'node', 'updated_resources', 'exception', 'all_resources', 'success', 'elapsed_time', 'start_time', 'backtrace']
140
- irb(main):006:0> r['elapsed_time'] => 0.00246
141
- ```
135
+ ```
136
+ irb(main):002:0> require 'json' => true
137
+ irb(main):003:0> require 'chef' => true
138
+ irb(main):004:0> r = JSON.parse(IO.read('/var/chef/reports/chef-run-report-20110322060731.json')) => ... output truncated
139
+ irb(main):005:0> r.keys => ['end_time', 'node', 'updated_resources', 'exception', 'all_resources', 'success', 'elapsed_time', 'start_time', 'backtrace']
140
+ irb(main):006:0> r['elapsed_time'] => 0.00246
141
+ ```
142
142
 
143
- Register the JsonFile handler
143
+ Register the JsonFile handler
144
144
 
145
- ```ruby
146
- chef_handler 'Chef::Handler::JsonFile' do
147
- source 'chef/handler/json_file'
148
- arguments path: '/var/chef/reports'
149
- action :enable
150
- end
151
- ```
145
+ ```ruby
146
+ chef_handler 'Chef::Handler::JsonFile' do
147
+ source 'chef/handler/json_file'
148
+ arguments path: '/var/chef/reports'
149
+ action :enable
150
+ end
151
+ ```
152
152
 
153
- **ErrorReport Handler**
153
+ **ErrorReport Handler**
154
154
 
155
- The ErrorReport handler is built into Chef Infra Client and can be used for both exceptions and reports. It serializes error report data to a JSON file. This handler may be enabled in one of the following ways.
155
+ The ErrorReport handler is built into Chef Infra Client and can be used for both exceptions and reports. It serializes error report data to a JSON file. This handler may be enabled in one of the following ways.
156
156
 
157
- By adding the following lines of Ruby code to either the client.rb file or the solo.rb file, depending on how Chef Infra Client is being run:
157
+ By adding the following lines of Ruby code to either the client.rb file or the solo.rb file, depending on how Chef Infra Client is being run:
158
158
 
159
- ```ruby
160
- require 'chef/handler/error_report'
161
- report_handlers << Chef::Handler::ErrorReport.new
162
- exception_handlers << Chef::Handler::ErrorReport.new
163
- ```
159
+ ```ruby
160
+ require 'chef/handler/error_report'
161
+ report_handlers << Chef::Handler::ErrorReport.new
162
+ exception_handlers << Chef::Handler::ErrorReport.new
163
+ ```
164
164
 
165
- By using the `chef_handler` resource in a recipe, similar to the following:
165
+ By using the `chef_handler` resource in a recipe, similar to the following:
166
166
 
167
- ```ruby
168
- chef_handler 'Chef::Handler::ErrorReport' do
169
- source 'chef/handler/error_report'
170
- action :enable
171
- end
172
- ```
167
+ ```ruby
168
+ chef_handler 'Chef::Handler::ErrorReport' do
169
+ source 'chef/handler/error_report'
170
+ action :enable
171
+ end
172
+ ```
173
173
  DOC
174
174
 
175
175
  property :class_name, String,
@@ -65,7 +65,7 @@ class Chef
65
65
  property :search, String, default: "*:*", desired_state: false,
66
66
  description: "Search query that would match the same used for the clients, gets stored as a field in the item."
67
67
 
68
- property :raw_data, [Hash, Mash], default: {},
68
+ property :raw_data, [Hash, Mash], default: {}, sensitive: true,
69
69
  description: "The raw data, as a Ruby Hash, that will be stored in the item."
70
70
 
71
71
  property :environment, [String, NilClass], desired_state: false,
@@ -23,26 +23,26 @@ class Chef
23
23
  description "Use the **chocolatey_config** resource to add or remove Chocolatey configuration keys. Note: The Chocolatey package manager is not installed on Windows by default. You will need to install it prior to using this resource by adding the [Chocolatey cookbook](https://supermarket.chef.io/cookbooks/chocolatey/) to your node's run list."
24
24
  introduced "14.3"
25
25
  examples <<~DOC
26
- **Set the Chocolatey cacheLocation config**:
26
+ **Set the Chocolatey cacheLocation config**:
27
27
 
28
- ```ruby
29
- chocolatey_config 'Set cacheLocation config' do
30
- config_key 'cacheLocation'
31
- value 'C:\\temp\\choco'
32
- end
33
- ```
28
+ ```ruby
29
+ chocolatey_config 'Set cacheLocation config' do
30
+ config_key 'cacheLocation'
31
+ value 'C:\\temp\\choco'
32
+ end
33
+ ```
34
34
 
35
- **Unset a Chocolatey config**:
35
+ **Unset a Chocolatey config**:
36
36
 
37
- ```ruby
38
- chocolatey_config 'BogusConfig' do
39
- action :unset
40
- end
41
- ```
37
+ ```ruby
38
+ chocolatey_config 'BogusConfig' do
39
+ action :unset
40
+ end
41
+ ```
42
42
  DOC
43
43
 
44
44
  property :config_key, String, name_property: true,
45
- description: "An optional property to set the config key name if it differs from the resource block's name."
45
+ description: "An optional property to set the config key name if it differs from the resource block's name."
46
46
 
47
47
  property :value, String,
48
48
  description: "The value to set."
@@ -40,7 +40,7 @@ class Chef
40
40
  DOC
41
41
 
42
42
  property :feature_name, String, name_property: true,
43
- description: "The name of the Chocolatey feature to enable or disable."
43
+ description: "The name of the Chocolatey feature to enable or disable."
44
44
 
45
45
  property :feature_state, [TrueClass, FalseClass], default: false, skip_docs: true
46
46
 
@@ -1,3 +1,6 @@
1
+ require "cgi" unless defined?(CGI)
2
+ require "uri" unless defined?(URI)
3
+
1
4
  class Chef
2
5
  class Resource
3
6
  class ChocolateyInstaller < Chef::Resource
@@ -6,48 +9,48 @@ class Chef
6
9
  description "Use the chocolatey_installer resource to ensure that Chocolatey itself is installed to your specification. Use the Chocolatey Feature resource to customize your install. Then use the Chocolatey Package resource to install packages on Windows via Chocolatey."
7
10
  introduced "18.3"
8
11
  examples <<~DOC
9
- **Install Chocolatey**
12
+ **Install Chocolatey**
10
13
 
11
- ```ruby
12
- chocolatey_installer 'latest' do
13
- action :install
14
- end
15
- ```
14
+ ```ruby
15
+ chocolatey_installer 'latest' do
16
+ action :install
17
+ end
18
+ ```
16
19
 
17
- **Uninstall Chocolatey**
20
+ **Uninstall Chocolatey**
18
21
 
19
- ```ruby
20
- chocolatey_installer 'Some random verbiage' do
21
- action :uninstall
22
- end
23
- ```
22
+ ```ruby
23
+ chocolatey_installer 'Some random verbiage' do
24
+ action :uninstall
25
+ end
26
+ ```
24
27
 
25
- **Install Chocolatey with Parameters**
28
+ **Install Chocolatey with Parameters**
26
29
 
27
- ```ruby
28
- chocolatey_installer 'latest' do
29
- action :install
30
- download_url "https://www.contoso.com/foo"
31
- chocolatey_version '2.12.24'
32
- end
33
- ```
30
+ ```ruby
31
+ chocolatey_installer 'latest' do
32
+ action :install
33
+ download_url "https://www.contoso.com/foo"
34
+ chocolatey_version '2.12.24'
35
+ end
36
+ ```
34
37
 
35
38
  ```ruby
36
39
  chocolatey_installer 'latest' do
37
40
  action :install
38
- download_url "c:\\foo\foo.nupkg"
41
+ download_url "c:\\foo\\foo.nupkg"
39
42
  chocolatey_version '2.12.24'
40
43
  end
41
44
  ```
42
45
 
43
- **Upgrade Chocolatey with Parameters**
46
+ **Upgrade Chocolatey with Parameters**
44
47
 
45
- ```ruby
46
- chocolatey_installer 'latest' do
47
- action :upgrade
48
- chocolatey_version '2.12.24'
49
- end
50
- ```
48
+ ```ruby
49
+ chocolatey_installer 'latest' do
50
+ action :upgrade
51
+ chocolatey_version '2.12.24'
52
+ end
53
+ ```
51
54
  DOC
52
55
 
53
56
  allowed_actions :install, :uninstall, :upgrade
@@ -70,7 +73,7 @@ class Chef
70
73
  property :proxy_user, String,
71
74
  description: "The username to use to build a proxy credential with. Will be consumed by the proxy_credential property if both this property and proxy_password are set"
72
75
 
73
- property :proxy_password, String,
76
+ property :proxy_password, String, sensitive: true,
74
77
  description: "The password to use to build a proxy credential with. Will be consumed by the proxy_credential property if both this property and proxy_user are set"
75
78
 
76
79
  load_current_value do
@@ -91,6 +94,25 @@ class Chef
91
94
  Gem::Version.new(get_choco_version)
92
95
  end
93
96
 
97
+ def download_url_path
98
+ return download_url if download_url.match?(%r{^[a-zA-Z]:[\\/]}) || download_url.start_with?("\\\\")
99
+
100
+ ::URI.parse(download_url).path
101
+ rescue URI::InvalidURIError
102
+ download_url
103
+ end
104
+
105
+ def download_url_script?
106
+ ::File.extname(download_url_path).casecmp(".ps1") == 0
107
+ end
108
+
109
+ def download_destination
110
+ filename = ::File.basename(::CGI.unescape(download_url_path.to_s))
111
+ filename = "chocolatey.nupkg" if filename.empty? || ["/", "\\", "."].include?(filename)
112
+
113
+ Chef::Util::PathHelper.join(ChefConfig::Config.etc_chef_dir(windows: true), filename)
114
+ end
115
+
94
116
  def define_resource_requirements
95
117
  requirements.assert(:install, :upgrade).each do |a|
96
118
  a.assertion do
@@ -133,16 +155,14 @@ class Chef
133
155
  if new_resource.download_url
134
156
  Chef::Log.info("Using custom download URL for Chocolatey installation: #{new_resource.download_url}")
135
157
  # If it's a PowerShell script, execute it directly (original behavior)
136
- if new_resource.download_url.downcase.end_with?(".ps1")
158
+ if download_url_script?
137
159
  powershell_exec("Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('#{new_resource.download_url}'))").error!
138
160
  else
139
161
  # Assume it's a direct link to a nupkg or other file and handle accordingly
140
- chef_dir = ChefConfig::Config.etc_chef_dir(windows: true)
162
+ destination = download_destination
141
163
 
142
- # Let PowerShell handle the filename - it will use the server's suggested filename
143
- # from Content-Disposition header, or fall back to the URL path
144
- powershell_exec("Invoke-WebRequest '#{new_resource.download_url}' -OutFile '#{chef_dir}'").error!
145
- Chef::Log.info("Downloaded file from #{new_resource.download_url} to #{chef_dir}")
164
+ powershell_exec("Invoke-WebRequest '#{new_resource.download_url}' -OutFile '#{destination}'").error!
165
+ Chef::Log.info("Downloaded file from #{new_resource.download_url} to #{destination}")
146
166
  end
147
167
  else
148
168
  powershell_exec("Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))").error!
@@ -151,11 +171,9 @@ class Chef
151
171
  end
152
172
 
153
173
  action :upgrade, description: "Upgrades the Chocolatey package manager" do
154
- if new_resource.chocolatey_version
155
- proposed_version = Gem::Version.new(new_resource.chocolatey_version)
156
- else
157
- proposed_version = nil
158
- end
174
+ proposed_version = if new_resource.chocolatey_version
175
+ Gem::Version.new(new_resource.chocolatey_version)
176
+ end
159
177
 
160
178
  if new_resource.download_url
161
179
  powershell_exec("Set-Item -path env:ChocolateyDownloadUrl -Value #{new_resource.download_url}")
@@ -193,7 +211,7 @@ class Chef
193
211
  end
194
212
 
195
213
  action :uninstall, description: "Uninstall Chocolatey package manager" do
196
- path = "c:\\programdata\\chocolatey\\bin"
214
+ path = 'c:\\programdata\\chocolatey\\bin'
197
215
  if File.exists?(path)
198
216
  converge_by("Uninstall Choco") do
199
217
  powershell_code = <<~CODE
@@ -219,4 +237,4 @@ class Chef
219
237
  end
220
238
  end
221
239
  end
222
- end
240
+ end
@@ -59,7 +59,7 @@ class Chef
59
59
  introduced: "15.3",
60
60
  description: "The username to authenticate feeds."
61
61
 
62
- property :password, String,
62
+ property :password, String, sensitive: true,
63
63
  introduced: "15.3",
64
64
  description: "The password to authenticate to the source."
65
65
 
@@ -41,42 +41,42 @@ class Chef
41
41
  DOC
42
42
 
43
43
  property :source_name, String, name_property: true,
44
- description: "An optional property to set the source name if it differs from the resource block's name."
44
+ description: "An optional property to set the source name if it differs from the resource block's name."
45
45
 
46
46
  property :source, String,
47
47
  description: "The source URL."
48
48
 
49
49
  property :bypass_proxy, [TrueClass, FalseClass], default: false,
50
- description: "Whether or not to bypass the system's proxy settings to access the source."
50
+ description: "Whether or not to bypass the system's proxy settings to access the source."
51
51
 
52
52
  property :admin_only, [TrueClass, FalseClass], default: false,
53
- description: "Whether or not to set the source to be accessible to only admins.",
54
- introduced: "15.1"
53
+ description: "Whether or not to set the source to be accessible to only admins.",
54
+ introduced: "15.1"
55
55
 
56
56
  property :allow_self_service, [TrueClass, FalseClass], default: false,
57
- description: "Whether or not to set the source to be used for self service.",
58
- introduced: "15.1"
57
+ description: "Whether or not to set the source to be used for self service.",
58
+ introduced: "15.1"
59
59
 
60
60
  property :priority, Integer, default: 0,
61
- description: "The priority level of the source."
61
+ description: "The priority level of the source."
62
62
 
63
63
  property :disabled, [TrueClass, FalseClass], default: false, desired_state: false, skip_docs: true
64
64
 
65
65
  property :username, String,
66
- description: "The username to use when authenticating against the source",
67
- introduced: "17.7"
66
+ description: "The username to use when authenticating against the source",
67
+ introduced: "17.7"
68
68
 
69
69
  property :password, String, sensitive: true, desired_state: false,
70
- description: "The password to use when authenticating against the source",
71
- introduced: "17.7"
70
+ description: "The password to use when authenticating against the source",
71
+ introduced: "17.7"
72
72
 
73
73
  property :cert, String,
74
- description: "The certificate to use when authenticating against the source",
75
- introduced: "17.7"
74
+ description: "The certificate to use when authenticating against the source",
75
+ introduced: "17.7"
76
76
 
77
77
  property :cert_password, String, sensitive: true, desired_state: false,
78
- description: "The password for the certificate to use when authenticating against the source",
79
- introduced: "17.7"
78
+ description: "The password for the certificate to use when authenticating against the source",
79
+ introduced: "17.7"
80
80
 
81
81
  load_current_value do
82
82
  element = fetch_source_element(source_name)
@@ -87,8 +87,6 @@ property :time_out, Hash,
87
87
  end
88
88
  }
89
89
 
90
- private
91
-
92
90
  # Convert weekday input value into crontab format that
93
91
  # could be written in the crontab
94
92
  # @return [Integer, String] A weekday formed as per the user inputs.