chef 17.3.48-universal-mingw32 → 17.6.15-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/chef.gemspec +2 -0
  4. data/lib/chef/application/base.rb +11 -1
  5. data/lib/chef/application.rb +3 -1
  6. data/lib/chef/client.rb +1 -2
  7. data/lib/chef/compliance/default_attributes.rb +5 -3
  8. data/lib/chef/compliance/input.rb +115 -0
  9. data/lib/chef/compliance/input_collection.rb +139 -0
  10. data/lib/chef/compliance/profile.rb +122 -0
  11. data/lib/chef/compliance/profile_collection.rb +109 -0
  12. data/lib/chef/compliance/reporter/automate.rb +1 -1
  13. data/lib/chef/compliance/runner.rb +62 -6
  14. data/lib/chef/compliance/waiver.rb +115 -0
  15. data/lib/chef/compliance/waiver_collection.rb +143 -0
  16. data/lib/chef/dsl/compliance.rb +38 -0
  17. data/lib/chef/dsl/reader_helpers.rb +51 -0
  18. data/lib/chef/dsl/recipe.rb +4 -2
  19. data/lib/chef/dsl/secret.rb +5 -7
  20. data/lib/chef/dsl/universal.rb +2 -0
  21. data/lib/chef/event_dispatch/base.rb +44 -2
  22. data/lib/chef/exceptions.rb +0 -2
  23. data/lib/chef/formatters/doc.rb +60 -13
  24. data/lib/chef/formatters/error_mapper.rb +2 -2
  25. data/lib/chef/formatters/minimal.rb +6 -5
  26. data/lib/chef/http/basic_client.rb +15 -7
  27. data/lib/chef/http.rb +12 -8
  28. data/lib/chef/provider/execute.rb +1 -1
  29. data/lib/chef/provider/file.rb +2 -0
  30. data/lib/chef/provider/group/dscl.rb +1 -1
  31. data/lib/chef/provider/launchd.rb +6 -6
  32. data/lib/chef/provider/link.rb +2 -2
  33. data/lib/chef/provider/registry_key.rb +3 -2
  34. data/lib/chef/provider/remote_file/http.rb +1 -1
  35. data/lib/chef/provider/subversion.rb +4 -4
  36. data/lib/chef/provider/support/yum_repo.erb +1 -1
  37. data/lib/chef/provider/systemd_unit.rb +17 -16
  38. data/lib/chef/provider/template.rb +1 -1
  39. data/lib/chef/provider/user/mac.rb +3 -3
  40. data/lib/chef/provider/yum_repository.rb +27 -43
  41. data/lib/chef/provider/zypper_repository.rb +3 -3
  42. data/lib/chef/provider.rb +26 -1
  43. data/lib/chef/provider_resolver.rb +8 -2
  44. data/lib/chef/resource/archive_file.rb +17 -14
  45. data/lib/chef/resource/chef_client_scheduled_task.rb +45 -2
  46. data/lib/chef/resource/chocolatey_config.rb +13 -13
  47. data/lib/chef/resource/execute.rb +2 -2
  48. data/lib/chef/resource/file/verification/json.rb +50 -0
  49. data/lib/chef/resource/file/verification/yaml.rb +52 -0
  50. data/lib/chef/resource/homebrew_cask.rb +1 -1
  51. data/lib/chef/resource/inspec_input.rb +127 -0
  52. data/lib/chef/resource/inspec_waiver.rb +184 -0
  53. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -2
  54. data/lib/chef/resource/launchd.rb +3 -3
  55. data/lib/chef/resource/mount.rb +1 -1
  56. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  57. data/lib/chef/resource/powershell_package_source.rb +234 -70
  58. data/lib/chef/resource/registry_key.rb +36 -48
  59. data/lib/chef/resource/remote_file.rb +99 -3
  60. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  61. data/lib/chef/resource/ruby_block.rb +100 -0
  62. data/lib/chef/resource/scm/subversion.rb +1 -1
  63. data/lib/chef/resource/sysctl.rb +2 -2
  64. data/lib/chef/resource/systemd_unit.rb +3 -3
  65. data/lib/chef/resource/timezone.rb +2 -2
  66. data/lib/chef/resource/user_ulimit.rb +1 -0
  67. data/lib/chef/resource/windows_printer.rb +1 -1
  68. data/lib/chef/resource/windows_uac.rb +3 -1
  69. data/lib/chef/resource/windows_user_privilege.rb +1 -1
  70. data/lib/chef/resource/yum_package.rb +1 -5
  71. data/lib/chef/resource.rb +13 -17
  72. data/lib/chef/resource_inspector.rb +6 -2
  73. data/lib/chef/resources.rb +2 -0
  74. data/lib/chef/run_context/cookbook_compiler.rb +112 -28
  75. data/lib/chef/run_context.rb +31 -1
  76. data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
  77. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +17 -5
  78. data/lib/chef/secret_fetcher/azure_key_vault.rb +32 -10
  79. data/lib/chef/secret_fetcher/base.rb +6 -2
  80. data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
  81. data/lib/chef/secret_fetcher.rb +13 -6
  82. data/lib/chef/version.rb +1 -1
  83. data/lib/chef/win32/version.rb +2 -1
  84. data/spec/data/archive_file/test_archive.tar.gz +0 -0
  85. data/spec/functional/resource/archive_file_spec.rb +87 -0
  86. data/spec/functional/resource/group_spec.rb +5 -1
  87. data/spec/functional/resource/link_spec.rb +8 -0
  88. data/spec/functional/resource/powershell_package_source_spec.rb +5 -6
  89. data/spec/integration/compliance/compliance_spec.rb +61 -0
  90. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  91. data/spec/spec_helper.rb +3 -0
  92. data/spec/support/platform_helpers.rb +4 -0
  93. data/spec/support/ruby_installer.rb +51 -0
  94. data/spec/unit/compliance/input_spec.rb +104 -0
  95. data/spec/unit/compliance/profile_spec.rb +120 -0
  96. data/spec/unit/compliance/runner_spec.rb +46 -2
  97. data/spec/unit/compliance/waiver_spec.rb +104 -0
  98. data/spec/unit/dsl/secret_spec.rb +8 -2
  99. data/spec/unit/formatters/doc_spec.rb +1 -1
  100. data/spec/unit/http/basic_client_spec.rb +30 -0
  101. data/spec/unit/http_spec.rb +8 -2
  102. data/spec/unit/provider/link_spec.rb +13 -7
  103. data/spec/unit/provider/remote_file/http_spec.rb +10 -0
  104. data/spec/unit/provider/template_spec.rb +2 -2
  105. data/spec/unit/provider_spec.rb +23 -0
  106. data/spec/unit/resource/archive_file_spec.rb +414 -3
  107. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
  108. data/spec/unit/resource/file/verification/json_spec.rb +72 -0
  109. data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
  110. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  111. data/spec/unit/resource/inspec_input_spec.rb +300 -0
  112. data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
  113. data/spec/unit/resource/mount_spec.rb +10 -0
  114. data/spec/unit/resource/powershell_package_source_spec.rb +63 -62
  115. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  116. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  117. data/spec/unit/resource/user_ulimit_spec.rb +14 -1
  118. data/spec/unit/resource_spec.rb +19 -8
  119. data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
  120. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  121. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +23 -16
  122. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
  123. data/spec/unit/secret_fetcher_spec.rb +9 -9
  124. data/tasks/rspec.rb +2 -1
  125. metadata +61 -6
