Skip to content

Commit

Permalink
Merge pull request #172 from Microsoft/release/2.9
Browse files Browse the repository at this point in the history
Release/2.9
  • Loading branch information
v-anshie authored Dec 31, 2018
2 parents ff376ba + cb49318 commit 64fe139
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 11 deletions.
File renamed without changes.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Bug Report
about: Create a report to help us improve
title: "[BUG]"
labels: ''
assignees: ''

---

## Describe the Bug
A clear and concise description of what the bug is.

## Error Message
Error message(s) if any.

## Chef Exception
Chef exception(s) if any.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Feature Request
about: Suggest an idea for this project
title: "[FEATURE]"
labels: ''
assignees: ''

---

## Describe the feature
A clear and concise description of what the feature is.

## Describe the reasoning behind the feature
A clear and concise description of why the feature should be implemented.
14 changes: 14 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Pull Request
about: File a pull request to help us improve
title: "[PR]"
labels: ''
assignees: ''

---

## Describe the Pull Request
A clear and concise description of what the Pull Request aims to do.

## Justification
A clear and concise description of issues the Pull Requests solves if any.
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog
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 with Github's [recommended community standards](https://opensource.guide).
- Added support for owner/group in the plist resource. Allows for plist files to be created under a specific owner. Defaults to root/wheel for compatibility with earlier versions of the cookbook. ([Issue #51](https://github.com/Microsoft/macos-cookbook/issues/51))
- Added support for setting the mode property when creating a plist using the `plist` resource. This allows control over setting the file permissions. ([Issue #51](https://github.com/Microsoft/macos-cookbook/issues/51))

## [2.8.1] - 2018-11-29
### Fixed
- Fixed an issue where the path for the `xcversion` utility was hard-coded when installed as a Chef gem, which caused failures when converging with ChefDK or Workstation.
Expand Down
3 changes: 3 additions & 0 deletions documentation/resource_plist.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ 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.
mode String, Integer
end
```

Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
description 'Resources for configuring and provisioning macOS'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
chef_version '>= 13.0' if respond_to?(:chef_version)
version '2.8.1'
version '2.9.0'

source_url 'https://github.com/Microsoft/macos-cookbook'
issues_url 'https://github.com/Microsoft/macos-cookbook/issues'
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

0 comments on commit 64fe139

Please sign in to comment.