chef 17.2.29-universal-mingw32 → 17.5.22-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -5
  3. data/chef.gemspec +3 -0
  4. data/lib/chef/application/base.rb +11 -1
  5. data/lib/chef/application.rb +3 -1
  6. data/lib/chef/client.rb +2 -3
  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/data_bag.rb +1 -2
  17. data/lib/chef/data_bag_item.rb +1 -2
  18. data/lib/chef/deprecated.rb +10 -4
  19. data/lib/chef/dsl/compliance.rb +38 -0
  20. data/lib/chef/dsl/reader_helpers.rb +51 -0
  21. data/lib/chef/dsl/recipe.rb +4 -2
  22. data/lib/chef/dsl/render_helpers.rb +44 -0
  23. data/lib/chef/dsl/secret.rb +62 -0
  24. data/lib/chef/dsl/toml.rb +116 -0
  25. data/lib/chef/dsl/universal.rb +7 -0
  26. data/lib/chef/dsl.rb +1 -0
  27. data/lib/chef/event_dispatch/base.rb +44 -2
  28. data/lib/chef/exceptions.rb +20 -0
  29. data/lib/chef/formatters/doc.rb +60 -13
  30. data/lib/chef/formatters/error_mapper.rb +2 -2
  31. data/lib/chef/formatters/minimal.rb +6 -5
  32. data/lib/chef/handler/slow_report.rb +1 -1
  33. data/lib/chef/http/basic_client.rb +15 -7
  34. data/lib/chef/http.rb +12 -8
  35. data/lib/chef/json_compat.rb +1 -1
  36. data/lib/chef/policy_builder/policyfile.rb +88 -45
  37. data/lib/chef/provider/execute.rb +1 -1
  38. data/lib/chef/provider/file.rb +4 -2
  39. data/lib/chef/provider/group/dscl.rb +1 -1
  40. data/lib/chef/provider/launchd.rb +6 -6
  41. data/lib/chef/provider/link.rb +2 -2
  42. data/lib/chef/provider/lwrp_base.rb +1 -1
  43. data/lib/chef/provider/package/habitat.rb +168 -0
  44. data/lib/chef/provider/package/powershell.rb +5 -0
  45. data/lib/chef/provider/registry_key.rb +3 -2
  46. data/lib/chef/provider/remote_file/http.rb +1 -1
  47. data/lib/chef/provider/subversion.rb +4 -4
  48. data/lib/chef/provider/support/yum_repo.erb +1 -1
  49. data/lib/chef/provider/systemd_unit.rb +17 -16
  50. data/lib/chef/provider/template.rb +1 -1
  51. data/lib/chef/provider/user/mac.rb +3 -3
  52. data/lib/chef/provider/yum_repository.rb +27 -43
  53. data/lib/chef/provider/zypper_repository.rb +3 -3
  54. data/lib/chef/provider.rb +26 -1
  55. data/lib/chef/provider_resolver.rb +8 -2
  56. data/lib/chef/providers.rb +1 -0
  57. data/lib/chef/resource/archive_file.rb +17 -14
  58. data/lib/chef/resource/chef_client_config.rb +7 -2
  59. data/lib/chef/resource/chef_client_cron.rb +1 -1
  60. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  61. data/lib/chef/resource/chef_client_scheduled_task.rb +46 -3
  62. data/lib/chef/resource/chef_client_systemd_timer.rb +1 -1
  63. data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
  64. data/lib/chef/resource/chef_vault_secret.rb +2 -2
  65. data/lib/chef/resource/chocolatey_config.rb +13 -13
  66. data/lib/chef/resource/dsc_resource.rb +1 -1
  67. data/lib/chef/resource/execute.rb +5 -5
  68. data/lib/chef/resource/file/verification/json.rb +50 -0
  69. data/lib/chef/resource/file/verification/yaml.rb +52 -0
  70. data/lib/chef/resource/gem_package.rb +2 -1
  71. data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
  72. data/lib/chef/resource/habitat/habitat_package.rb +129 -0
  73. data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
  74. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
  75. data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
  76. data/lib/chef/resource/habitat_config.rb +107 -0
  77. data/lib/chef/resource/habitat_install.rb +247 -0
  78. data/lib/chef/resource/habitat_service.rb +451 -0
  79. data/lib/chef/resource/habitat_user_toml.rb +92 -0
  80. data/lib/chef/resource/homebrew_cask.rb +1 -1
  81. data/lib/chef/resource/inspec_input.rb +128 -0
  82. data/lib/chef/resource/inspec_waiver.rb +185 -0
  83. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -2
  84. data/lib/chef/resource/launchd.rb +3 -3
  85. data/lib/chef/resource/lwrp_base.rb +1 -1
  86. data/lib/chef/resource/mount.rb +1 -1
  87. data/lib/chef/resource/registry_key.rb +36 -48
  88. data/lib/chef/resource/remote_file.rb +99 -3
  89. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  90. data/lib/chef/resource/ruby_block.rb +100 -0
  91. data/lib/chef/resource/scm/subversion.rb +1 -1
  92. data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
  93. data/lib/chef/resource/support/client.erb +8 -1
  94. data/lib/chef/resource/support/sup.toml.erb +179 -0
  95. data/lib/chef/resource/sysctl.rb +2 -2
  96. data/lib/chef/resource/systemd_unit.rb +3 -3
  97. data/lib/chef/resource/timezone.rb +2 -2
  98. data/lib/chef/resource/user_ulimit.rb +1 -0
  99. data/lib/chef/resource/windows_defender.rb +163 -0
  100. data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
  101. data/lib/chef/resource/windows_printer.rb +78 -44
  102. data/lib/chef/resource/windows_printer_port.rb +1 -1
  103. data/lib/chef/resource/windows_uac.rb +3 -1
  104. data/lib/chef/resource/windows_update_settings.rb +259 -0
  105. data/lib/chef/resource/windows_user_privilege.rb +1 -1
  106. data/lib/chef/resource/yum_package.rb +1 -5
  107. data/lib/chef/resource.rb +13 -17
  108. data/lib/chef/resource_inspector.rb +6 -2
  109. data/lib/chef/resources.rb +14 -1
  110. data/lib/chef/run_context/cookbook_compiler.rb +112 -28
  111. data/lib/chef/run_context.rb +31 -1
  112. data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
  113. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
  114. data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
  115. data/lib/chef/secret_fetcher/base.rb +76 -0
  116. data/lib/chef/secret_fetcher/example.rb +46 -0
  117. data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
  118. data/lib/chef/secret_fetcher.rb +61 -0
  119. data/lib/chef/version.rb +1 -1
  120. data/spec/data/archive_file/test_archive.tar.gz +0 -0
  121. data/spec/functional/mixin/from_file_spec.rb +1 -1
  122. data/spec/functional/resource/archive_file_spec.rb +87 -0
  123. data/spec/functional/resource/group_spec.rb +5 -1
  124. data/spec/functional/resource/link_spec.rb +8 -0
  125. data/spec/integration/compliance/compliance_spec.rb +61 -0
  126. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  127. data/spec/integration/recipes/resource_action_spec.rb +6 -6
  128. data/spec/spec_helper.rb +3 -0
  129. data/spec/support/platform_helpers.rb +4 -0
  130. data/spec/support/ruby_installer.rb +51 -0
  131. data/spec/support/shared/unit/provider/file.rb +2 -8
  132. data/spec/unit/compliance/input_spec.rb +104 -0
  133. data/spec/unit/compliance/profile_spec.rb +120 -0
  134. data/spec/unit/compliance/runner_spec.rb +46 -2
  135. data/spec/unit/compliance/waiver_spec.rb +104 -0
  136. data/spec/unit/data_bag_item_spec.rb +2 -2
  137. data/spec/unit/data_bag_spec.rb +1 -1
  138. data/spec/unit/dsl/render_helpers_spec.rb +102 -0
  139. data/spec/unit/dsl/secret_spec.rb +71 -0
  140. data/spec/unit/formatters/doc_spec.rb +1 -1
  141. data/spec/unit/http/basic_client_spec.rb +30 -0
  142. data/spec/unit/http_spec.rb +8 -2
  143. data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
  144. data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
  145. data/spec/unit/provider/apt_update_spec.rb +3 -1
  146. data/spec/unit/provider/link_spec.rb +13 -7
  147. data/spec/unit/provider/mount/aix_spec.rb +1 -1
  148. data/spec/unit/provider/package/powershell_spec.rb +74 -12
  149. data/spec/unit/provider/remote_file/http_spec.rb +10 -0
  150. data/spec/unit/provider/template_spec.rb +2 -2
  151. data/spec/unit/provider_spec.rb +23 -0
  152. data/spec/unit/resource/archive_file_spec.rb +414 -3
  153. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
  154. data/spec/unit/resource/file/verification/json_spec.rb +72 -0
  155. data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
  156. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  157. data/spec/unit/resource/inspec_input_spec.rb +300 -0
  158. data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
  159. data/spec/unit/resource/mount_spec.rb +10 -0
  160. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  161. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  162. data/spec/unit/resource/user_ulimit_spec.rb +14 -1
  163. data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
  164. data/spec/unit/resource/windows_defender_spec.rb +71 -0
  165. data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
  166. data/spec/unit/resource_spec.rb +19 -8
  167. data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
  168. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  169. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
  170. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
  171. data/spec/unit/secret_fetcher_spec.rb +82 -0
  172. data/tasks/rspec.rb +2 -1
  173. metadata +106 -7