@@ -18,6 +18,7 @@
18
18
 
19
19
  require_relative "../resource"
20
20
  require_relative "../digester"
21
+ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
21
22
 
22
23
  class Chef
23
24
  class Resource
@@ -26,7 +27,7 @@ class Chef
26
27
 
27
28
  provides(:registry_key) { true }
28
29
 
29
- description "Use the **registry_key** resource to create and delete registry keys in Microsoft Windows."
30
+ description "Use the **registry_key** resource to create and delete registry keys in Microsoft Windows. Note: 64-bit versions of Microsoft Windows have a 32-bit compatibility layer in the registry that reflects and redirects certain keys (and their values) into specific locations (or logical views) of the registry hive.\n\n#{ChefUtils::Dist::Infra::PRODUCT} can access any reflected or redirected registry key. The machine architecture of the system on which #{ChefUtils::Dist::Infra::PRODUCT} is running is used as the default (non-redirected) location. Access to the SysWow64 location is redirected must be specified. Typically, this is only necessary to ensure compatibility with 32-bit applications that are running on a 64-bit operating system.\n\nFor more information, see: [Registry Reflection](https://docs.microsoft.com/en-us/windows/win32/winprog64/registry-reflection)."
30
31
  examples <<~'DOC'
31
32
  **Create a registry key**
