chef 17.4.38-universal-mingw32 → 17.7.22-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -0
  3. data/chef.gemspec +3 -0
  4. data/lib/chef/application/base.rb +11 -1
  5. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  6. data/lib/chef/chef_fs/path_utils.rb +1 -1
  7. data/lib/chef/client.rb +1 -2
  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/runner.rb +47 -5
  13. data/lib/chef/compliance/waiver.rb +115 -0
  14. data/lib/chef/compliance/waiver_collection.rb +143 -0
  15. data/lib/chef/data_collector/run_end_message.rb +1 -1
  16. data/lib/chef/dsl/compliance.rb +38 -0
  17. data/lib/chef/dsl/reader_helpers.rb +51 -0
  18. data/lib/chef/dsl/reboot_pending.rb +1 -1
  19. data/lib/chef/dsl/recipe.rb +4 -2
  20. data/lib/chef/dsl/secret.rb +2 -4
  21. data/lib/chef/dsl/universal.rb +2 -0
  22. data/lib/chef/event_dispatch/base.rb +44 -2
  23. data/lib/chef/exceptions.rb +10 -0
  24. data/lib/chef/formatters/doc.rb +46 -0
  25. data/lib/chef/http/basic_client.rb +15 -7
  26. data/lib/chef/http.rb +7 -3
  27. data/lib/chef/provider/cron.rb +4 -1
  28. data/lib/chef/provider/file.rb +2 -0
  29. data/lib/chef/provider/git.rb +1 -1
  30. data/lib/chef/provider/ifconfig/debian.rb +1 -1
  31. data/lib/chef/provider/link.rb +2 -2
  32. data/lib/chef/provider/registry_key.rb +3 -2
  33. data/lib/chef/provider/remote_file/http.rb +1 -1
  34. data/lib/chef/provider/subversion.rb +5 -5
  35. data/lib/chef/provider/template.rb +1 -1
  36. data/lib/chef/resource/archive_file.rb +17 -14
  37. data/lib/chef/resource/chef_client_scheduled_task.rb +45 -2
  38. data/lib/chef/resource/chocolatey_config.rb +14 -14
  39. data/lib/chef/resource/chocolatey_feature.rb +1 -1
  40. data/lib/chef/resource/chocolatey_source.rb +24 -2
  41. data/lib/chef/resource/directory.rb +1 -1
  42. data/lib/chef/resource/file/verification/json.rb +50 -0
  43. data/lib/chef/resource/file/verification/yaml.rb +52 -0
  44. data/lib/chef/resource/habitat_install.rb +3 -3
  45. data/lib/chef/resource/inspec_input.rb +127 -0
  46. data/lib/chef/resource/inspec_waiver.rb +184 -0
  47. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  48. data/lib/chef/resource/kernel_module.rb +27 -2
  49. data/lib/chef/resource/macos_userdefaults.rb +43 -128
  50. data/lib/chef/resource/mount.rb +1 -1
  51. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  52. data/lib/chef/resource/powershell_package_source.rb +234 -70
  53. data/lib/chef/resource/registry_key.rb +36 -48
  54. data/lib/chef/resource/remote_file.rb +98 -2
  55. data/lib/chef/resource/timezone.rb +2 -2
  56. data/lib/chef/resource/user_ulimit.rb +1 -0
  57. data/lib/chef/resource/windows_auto_run.rb +1 -1
  58. data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
  59. data/lib/chef/resource/windows_printer.rb +1 -1
  60. data/lib/chef/resource/windows_uac.rb +3 -1
  61. data/lib/chef/resource/windows_update_settings.rb +3 -3
  62. data/lib/chef/resource/windows_user_privilege.rb +1 -1
  63. data/lib/chef/resource.rb +1 -1
  64. data/lib/chef/resource_reporter.rb +1 -1
  65. data/lib/chef/resources.rb +2 -0
  66. data/lib/chef/run_context/cookbook_compiler.rb +112 -28
  67. data/lib/chef/run_context.rb +31 -1
  68. data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
  69. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +1 -1
  70. data/lib/chef/secret_fetcher/azure_key_vault.rb +63 -9
  71. data/lib/chef/secret_fetcher/base.rb +1 -1
  72. data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
  73. data/lib/chef/secret_fetcher.rb +8 -3
  74. data/lib/chef/version.rb +1 -1
  75. data/lib/chef/win32/version.rb +2 -1
  76. data/spec/data/archive_file/test_archive.tar.gz +0 -0
  77. data/spec/functional/dsl/reboot_pending_spec.rb +3 -3
  78. data/spec/functional/dsl/registry_helper_spec.rb +1 -1
  79. data/spec/functional/resource/archive_file_spec.rb +87 -0
  80. data/spec/functional/resource/dsc_script_spec.rb +2 -2
  81. data/spec/functional/resource/group_spec.rb +5 -1
  82. data/spec/functional/resource/link_spec.rb +8 -0
  83. data/spec/functional/resource/macos_userdefaults_spec.rb +119 -0
  84. data/spec/functional/resource/powershell_package_source_spec.rb +5 -6
  85. data/spec/functional/resource/registry_spec.rb +81 -81
  86. data/spec/functional/win32/registry_spec.rb +8 -8
  87. data/spec/integration/compliance/compliance_spec.rb +60 -0
  88. data/spec/spec_helper.rb +3 -0
  89. data/spec/support/platform_helpers.rb +4 -0
  90. data/spec/support/ruby_installer.rb +51 -0
  91. data/spec/unit/compliance/input_spec.rb +104 -0
  92. data/spec/unit/compliance/profile_spec.rb +120 -0
  93. data/spec/unit/compliance/waiver_spec.rb +104 -0
  94. data/spec/unit/data_collector_spec.rb +24 -1
  95. data/spec/unit/dsl/reboot_pending_spec.rb +1 -1
  96. data/spec/unit/http/basic_client_spec.rb +30 -0
  97. data/spec/unit/http_spec.rb +8 -2
  98. data/spec/unit/mixin/default_paths_spec.rb +1 -1
  99. data/spec/unit/mixin/securable_spec.rb +3 -3
  100. data/spec/unit/provider/cron_spec.rb +45 -0
  101. data/spec/unit/provider/link_spec.rb +13 -7
  102. data/spec/unit/provider/package/rubygems_spec.rb +5 -5
  103. data/spec/unit/provider/package/windows_spec.rb +1 -1
  104. data/spec/unit/provider/registry_key_spec.rb +4 -4
  105. data/spec/unit/provider/remote_file/http_spec.rb +10 -0
  106. data/spec/unit/provider/service/windows_spec.rb +5 -5
  107. data/spec/unit/provider/subversion_spec.rb +4 -4
  108. data/spec/unit/provider/template_spec.rb +2 -2
  109. data/spec/unit/provider/windows_env_spec.rb +1 -1
  110. data/spec/unit/provider/zypper_repository_spec.rb +1 -1
  111. data/spec/unit/resource/archive_file_spec.rb +414 -3
  112. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
  113. data/spec/unit/resource/chocolatey_config_spec.rb +1 -1
  114. data/spec/unit/resource/chocolatey_feature_spec.rb +1 -1
  115. data/spec/unit/resource/chocolatey_source_spec.rb +1 -1
  116. data/spec/unit/resource/file/verification/json_spec.rb +72 -0
  117. data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
  118. data/spec/unit/resource/inspec_input_spec.rb +300 -0
  119. data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
  120. data/spec/unit/resource/kernel_module_spec.rb +2 -1
  121. data/spec/unit/resource/macos_user_defaults_spec.rb +36 -96
  122. data/spec/unit/resource/mount_spec.rb +10 -0
  123. data/spec/unit/resource/powershell_package_source_spec.rb +63 -62
  124. data/spec/unit/resource/registry_key_spec.rb +10 -10
  125. data/spec/unit/resource/user_ulimit_spec.rb +14 -1
  126. data/spec/unit/resource/windows_auto_run_spec.rb +1 -1
  127. data/spec/unit/resource/windows_feature_powershell_spec.rb +1 -1
  128. data/spec/unit/resource/windows_firewall_rule_spec.rb +2 -2
  129. data/spec/unit/resource/windows_task_spec.rb +3 -3
  130. data/spec/unit/resource_reporter_spec.rb +2 -2
  131. data/spec/unit/resource_spec.rb +5 -0
  132. data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
  133. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +99 -20
  134. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
  135. data/spec/unit/util/backup_spec.rb +1 -1
  136. data/spec/unit/win32/registry_spec.rb +3 -3
  137. data/tasks/rspec.rb +2 -1
  138. metadata +75 -6