@@ -0,0 +1,185 @@
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require_relative "../resource"
18
+
19
+ class Chef
20
+ class Resource
21
+ class InspecWaiver < Chef::Resource
22
+ provides :inspec_waiver
23
+ unified_mode true
24
+
25
+ description "Use the **inspec_waiver** resource to add a waiver to the Compliance Phase."
26
+ introduced "17.5"
27
+ examples <<~DOC
28
+ **Activate the default waiver in the openssh cookbook's compliance segment**:
29
+
30
+ ```ruby
31
+ inspec_waiver 'openssh' do
32
+ action :add
33
+ end
34
+ ```
35
+
36
+ **Activate all waivers in the openssh cookbook's compliance segment**:
37
+
38
+ ```ruby
39
+ inspec_waiver 'openssh::.*' do
40
+ action :add
41
+ end
42
+ ```
43
+
44
+ **Add an InSpec waiver to the Compliance Phase**:
45
+
46
+ ```ruby
47
+ inspec_waiver 'Add waiver entry for control' do
48
+ control 'my_inspec_control_01'
49
+ run_test false
50
+ justification "The subject of this control is not managed by #{ChefUtils::Dist::Infra::PRODUCT} on the systems in policy group \#{node['policy_group']}"
51
+ expiration '2022-01-01'
52
+ action :add
53
+ end
54
+ ```
55
+
56
+ **Add an InSpec waiver to the Compliance Phase using the 'name' property to identify the control**:
57
+
58
+ ```ruby
59
+ inspec_waiver 'my_inspec_control_01' do
60
+ justification "The subject of this control is not managed by #{ChefUtils::Dist::Infra::PRODUCT} on the systems in policy group \#{node['policy_group']}"
61
+ action :add
62
+ end
63
+ ```
64
+
65
+ **Add an InSpec waiver to the Compliance Phase using an arbitrary YAML, JSON or TOML file**:
66
+
67
+ ```ruby
68
+ # files ending in .yml or .yaml that exist are parsed as YAML
69
+ inspec_waiver "/path/to/my/waiver.yml"
70
+
71
+ inspec_waiver "my-waiver-name" do
72
+ source "/path/to/my/waiver.yml"
73
+ end
74
+
75
+ # files ending in .json that exist are parsed as JSON
76
+ inspec_waiver "/path/to/my/waiver.json"
77
+
78
+ inspec_waiver "my-waiver-name" do
79
+ source "/path/to/my/waiver.json"
80
+ end
81
+
82
+ # files ending in .toml that exist are parsed as TOML
83
+ inspec_waiver "/path/to/my/waiver.toml"
84
+
85
+ inspec_waiver "my-waiver-name" do
86
+ source "/path/to/my/waiver.toml"
87
+ end
88
+ ```
89
+
90
+ **Add an InSpec waiver to the Compliance Phase using a hash**:
91
+
92
+ ```ruby
93
+ my_hash = { "ssh-01" => {
94
+ "expiration_date" => "2033-07-31",
95
+ "run" => false,
96
+ "justification" => "because"
97
+ } }
98
+
99
+ inspec_waiver "my-waiver-name" do
100
+ source my_hash
101
+ end
102
+ ```
103
+
104
+ Note that the inspec_waiver resource does not update and will not fire notifications (similar to the log resource). This is done to preserve the ability to use
105
+ the resource while not causing the updated resource count to be larger than zero. Since the resource does not update the state of the node being managed this
106
+ behavior is still consistent with the configuration management model. Events should be used to observe configuration changes for the compliance phase. It is
107
+ possible to use the `notify_group` resource to chain notifications of the two resources, but notifications are the wrong model to use and pure ruby conditionals
108
+ should be used instead. Compliance configuration should be independent of other resources and should only be made conditional based on state/attributes not
109
+ on other resources.
110
+ DOC
111
+
112
+ property :control, String,
113
+ name_property: true,
114
+ description: "The name of the control being waived"
115
+
116
+ property :expiration, String,
117
+ description: "The expiration date of the waiver - provided in YYYY-MM-DD format",
118
+ callbacks: {
119
+ "Expiration date should be a valid calendar date and match the following format: YYYY-MM-DD" => proc { |e|
120
+ re = Regexp.new('\d{4}-\d{2}-\d{2}$').freeze
121
+ if re.match?(e)
122
+ Date.valid_date?(*e.split("-").map(&:to_i))
123
+ else
124
+ e.nil?
125
+ end
126
+ },
127
+ }
128
+
129
+ property :run_test, [true, false],
130
+ description: "If present and true, the control will run and be reported, but failures in it won’t make the overall run fail. If absent or false, the control will not be run."
131
+
132
+ property :justification, String,
133
+ description: "Can be any text you want and might include a reason for the waiver as well as who signed off on the waiver."
134
+
135
+ property :source, [ Hash, String ]
136
+
137
+ action :add, description: "Add a waiver to the compliance phase" do
138
+ if run_context.waiver_collection.valid?(new_resource.control)
139
+ include_waiver(new_resource.control)
140
+ else
141
+ include_waiver(waiver_hash)
142
+ end
143
+ end
144
+
145
+ action_class do
146
+ # If the source is nil and the control / name_property contains a file separator and is a string of a
147
+ # file that exists, then use that as the file (similar to the package provider automatic source property). Otherwise
148
+ # just return the source.
149
+ #
150
+ # @api private
151
+ def source
152
+ @source ||= build_source
153
+ end
154
+
155
+ def build_source
156
+ return new_resource.source unless new_resource.source.nil?
157
+ return nil unless new_resource.control.count(::File::SEPARATOR) > 0 || (::File::ALT_SEPARATOR && new_resource.control.count(::File::ALT_SEPARATOR) > 0 )
158
+ return nil unless ::File.exist?(new_resource.control)
159
+
160
+ new_resource.control
161
+ end
162
+
163
+ def waiver_hash
164
+ case source
165
+ when Hash
166
+ source
167
+ when String
168
+ parse_file(source)
169
+ when nil
170
+ if new_resource.justification.nil? || new_resource.justification == ""
171
+ raise Chef::Exceptions::ValidationFailed, "Entries for an InSpec waiver must have a justification given, this parameter must have a value."
172
+ end
173
+
174
+ control_hash = {}
175
+ control_hash["expiration_date"] = new_resource.expiration.to_s unless new_resource.expiration.nil?
176
+ control_hash["run"] = new_resource.run_test unless new_resource.run_test.nil?
177
+ control_hash["justification"] = new_resource.justification.to_s
178
+
179
+ { new_resource.control => control_hash }
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
@@ -84,13 +84,13 @@ class Chef
84
84
  }