32
33
 
@@ -66,7 +67,7 @@ class Chef
66
67
  end
67
68
  ```
68
69
 
69
- **Set proxy settings to be the same as those used by Chef Infra Client**
70
+ **Set proxy settings to be the same as those used by #{ChefUtils::Dist::Infra::PRODUCT}**
70
71
 
71
72
  ```ruby
72
73
  proxy = URI.parse(Chef::Config[:http_proxy])
@@ -115,14 +116,42 @@ class Chef
115
116
  end
116
117
  ```
117
118
 
118
- Note: Be careful when using the :delete_key action with the recursive attribute. This will delete the registry key, all of its values and all of the names, types, and data associated with them. This cannot be undone by Chef Infra Client.
119
+ Note: Be careful when using the :delete_key action with the recursive attribute. This will delete the registry key, all of its values and all of the names, types, and data associated with them. This cannot be undone by #{ChefUtils::Dist::Infra::PRODUCT}.
119
120
  DOC
120
121
 
121
- state_attrs :values
122
-
123
122
  default_action :create
124
123
  allowed_actions :create, :create_if_missing, :delete, :delete_key
125
124
 
125
+ VALID_VALUE_HASH_KEYS = %i{name type data}.freeze
126
+
127
+ property :key, String, name_property: true
128
+ property :values, [Hash, Array],
129
+ default: [],
130
+ coerce: proc { |v|
131
+ @unscrubbed_values =
132
+ case v
133
+ when Hash
134
+ [ Mash.new(v).symbolize_keys ]
135
+ when Array
136
+ v.map { |value| Mash.new(value).symbolize_keys }
137
+ else
138
+ raise ArgumentError, "Bad type for RegistryKey resource, use Hash or Array"
139
+ end
140
+ scrub_values(@unscrubbed_values)
141
+ },
142
+ callbacks: {
143
+ "Missing name key in RegistryKey values hash" => lambda { |v| v.all? { |value| value.key?(:name) } },
144
+ "Bad key in RegistryKey values hash. Should be one of: #{VALID_VALUE_HASH_KEYS}" => lambda do |v|
145
+ v.all? do |value|
146
+ value.keys.all? { |key| VALID_VALUE_HASH_KEYS.include?(key) }
147
+ end
148
+ end,
149
+ "Type of name should be a string" => lambda { |v| v.all? { |value| value[:name].is_a?(String) } },
150
+ "Type of type should be a symbol" => lambda { |v| v.all? { |value| value[:type] ? value[:type].is_a?(Symbol) : true } },
151
+ }
152
+ property :recursive, [TrueClass, FalseClass], default: false
153
+ property :architecture, Symbol, default: :machine, equal_to: %i{machine x86_64 i386}
154
+
126
155
  # Some registry key data types may not be safely reported as json.
127
156
  # Example (CHEF-5323):
128
157
  #
@@ -152,51 +181,10 @@ class Chef
152
181
  # may want to extend the state_attrs API with the ability to rename POST'd attrs.
153
182
  #
154
183
  # See lib/chef/resource_reporter.rb for more information.
155
- attr_reader :unscrubbed_values
156
-
157
- def initialize(name, run_context = nil)
158
- super
159
- @values, @unscrubbed_values = [], []
160
- end
161
-
162
- property :key, String, name_property: true
163
-
164
- VALID_VALUE_HASH_KEYS = %i{name type data}.freeze
165
-
166
- def values(arg = nil)
167
- if not arg.nil?
168
- if arg.is_a?(Hash)
169
- @values = [ Mash.new(arg).symbolize_keys ]
170
- elsif arg.is_a?(Array)
171
- @values = []
172
- arg.each do |value|
173
- @values << Mash.new(value).symbolize_keys
174
- end
175
- else
176
- raise ArgumentError, "Bad type for RegistryKey resource, use Hash or Array"
177
- end
178
-
179
- @values.each do |v|
180
- raise ArgumentError, "Missing name key in RegistryKey values hash" unless v.key?(:name)
181
-
182
- v.each_key do |key|
183
- raise ArgumentError, "Bad key #{key} in RegistryKey values hash" unless VALID_VALUE_HASH_KEYS.include?(key)
184
- end
185
- raise ArgumentError, "Type of name => #{v[:name]} should be string" unless v[:name].is_a?(String)
186
-
187
- if v[:type]
188
- raise ArgumentError, "Type of type => #{v[:type]} should be symbol" unless v[:type].is_a?(Symbol)
189
- end
190
- end
191
- @unscrubbed_values = @values
192
- elsif instance_variable_defined?(:@values)
193
- scrub_values(@values)
194
- end
184
+ def unscrubbed_values
185
+ @unscrubbed_values ||= []
195
186
  end
196
187
 
197
- property :recursive, [TrueClass, FalseClass], default: false
198
- property :architecture, Symbol, default: :machine, equal_to: %i{machine x86_64 i386}
199
-
200
188
  private
201
189
 
202
190
  def scrub_values(values)
@@ -34,6 +34,78 @@ class Chef
34
34
 
35
35
  description "Use the **remote_file** resource to transfer a file from a remote location using file specificity. This resource is similar to the **file** resource. Note: Fetching files from the `files/` directory in a cookbook should be done with the **cookbook_file** resource."
36
36
 
37
+ examples <<~'DOC'
38
+ **Download a file without checking the checksum**:
39
+
40
+ ```ruby
41
+ remote_file '/tmp/remote.txt' do
42
+ source 'https://example.org/remote.txt'
43
+ end
44
+ ```
45
+
46
+ **Download a file with a checksum to validate**:
47
+
48
+ ```ruby
49
+ remote_file '/tmp/test_file' do
50
+ source 'http://www.example.com/tempfiles/test_file'
51
+ mode '0755'
52
+ checksum '3a7dac00b1' # A SHA256 (or portion thereof) of the file.
53
+ end
54
+ ```
55
+
56
+ **Download a file only if it's not already present**:
57
+
58
+ ```ruby
59
+ remote_file '/tmp/remote.txt' do
60
+ source 'https://example.org/remote.txt'
61
+ checksum '3a7dac00b1' # A SHA256 (or portion thereof) of the file.
62
+ action :create_if_missing
63
+ end
64
+ ```
65
+
66
+ **Using HTTP Basic Authentication in Headers**:
67
+
68
+ ```ruby
69
+ remote_file '/tmp/remote.txt' do
70
+ source 'https://example.org/remote.txt'
71
+ headers('Authorization' => "Basic #{Base64.encode64("USERNAME_VALUE:PASSWORD_VALUE").delete("\n")}")
72
+ checksum '3a7dac00b1' # A SHA256 (or portion thereof) of the file.
73
+ action :create_if_missing
74
+ end
75
+ ```
76
+
77
+ **Downloading a file to the Chef file cache dir for execution**:
78
+
79
+ ```ruby
80
+ remote_file '#{Chef::Config['file_cache_path']}/install.sh' do
81
+ source 'https://example.org/install.sh'
82
+ action :create_if_missing
83
+ end
84
+
85
+ execute '#{Chef::Config['file_cache_path']}/install.sh'
86
+ ```
87
+
88
+ **Specify advanced HTTP connection options including Net::HTTP (nethttp) options:**
89
+
90
+ ```ruby
91
+ remote_file '/tmp/remote.txt' do
92
+ source 'https://example.org/remote.txt'
93
+ http_options({
94
+ http_retry_delay: 0,
95
+ http_retry_count: 0,
96
+ keepalives: false,
97
+ nethttp: {
98
+ continue_timeout: 5,
99
+ max_retries: 5,
100
+ read_timeout: 5,
101
+ write_timeout: 5,
102
+ ssl_timeout: 5,
103
+ },
104
+ })
105
+ end
106
+ ```
107
+ DOC
108
+
37
109
  def initialize(name, run_context = nil)
38
110
  super
39
111
  @source = []
@@ -85,7 +157,7 @@ class Chef
85
157
  end
86
158
 
87
159
  property :use_etag, [ TrueClass, FalseClass ], default: true,
88
- description: "Enable ETag headers. Set to false to disable ETag headers. To use this setting, `use_conditional_get` must also be set to true."
160
+ description: "Enable ETag headers. Set to `false` to disable ETag headers. To use this setting, `use_conditional_get` must also be set to true."
89
161
 
90
162
  alias :use_etags :use_etag
91
163
 
@@ -96,9 +168,29 @@ class Chef
96
168
  description: "Whether #{ChefUtils::Dist::Infra::PRODUCT} uses active or passive FTP. Set to `true` to use active FTP."
97
169
 
98
170
  property :headers, Hash, default: {},
99
- description: "A Hash of custom HTTP headers."
171
+ description: <<~'DOCS'
172
+ A Hash of custom headers. For example:
173
+
174
+ ```ruby
175
+ headers({ "Cookie" => "user=some_user; pass=p@ssw0rd!" })
176
+ ```
100
177
 
101
- property :show_progress, [ TrueClass, FalseClass ], default: false
178
+ or:
179
+
180
+ ```ruby
181
+ headers({ "Referer" => "#{header}" })
182
+ ```
183
+
184
+ or:
185
+
186
+ ```ruby
187
+ headers( "Authorization"=>"Basic #{ Base64.encode64("#{username}:#{password}").gsub("\n", "") }" )
188
+ ```
189
+ DOCS
190
+
191
+ property :show_progress, [ TrueClass, FalseClass ],
192
+ description: "Displays the progress of the file download.",
193
+ default: false
102
194
 
103
195
  property :ssl_verify_mode, Symbol, equal_to: %i{verify_none verify_peer},
104
196
  introduced: "16.2",
@@ -118,6 +210,10 @@ class Chef
118
210
 
119
211
  property :authentication, Symbol, equal_to: %i{remote local}, default: :remote
120
212
 
213
+ property :http_options, Hash, default: {},
214
+ introduced: "17.5",
215
+ description: "A Hash of custom HTTP options. For example: `http_options({ http_retry_count: 0, http_retry_delay: 2 })`"
216
+
121
217
  def after_created
122
218
  validate_identity_platform(remote_user, remote_password, remote_domain)
123
219
  identity = qualify_user(remote_user, remote_password, remote_domain)
@@ -32,11 +32,11 @@ class Chef
32
32
  name_property: true
33
33
 
34
34
  action :attach, description: "Attach the node to a subscription pool." do
35
- execute "Attach subscription pool #{new_resource.pool_id}" do
36
- command "subscription-manager attach --pool=#{new_resource.pool_id}"
37
- default_env true
38
- action :run
39
- not_if { subscription_attached?(new_resource.pool_id) }
35
+ unless subscription_attached?(new_resource.pool_id)
36
+ converge_by("attach subscription pool #{new_resource.pool_id}") do
37
+ shell_out!("subscription-manager attach --pool=#{new_resource.pool_id}")
38
+ build_resource(:package, "rhsm_subscription-#{new_resource.pool_id}-flush_cache").run_action(:flush_cache)
39
+ end
40
40
  end
41
41
  end
42
42
 
@@ -29,6 +29,106 @@ class Chef
29
29
  provides :ruby_block, target_mode: true
30
30
 
31
31
  description "Use the **ruby_block** resource to execute Ruby code during a #{ChefUtils::Dist::Infra::PRODUCT} run. Ruby code in the `ruby_block` resource is evaluated with other resources during convergence, whereas Ruby code outside of a `ruby_block` resource is evaluated before other resources, as the recipe is compiled."
32
+ examples <<~'DOC'
33
+ **Reload Chef Infra Client configuration data**
34
+
35
+ ```ruby
36
+ ruby_block 'reload_client_config' do
37
+ block do
38
+ Chef::Config.from_file('/etc/chef/client.rb')
39
+ end
40
+ action :run
41
+ end
42
+ ```
43
+
44
+ **Run a block on a particular platform**
45
+
46
+ The following example shows how an if statement can be used with the `windows?` method in the Chef Infra Language to run code specific to Microsoft Windows. The code is defined using the ruby_block resource:
47
+
48
+ ```ruby
49
+ if windows?
50
+ ruby_block 'copy libmysql.dll into ruby path' do
51
+ block do
52
+ require 'fileutils'
53
+ FileUtils.cp "#{node['mysql']['client']['lib_dir']}\\libmysql.dll",
54
+ node['mysql']['client']['ruby_dir']
55
+ end
56
+ not_if { ::File.exist?("#{node['mysql']['client']['ruby_dir']}\\libmysql.dll") }
57
+ end
58
+ end
59
+ ```
60
+
61
+ **Stash a file in a data bag**
62
+
63
+ The following example shows how to use the ruby_block resource to stash a BitTorrent file in a data bag so that it can be distributed to nodes in the organization.
64
+
65
+ ```ruby
66
+ ruby_block 'share the torrent file' do
67
+ block do
68
+ f = File.open(node['bittorrent']['torrent'],'rb')
69
+ #read the .torrent file and base64 encode it
70
+ enc = Base64.encode64(f.read)
71
+ data = {
72
+ 'id'=>bittorrent_item_id(node['bittorrent']['file']),
73
+ 'seed'=>node.ipaddress,
74
+ 'torrent'=>enc
75
+ }
76
+ item = Chef::DataBagItem.new
77
+ item.data_bag('bittorrent')
78
+ item.raw_data = data
79
+ item.save
80
+ end
81
+ action :nothing
82
+ subscribes :create, "bittorrent_torrent[#{node['bittorrent']['torrent']}]", :immediately
83
+ end
84
+ ```
85
+
86
+ **Update the /etc/hosts file**
87
+
88
+ The following example shows how the ruby_block resource can be used to update the /etc/hosts file:
89
+
90
+ ```ruby
91
+ ruby_block 'edit etc hosts' do
92
+ block do
93
+ rc = Chef::Util::FileEdit.new('/etc/hosts')
94
+ rc.search_file_replace_line(/^127\.0\.0\.1 localhost$/,
95
+ '127.0.0.1 #{new_fqdn} #{new_hostname} localhost')
96
+ rc.write_file
97
+ end
98
+ end
99
+ ```
100
+
101
+ **Set environment variables**
102
+
103
+ The following example shows how to use variables within a Ruby block to set environment variables using rbenv.
104
+
105
+ ```ruby
106
+ node.override[:rbenv][:root] = rbenv_root
107
+ node.override[:ruby_build][:bin_path] = rbenv_binary_path
108
+
109
+ ruby_block 'initialize' do
110
+ block do
111
+ ENV['RBENV_ROOT'] = node[:rbenv][:root]
112
+ ENV['PATH'] = "#{node[:rbenv][:root]}/bin:#{node[:ruby_build][:bin_path]}:#{ENV['PATH']}"
113
+ end
114
+ end
115
+ ```
116
+
117
+ **Call methods in a gem**
118
+
119
+ The following example shows how to call methods in gems not shipped in Chef Infra Client
120
+
121
+ ```ruby
122
+ chef_gem 'mongodb'
123
+
124
+ ruby_block 'config_replicaset' do
125
+ block do
126
+ MongoDB.configure_replicaset(node, replicaset_name, rs_nodes)
127
+ end
128
+ action :run
129
+ end
130
+ ```
131
+ DOC
32
132
 
33
133
  default_action :run
34
134
  allowed_actions :create, :run
@@ -28,7 +28,7 @@ class Chef
28
28
 
29
29
  provides :subversion
30
30
 
31
- description "Use the **subversion** resource to manage source control resources that exist in a Subversion repository."
31
+ description "Use the **subversion** resource to manage source control resources that exist in a Subversion repository. Warning: The subversion resource has known bugs and may not work as expected. For more information see Chef GitHub issues, particularly [#4050](https://github.com/chef/chef/issues/4050) and [#4257](https://github.com/chef/chef/issues/4257)."
32
32
  examples <<~DOC
33
33
  **Get the latest version of an application**
34
34
 
@@ -131,7 +131,7 @@ class Chef
131
131
 
132
132
  end
133
133
 
134
- action :apply, description: "Apply a sysctl value." do
134
+ action :apply, description: "Set the kernel parameter and update the `sysctl` settings." do
135
135
  converge_if_changed do
136
136
  # set it temporarily
137
137
  set_sysctl_param(new_resource.key, new_resource.value)
@@ -150,7 +150,7 @@ class Chef
150
150
  end
151
151
  end
152
152
 
153
- action :remove, description: "Remove a sysctl value." do
153
+ action :remove, description: "Remove the kernel parameter and update the `sysctl` settings." do
154
154
  # only converge the resource if the file actually exists to delete
155
155
  if ::File.exist?("#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr("/", ".")}.conf")
156
156
  converge_by "removing sysctl config at #{new_resource.conf_dir}/99-chef-#{new_resource.key.tr("/", ".")}.conf" do
@@ -34,7 +34,7 @@ class Chef
34
34
 
35
35
  ```ruby
36
36
  systemd_unit 'etcd.service' do
37
- content(Unit: {
37
+ content({ Unit: {
38
38
  Description: 'Etcd',
39
39
  Documentation: ['https://coreos.com/etcd', 'man:etcd(1)'],
40
40
  After: 'network.target',
@@ -46,7 +46,7 @@ class Chef
46
46
  },
47
47
  Install: {
48
48
  WantedBy: 'multi-user.target',
49
- })
49
+ } })
50
50
  action [:create, :enable]
51
51
  end
52
52
  ```
@@ -113,7 +113,7 @@ class Chef
113
113
  when Hash
114
114
  IniParse.gen do |doc|
115
115
  content.each_pair do |sect, opts|
116
- doc.section(sect) do |section|
116
+ doc.section(sect, { option_sep: "=" }) do |section|
117
117
  opts.each_pair do |opt, val|
118
118
  [val].flatten.each do |v|
119
119
  section.option(opt, v)
@@ -38,7 +38,7 @@ class Chef
38
38
  **Set the timezone to America/Los_Angeles with a friendly resource name on Linux/macOS**
39
39
 
40
40
  ```ruby
41
- timezone 'Set the host's timezone to America/Los_Angeles' do
41
+ timezone "Set the host's timezone to America/Los_Angeles" do
42
42
  timezone 'America/Los_Angeles'
43
43
  end
44
44
  ```
@@ -46,7 +46,7 @@ class Chef
46
46
  **Set the timezone to PST with a friendly resource name on Windows**
47
47
 
48
48
  ```ruby
49
- timezone 'Set the host's timezone to PST' do
49
+ timezone "Set the host's timezone to PST" do
50
50
  timezone 'Pacific Standard time'
51
51
  end
52
52
  ```
@@ -83,6 +83,7 @@ class Chef
83
83
  source ::File.expand_path("support/ulimit.erb", __dir__)
84
84
  local true
85
85
  mode "0644"
86
+ sensitive new_resource.sensitive
86
87
  variables(
87
88
  ulimit_user: new_resource.username,
88
89
  filehandle_limit: new_resource.filehandle_limit,
@@ -33,7 +33,7 @@ class Chef
33
33
 
34
34
  provides(:windows_printer) { true }
35
35
 
36
- description "Use the **windows_printer** resource to setup Windows printers. This resource will automatically install the driver specified in the `driver_name` property and will automatically create a printer port using either the `ipv4_address` property or the `port_name property."
36
+ description "Use the **windows_printer** resource to setup Windows printers. This resource will automatically install the driver specified in the `driver_name` property and will automatically create a printer port using either the `ipv4_address` property or the `port_name` property."
37
37
  introduced "14.0"
38
38
  examples <<~DOC
39
39
  **Create a printer**:
@@ -104,7 +104,9 @@ class Chef
104
104
  #
105
105
  # @return [Integer]
106
106
  def consent_behavior_users_symbol_to_reg(sym)
107
- %i{auto_deny secure_prompt_for_creds prompt_for_creds}.index(sym)
107
+ # Since 2 isn't a valid value for ConsentPromptBehaviorUser, assign the value at index as nil.
108
+ # https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#registry-key-settings
109
+ [:auto_deny, :secure_prompt_for_creds, nil, :prompt_for_creds].index(sym)
108
110
  end
109
111
  end
110
112
  end
@@ -139,7 +139,7 @@ class Chef
139
139
  coerce: proc { |v| Array(v) },
140
140
  callbacks: {
141
141
  "Privilege property restricted to the following values: #{PRIVILEGE_OPTS}" => lambda { |n| (n - PRIVILEGE_OPTS).empty? },
142
- }
142
+ }, identity: true
143
143
 