@@ -0,0 +1,184 @@
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 managed node, this behavior
106
+ is still consistent with the configuration management model. Instead, you should use events 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 you should use pure ruby
108
+ conditionals instead. Compliance configuration should be independent of other resources and should only be conditional based on state/attributes, not other resources.
109
+ DOC
110
+
111
+ property :control, String,
112
+ name_property: true,
113
+ description: "The name of the control being waived"
114
+
115
+ property :expiration, String,
116
+ description: "The expiration date of the waiver - provided in YYYY-MM-DD format",
117
+ callbacks: {
118
+ "Expiration date should be a valid calendar date and match the following format: YYYY-MM-DD" => proc { |e|
119
+ re = Regexp.new("\\d{4}-\\d{2}-\\d{2}$").freeze
120
+ if re.match?(e)
121
+ Date.valid_date?(*e.split("-").map(&:to_i))
122
+ else
123
+ e.nil?
124
+ end
125
+ },
126
+ }
127
+
128
+ property :run_test, [true, false],
129
+ 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."
130
+
131
+ property :justification, String,
132
+ description: "Can be any text you want and might include a reason for the waiver as well as who signed off on the waiver."
133
+
134
+ property :source, [ Hash, String ]
135
+
136
+ action :add, description: "Add a waiver to the compliance phase" do
137
+ if run_context.waiver_collection.valid?(new_resource.control)
138
+ include_waiver(new_resource.control)
139
+ else
140
+ include_waiver(waiver_hash)
141
+ end
142
+ end
143
+
144
+ action_class do
145
+ # If the source is nil and the control / name_property contains a file separator and is a string of a
146
+ # file that exists, then use that as the file (similar to the package provider automatic source property). Otherwise
147
+ # just return the source.
148
+ #
149
+ # @api private
150
+ def source
151
+ @source ||= build_source
152
+ end
153
+
154
+ def build_source
155
+ return new_resource.source unless new_resource.source.nil?
156
+ return nil unless new_resource.control.count(::File::SEPARATOR) > 0 || (::File::ALT_SEPARATOR && new_resource.control.count(::File::ALT_SEPARATOR) > 0 )
157
+ return nil unless ::File.exist?(new_resource.control)
158
+
159
+ new_resource.control
160
+ end
161
+
162
+ def waiver_hash
163
+ case source
164
+ when Hash
165
+ source
166
+ when String
167
+ parse_file(source)
168
+ when nil
169
+ if new_resource.justification.nil? || new_resource.justification == ""
170
+ raise Chef::Exceptions::ValidationFailed, "Entries for an InSpec waiver must have a justification given, this parameter must have a value."
171
+ end
172
+
173
+ control_hash = {}
174
+ control_hash["expiration_date"] = new_resource.expiration.to_s unless new_resource.expiration.nil?
175
+ control_hash["run"] = new_resource.run_test unless new_resource.run_test.nil?
176
+ control_hash["justification"] = new_resource.justification.to_s
177
+
178
+ { new_resource.control => control_hash }
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
@@ -74,7 +74,7 @@ class Chef
74
74
  description: "The expiration date of the given waiver - provided in YYYY-MM-DD format",