85
85
 
86
86
  property :run_test, [true, false],
87
- description: "If present and true, the control will run and be reported, but failures in it won’t make the overall run fail. If absent or false, the control will not be run."
87
+ description: "If present and `true`, the control will run and be reported, but failures in it won’t make the overall run fail. If absent or `false`, the control will not be run."
88
88
 
89
89
  property :justification, String,
90
90
  description: "Can be any text you want and might include a reason for the waiver as well as who signed off on the waiver."
91
91
 
92
92
  property :backup, [false, Integer],
93
- description: "The number of backups to be kept in /var/chef/backup (for UNIX- and Linux-based platforms) or C:/chef/backup (for the Microsoft Windows platform). Set to false to prevent backups from being kept.",
93
+ description: "The number of backups to be kept in `/var/chef/backup` (for UNIX- and Linux-based platforms) or `C:/chef/backup` (for the Microsoft Windows platform). Set to `false` to prevent backups from being kept.",
94
94
  default: false
95
95
 
96
96
  action :add do
@@ -36,7 +36,7 @@ class Chef
36
36
 
37
37
  property :backup, [Integer, FalseClass],
38
38
  desired_state: false,
39
- description: "The number of backups to be kept in /var/chef/backup. Set to false to prevent backups from being kept."
39
+ description: "The number of backups to be kept in `/var/chef/backup`. Set to `false` to prevent backups from being kept."
40
40
 