144
144
  load_current_value do |new_resource|
145
145
  if new_resource.principal && (new_resource.action.include?(:add) || new_resource.action.include?(:remove))
@@ -27,11 +27,7 @@ class Chef
27
27
  provides :yum_package
28
28
  provides :package, platform_family: "fedora_derived"
29
29
 
30
- description "Use the **yum_package** resource to install, upgrade, and remove packages with Yum"\
31
- " for the Red Hat and CentOS platforms. The yum_package resource is able to resolve"\
32
- " `provides` data for packages much like Yum can do when it is run from the command line."\
33
- " This allows a variety of options for installing packages, like minimum versions,"\
34
- " virtual provides, and library names."
30
+ description "Use the **yum_package** resource to install, upgrade, and remove packages with Yum for the Red Hat and CentOS platforms. The yum_package resource is able to resolve `provides` data for packages much like Yum can do when it is run from the command line. This allows a variety of options for installing packages, like minimum versions, virtual provides, and library names. Note: Support for using file names to install packages (as in `yum_package '/bin/sh'`) is not available because the volume of data required to parse for this is excessive."
35
31
  examples <<~DOC
36
32
  **Install an exact version**:
37
33
 
data/lib/chef/resource.rb CHANGED
@@ -1063,7 +1063,8 @@ class Chef
1063
1063
  # action for the resource.
