summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-20 17:07:42 -0700
committerTim Smith <tsmith84@gmail.com>2020-07-20 17:07:42 -0700
commit7bc7edc2223993c32823c36f7f8ea0edc61a1649 (patch)
tree5bd0cf937d9afd15a6b2ce50a7f4d809a06c3484
parent9899f2e1232fcc0fa23a3e31e313193407cd5ee9 (diff)
downloadchef-7bc7edc2223993c32823c36f7f8ea0edc61a1649.tar.gz
Make key part of the desired state so we can handle new keys
This improved log output and prevents failures when no key has been set: ``` ❰tsmith❙~/dev/work/chef(git✱≠macos_userdefaults)❱✔≻ bundle exec chef-apply test.rb Recipe: (chef-apply cookbook)::(chef-apply recipe) * macos_userdefaults[Add String key] action write - create Add String key - set key to "StringKey2" - set value to "/usr/local/tim" * macos_userdefaults[Add boolean key] action write (up to date) * macos_userdefaults[Add array key] action write (up to date) ❰tsmith❙~/dev/work/chef(git✱≠macos_userdefaults)❱✔≻ bundle exec chef-apply test.rb Recipe: (chef-apply cookbook)::(chef-apply recipe) * macos_userdefaults[Add String key] action write - update Add String key - set value to "/usr/local/tim2" (was "/usr/local/tim") * macos_userdefaults[Add boolean key] action write (up to date) * macos_userdefaults[Add array key] action write (up to date) ``` Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/macos_userdefaults.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb
index 15a0f17a39..f45141957a 100644
--- a/lib/chef/resource/macos_userdefaults.rb
+++ b/lib/chef/resource/macos_userdefaults.rb
@@ -75,8 +75,7 @@ class Chef
property :key, String,
description: "The preference key.",
- required: true,
- desired_state: false
+ required: true
property :host, [String, Symbol],
description: "Set either :current or a hostname to set the user default at the host level.",
@@ -116,9 +115,14 @@ class Chef
plist_data = ::Plist.parse_xml(state.stdout)
- current_value_does_not_exist! unless current_value_does_not_exist!.key?(key)
+ # handle the situation where the key doesn't exist in the domain
+ if plist_data.key?(desired.key)
+ key desired.key
+ else
+ current_value_does_not_exist!
+ end
- value plist_data[key]
+ value plist_data[desired.key]
end
#