chef 17.4.38-universal-mingw32 → 17.7.22-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/chef.gemspec +3 -0
- data/lib/chef/application/base.rb +11 -1
- data/lib/chef/chef_fs/file_pattern.rb +1 -1
- data/lib/chef/chef_fs/path_utils.rb +1 -1
- data/lib/chef/client.rb +1 -2
- data/lib/chef/compliance/input.rb +115 -0
- data/lib/chef/compliance/input_collection.rb +139 -0
- data/lib/chef/compliance/profile.rb +122 -0
- data/lib/chef/compliance/profile_collection.rb +109 -0
- data/lib/chef/compliance/runner.rb +47 -5
- data/lib/chef/compliance/waiver.rb +115 -0
- data/lib/chef/compliance/waiver_collection.rb +143 -0
- data/lib/chef/data_collector/run_end_message.rb +1 -1
- data/lib/chef/dsl/compliance.rb +38 -0
- data/lib/chef/dsl/reader_helpers.rb +51 -0
- data/lib/chef/dsl/reboot_pending.rb +1 -1
- data/lib/chef/dsl/recipe.rb +4 -2
- data/lib/chef/dsl/secret.rb +2 -4
- data/lib/chef/dsl/universal.rb +2 -0
- data/lib/chef/event_dispatch/base.rb +44 -2
- data/lib/chef/exceptions.rb +10 -0
- data/lib/chef/formatters/doc.rb +46 -0
- data/lib/chef/http/basic_client.rb +15 -7
- data/lib/chef/http.rb +7 -3
- data/lib/chef/provider/cron.rb +4 -1
- data/lib/chef/provider/file.rb +2 -0
- data/lib/chef/provider/git.rb +1 -1
- data/lib/chef/provider/ifconfig/debian.rb +1 -1
- data/lib/chef/provider/link.rb +2 -2
- data/lib/chef/provider/registry_key.rb +3 -2
- data/lib/chef/provider/remote_file/http.rb +1 -1
- data/lib/chef/provider/subversion.rb +5 -5
- data/lib/chef/provider/template.rb +1 -1
- data/lib/chef/resource/archive_file.rb +17 -14
- data/lib/chef/resource/chef_client_scheduled_task.rb +45 -2
- data/lib/chef/resource/chocolatey_config.rb +14 -14
- data/lib/chef/resource/chocolatey_feature.rb +1 -1
- data/lib/chef/resource/chocolatey_source.rb +24 -2
- data/lib/chef/resource/directory.rb +1 -1
- data/lib/chef/resource/file/verification/json.rb +50 -0
- data/lib/chef/resource/file/verification/yaml.rb +52 -0
- data/lib/chef/resource/habitat_install.rb +3 -3
- data/lib/chef/resource/inspec_input.rb +127 -0
- data/lib/chef/resource/inspec_waiver.rb +184 -0
- data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
- data/lib/chef/resource/kernel_module.rb +27 -2
- data/lib/chef/resource/macos_userdefaults.rb +43 -128
- data/lib/chef/resource/mount.rb +1 -1
- data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
- data/lib/chef/resource/powershell_package_source.rb +234 -70
- data/lib/chef/resource/registry_key.rb +36 -48
- data/lib/chef/resource/remote_file.rb +98 -2
- data/lib/chef/resource/timezone.rb +2 -2
- data/lib/chef/resource/user_ulimit.rb +1 -0
- data/lib/chef/resource/windows_auto_run.rb +1 -1
- data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
- data/lib/chef/resource/windows_printer.rb +1 -1
- data/lib/chef/resource/windows_uac.rb +3 -1
- data/lib/chef/resource/windows_update_settings.rb +3 -3
- data/lib/chef/resource/windows_user_privilege.rb +1 -1
- data/lib/chef/resource.rb +1 -1
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/run_context/cookbook_compiler.rb +112 -28
- data/lib/chef/run_context.rb +31 -1
- data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
- data/lib/chef/secret_fetcher/aws_secrets_manager.rb +1 -1
- data/lib/chef/secret_fetcher/azure_key_vault.rb +63 -9
- data/lib/chef/secret_fetcher/base.rb +1 -1
- data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
- data/lib/chef/secret_fetcher.rb +8 -3
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/version.rb +2 -1
- data/spec/data/archive_file/test_archive.tar.gz +0 -0
- data/spec/functional/dsl/reboot_pending_spec.rb +3 -3
- data/spec/functional/dsl/registry_helper_spec.rb +1 -1
- data/spec/functional/resource/archive_file_spec.rb +87 -0
- data/spec/functional/resource/dsc_script_spec.rb +2 -2
- data/spec/functional/resource/group_spec.rb +5 -1
- data/spec/functional/resource/link_spec.rb +8 -0
- data/spec/functional/resource/macos_userdefaults_spec.rb +119 -0
- data/spec/functional/resource/powershell_package_source_spec.rb +5 -6
- data/spec/functional/resource/registry_spec.rb +81 -81
- data/spec/functional/win32/registry_spec.rb +8 -8
- data/spec/integration/compliance/compliance_spec.rb +60 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/platform_helpers.rb +4 -0
- data/spec/support/ruby_installer.rb +51 -0
- data/spec/unit/compliance/input_spec.rb +104 -0
- data/spec/unit/compliance/profile_spec.rb +120 -0
- data/spec/unit/compliance/waiver_spec.rb +104 -0
- data/spec/unit/data_collector_spec.rb +24 -1
- data/spec/unit/dsl/reboot_pending_spec.rb +1 -1
- data/spec/unit/http/basic_client_spec.rb +30 -0
- data/spec/unit/http_spec.rb +8 -2
- data/spec/unit/mixin/default_paths_spec.rb +1 -1
- data/spec/unit/mixin/securable_spec.rb +3 -3
- data/spec/unit/provider/cron_spec.rb +45 -0
- data/spec/unit/provider/link_spec.rb +13 -7
- data/spec/unit/provider/package/rubygems_spec.rb +5 -5
- data/spec/unit/provider/package/windows_spec.rb +1 -1
- data/spec/unit/provider/registry_key_spec.rb +4 -4
- data/spec/unit/provider/remote_file/http_spec.rb +10 -0
- data/spec/unit/provider/service/windows_spec.rb +5 -5
- data/spec/unit/provider/subversion_spec.rb +4 -4
- data/spec/unit/provider/template_spec.rb +2 -2
- data/spec/unit/provider/windows_env_spec.rb +1 -1
- data/spec/unit/provider/zypper_repository_spec.rb +1 -1
- data/spec/unit/resource/archive_file_spec.rb +414 -3
- data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
- data/spec/unit/resource/chocolatey_config_spec.rb +1 -1
- data/spec/unit/resource/chocolatey_feature_spec.rb +1 -1
- data/spec/unit/resource/chocolatey_source_spec.rb +1 -1
- data/spec/unit/resource/file/verification/json_spec.rb +72 -0
- data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
- data/spec/unit/resource/inspec_input_spec.rb +300 -0
- data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
- data/spec/unit/resource/kernel_module_spec.rb +2 -1
- data/spec/unit/resource/macos_user_defaults_spec.rb +36 -96
- data/spec/unit/resource/mount_spec.rb +10 -0
- data/spec/unit/resource/powershell_package_source_spec.rb +63 -62
- data/spec/unit/resource/registry_key_spec.rb +10 -10
- data/spec/unit/resource/user_ulimit_spec.rb +14 -1
- data/spec/unit/resource/windows_auto_run_spec.rb +1 -1
- data/spec/unit/resource/windows_feature_powershell_spec.rb +1 -1
- data/spec/unit/resource/windows_firewall_rule_spec.rb +2 -2
- data/spec/unit/resource/windows_task_spec.rb +3 -3
- data/spec/unit/resource_reporter_spec.rb +2 -2
- data/spec/unit/resource_spec.rb +5 -0
- data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
- data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +99 -20
- data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
- data/spec/unit/util/backup_spec.rb +1 -1
- data/spec/unit/win32/registry_spec.rb +3 -3
- data/tasks/rspec.rb +2 -1
- metadata +75 -6
@@ -0,0 +1,184 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require_relative "../resource"
|
18
|
+
|
19
|
+
class Chef
|
20
|
+
class Resource
|
21
|
+
class InspecWaiver < Chef::Resource
|
22
|
+
provides :inspec_waiver
|
23
|
+
unified_mode true
|
24
|
+
|
25
|
+
description "Use the **inspec_waiver** resource to add a waiver to the Compliance Phase."
|
26
|
+
introduced "17.5"
|
27
|
+
examples <<~DOC
|
28
|
+
**Activate the default waiver in the openssh cookbook's compliance segment**:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
inspec_waiver 'openssh' do
|
32
|
+
action :add
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
**Activate all waivers in the openssh cookbook's compliance segment**:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
inspec_waiver 'openssh::.*' do
|
40
|
+
action :add
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
**Add an InSpec waiver to the Compliance Phase**:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
inspec_waiver 'Add waiver entry for control' do
|
48
|
+
control 'my_inspec_control_01'
|
49
|
+
run_test false
|
50
|
+
justification "The subject of this control is not managed by #{ChefUtils::Dist::Infra::PRODUCT} on the systems in policy group \#{node['policy_group']}"
|
51
|
+
expiration '2022-01-01'
|
52
|
+
action :add
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
**Add an InSpec waiver to the Compliance Phase using the 'name' property to identify the control**:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
inspec_waiver 'my_inspec_control_01' do
|
60
|
+
justification "The subject of this control is not managed by #{ChefUtils::Dist::Infra::PRODUCT} on the systems in policy group \#{node['policy_group']}"
|
61
|
+
action :add
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
**Add an InSpec waiver to the Compliance Phase using an arbitrary YAML, JSON, or TOML file**:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
# files ending in .yml or .yaml that exist are parsed as YAML
|
69
|
+
inspec_waiver "/path/to/my/waiver.yml"
|
70
|
+
|
71
|
+
inspec_waiver "my-waiver-name" do
|
72
|
+
source "/path/to/my/waiver.yml"
|
73
|
+
end
|
74
|
+
|
75
|
+
# files ending in .json that exist are parsed as JSON
|
76
|
+
inspec_waiver "/path/to/my/waiver.json"
|
77
|
+
|
78
|
+
inspec_waiver "my-waiver-name" do
|
79
|
+
source "/path/to/my/waiver.json"
|
80
|
+
end
|
81
|
+
|
82
|
+
# files ending in .toml that exist are parsed as TOML
|
83
|
+
inspec_waiver "/path/to/my/waiver.toml"
|
84
|
+
|
85
|
+
inspec_waiver "my-waiver-name" do
|
86
|
+
source "/path/to/my/waiver.toml"
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
**Add an InSpec waiver to the Compliance Phase using a hash**:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
my_hash = { "ssh-01" => {
|
94
|
+
"expiration_date" => "2033-07-31",
|
95
|
+
"run" => false,
|
96
|
+
"justification" => "because"
|
97
|
+
} }
|
98
|
+
|
99
|
+
inspec_waiver "my-waiver-name" do
|
100
|
+
source my_hash
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
Note that the **inspec_waiver** resource does not update and will not fire notifications (similar to the log resource). This is done to preserve the ability to use
|
105
|
+
the resource while not causing the updated resource count to be larger than zero. Since the resource does not update the state of the managed node, this behavior
|
106
|
+
is still consistent with the configuration management model. Instead, you should use events to observe configuration changes for the compliance phase. It is
|
107
|
+
possible to use the `notify_group` resource to chain notifications of the two resources, but notifications are the wrong model to use, and you should use pure ruby
|
108
|
+
conditionals instead. Compliance configuration should be independent of other resources and should only be conditional based on state/attributes, not other resources.
|
109
|
+
DOC
|
110
|
+
|
111
|
+
property :control, String,
|
112
|
+
name_property: true,
|
113
|
+
description: "The name of the control being waived"
|
114
|
+
|
115
|
+
property :expiration, String,
|
116
|
+
description: "The expiration date of the waiver - provided in YYYY-MM-DD format",
|
117
|
+
callbacks: {
|
118
|
+
"Expiration date should be a valid calendar date and match the following format: YYYY-MM-DD" => proc { |e|
|
119
|
+
re = Regexp.new("\\d{4}-\\d{2}-\\d{2}$").freeze
|
120
|
+
if re.match?(e)
|
121
|
+
Date.valid_date?(*e.split("-").map(&:to_i))
|
122
|
+
else
|
123
|
+
e.nil?
|
124
|
+
end
|
125
|
+
},
|
126
|
+
}
|
127
|
+
|
128
|
+
property :run_test, [true, false],
|
129
|
+
description: "If present and true, the control will run and be reported, but failures in it won’t make the overall run fail. If absent or false, the control will not be run."
|
130
|
+
|
131
|
+
property :justification, String,
|
132
|
+
description: "Can be any text you want and might include a reason for the waiver as well as who signed off on the waiver."
|
133
|
+
|
134
|
+
property :source, [ Hash, String ]
|
135
|
+
|
136
|
+
action :add, description: "Add a waiver to the compliance phase" do
|
137
|
+
if run_context.waiver_collection.valid?(new_resource.control)
|
138
|
+
include_waiver(new_resource.control)
|
139
|
+
else
|
140
|
+
include_waiver(waiver_hash)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
action_class do
|
145
|
+
# If the source is nil and the control / name_property contains a file separator and is a string of a
|
146
|
+
# file that exists, then use that as the file (similar to the package provider automatic source property). Otherwise
|
147
|
+
# just return the source.
|
148
|
+
#
|
149
|
+
# @api private
|
150
|
+
def source
|
151
|
+
@source ||= build_source
|
152
|
+
end
|
153
|
+
|
154
|
+
def build_source
|
155
|
+
return new_resource.source unless new_resource.source.nil?
|
156
|
+
return nil unless new_resource.control.count(::File::SEPARATOR) > 0 || (::File::ALT_SEPARATOR && new_resource.control.count(::File::ALT_SEPARATOR) > 0 )
|
157
|
+
return nil unless ::File.exist?(new_resource.control)
|
158
|
+
|
159
|
+
new_resource.control
|
160
|
+
end
|
161
|
+
|
162
|
+
def waiver_hash
|
163
|
+
case source
|
164
|
+
when Hash
|
165
|
+
source
|
166
|
+
when String
|
167
|
+
parse_file(source)
|
168
|
+
when nil
|
169
|
+
if new_resource.justification.nil? || new_resource.justification == ""
|
170
|
+
raise Chef::Exceptions::ValidationFailed, "Entries for an InSpec waiver must have a justification given, this parameter must have a value."
|
171
|
+
end
|
172
|
+
|
173
|
+
control_hash = {}
|
174
|
+
control_hash["expiration_date"] = new_resource.expiration.to_s unless new_resource.expiration.nil?
|
175
|
+
control_hash["run"] = new_resource.run_test unless new_resource.run_test.nil?
|
176
|
+
control_hash["justification"] = new_resource.justification.to_s
|
177
|
+
|
178
|
+
{ new_resource.control => control_hash }
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -74,7 +74,7 @@ class Chef
|
|
74
74
|
description: "The expiration date of the given waiver - provided in YYYY-MM-DD format",
|
75
75
|
callbacks: {
|
76
76
|
"Expiration date should be a valid calendar date and match the following format: YYYY-MM-DD" => proc { |e|
|
77
|
-
re = Regexp.new(
|
77
|
+
re = Regexp.new("\\d{4}-\\d{2}-\\d{2}$").freeze
|
78
78
|
if re.match?(e)
|
79
79
|
Date.valid_date?(*e.split("-").map(&:to_i))
|
80
80
|
else
|
@@ -15,7 +15,7 @@ class Chef
|
|
15
15
|
|
16
16
|
provides :kernel_module
|
17
17
|
|
18
|
-
description "Use the **kernel_module** resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, install, and uninstall modules."
|
18
|
+
description "Use the **kernel_module** resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, enable, install, and uninstall modules."
|
19
19
|
introduced "14.3"
|
20
20
|
examples <<~DOC
|
21
21
|
Install and load a kernel module, and ensure it loads on reboot.
|
@@ -68,13 +68,21 @@ class Chef
|
|
68
68
|
end
|
69
69
|
```
|
70
70
|
|
71
|
-
Disable a kernel module.
|
71
|
+
Disable a kernel module so that it is not installable.
|
72
72
|
|
73
73
|
```ruby
|
74
74
|
kernel_module 'loop' do
|
75
75
|
action :disable
|
76
76
|
end
|
77
77
|
```
|
78
|
+
|
79
|
+
Enable a kernel module so that it is can be installed. Does not load or install.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
kernel_module 'loop' do
|
83
|
+
action :enable
|
84
|
+
end
|
85
|
+
```
|
78
86
|
DOC
|
79
87
|
|
80
88
|
property :modname, String,
|
@@ -101,6 +109,9 @@ class Chef
|
|
101
109
|
end
|
102
110
|
end
|
103
111
|
|
112
|
+
# Remove the "disable file" before trying to install
|
113
|
+
action_enable
|
114
|
+
|
104
115
|
# create options file before loading the module
|
105
116
|
unless new_resource.options.nil?
|
106
117
|
file "#{new_resource.unload_dir}/options_#{new_resource.modname}.conf" do
|
@@ -178,6 +189,20 @@ class Chef
|
|
178
189
|
action_unload
|
179
190
|
end
|
180
191
|
|
192
|
+
action :enable, description: "Enable a kernel module. Reverse :disable actions" do
|
193
|
+
with_run_context :root do
|
194
|
+
find_resource(:execute, "update initramfs") do
|
195
|
+
command initramfs_command
|
196
|
+
action :nothing
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
file "#{new_resource.unload_dir}/disable_#{new_resource.modname}.conf" do
|
201
|
+
action :delete
|
202
|
+
notifies :run, "execute[update initramfs]", :delayed
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
181
206
|
action :load, description: "Load a kernel module." do
|
182
207
|
unless module_loaded?
|
183
208
|
converge_by("load kernel module #{new_resource.modname}") do
|
@@ -78,172 +78,87 @@ class Chef
|
|
78
78
|
required: true
|
79
79
|
|
80
80
|
property :host, [String, Symbol],
|
81
|
-
description: "Set either :current or a hostname to set the user default at the host level.",
|
81
|
+
description: "Set either :current, :all or a hostname to set the user default at the host level.",
|
82
82
|
desired_state: false,
|
83
|
-
introduced: "16.3"
|
83
|
+
introduced: "16.3",
|
84
|
+
coerce: proc { |value| to_cf_host(value) }
|
84
85
|
|
85
86
|
property :value, [Integer, Float, String, TrueClass, FalseClass, Hash, Array],
|
86
87
|
description: "The value of the key. Note: With the `type` property set to `bool`, `String` forms of Boolean true/false values that Apple accepts in the defaults command will be coerced: 0/1, 'TRUE'/'FALSE,' 'true'/false', 'YES'/'NO', or 'yes'/'no'.",
|
87
|
-
required: [:write]
|
88
|
-
coerce: proc { |v| v.is_a?(Hash) ? v.transform_keys(&:to_s) : v } # make sure keys are all strings for comparison
|
88
|
+
required: [:write]
|
89
89
|
|
90
90
|
property :type, String,
|
91
91
|
description: "The value type of the preference key.",
|
92
92
|
equal_to: %w{bool string int float array dict},
|
93
|
-
desired_state: false
|
93
|
+
desired_state: false,
|
94
|
+
deprecated: true
|
94
95
|
|
95
|
-
property :user, String,
|
96
|
-
description: "The system user that the default will be applied to.",
|
97
|
-
desired_state: false
|
96
|
+
property :user, [String, Symbol],
|
97
|
+
description: "The system user that the default will be applied to. Set :current for current user, :all for all users or pass a valid username",
|
98
|
+
desired_state: false,
|
99
|
+
coerce: proc { |value| to_cf_user(value) }
|
98
100
|
|
99
101
|
property :sudo, [TrueClass, FalseClass],
|
100
102
|
description: "Set to true if the setting you wish to modify requires privileged access. This requires passwordless sudo for the `/usr/bin/defaults` command to be setup for the user running #{ChefUtils::Dist::Infra::PRODUCT}.",
|
101
103
|
default: false,
|
102
|
-
desired_state: false
|
104
|
+
desired_state: false,
|
105
|
+
deprecated: true
|
103
106
|
|
104
107
|
load_current_value do |new_resource|
|
105
|
-
Chef::Log.debug "#load_current_value:
|
106
|
-
state = shell_out(defaults_export_cmd(new_resource), user: new_resource.user)
|
107
|
-
|
108
|
-
if state.error? || state.stdout.empty?
|
109
|
-
Chef::Log.debug "#load_current_value: #{defaults_export_cmd(new_resource).join(" ")} returned stdout: #{state.stdout} and stderr: #{state.stderr}"
|
110
|
-
current_value_does_not_exist!
|
111
|
-
end
|
112
|
-
|
113
|
-
plist_data = ::Plist.parse_xml(state.stdout)
|
114
|
-
|
115
|
-
# handle the situation where the key doesn't exist in the domain
|
116
|
-
if plist_data.key?(new_resource.key)
|
117
|
-
key new_resource.key
|
118
|
-
else
|
119
|
-
current_value_does_not_exist!
|
120
|
-
end
|
108
|
+
Chef::Log.debug "#load_current_value: attempting to read \"#{new_resource.domain}\" value from preferences to determine state"
|
121
109
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
#
|
126
|
-
# The defaults command to export a domain
|
127
|
-
#
|
128
|
-
# @return [Array] defaults command
|
129
|
-
#
|
130
|
-
def defaults_export_cmd(resource)
|
131
|
-
state_cmd = ["/usr/bin/defaults"]
|
132
|
-
|
133
|
-
if resource.host == "current"
|
134
|
-
state_cmd.concat(["-currentHost"])
|
135
|
-
elsif resource.host # they specified a non-nil value, which is a hostname
|
136
|
-
state_cmd.concat(["-host", resource.host])
|
137
|
-
end
|
110
|
+
pref = get_preference(new_resource)
|
111
|
+
current_value_does_not_exist! if pref.nil?
|
138
112
|
|
139
|
-
|
140
|
-
|
113
|
+
key new_resource.key
|
114
|
+
value pref
|
141
115
|
end
|
142
116
|
|
143
117
|
action :write, description: "Write the value to the specified domain/key." do
|
144
118
|
converge_if_changed do
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
shell_out!(cmd, user: new_resource.user)
|
119
|
+
Chef::Log.debug("Updating defaults value for #{new_resource.key} in #{new_resource.domain}")
|
120
|
+
CF::Preferences.set!(new_resource.key, new_resource.value, new_resource.domain, new_resource.user, new_resource.host)
|
149
121
|
end
|
150
122
|
end
|
151
123
|
|
152
124
|
action :delete, description: "Delete a key from a domain." do
|
153
125
|
# if it's not there there's nothing to remove
|
154
|
-
return
|
126
|
+
return if current_resource.nil?
|
155
127
|
|
156
128
|
converge_by("delete domain:#{new_resource.domain} key:#{new_resource.key}") do
|
157
|
-
|
158
|
-
|
159
|
-
Chef::Log.debug("Removing defaults key by shelling out: #{cmd.join(" ")}")
|
160
|
-
|
161
|
-
shell_out!(cmd, user: new_resource.user)
|
129
|
+
Chef::Log.debug("Removing defaults key: #{new_resource.key}")
|
130
|
+
CF::Preferences.set!(new_resource.key, nil, new_resource.domain, new_resource.user, new_resource.host)
|
162
131
|
end
|
163
132
|
end
|
164
133
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
#
|
169
|
-
# @return [Array] Array representation of defaults command to run
|
170
|
-
#
|
171
|
-
def defaults_modify_cmd
|
172
|
-
cmd = ["/usr/bin/defaults"]
|
173
|
-
|
174
|
-
if new_resource.host == :current
|
175
|
-
cmd.concat(["-currentHost"])
|
176
|
-
elsif new_resource.host # they specified a non-nil value, which is a hostname
|
177
|
-
cmd.concat(["-host", new_resource.host])
|
178
|
-
end
|
134
|
+
def get_preference(new_resource)
|
135
|
+
CF::Preferences.get(new_resource.key, new_resource.domain, new_resource.user, new_resource.host)
|
136
|
+
end
|
179
137
|
|
180
|
-
|
181
|
-
|
182
|
-
cmd.prepend("sudo") if new_resource.sudo
|
183
|
-
cmd
|
184
|
-
end
|
138
|
+
action_class do
|
139
|
+
require "corefoundation" if RUBY_PLATFORM.match?(/darwin/)
|
185
140
|
|
186
|
-
#
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
# when dict this creates an array of values ["Key1", "Value1", "Key2", "Value2" ...]
|
195
|
-
cmd_values = ["-#{type}"]
|
196
|
-
|
197
|
-
case type
|
198
|
-
when "dict"
|
199
|
-
cmd_values.concat(new_resource.value.flatten)
|
200
|
-
when "array"
|
201
|
-
cmd_values.concat(new_resource.value)
|
202
|
-
when "bool"
|
203
|
-
cmd_values.concat(bool_to_defaults_bool(new_resource.value))
|
141
|
+
# Return valid hostname based on the input from host property
|
142
|
+
def to_cf_host(value)
|
143
|
+
case value
|
144
|
+
when :all
|
145
|
+
CF::Preferences::ALL_HOSTS
|
146
|
+
when :current
|
147
|
+
CF::Preferences::CURRENT_HOST
|
204
148
|
else
|
205
|
-
|
149
|
+
value
|
206
150
|
end
|
207
|
-
|
208
|
-
cmd_values
|
209
151
|
end
|
210
152
|
|
211
|
-
#
|
212
|
-
|
213
|
-
#
|
214
|
-
# @param [String, Integer, Boolean] input <description>
|
215
|
-
#
|
216
|
-
# @return [String] TRUE or FALSE
|
217
|
-
#
|
218
|
-
def bool_to_defaults_bool(input)
|
219
|
-
return ["TRUE"] if [true, "TRUE", "1", "true", "YES", "yes"].include?(input)
|
220
|
-
return ["FALSE"] if [false, "FALSE", "0", "false", "NO", "no"].include?(input)
|
221
|
-
|
222
|
-
# make sure it's very clear bad input was given
|
223
|
-
raise ArgumentError, "#{input} cannot be converted to a boolean value for use with Apple's defaults command. Acceptable values are: 'TRUE', 'YES', 'true, 'yes', '0', true, 'FALSE', 'false', 'NO', 'no', '1', or false."
|
224
|
-
end
|
225
|
-
|
226
|
-
#
|
227
|
-
# convert ruby type to defaults type
|
228
|
-
#
|
229
|
-
# @param [Integer, Float, String, TrueClass, FalseClass, Hash, Array] value The value being set
|
230
|
-
#
|
231
|
-
# @return [string, nil] the type value used by defaults or nil if not applicable
|
232
|
-
#
|
233
|
-
def value_type(value)
|
153
|
+
# Return valid username based on the input from user property
|
154
|
+
def to_cf_user(value)
|
234
155
|
case value
|
235
|
-
when
|
236
|
-
|
237
|
-
when
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
when Hash
|
242
|
-
"dict"
|
243
|
-
when Array
|
244
|
-
"array"
|
245
|
-
when String
|
246
|
-
"string"
|
156
|
+
when :all
|
157
|
+
CF::Preferences::ALL_USERS
|
158
|
+
when :current
|
159
|
+
CF::Preferences::CURRENT_USER
|
160
|
+
else
|
161
|
+
value
|
247
162
|
end
|
248
163
|
end
|
249
164
|
end
|
data/lib/chef/resource/mount.rb
CHANGED
@@ -42,7 +42,7 @@ class Chef
|
|
42
42
|
sensitive: true
|
43
43
|
|
44
44
|
property :mount_point, String, name_property: true,
|
45
|
-
coerce: proc { |arg| arg.chomp("/") }, # Removed "/" from the end of str, because it was causing idempotency issue.
|
45
|
+
coerce: proc { |arg| (arg == "/" || arg.match?(":/$")) ? arg : arg.chomp("/") }, # Removed "/" from the end of str, because it was causing idempotency issue.
|
46
46
|
description: "The directory (or path) in which the device is to be mounted. Defaults to the name of the resource block if not provided."
|
47
47
|
|
48
48
|
property :device, String, identity: true,
|