Skip to content

Commit 3ca39c8

Browse files
jazavalamericanhanko
authored andcommitted
Release plist and macos_user resources, new Xcode libraries, test cookbook and documentation. (#24)
* first commit plistbuddy * all recipe/plist in macos * extract plistbuddy to resource * Straighten out unit tests - Correctly include modules - Correctly setup spec_helper - Correct unit test / respec setup * first passing test * add more data type tests * Most data types passing - Boolean values are working - Array and data type values are not - PlistBuddy "commands" (add, print, etc.) are passing * More testing - Skip Array and Dict types as their implementation will be more complicated - Add test for float type - Put the correct type in the test description - Cookstyle changes * PlistBuddy and testing update - Add separate test cookbook for PlistBuddy resource - Add kitchen.yml for the above purpose - Modify and update plistbuddy resource/helpers * remove extra newline * add metadata file * edit metadata; add Berksfile * move Berksfile to correct location * add testing requirements for berks vendor * move kitchen file * Converge passing in test cookbook - Opportunistic cleanup of xcode test - some temp debugging info in resource definition - Rename name_property to command so as to not override action * Itempotence - Removed 'bool' prefix from boolean types, as that was somehow causing issues - Changed name_property to the path and removed that property - Use actual actions in the resource for the PlistBuddy commands * Fix false positive? - Not sure how the previous test was passing previously, but I adjusted the boolean value for the BazEntry test so that the signature input matches the output * Add logic for adding a value - The data type should only be used when adding a value to a plist. Otherwise, we don't need to use the data type * remove debugging; fix smoke tests * remove .kitchen.yml * bump version to 0.8.5 * unskip ChefSpec tests - they're passing * mark args_formatter as private method * Feature/macos user (#14) * first commit add_user recipe * Testing Refactor & macos_user resource - Create new testing cookbook that contains tests for both plistbuddy and macos_user resources. The hope here is to have a single testing cookbook that contains multiple suites and suite testing variations - Create new macos_user resource - contains single boolean 'true' settings for autologin and admin user. Still work to be done for admin user and all steps that need to be taken to acheive the task. * fix method call * fix another method call * user native ruby File class and not overriden * fix some minor issues with resource; add kcpassword file * Add OG Ruby kcpassword file helper module * slightly different approach for Kcpassword module * passing test * Fix up kcpassword library module, smoke tests - Modify Kcpassword helper module to use a method for magic bits. This isn't ideal, but it works for now - Update smoke tests so that john_jr's group ID is 20. This may not be correct, but setting as 20 until it is further investigated * opportunistic refactor of keep_awake recipe * Refactor testing cookbook layout - Consolodate testing suites into single default suite - Add tests for keep_awake recipe - Use more common examples to test PlistBuddy resource * move xcode test to test cookbook * Opportunistic bug fix for plistbuddy resource - Previously, the plistbuddy resource did not allow any keys with spaces unless they were used in the value itself. Now, you can use keys with spaces in the value property without needing to double-quote it - Also, fix the PlistBuddy executable string to be correct * revert kcpassword.rb helper to a671164 * fix incorrect PlistBuddy data type name * Fix kcpassword.rb and update plistbuddy UTs * Extract disabling screen saver to plistbuddy - Also, skip Xcode test temporarily * PlistBuddy idempotence - Remove systemsetup and pmset resource calls in keep_awake until they are made idempotent * update test and plist name * Implement binary plist conversion - Changes to binary plists via PlistBuddy must be converted back to binary since the change implicitly converts the file to xml. This change contains logic to convert back to binary if the file is detected to be binary in the first place. * attempts at idempotence using chef helper methods * early commit to get it on the remote * implement logic for plist return type to ruby data type * Add floating type value support A wild FAILING TEST appeared! ... HANKO used TDD! It's super effective! * move function * real idempotence! * passing all unit tests * update test cookbook name * update new_users integration tests * systemsetup idempotence * all smoke and unit tests passing * quick fix for timezone bug * remove kcpassword file as it is no longer needed * update path for test cookbook to be default repo name * Rename keep_awake_spec.rb to keep_awake_test.rb * Rename preferences_spec.rb to preferences_test.rb * Rename new_users_spec.rb to new_users_test.rb * fix typo * Use relative path for macos cookbook source * Improve readability of relative path for macos cookbook source * Bump version * Addressing changes in Pull Request #14 - Fix bug where screensaver was not properly being disabled, update tests accordingly - Rename plistbuddy resource to plist, including all related files and callers - Rename kcpassword helper to macos_user to match helper -> resource convention; fix top level namespace to be MacOS - Correctly name recipe unit tests - Implement plist resource into disable_software_updates.rb recipe - Add disable_software_updates.rb recipe to default kitchen suite and appropriate smoke tests - Remove relatively useless logic in systemsetup value property coercion * Implement binary plist conversion * Fix unit test and apply the Law of Demeter * update helper pattern to match current standard; include everywhere * remove helper reference in Xcode resource * bump version * update Xcode attribute to latest * extract xcode smoke tests to a different suite * update xcversion path for simulators test * update namespace again * refactor XcodeHelper modules in XCVersion, Xcode, and XCVersion modules updated methods to simplify site calls in resource * updated method calls for new modules * bump version * extract xcversion module to separate library file * add missing macos module * include parent module macos instead of child for xcode and xcversion * update available_simulator_versions to new method * bump version * add platform-specific smoke test for xcode * add xcode test recipe * update kitchen with xcode suite * refactor simulator method to call it's own available list of simulators * use new simulator method to find highest available version * move xcode prep work into the setup action * clear kitchen customizations * lazily evalutate ios simulator property * move lazy evaluation to simulator action in xcode resource * revert lazy execution * warn and retry if simulator list is empty * restore spacing * more whitespace * refactor highest_semantic_simulator method into class, smaller methods * implement simulator class * add more xcversion command methods * implement xcversion command methods * implement command methods correctly * add list methods for xcversion * implement xcversion list methods * implement install xcode correctly * reorder methods * add method to list installed xcodes * use more descriptive name for 'command' method * move where the space lives * implement installed xcodes command * implement install xcodes correctly * disable downloads prior to disabling software update check * Renamed name to device_name * Change name.rb to machine_name.rb to be similar with the apex automation cookbook. Instances of name are also all changed to machine_name. * Add new test recipe and smoke test for machine_name. * add disable-swu test suite * Bump up cookbook version numbers. * update kitchen test suite order, remove standalone swu testing * add sleep for El Capitan platform to avoid race condition this occurs when integrated with the macos-user test recipe * Improve README/Documentation (#23) * implement build definition badge and minor tweaks * Add descriptions and attribute lists for recipes * Remove 'description' label from recipe names * Bump version, add documentation dir * Fix up the last commit * Separate 10.12 and 10.13 build status * Add table for build status * Add plist resource documentation * Add Xcode documentation * bump version
1 parent 20c24e8 commit 3ca39c8

40 files changed

+1374
-176
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ kitchen-tests/vendor
6868

6969
# Visual Studio Code files
7070
.vscode
71+
*/**/*.code-workspace
7172
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
7273
.idea
7374

@@ -101,3 +102,4 @@ Vagrantfile
101102
.rubocop.yml
102103
.vagrant
103104
data_bags
105+
*.code-workspace

README.md

Lines changed: 96 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1-
# macOS Cookbook
1+
macOS Cookbook
2+
==============
23

3-
This cookbook provides:
4-
- Resources for configuring and provisioning macOS.
5-
- Recipes that implement common use-cases of the macOS cookbook's recources.
4+
The macOS cookbook is a Chef library cookbook that provides resources for configuring
5+
and provisioning macOS. Additionally, it provides recipes that implement common
6+
use-cases of the macOS cookbook's recources.
67

7-
## Platforms
8+
|||
9+
|-|-|
10+
| macOS Sierra 10.12 | ![build-status-1012](https://office.visualstudio.com/_apis/public/build/definitions/59d72877-1cea-4eb6-9d06-66716573631a/2143/badge) |
11+
| macOS High Sierra 10.13 | ![build-status-1013](https://office.visualstudio.com/_apis/public/build/definitions/59d72877-1cea-4eb6-9d06-66716573631a/2140/badge) |
12+
|||
813

9-
- macOS
14+
Requirements
15+
------------
1016

11-
## Chef
17+
- Only tested on Chef 13
18+
- Surprisingly, this cookbook is only compatible with macOS
1219

13-
- Chef 13+
20+
Supported OS Versions
21+
---------------------
1422

15-
## Attributes
23+
- OS X El Capitan 10.11
24+
- macOS Sierra 10.12
25+
- macOS High Sierra 10.13
26+
27+
Attributes
28+
----------
1629

1730
### Admin User and Password
1831

@@ -22,33 +35,89 @@ node['macos']['admin_password'] = 'vagrant'
2235
```
2336

2437
Each of these attributes defaults to vagrant since our resources are developed
25-
with the Vagrant paradigm. In other words, the use and password declared here
26-
should be an admin user.
38+
with the Vagrant paradigm. In other words, the user and password declared here
39+
should be an admin user with passwordless super-user rights.
40+
41+
Recipes
42+
-------
43+
44+
### Disable Software Updates
45+
46+
Disables automatic checking and downloading of software updates.
47+
48+
**Usage:** `include_recipe macos::disable_software_updates`
49+
50+
No attributes used in this recipe.
51+
52+
### Keep Awake
53+
54+
Prevent macOS from falling asleep, disable the screensaver, and
55+
several other settings to always keep macOS on. Uses the `plistbuddy` and `pmset`
56+
resources.
57+
58+
**Usage:** `include_recipe macos::keep_awake`
59+
60+
| Attribute used | Default value |
61+
|---------------------------------------|-------------------------|
62+
| `node['macos']['network_time_server']`| `'time.windows.com'` |
63+
| `node['macos']['time_zone']` | `'America/Los_Angeles'` |
2764

2865
### Mono
2966

30-
_TODO_
67+
Installs [Mono](http://www.mono-project.com/docs/about-mono/). Requires package
68+
name, version number, and checksum in order to override.
3169

32-
---
70+
**Usage:** `include_recipe macos::mono`
3371

34-
## Resources
72+
| Attribute used | Default value |
73+
|-------------------------------------|----------------------------------------|
74+
| `node['macos']['mono']['package']` | `'MonoFramework-MDK-4.4.2.11.macos10.xamarin.universal.pkg'` |
75+
| `node['macos']['mono']['version']` | `'4.4.2'` |
76+
| `node['macos']['mono']['checksum']` | `'d8bfbee7ae4d0d1facaf0ddfb70c0de4b1a3d94bb1b4c38e8fa4884539f54e23'` |
3577

36-
- `ard`
37-
- `name`
38-
- `defaults`
39-
- `pmset`
40-
- `systemsetup`
41-
- `xcode`
78+
### Xcode
4279

43-
Checkout the [Wiki](https://github.com/Microsoft/macos-cookbook/wiki) for details about the macOS Cookbook resources.
80+
Installs Xcode 9.1 and simulators for iOS 10 and iOS 11. Check out
81+
the documentation for the Xcode resource if you need more flexibility.
4482

45-
---
83+
:large_orange_diamond: Requires an `apple_id` data bag item.
4684

47-
## Recipes
85+
**Usage:** `include_recipe macos::xcode`
4886

49-
- `disable_software_updates`
50-
- `keep_awake`
51-
- `mono`
52-
- `configurator`
87+
| Attribute Used | Default value |
88+
|---------------------------------------------------------------|---------------|
89+
| `node['macos']['xcode']['version']` | `'9.1'` |
90+
| `node['macos']['xcode']['simulator']['major_version']` | `%w(11 10)` |
91+
92+
### Apple Configurator 2
93+
94+
Installs Apple Configurator 2 using `mas` and links `cfgutil` to
95+
`/usr/local/bin`.
96+
97+
:large_orange_diamond: Requires an `apple_id` data bag item.
98+
99+
**Usage:** `include_recipe macos::configurator`
100+
101+
**Attributes**: No attributes used in this recipe.
102+
103+
#### Data Bags
104+
105+
Both the `macos::xcode` and `macos::configurator` recipes require a data bag
106+
item named `apple_id` containing valid Apple ID credentials. For example:
107+
108+
**Example:**
109+
110+
```json
111+
{
112+
"id": "apple_id",
113+
"apple_id": "[email protected]",
114+
"password": "0k@yN0cR34m"
115+
}
116+
```
53117

118+
Resources
119+
---------
54120

121+
- [ARD (Apple Remote Desktop)](./documentation/resource_ard.md)
122+
- [Plist](./documentation/resource_plist.md)
123+
- [Xcode](./documentation/resource_xcode.md)

attributes/default.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
default['macos']['mono']['version'] = '4.4.2'
66
default['macos']['mono']['checksum'] = 'd8bfbee7ae4d0d1facaf0ddfb70c0de4b1a3d94bb1b4c38e8fa4884539f54e23'
77

8-
default['macos']['xcode']['version'] = '9.0'
8+
default['macos']['xcode']['version'] = '9.1'
99
default['macos']['xcode']['simulator']['major_version'] = %w(11 10)
10+
11+
default['macos']['network_time_server'] = 'time.windows.com'
12+
default['macos']['time_zone'] = 'America/Los_Angeles'

documentation/resource_ard.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
ard
2+
===
3+
4+
Use the **ard** resource to manage Remote Desktop settings and preferences.
5+
Under the hood, an **ard** resource executes the `kickstart` command, located
6+
in ARDAgent.app (one of the CoreServices of macOS). It has some basic actions,
7+
which pertain to the simple `kickstart` subcommands. It also has the more
8+
complicated `:configure` action, which requires some familiarity with
9+
`kickstart`.
10+
11+
[Learn more about the `kickstart` command](https://support.apple.com/en-us/HT201710).
12+
13+
Syntax
14+
------
15+
16+
A **ard** resource block declares a basic description of the command configuration
17+
and a set of properties depending on the actions executed. For example:
18+
19+
```ruby
20+
ard 'activate and configure ard' do
21+
action [:activate, :configure]
22+
end
23+
```
24+
25+
where
26+
27+
- `:activate` activates the ARD agent
28+
- `:configure` configures the agent using the `kickstart` defaut commandline arguments.
29+
30+
The full syntax for all of the properties that are available to the **ard**
31+
resource is:
32+
33+
```ruby
34+
ard 'description' do
35+
install_package String
36+
uninstall_options Array, # defaults to ['-files', '-settings', '-prefs'] if not specified
37+
restart_options Array, # defaults to ['-agent', '-console', '-menu'] if not specified
38+
users Array
39+
privs Array, # defaults to ['-all'] if not specified
40+
access String, # defaults to '-on' if not specified
41+
allow_access_for String, # defaults to '-allUsers' if not specified
42+
computerinfo Array
43+
clientopts Array
44+
action Symbol # defaults to [:activate, :configure] if not specified
45+
end
46+
```
47+
48+
**Note:** Not all properties are compatible with each action.
49+
50+
Actions
51+
-------
52+
53+
This resource has the following actions:
54+
55+
`:activate`
56+
57+
      Activate the remote desktop agent.
58+
59+
`:deactivate`
60+
61+
      Deactivate the remote desktop agent.
62+
63+
`:uninstall`
64+
65+
      Uninstall a package from another remotely
66+
managed mac.
67+
68+
`:stop`
69+
70+
      Stop the agent.
71+
72+
`:restart`
73+
74+
      Restart the remote desktop agent.
75+
76+
`:configure`
77+
78+
      Configure the setup of the remote desktop
79+
agent using the default options. If you were to configure the default options,
80+
your settings would look like this in the GUI:
81+
82+
Properties
83+
----------
84+
85+
`install_package`
86+
87+
      **Ruby Type:** `String`
88+
89+
`uninstall_options`
90+
91+
      **Ruby type:** `Array`
92+
93+
      default options: `['-files', '-settings', '-prefs']`
94+
95+
`restart_options`
96+
97+
      **Ruby type:** `Array`
98+
99+
      default options: `['-agent', '-console', '-menu']`
100+
101+
`users`
102+
103+
      **Ruby type:** `Array`
104+
105+
`privs`
106+
107+
      **Ruby type:** `Array`
108+
109+
      default: `['-all']`
110+
111+
`access`
112+
113+
      **Ruby type:** `String`
114+
115+
      default: `'-on'`
116+
117+
`allow_access_for`
118+
119+
      **Ruby type:** `String`
120+
121+
      default: `'-allUsers'`
122+
123+
`computerinfo`
124+
125+
      **Ruby type:** `Array`
126+
127+
`clientopts`
128+
129+
      **Ruby type:** `Array`
130+
131+
`action`
132+
133+
      **Ruby type:** `Symbol`

documentation/resource_plist.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
plist
2+
=====
3+
4+
Use the **plist** resource to manage property list files (plists) and their content.
5+
A **plist** resource instance represents the state of a single key-value pair in
6+
the delared plist `path`. Since each plist resource instance represents only one
7+
setting, you may end up with several plist resource calls in a given recipe. Although
8+
this may seem like overkill, it allows us to have a fully idempotent resource with
9+
fine granularity.
10+
11+
During the `chef-client` run, the client knows to check the state of the plist
12+
before changing any values. It also makes sure that the plist is in binary format
13+
so that the settings can be interpreted correctly by the operating system.
14+
15+
Prior knowledge of using commandline utilities such as `/usr/bin/defaults`
16+
and `/usr/libexec/PlistBuddy` will be useful when implementing the
17+
**plist** resource.
18+
19+
[Learn more about property lists.](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/PropertyLists/QuickStartPlist/QuickStartPlist.html#//apple_ref/doc/uid/10000048i-CH4-SW5)
20+
21+
Syntax
22+
------
23+
24+
The full syntax for all of the properties that are available to the **plist**
25+
resource is:
26+
27+
```ruby
28+
plist 'description' do
29+
path String # defaults to 'description' if not specified
30+
entry String
31+
value TrueClass, FalseClass, String, Integer, Float
32+
action Symbol # defaults to :set if not specified
33+
end
34+
```
35+
36+
Actions
37+
-------
38+
39+
This resource has the following actions:
40+
41+
`:set`
42+
43+
      Set `entry` to `value` in `path`
44+
45+
Examples
46+
--------
47+
48+
Enabling the setting to show both visible and invisible files.
49+
50+
```ruby
51+
plist 'show hidden files' do
52+
path '/Users/vagrant/Library/Preferences/com.apple.finder.plist'
53+
entry 'AppleShowAllFiles'
54+
value true
55+
end
56+
```
57+
58+
where
59+
60+
`path` is the absolute path to the `com.apple.finder.plist` plist file
61+
62+
`entry` is the representing the plist entry `'AppleShowAllFiles'`
63+
64+
`value` is the entry's value to boolean type: `true`

0 commit comments

Comments
 (0)