From 2cdf4af03dfe077806c34921613eff54684e0635 Mon Sep 17 00:00:00 2001 From: Eric Hanko Date: Wed, 21 Nov 2018 15:04:00 -0800 Subject: [PATCH 01/12] Add support for owner/group to plist resource - Paired with Andre Shields and Chris Gilbert --- .kitchen.yml | 1 + resources/plist.rb | 35 ++++++++++++++----- .../macos_test/recipes/preferences.rb | 24 +++++++++++++ .../integration/default/controls/dock_test.rb | 5 +++ .../default/controls/general_test.rb | 25 +++++++++++++ 5 files changed, 82 insertions(+), 8 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 77358c1e..17cadf86 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -85,6 +85,7 @@ suites: - dock-appearance - show-all-files - updates-disabled + - plist-creation - name: power-management provisioner: diff --git a/resources/plist.rb b/resources/plist.rb index c2b5944a..c9a1f42a 100644 --- a/resources/plist.rb +++ b/resources/plist.rb @@ -4,6 +4,8 @@ property :entry, String, desired_state: true property :value, [TrueClass, FalseClass, String, Integer, Float], desired_state: true property :encoding, String, desired_state: true, default: 'binary' +property :owner, String, desired_state: true, default: 'root' +property :group, String, desired_state: true, default: 'wheel' load_current_value do |desired| current_value_does_not_exist! unless ::File.exist? desired.path @@ -14,20 +16,21 @@ file_type_cmd = shell_out '/usr/bin/file', '--brief', '--mime-encoding', '--preserve-date', desired.path encoding file_type_cmd.stdout.chomp + + file_owner_cmd = shell_out('/usr/bin/stat', '-f', '%Su', desired.path) + owner file_owner_cmd.stdout.chomp + + file_group_cmd = shell_out('/usr/bin/stat', '-f', '%Sg', desired.path) + group file_group_cmd.stdout.chomp end action :set do converge_if_changed :path do converge_by "create new plist: '#{new_resource.path}'" do file new_resource.path do - content <<-EOF - - - - - - -EOF + content {}.to_plist + owner new_resource.owner + group new_resource.group end end end @@ -60,4 +63,20 @@ end end end + + converge_if_change :owner do + converge_by "update owner to #{new_resource.owner}" do + file new_resource.path do + owner new_resource.owner + end + end + end + + converge_if_change :group do + converge_by "update group to #{new_resource.group}" do + file new_resource.path do + group new_resource.group + end + end + end end diff --git a/test/cookbooks/macos_test/recipes/preferences.rb b/test/cookbooks/macos_test/recipes/preferences.rb index 66379db0..1433432a 100644 --- a/test/cookbooks/macos_test/recipes/preferences.rb +++ b/test/cookbooks/macos_test/recipes/preferences.rb @@ -2,16 +2,40 @@ path '/Users/vagrant/Library/Preferences/com.apple.finder.plist' entry 'AppleShowAllFiles' value true + owner 'vagrant' + group 'staff' end plist 'put the Dock on the left side' do path '/Users/vagrant/Library/Preferences/com.apple.dock.plist' entry 'orientation' value 'left' + owner 'vagrant' + group 'staff' end plist 'disable window animations and Get Info animations' do path '/Users/vagrant/Library/Preferences/com.apple.dock.plist' entry 'DisableAllAnimations' value true + owner 'vagrant' + group 'staff' +end + +plist 'create a plist that does not exist to test plist creation' do + path '/Users/vagrant/com.microsoft.macoscookbook.plist' + entry 'PokeballEatenByDog' + value true + owner 'vagrant' + group 'staff' + encoding 'ascii' +end + +plist 'add another value to the new plist' do + path '/Users/vagrant/com.microsoft.macoscookbook.plist' + entry 'CaughtEmAll' + value false + owner 'vagrant' + group 'staff' + encoding 'ascii' end diff --git a/test/integration/default/controls/dock_test.rb b/test/integration/default/controls/dock_test.rb index 8514766c..e8501e7a 100644 --- a/test/integration/default/controls/dock_test.rb +++ b/test/integration/default/controls/dock_test.rb @@ -13,4 +13,9 @@ describe command("/usr/libexec/PlistBuddy -c 'Print :DisableAllAnimations' #{user_home}/Library/Preferences/com.apple.dock.plist") do its('stdout') { should match 'true' } end + + describe file("#{user_home}/Library/Preferences/com.apple.dock.plist") do + its('owner') { should eq 'vagrant' } + its('group') { should eq 'staff' } + end end diff --git a/test/integration/default/controls/general_test.rb b/test/integration/default/controls/general_test.rb index 7aceec4c..c2fc2837 100644 --- a/test/integration/default/controls/general_test.rb +++ b/test/integration/default/controls/general_test.rb @@ -10,4 +10,29 @@ describe command("/usr/libexec/PlistBuddy -c 'Print :AppleShowAllFiles' #{finder_plist}") do its('stdout') { should match 'true' } end + + describe file(finder_plist) do + its('owner') { should eq 'vagrant' } + its('group') { should eq 'staff' } + end +end + +control 'plist-creation' do + title 'arbitrary plist creation' + desc 'creation and modification of a property list' + + macos_cookbook_plist = '/Users/vagrant/com.microsoft.macoscookbook.plist' + + describe command("/usr/libexec/PlistBuddy -c 'Print :PokeballEatenByDog' #{macos_cookbook_plist}") do + its('stdout') { should match 'true' } + end + + describe command("/usr/libexec/PlistBuddy -c 'Print :CaughtEmAll' #{macos_cookbook_plist}") do + its('stdout') { should match 'false' } + end + + describe file(macos_cookbook_plist) do + its('owner') { should eq 'vagrant' } + its('group') { should eq 'staff' } + end end From 66606cffead602059d43baa0b52e8f5cf081460b Mon Sep 17 00:00:00 2001 From: Jacob Zaval Date: Fri, 7 Dec 2018 13:38:20 -0800 Subject: [PATCH 02/12] Update resources/plist.rb Co-Authored-By: v-anshie --- resources/plist.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/plist.rb b/resources/plist.rb index c9a1f42a..058b296d 100644 --- a/resources/plist.rb +++ b/resources/plist.rb @@ -64,7 +64,7 @@ end end - converge_if_change :owner do + converge_if_changed :owner do converge_by "update owner to #{new_resource.owner}" do file new_resource.path do owner new_resource.owner From 3bf2d30f8ed730ee71ff5bc1d0633a128c68d804 Mon Sep 17 00:00:00 2001 From: v-anshie Date: Fri, 7 Dec 2018 14:32:34 -0800 Subject: [PATCH 03/12] create variables for multi plist paths --- test/cookbooks/macos_test/recipes/preferences.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/cookbooks/macos_test/recipes/preferences.rb b/test/cookbooks/macos_test/recipes/preferences.rb index 1433432a..f80d5e66 100644 --- a/test/cookbooks/macos_test/recipes/preferences.rb +++ b/test/cookbooks/macos_test/recipes/preferences.rb @@ -1,3 +1,6 @@ +dock = "/Users/vagrant/Library/Preferences/com.apple.dock.plist" +macoscookbook = "/Users/vagrant/com.microsoft.macoscookbook.plist" + plist 'show hidden files' do path '/Users/vagrant/Library/Preferences/com.apple.finder.plist' entry 'AppleShowAllFiles' @@ -7,7 +10,7 @@ end plist 'put the Dock on the left side' do - path '/Users/vagrant/Library/Preferences/com.apple.dock.plist' + path dock entry 'orientation' value 'left' owner 'vagrant' @@ -15,7 +18,7 @@ end plist 'disable window animations and Get Info animations' do - path '/Users/vagrant/Library/Preferences/com.apple.dock.plist' + path dock entry 'DisableAllAnimations' value true owner 'vagrant' @@ -23,7 +26,7 @@ end plist 'create a plist that does not exist to test plist creation' do - path '/Users/vagrant/com.microsoft.macoscookbook.plist' + path macoscookbook entry 'PokeballEatenByDog' value true owner 'vagrant' @@ -32,7 +35,7 @@ end plist 'add another value to the new plist' do - path '/Users/vagrant/com.microsoft.macoscookbook.plist' + path macoscookbook entry 'CaughtEmAll' value false owner 'vagrant' From 32aa211ba5fd0aff213e843c06a266fd16ad17fa Mon Sep 17 00:00:00 2001 From: v-anshie Date: Fri, 7 Dec 2018 14:35:39 -0800 Subject: [PATCH 04/12] update to better variable names --- test/cookbooks/macos_test/recipes/preferences.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/cookbooks/macos_test/recipes/preferences.rb b/test/cookbooks/macos_test/recipes/preferences.rb index f80d5e66..5ef09276 100644 --- a/test/cookbooks/macos_test/recipes/preferences.rb +++ b/test/cookbooks/macos_test/recipes/preferences.rb @@ -1,5 +1,5 @@ -dock = "/Users/vagrant/Library/Preferences/com.apple.dock.plist" -macoscookbook = "/Users/vagrant/com.microsoft.macoscookbook.plist" +dock_plist = "/Users/vagrant/Library/Preferences/com.apple.dock.plist" +macoscookbook_plist = "/Users/vagrant/com.microsoft.macoscookbook.plist" plist 'show hidden files' do path '/Users/vagrant/Library/Preferences/com.apple.finder.plist' @@ -10,7 +10,7 @@ end plist 'put the Dock on the left side' do - path dock + path dock_plist entry 'orientation' value 'left' owner 'vagrant' @@ -18,7 +18,7 @@ end plist 'disable window animations and Get Info animations' do - path dock + path dock_plist entry 'DisableAllAnimations' value true owner 'vagrant' @@ -26,7 +26,7 @@ end plist 'create a plist that does not exist to test plist creation' do - path macoscookbook + path macoscookbook_plist entry 'PokeballEatenByDog' value true owner 'vagrant' @@ -35,7 +35,7 @@ end plist 'add another value to the new plist' do - path macoscookbook + path macoscookbook_plist entry 'CaughtEmAll' value false owner 'vagrant' From fee1995e58f9a3b8fee161c6db7bf417c83e64d4 Mon Sep 17 00:00:00 2001 From: v-anshie Date: Fri, 7 Dec 2018 15:25:44 -0800 Subject: [PATCH 05/12] cookstyle change --- test/cookbooks/macos_test/recipes/preferences.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cookbooks/macos_test/recipes/preferences.rb b/test/cookbooks/macos_test/recipes/preferences.rb index 5ef09276..b84d439a 100644 --- a/test/cookbooks/macos_test/recipes/preferences.rb +++ b/test/cookbooks/macos_test/recipes/preferences.rb @@ -1,5 +1,5 @@ -dock_plist = "/Users/vagrant/Library/Preferences/com.apple.dock.plist" -macoscookbook_plist = "/Users/vagrant/com.microsoft.macoscookbook.plist" +dock_plist = '/Users/vagrant/Library/Preferences/com.apple.dock.plist' +macoscookbook_plist = '/Users/vagrant/com.microsoft.macoscookbook.plist' plist 'show hidden files' do path '/Users/vagrant/Library/Preferences/com.apple.finder.plist' From 5901edde6e9314aff8f25d4cd1915edd777da5d6 Mon Sep 17 00:00:00 2001 From: v-anshie Date: Fri, 7 Dec 2018 15:31:30 -0800 Subject: [PATCH 06/12] spelling error --- resources/plist.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/plist.rb b/resources/plist.rb index 058b296d..822f7dcb 100644 --- a/resources/plist.rb +++ b/resources/plist.rb @@ -72,7 +72,7 @@ end end - converge_if_change :group do + converge_if_changed :group do converge_by "update group to #{new_resource.group}" do file new_resource.path do group new_resource.group From 020bc68dc88f6ece6f931bfb2afa52b97f604937 Mon Sep 17 00:00:00 2001 From: Eric Hanko Date: Tue, 11 Dec 2018 10:42:16 -0800 Subject: [PATCH 07/12] declare plist content as separate variable --- resources/plist.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/plist.rb b/resources/plist.rb index 822f7dcb..7026b54d 100644 --- a/resources/plist.rb +++ b/resources/plist.rb @@ -28,7 +28,8 @@ converge_if_changed :path do converge_by "create new plist: '#{new_resource.path}'" do file new_resource.path do - content {}.to_plist + empty_plist = {}.to_plist + content empty_plist owner new_resource.owner group new_resource.group end From dde5b16b2ecde8b3f32590506e4d8b5f04c6151b Mon Sep 17 00:00:00 2001 From: Jacob Zaval Date: Tue, 11 Dec 2018 15:58:09 -0800 Subject: [PATCH 08/12] update ascii to us-ascii --- test/cookbooks/macos_test/recipes/preferences.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cookbooks/macos_test/recipes/preferences.rb b/test/cookbooks/macos_test/recipes/preferences.rb index b84d439a..72f7e396 100644 --- a/test/cookbooks/macos_test/recipes/preferences.rb +++ b/test/cookbooks/macos_test/recipes/preferences.rb @@ -31,7 +31,7 @@ value true owner 'vagrant' group 'staff' - encoding 'ascii' + encoding 'us-ascii' end plist 'add another value to the new plist' do @@ -40,5 +40,5 @@ value false owner 'vagrant' group 'staff' - encoding 'ascii' + encoding 'us-ascii' end From cab770bbf1eba14ce6e5d48c2cb4bdd655f6fd4b Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 7 Dec 2018 16:54:17 -0800 Subject: [PATCH 09/12] Updated CHANGELOG.md added description of user/group plist support. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9047311d..bc505a40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. ## [2.9.0] - 2018-12-06 ### Added - Added templates for bug reports, feature requests, and pull requests to adhere to adhere with Github's [recommended community standards](https://opensource.guide). +- Adds support for owner/group in the plist resource. Allows for plist files to be created under a specific owner. Defaults to root/wheel for compatablity with earlier versions of the cookbook. ## [2.8.1] - 2018-11-29 ### Fixed From f54ccaa98615adaa636775f51f095bea969573ae Mon Sep 17 00:00:00 2001 From: Andre Shields Date: Wed, 12 Dec 2018 15:13:53 -0800 Subject: [PATCH 10/12] updated documentation witn owner/group change --- documentation/resource_plist.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/resource_plist.md b/documentation/resource_plist.md index c5b84073..92a512ea 100644 --- a/documentation/resource_plist.md +++ b/documentation/resource_plist.md @@ -31,6 +31,8 @@ plist 'description' do value TrueClass, FalseClass, String, Integer, Float action Symbol # defaults to :set if not specified encoding String # defaults to 'binary' if not specified. + owner String # defaults to 'root' if not specified. + group String # defaults to 'wheel' if not specified. end ``` From e067a11a0dfd4d41e05d0a4ed0d453970fbbc936 Mon Sep 17 00:00:00 2001 From: Eric Hanko Date: Wed, 19 Dec 2018 15:40:21 -0800 Subject: [PATCH 11/12] Implement mode property properly. Hopefully. Paired with Chris Gilbert, Andre Shields, Carrol Fifer --- resources/plist.rb | 2 ++ test/cookbooks/macos_test/recipes/preferences.rb | 1 + test/integration/default/controls/general_test.rb | 2 ++ 3 files changed, 5 insertions(+) diff --git a/resources/plist.rb b/resources/plist.rb index 7026b54d..f4a851c6 100644 --- a/resources/plist.rb +++ b/resources/plist.rb @@ -6,6 +6,7 @@ property :encoding, String, desired_state: true, default: 'binary' property :owner, String, desired_state: true, default: 'root' property :group, String, desired_state: true, default: 'wheel' +property :mode, [String, Integer] load_current_value do |desired| current_value_does_not_exist! unless ::File.exist? desired.path @@ -32,6 +33,7 @@ content empty_plist owner new_resource.owner group new_resource.group + mode new_resource.mode if property_is_set?(:mode) end end end diff --git a/test/cookbooks/macos_test/recipes/preferences.rb b/test/cookbooks/macos_test/recipes/preferences.rb index 72f7e396..5c0635f2 100644 --- a/test/cookbooks/macos_test/recipes/preferences.rb +++ b/test/cookbooks/macos_test/recipes/preferences.rb @@ -32,6 +32,7 @@ owner 'vagrant' group 'staff' encoding 'us-ascii' + mode '0600' end plist 'add another value to the new plist' do diff --git a/test/integration/default/controls/general_test.rb b/test/integration/default/controls/general_test.rb index c2fc2837..3894defb 100644 --- a/test/integration/default/controls/general_test.rb +++ b/test/integration/default/controls/general_test.rb @@ -14,6 +14,7 @@ describe file(finder_plist) do its('owner') { should eq 'vagrant' } its('group') { should eq 'staff' } + its('mode') { should eq '0600' } end end @@ -34,5 +35,6 @@ describe file(macos_cookbook_plist) do its('owner') { should eq 'vagrant' } its('group') { should eq 'staff' } + its('mode') { should eq '0600' } end end From 9c249e9f76637811578bef0f9c9acd9c6411ef9f Mon Sep 17 00:00:00 2001 From: Eric Hanko Date: Wed, 19 Dec 2018 15:47:48 -0800 Subject: [PATCH 12/12] change mode matcher to cmp --- test/integration/default/controls/general_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/default/controls/general_test.rb b/test/integration/default/controls/general_test.rb index 3894defb..295c6ef4 100644 --- a/test/integration/default/controls/general_test.rb +++ b/test/integration/default/controls/general_test.rb @@ -14,7 +14,7 @@ describe file(finder_plist) do its('owner') { should eq 'vagrant' } its('group') { should eq 'staff' } - its('mode') { should eq '0600' } + its('mode') { should cmp '0600' } end end @@ -35,6 +35,6 @@ describe file(macos_cookbook_plist) do its('owner') { should eq 'vagrant' } its('group') { should eq 'staff' } - its('mode') { should eq '0600' } + its('mode') { should cmp '0600' } end end