Skip to content

Commit 0db7830

Browse files
Release/1.9 (#73)
* Add documentation detailing new certificate resource changes incorporating the -T option * modify security library and certificate resource to accomodate -T option * Testing for new and improved certificate resource * Fix Chef Spec tests * bump version to 1.9.0 * hotfix for plist encoding type utf-8 * move plutil_format_map to libraries * using Chef::Application.fatal to enforce encoding types * add one second after each systemsetup call * Add support for more hypervisors in keep_awake - Leverage the node['virtualization']['systems'] ohai attribute to determine whether we are a guest or a host - Add appropriate chefspec tests * Add another context for empty virtualization hash * bump to 1.8.1 * ensure xcode-install gem is in Chef embedded even if ChefDK is present * adjust implementation of running_in_a_vm? * fix rspec shared context * re-arrange chefspec keep_awake unit tests
1 parent df5457d commit 0db7830

File tree

14 files changed

+178
-31
lines changed

14 files changed

+178
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Resources
126126
---------
127127

128128
- [ARD (Apple Remote Desktop)](https://github.com/Microsoft/macos-cookbook/blob/master/documentation/resource_ard.md)
129-
- [Certificate](https://github.com/Microsoft/macos-cookbook/blob/master/documentation/resource_certificate.md)
129+
- [Certificate (security)](https://github.com/Microsoft/macos-cookbook/blob/master/documentation/resource_certificate.md)
130130
- [Machine Name](https://github.com/Microsoft/macos-cookbook/blob/master/documentation/resource_machine_name.md)
131131
- [Plist](https://github.com/Microsoft/macos-cookbook/blob/master/documentation/resource_plist.md)
132132
- [Spotlight (mdutil)](https://github.com/Microsoft/macos-cookbook/blob/master/documentation/resource_spotlight.md)

documentation/resource_certificate.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ certificate 'cert name' do
2020
certfile String # certificate in .p12(PFX) or .cer(SSl certificate file) format
2121
cert_passwd String # password for PFX format certificate file
2222
keychain String # keychain to install certificate to
23+
apps Array # list of apps that may access the imported key
2324
end
2425
```
2526

@@ -69,4 +70,13 @@ certificate 'cert name' do
6970
certfile '/User/edward/Documents/cert.p12'
7071
keychain '/User/edward/Library/Keychains/florida.keychain'
7172
end
73+
```
74+
75+
**Install PFX format certificate to default keychain, accessible by certain app**
76+
```ruby
77+
certificate 'cert name' do
78+
certfile '/User/edward/Documents/cert.p12'
79+
cert_passwd 'teach'
80+
apps ['/Applications/Maps.app', '/Applications/Time Machine.app']
81+
end
7282
```

libraries/plist.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ def setting_from_plist(entry, path)
8080
{ key_type: defaults_read_type_output.split.last, key_value: defaults_read_output.strip }
8181
end
8282

83+
def plutil_format_map
84+
{ 'us-ascii' => 'xml1',
85+
'text/xml' => 'xml1',
86+
'utf-8' => 'xml1',
87+
'binary' => 'binary1' }
88+
end
89+
8390
private
8491

8592
def defaults_executable
@@ -92,5 +99,6 @@ def plistbuddy_executable
9299
end
93100
end
94101

95-
Chef::Recipe.include(MacOS::PlistHelpers)
96-
Chef::Resource.include(MacOS::PlistHelpers)
102+
Chef::Recipe.include MacOS::PlistHelpers
103+
Chef::Resource.include MacOS::PlistHelpers
104+
Chef::DSL::Recipe.include MacOS::MachineName

libraries/security_cmd.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,28 @@ def add_certificates
2020
@keychain == '' ? [@security_cmd, 'add-certificates', @cert] : [@security_cmd, 'add-certificates', @cert, '-k', @keychain]
2121
end
2222

23-
def import(cert_passwd)
24-
@keychain == '' ? [@security_cmd, 'import', @cert, '-P', cert_passwd] : [@security_cmd, 'import', @cert, '-P', cert_passwd, '-k', @keychain]
23+
def import(cert_passwd, apps)
24+
app_array = []
25+
26+
apps.each do |app|
27+
app_array.push('-T')
28+
app_array.push(app)
29+
end
30+
@keychain == '' ? [@security_cmd, 'import', @cert, '-P', cert_passwd, *app_array] : [@security_cmd, 'import', @cert, '-P', cert_passwd, '-k', @keychain, *app_array]
2531
end
2632

27-
def install_certificate(cert_passwd)
33+
def install_certificate(cert_passwd, apps)
2834
valid_pkcs12 = ['.p12', '.pfx']
2935
valid_certs = ['.der', '.crt', '.cer']
3036

37+
apps.each do |app|
38+
unless app.is_a? String
39+
Chef::Exception.fatal("Invalid application: #{@app}.")
40+
end
41+
end
42+
3143
if valid_pkcs12.any? { |extension| ::File.extname(@cert).match? extension }
32-
import(cert_passwd)
44+
import(cert_passwd, apps)
3345
elsif valid_certs.any? { |extension| ::File.extname(@cert).match? extension }
3446
add_certificates
3547
else

libraries/systemsetup.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module MacOS
22
module SystemSetup
33
def running_in_a_vm?
4-
Chef.node['hardware']['machine_model'].match?(/Parallels/) # TODO: cover more hypervisors
4+
virtualization_systems = Chef.node['virtualization']['systems']
5+
virtualization_systems.empty? || virtualization_systems.values.include?('guest') ? true : false
56
end
67

78
def power_button_model?

metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
description 'Resources for configuring and provisioning macOS'
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
77
chef_version '~> 13.0' if respond_to?(:chef_version)
8-
version '1.8.2'
8+
version '1.9.0'
99

1010
source_url 'https://github.com/Microsoft/macos-cookbook'
1111
issues_url 'https://github.com/Microsoft/macos-cookbook/issues'

resources/certificate.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
property :certfile, String
44
property :cert_password, String
55
property :keychain, String
6+
property :apps, Array
67

78
action_class do
89
def keychain
@@ -18,6 +19,6 @@ def keychain
1819
end
1920

2021
execute 'install-certificate' do
21-
command [*cert.install_certificate(new_resource.cert_password)]
22+
command [*cert.install_certificate(new_resource.cert_password, new_resource.apps)]
2223
end
2324
end

resources/plist.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
property :path, String, name_property: true, desired_state: true
44
property :entry, String, desired_state: true
55
property :value, [TrueClass, FalseClass, String, Integer, Float], desired_state: true
6-
property :encoding, String, desired_state: true, default: 'binary', equal_to: ['text/xml', 'binary', 'us-ascii']
6+
property :encoding, String, desired_state: true, default: 'binary'
77

88
load_current_value do |desired|
99
current_value_does_not_exist! unless ::File.exist? desired.path
@@ -52,17 +52,12 @@
5252

5353
converge_if_changed :encoding do
5454
converge_by 'change format' do
55+
Chef::Application.fatal!(
56+
"Option encoding must be equal to one of: #{plutil_format_map.keys}! You passed \"#{new_resource.encoding}\"."
57+
) unless plutil_format_map.keys.include? new_resource.encoding
5558
execute ['/usr/bin/plutil', '-convert', plutil_format_map[new_resource.encoding], new_resource.path] do
5659
action :run
5760
end
5861
end
5962
end
6063
end
61-
62-
action_class do
63-
def plutil_format_map
64-
{ 'us-ascii' => 'xml1',
65-
'text/xml' => 'xml1',
66-
'binary' => 'binary1' }
67-
end
68-
end

resources/system_preference.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
converge_by "set #{new_resource.preference} to #{new_resource.setting}" do
2121
set_pref = ['-set', new_resource.preference.to_s].join('')
2222
execute ['/usr/sbin/systemsetup', set_pref, new_resource.setting]
23+
ruby_block 'sleep one second' do
24+
block do
25+
sleep 1
26+
end
27+
end
2328
end
2429
end
2530
end

resources/xcode.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
action :setup do
99
chef_gem 'xcode-install' do
10-
options('--no-document')
10+
options('--no-document --no-user-install')
1111
end
1212

1313
CREDENTIALS_DATA_BAG = data_bag_item(:credentials, :apple_id)

0 commit comments

Comments
 (0)