diff options
author | Lamont Granquist <454857+lamont-granquist@users.noreply.github.com> | 2021-11-16 12:33:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 12:33:24 -0800 |
commit | bc93485d017b5a398bfdb6e5c24b057d842ee098 (patch) | |
tree | e348552d8e753b897c36d36a4b9c8b85a0ef87ad | |
parent | 82075173b1134f0062a38657eaf670e3a50dd297 (diff) | |
parent | af0fd593ad2de7765334c5a778413224eb6f474a (diff) | |
download | chef-bc93485d017b5a398bfdb6e5c24b057d842ee098.tar.gz |
Merge pull request #12234 from chef/add-pointer-to-accepted-types
-rw-r--r-- | lib/chef/resource/macos_userdefaults.rb | 12 | ||||
-rw-r--r-- | spec/functional/resource/macos_userdefaults_spec.rb | 20 |
2 files changed, 25 insertions, 7 deletions
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb index b0b9c32fe0..9daea38aa4 100644 --- a/lib/chef/resource/macos_userdefaults.rb +++ b/lib/chef/resource/macos_userdefaults.rb @@ -81,8 +81,7 @@ 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", - coerce: proc { |value| to_cf_host(value) } + introduced: "16.3" 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'.", @@ -96,8 +95,7 @@ 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, - coerce: proc { |value| to_cf_user(value) } + desired_state: false 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}.", @@ -118,7 +116,7 @@ class Chef action :write, description: "Write the value to the specified domain/key." do converge_if_changed do Chef::Log.debug("Updating defaults value for #{new_resource.key} in #{new_resource.domain}") - CF::Preferences.set!(new_resource.key, new_resource.value, new_resource.domain, new_resource.user, new_resource.host) + CF::Preferences.set!(new_resource.key, new_resource.value, new_resource.domain, to_cf_user(new_resource.user), to_cf_host(new_resource.host)) end end @@ -128,12 +126,12 @@ class Chef converge_by("delete domain:#{new_resource.domain} key:#{new_resource.key}") do Chef::Log.debug("Removing defaults key: #{new_resource.key}") - CF::Preferences.set!(new_resource.key, nil, new_resource.domain, new_resource.user, new_resource.host) + CF::Preferences.set!(new_resource.key, nil, new_resource.domain, to_cf_user(new_resource.user), to_cf_host(new_resource.host)) end end def get_preference(new_resource) - CF::Preferences.get(new_resource.key, new_resource.domain, new_resource.user, new_resource.host) + CF::Preferences.get(new_resource.key, new_resource.domain, to_cf_user(new_resource.user), to_cf_host(new_resource.host)) end # Return valid hostname based on the input from host property diff --git a/spec/functional/resource/macos_userdefaults_spec.rb b/spec/functional/resource/macos_userdefaults_spec.rb index 2f79135c45..0ed7839ad0 100644 --- a/spec/functional/resource/macos_userdefaults_spec.rb +++ b/spec/functional/resource/macos_userdefaults_spec.rb @@ -116,4 +116,24 @@ describe Chef::Resource::MacosUserDefaults, :macos_only do resource.key "titlesize" expect { resource.run_action(:delete) }. to_not raise_error end + + context "resource can process FFI::Pointer type" do + it "for host property" do + resource.domain "/Library/Preferences/ManagedInstalls" + resource.key "TestDictionaryValues" + resource.value "User": "/Library/Managed Installs/way_fake.log" + resource.host :current + resource.run_action(:write) + expect { resource.run_action(:write) }. to_not raise_error + end + + it "for user property" do + resource.domain "/Library/Preferences/ManagedInstalls" + resource.key "TestDictionaryValues" + resource.value "User": "/Library/Managed Installs/way_fake.log" + resource.user :current + resource.run_action(:write) + expect { resource.run_action(:write) }. to_not raise_error + end + end end |