41
41
  property :cookbook, String,
42
42
  desired_state: false,
@@ -197,10 +197,10 @@ class Chef
197
197
  description: "The intended purpose of the job: `Adaptive`, `Background`, `Interactive`, or `Standard`."
198
198
 
199
199
  property :program, String,
200
- description: "The first argument of execvp, typically the file name associated with the file to be executed. This value must be specified if program_arguments is not specified, and vice-versa."
200
+ description: "The first argument of `execvp`, typically the file name associated with the file to be executed. This value must be specified if `program_arguments` is not specified, and vice-versa."
201
201
 
202
202
  property :program_arguments, Array,
203
- description: "The second argument of execvp. If program is not specified, this property must be specified and will be handled as if it were the first argument."
203
+ description: "The second argument of `execvp`. If program is not specified, this property must be specified and will be handled as if it were the first argument."
204
204
 
205
205
  property :queue_directories, Array,
206
206
  description: "An array of non-empty directories which, if any are modified, will cause a job to be started."
@@ -37,7 +37,7 @@ class Chef
37
37
  class LWRPBase < Resource
38
38
 
39
39
  # Class methods
40
- class <<self
40
+ class << self
41
41
 
42
42
  include Chef::Mixin::ConvertToClassName
43
43
  include Chef::Mixin::FromFile