75
75
  callbacks: {
76
76
  "Expiration date should be a valid calendar date and match the following format: YYYY-MM-DD" => proc { |e|
77
- re = Regexp.new('\d{4}-\d{2}-\d{2}$').freeze
77
+ re = Regexp.new("\\d{4}-\\d{2}-\\d{2}$").freeze
78
78
  if re.match?(e)
79
79
  Date.valid_date?(*e.split("-").map(&:to_i))
80
80
  else
@@ -15,7 +15,7 @@ class Chef
15
15
 
16
16
  provides :kernel_module
17
17
 
18
- description "Use the **kernel_module** resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, install, and uninstall modules."
18
+ description "Use the **kernel_module** resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, enable, install, and uninstall modules."
19
19
  introduced "14.3"
20
20
  examples <<~DOC
21
21
  Install and load a kernel module, and ensure it loads on reboot.
@@ -68,13 +68,21 @@ class Chef
68
68
  end
69
69
  ```
70
70
 
71
- Disable a kernel module.
71
+ Disable a kernel module so that it is not installable.
72
72
 
73
73
  ```ruby
74
74
  kernel_module 'loop' do
75
75
  action :disable
76
76
  end
77
77
  ```
78
+
79
+ Enable a kernel module so that it is can be installed. Does not load or install.
80
+
81
+ ```ruby
82
+ kernel_module 'loop' do
83
+ action :enable
84
+ end
85
+ ```
78
86
  DOC
79
87
 
80
88
  property :modname, String,
@@ -101,6 +109,9 @@ class Chef
101
109
  end
102
110
  end
103
111
 
112
+ # Remove the "disable file" before trying to install
113
+ action_enable
114
+
104
115
  # create options file before loading the module
105
116
  unless new_resource.options.nil?
106
117
  file "#{new_resource.unload_dir}/options_#{new_resource.modname}.conf" do
@@ -178,6 +189,20 @@ class Chef
178
189
  action_unload
179
190
  end
180
191
 
192
+ action :enable, description: "Enable a kernel module. Reverse :disable actions" do
193
+ with_run_context :root do
194
+ find_resource(:execute, "update initramfs") do
195
+ command initramfs_command
196
+ action :nothing
197
+ end
198
+ end
199
+
200
+ file "#{new_resource.unload_dir}/disable_#{new_resource.modname}.conf" do
201
+ action :delete
202
+ notifies :run, "execute[update initramfs]", :delayed
203
+ end
204
+ end
205
+
181
206
  action :load, description: "Load a kernel module." do
182
207
  unless module_loaded?
183
208
  converge_by("load kernel module #{new_resource.modname}") do
@@ -78,172 +78,87 @@ class Chef
78
78
  required: true
79
79
 
80
80
  property :host, [String, Symbol],
81
- description: "Set either :current or a hostname to set the user default at the host level.",
81
+ description: "Set either :current, :all or a hostname to set the user default at the host level.",
82
82
  desired_state: false,
83
- introduced: "16.3"
83
+ introduced: "16.3",
84
+ coerce: proc { |value| to_cf_host(value) }
84
85
 
85
86
  property :value, [Integer, Float, String, TrueClass, FalseClass, Hash, Array],
86
87
  description: "The value of the key. Note: With the `type` property set to `bool`, `String` forms of Boolean true/false values that Apple accepts in the defaults command will be coerced: 0/1, 'TRUE'/'FALSE,' 'true'/false', 'YES'/'NO', or 'yes'/'no'.",
87
- required: [:write],
88
- coerce: proc { |v| v.is_a?(Hash) ? v.transform_keys(&:to_s) : v } # make sure keys are all strings for comparison
88
+ required: [:write]
89
89
 
90
90
  property :type, String,
91
91
  description: "The value type of the preference key.",
92
92
  equal_to: %w{bool string int float array dict},
93
- desired_state: false
93
+ desired_state: false,
94
+ deprecated: true
94
95
 
95
- property :user, String,
96
- description: "The system user that the default will be applied to.",
97
- desired_state: false
96
+ property :user, [String, Symbol],
97
+ description: "The system user that the default will be applied to. Set :current for current user, :all for all users or pass a valid username",
98
+ desired_state: false,
99
+ coerce: proc { |value| to_cf_user(value) }
98
100
 
99
101
  property :sudo, [TrueClass, FalseClass],
100
102
  description: "Set to true if the setting you wish to modify requires privileged access. This requires passwordless sudo for the `/usr/bin/defaults` command to be setup for the user running #{ChefUtils::Dist::Infra::PRODUCT}.",
101
103
  default: false,
102
- desired_state: false
104
+ desired_state: false,
105
+ deprecated: true
103
106
 
104
107
  load_current_value do |new_resource|
105
- Chef::Log.debug "#load_current_value: shelling out \"#{defaults_export_cmd(new_resource).join(" ")}\" to determine state"
106
- state = shell_out(defaults_export_cmd(new_resource), user: new_resource.user)
107
-
108
- if state.error? || state.stdout.empty?
109
- Chef::Log.debug "#load_current_value: #{defaults_export_cmd(new_resource).join(" ")} returned stdout: #{state.stdout} and stderr: #{state.stderr}"
110
- current_value_does_not_exist!
111
- end
112
-
113
- plist_data = ::Plist.parse_xml(state.stdout)
114
-
115
- # handle the situation where the key doesn't exist in the domain
116
- if plist_data.key?(new_resource.key)
117
- key new_resource.key
118
- else
119
- current_value_does_not_exist!
120
- end
108
+ Chef::Log.debug "#load_current_value: attempting to read \"#{new_resource.domain}\" value from preferences to determine state"
121
109
 
122
- value plist_data[new_resource.key]
123
- end
124
-
125
- #
126
- # The defaults command to export a domain
127
- #
128
- # @return [Array] defaults command
129
- #
130
- def defaults_export_cmd(resource)
131
- state_cmd = ["/usr/bin/defaults"]
132
-
133
- if resource.host == "current"
134
- state_cmd.concat(["-currentHost"])
135
- elsif resource.host # they specified a non-nil value, which is a hostname
136
- state_cmd.concat(["-host", resource.host])
137
- end
110
+ pref = get_preference(new_resource)
111
+ current_value_does_not_exist! if pref.nil?
138
112
 
139
- state_cmd.concat(["export", resource.domain, "-"])
140
- state_cmd
113
+ key new_resource.key
114
+ value pref
141
115
  end
142
116
 
143
117
  action :write, description: "Write the value to the specified domain/key." do
144
118
  converge_if_changed do
145
- cmd = defaults_modify_cmd
146
- Chef::Log.debug("Updating defaults value by shelling out: #{cmd.join(" ")}")
147
-
148
- shell_out!(cmd, user: new_resource.user)
119
+ Chef::Log.debug("Updating defaults value for #{new_resource.key} in #{new_resource.domain}")
120
+ CF::Preferences.set!(new_resource.key, new_resource.value, new_resource.domain, new_resource.user, new_resource.host)
149
121
  end
150
122
  end
151
123
 
152
124
  action :delete, description: "Delete a key from a domain." do
153
125
  # if it's not there there's nothing to remove
154
- return unless current_resource
126
+ return if current_resource.nil?
155
127
 
156
128
  converge_by("delete domain:#{new_resource.domain} key:#{new_resource.key}") do
157
-
158
- cmd = defaults_modify_cmd
159
- Chef::Log.debug("Removing defaults key by shelling out: #{cmd.join(" ")}")
160
-
161
- shell_out!(cmd, user: new_resource.user)
129
+ Chef::Log.debug("Removing defaults key: #{new_resource.key}")
130
+ CF::Preferences.set!(new_resource.key, nil, new_resource.domain, new_resource.user, new_resource.host)
162
131
  end
163
132
  end
164
133
 
165
- action_class do
166
- #
167
- # The command used to write or delete delete values from domains
168
- #
169
- # @return [Array] Array representation of defaults command to run
170
- #
171
- def defaults_modify_cmd
172
- cmd = ["/usr/bin/defaults"]
173
-
174
- if new_resource.host == :current
175
- cmd.concat(["-currentHost"])
176
- elsif new_resource.host # they specified a non-nil value, which is a hostname
177
- cmd.concat(["-host", new_resource.host])
178
- end
134
+ def get_preference(new_resource)
135
+ CF::Preferences.get(new_resource.key, new_resource.domain, new_resource.user, new_resource.host)
136
+ end
179
137
 
180
- cmd.concat([action.to_s, new_resource.domain, new_resource.key])
181
- cmd.concat(processed_value) if action == :write
182
- cmd.prepend("sudo") if new_resource.sudo
183
- cmd
184
- end
138
+ action_class do
139
+ require "corefoundation" if RUBY_PLATFORM.match?(/darwin/)
185
140
 
186
- #
187
- # convert the provided value into the format defaults expects
188
- #
189
- # @return [array] array of values starting with the type if applicable
190
- #
191
- def processed_value
192
- type = new_resource.type || value_type(new_resource.value)
193
-
194
- # when dict this creates an array of values ["Key1", "Value1", "Key2", "Value2" ...]
195
- cmd_values = ["-#{type}"]
196
-
197
- case type
198
- when "dict"
199
- cmd_values.concat(new_resource.value.flatten)
200
- when "array"
201
- cmd_values.concat(new_resource.value)
202
- when "bool"
203
- cmd_values.concat(bool_to_defaults_bool(new_resource.value))
141
+ # Return valid hostname based on the input from host property
142
+ def to_cf_host(value)
143
+ case value
144
+ when :all
145
+ CF::Preferences::ALL_HOSTS
146
+ when :current
147
+ CF::Preferences::CURRENT_HOST
204
148
  else
205
- cmd_values.concat([new_resource.value])
149
+ value
206
150
  end
207
-
208
- cmd_values
209
151
  end
210
152
 
211
- #
212
- # defaults booleans on the CLI must be 'TRUE' or 'FALSE' so convert various inputs to that
213
- #
214
- # @param [String, Integer, Boolean] input <description>
215
- #
216
- # @return [String] TRUE or FALSE
217
- #
218
- def bool_to_defaults_bool(input)
219
- return ["TRUE"] if [true, "TRUE", "1", "true", "YES", "yes"].include?(input)
220
- return ["FALSE"] if [false, "FALSE", "0", "false", "NO", "no"].include?(input)
221
-
222
- # make sure it's very clear bad input was given
223
- raise ArgumentError, "#{input} cannot be converted to a boolean value for use with Apple's defaults command. Acceptable values are: 'TRUE', 'YES', 'true, 'yes', '0', true, 'FALSE', 'false', 'NO', 'no', '1', or false."
224
- end
225
-
226
- #
227
- # convert ruby type to defaults type
228
- #
229
- # @param [Integer, Float, String, TrueClass, FalseClass, Hash, Array] value The value being set
230
- #
231
- # @return [string, nil] the type value used by defaults or nil if not applicable
232
- #
233
- def value_type(value)
153
+ # Return valid username based on the input from user property
154
+ def to_cf_user(value)
234
155
  case value
235
- when true, false
236
- "bool"
237
- when Integer
238
- "int"
239
- when Float
240
- "float"
241
- when Hash
242
- "dict"
243
- when Array
244
- "array"
245
- when String
246
- "string"
156
+ when :all
157
+ CF::Preferences::ALL_USERS
158
+ when :current
159
+ CF::Preferences::CURRENT_USER
160
+ else
161
+ value
247
162
  end
248
163
  end
249
164
  end
@@ -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,
@@ -226,7 +226,7 @@ class Chef
226
226
  end
227
227
 
228
228
  def ca_private_key
229
- if new_resource.csr_file.nil?
229
+ if new_resource.ca_key_file.nil?
230
230
  key
231
231
  else
232
232
  OpenSSL::PKey.read ::File.read(new_resource.ca_key_file), new_resource.ca_key_pass