Skip to content
1 change: 1 addition & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ suites:
- dock-appearance
- show-all-files
- updates-disabled
- plist-creation

- name: power-management
provisioner:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions documentation/resource_plist.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
38 changes: 30 additions & 8 deletions resources/plist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
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'
property :mode, [String, Integer]

load_current_value do |desired|
current_value_does_not_exist! unless ::File.exist? desired.path
Expand All @@ -14,20 +17,23 @@

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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
EOF
empty_plist = {}.to_plist
content empty_plist
owner new_resource.owner
group new_resource.group
mode new_resource.mode if property_is_set?(:mode)
end
end
end
Expand Down Expand Up @@ -60,4 +66,20 @@
end
end
end

converge_if_changed :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_changed :group do
converge_by "update group to #{new_resource.group}" do
file new_resource.path do
group new_resource.group
end
end
end
end
32 changes: 30 additions & 2 deletions test/cookbooks/macos_test/recipes/preferences.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
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'
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'
path 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'
path 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 macoscookbook_plist
entry 'PokeballEatenByDog'
value true
owner 'vagrant'
group 'staff'
encoding 'us-ascii'
mode '0600'
end

plist 'add another value to the new plist' do
path macoscookbook_plist
entry 'CaughtEmAll'
value false
owner 'vagrant'
group 'staff'
encoding 'us-ascii'
end
5 changes: 5 additions & 0 deletions test/integration/default/controls/dock_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions test/integration/default/controls/general_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,31 @@
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' }
its('mode') { should cmp '0600' }
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' }
its('mode') { should cmp '0600' }
end
end