1064
1064
  #
1065
1065
  # @param name [Symbol] The action name to define.
1066
- # @param description [String] optional description for the action
1066
+ # @param description [String] optional description for the action. Used for
1067
+ # documentation generation.
1067
1068
  # @param recipe_block The recipe to run when the action is taken. This block
1068
1069
  # takes no parameters, and will be evaluated in a new context containing:
1069
1070
  #
@@ -1076,11 +1077,8 @@ class Chef
1076
1077
  def self.action(action, description: nil, &recipe_block)
1077
1078
  action = action.to_sym
1078
1079
  declare_action_class
1079
- action_class.action(action, &recipe_block)
1080
+ action_class.action(action, description: description, &recipe_block)
1080
1081
  self.allowed_actions += [ action ]
1081
- # Accept any non-nil description, which will correctly override
1082
- # any specific inherited description.
1083
- action_descriptions[action] = description unless description.nil?
1084
1082
  default_action action if Array(default_action) == [:nothing]
1085
1083
  end
1086
1084
 
@@ -1090,18 +1088,15 @@ class Chef
1090
1088
  # @param action [Symbol,String] the action name
1091
1089
  # @return the description of the action provided, or nil if no description
1092
1090
  # was defined
1093
- def self.action_description(action)
1094
- action_descriptions[action.to_sym]
1095
- end
1096
-
1097
- # @api private
1098
- #
1099
- # @return existing action description hash, or newly-initialized
1100
- # hash containing action descriptions inherited from parent Resource,
1101
- # if any.
1102
- def self.action_descriptions
1103
- @action_descriptions ||=
1104
- superclass.respond_to?(:action_descriptions) ? superclass.action_descriptions.dup : { nothing: nil }
1091
+ def action_description(action)
1092
+ provider_for_action(action).class.action_description(action)
1093
+ rescue Chef::Exceptions::ProviderNotFound
1094
+ # If a provider can't be found, there can be no description defined on the provider.
1095
+ nil
1096
+ rescue NameError => e
1097
+ # This can happen when attempting to load a provider in a platform-specific
1098
+ # environment where we have not required the necessary files yet
1099
+ raise unless e.message =~ /uninitialized constant/
1105
1100
  end