@@ -42,7 +42,7 @@ class Chef
42
42
  sensitive: true
43
43
 
44
44
  property :mount_point, String, name_property: true,
45
- coerce: proc { |arg| arg.chomp("/") }, # Removed "/" from the end of str, because it was causing idempotency issue.
45
+ coerce: proc { |arg| (arg == "/" || arg.match?(":/$")) ? arg : arg.chomp("/") }, # Removed "/" from the end of str, because it was causing idempotency issue.
46
46
  description: "The directory (or path) in which the device is to be mounted. Defaults to the name of the resource block if not provided."
47
47
 
48
48
  property :device, String, identity: true,
@@ -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
 
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <configuration>
3
+ <appSettings>
4
+ <add key="debug" value="false" />
5
+ <% if @auth_token %>
6
+ <add key="ENV_HAB_AUTH_TOKEN" value="<%= @auth_token %>" />
7
+ <% end %>
8
+ <% if @gateway_auth_token %>
9
+ <add key="ENV_HAB_SUP_GATEWAY_AUTH_TOKEN" value="<%= @gateway_auth_token %>" />
10
+ <% end %>
11
+ <% if @bldr_url %>
12
+ <add key="ENV_HAB_BLDR_URL" value="<%= @bldr_url %>" />
13
+ <% end %>
14
+ <%if @exec_start_options %>
15
+ <add key="launcherArgs" value="--no-color <%= @exec_start_options %>" />
16
+ <% end %>
17
+ <add key="launcherPath" value="C:\Hab\pkgs\<%= `hab pkg list core/hab-launcher`.split().last %>\bin\hab-launch.exe"/>
18
+ </appSettings>
19
+ </configuration>
@@ -18,10 +18,17 @@
18
18
  @pid_file
19
19
  @policy_group
20
20
  @policy_name
21
- @ssl_verify_mode).each do |prop| -%>
21
+ @ssl_verify_mode
22
+ @policy_persist_run_list).each do |prop| -%>
22
23
  <% next if instance_variable_get(prop).nil? || instance_variable_get(prop).empty? -%>
23
24
  <%=prop.delete_prefix("@") %> <%= instance_variable_get(prop).inspect %>
24
25
  <% end -%>
26
+ <%# ohai_disabled_plugins and ohai_optional_plugins properties don't match the config value perfectly-%>
27
+ <% %w(@ohai_disabled_plugins
28
+ @ohai_optional_plugins).each do |prop| -%>
29
+ <% next if instance_variable_get(prop).nil? || instance_variable_get(prop).empty? -%>
30
+ <%=prop.gsub("@ohai_", "ohai.") %> <%= instance_variable_get(prop).inspect %>
31
+ <% end -%>
25
32
  <%# log_location is special due to STDOUT/STDERR from String -> IO Object -%>
26
33
  <% unless @log_location.nil? %>
27
34
  <% if @log_location.is_a?(String) && %w(STDOUT STDERR).include?(@log_location) -%>