diff options
author | rishichawda <rishichawda@users.noreply.github.com> | 2021-08-12 16:39:53 +0530 |
---|---|---|
committer | rishichawda <rishichawda@users.noreply.github.com> | 2021-09-25 02:00:28 +0530 |
commit | e242e28436bcb23efc412fb26c77ea79cb98d867 (patch) | |
tree | 59a5b5acb9541c22cc06305e571b7a3ef1d068be | |
parent | c5bc23e24c1fe8cfdc6bce18f43879f62c3e2761 (diff) | |
download | chef-e242e28436bcb23efc412fb26c77ea79cb98d867.tar.gz |
transform values at source with coerce
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
-rw-r--r-- | lib/chef/resource/macos_userdefaults.rb | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb index 2aad7c9936..24a4e7cc7f 100644 --- a/lib/chef/resource/macos_userdefaults.rb +++ b/lib/chef/resource/macos_userdefaults.rb @@ -81,7 +81,8 @@ class Chef property :host, [String, Symbol], description: "Set either :current, :all or a hostname to set the user default at the host level.", desired_state: false, - introduced: "16.3" + introduced: "16.3", + coerce: proc { |value| to_cf_host(value) } property :value, [Integer, Float, String, TrueClass, FalseClass, Hash, Array], 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'.", @@ -95,7 +96,8 @@ class Chef property :user, [String, Symbol], 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", - desired_state: false + desired_state: false, + coerce: proc { |value| to_cf_user(value) } property :sudo, [TrueClass, FalseClass], 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}.", @@ -126,22 +128,16 @@ class Chef converge_by("delete domain:#{new_resource.domain} key:#{new_resource.key}") do Chef::Log.debug("Removing defaults key: #{new_resource.key}") - user = to_cf_user new_resource.user - host = to_cf_host new_resource.host - CF::Preferences.set!(new_resource.key, nil, new_resource.domain, user, host) + CF::Preferences.set!(new_resource.key, nil, new_resource.domain, new_resource.user, new_resource.host) end end def get_preference(new_resource) - user = to_cf_user new_resource.user - host = to_cf_host new_resource.host - CF::Preferences.get(new_resource.key, new_resource.domain, user, host) + CF::Preferences.get(new_resource.key, new_resource.domain, new_resource.user, new_resource.host) end def set_preference(new_resource) - user = to_cf_user new_resource.user - host = to_cf_host new_resource.host - CF::Preferences.set!(new_resource.key, new_resource.value, new_resource.domain, user, host) + CF::Preferences.set!(new_resource.key, new_resource.value, new_resource.domain, new_resource.user, new_resource.host) end # Return valid hostname based on the input from host property |