1106
1101
 
1107
1102
  # Define a method to load up this resource's properties with the current
@@ -1191,6 +1186,7 @@ class Chef
1191
1186
  if superclass.custom_resource?
1192
1187
  superclass.action_class
1193
1188
  else
1189
+
1194
1190
  ActionClass
1195
1191
  end
1196
1192
 
@@ -23,6 +23,11 @@ require_relative "node"
23
23
  require_relative "resources"
24
24
  require_relative "json_compat"
25
25
 
26
+ # We need to require providers so that we can resolve
27
+ # action documentation that may have been defined on the providers
28
+ # instead of the resources.
29
+ require_relative "providers"
30
+
26
31
  class Chef
27
32
  module ResourceInspector
28
33
  def self.get_default(default)
@@ -39,11 +44,10 @@ class Chef
39
44
  def self.extract_resource(resource, complete = false)
40
45
  data = {}
41
46
  data[:description] = resource.description
42
- # data[:deprecated] = resource.deprecated || false
43
47
  data[:default_action] = resource.default_action
44
48
  data[:actions] = {}
45
49
  resource.allowed_actions.each do |action|
46
- data[:actions][action] = resource.action_description(action)
50
+ data[:actions][action] = resource.new(resource.to_s, nil).action_description(action)
47
51
  end
48
52
 
49
53
  data[:examples] = resource.examples
@@ -73,6 +73,8 @@ require_relative "resource/homebrew_package"
73
73
  require_relative "resource/homebrew_tap"
74
74
  require_relative "resource/homebrew_update"
75
75
  require_relative "resource/ifconfig"
76
+ require_relative "resource/inspec_input"
77
+ require_relative "resource/inspec_waiver"
76
78
  require_relative "resource/inspec_waiver_file_entry"
77
79
  require_relative "resource/kernel_module"
78
80
  require_relative "resource/ksh"