chef 17.6.18 → 17.7.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -0
  3. data/chef.gemspec +1 -0
  4. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  5. data/lib/chef/chef_fs/path_utils.rb +1 -1
  6. data/lib/chef/data_collector/run_end_message.rb +1 -1
  7. data/lib/chef/dsl/reboot_pending.rb +1 -1
  8. data/lib/chef/exceptions.rb +10 -0
  9. data/lib/chef/provider/cron.rb +4 -1
  10. data/lib/chef/provider/git.rb +1 -1
  11. data/lib/chef/provider/ifconfig/debian.rb +1 -1
  12. data/lib/chef/provider/subversion.rb +5 -5
  13. data/lib/chef/resource/chocolatey_config.rb +1 -1
  14. data/lib/chef/resource/chocolatey_feature.rb +1 -1
  15. data/lib/chef/resource/chocolatey_source.rb +24 -2
  16. data/lib/chef/resource/directory.rb +1 -1
  17. data/lib/chef/resource/habitat_install.rb +3 -3
  18. data/lib/chef/resource/inspec_waiver.rb +1 -1
  19. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  20. data/lib/chef/resource/kernel_module.rb +27 -2
  21. data/lib/chef/resource/macos_userdefaults.rb +43 -128
  22. data/lib/chef/resource/windows_auto_run.rb +1 -1
  23. data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
  24. data/lib/chef/resource/windows_update_settings.rb +3 -3
  25. data/lib/chef/resource.rb +1 -1
  26. data/lib/chef/resource_reporter.rb +1 -1
  27. data/lib/chef/secret_fetcher/azure_key_vault.rb +62 -8
  28. data/lib/chef/secret_fetcher.rb +0 -1
  29. data/lib/chef/version.rb +1 -1
  30. data/spec/functional/dsl/reboot_pending_spec.rb +3 -3
  31. data/spec/functional/dsl/registry_helper_spec.rb +1 -1
  32. data/spec/functional/resource/dsc_script_spec.rb +2 -2
  33. data/spec/functional/resource/macos_userdefaults_spec.rb +119 -0
  34. data/spec/functional/resource/registry_spec.rb +81 -81
  35. data/spec/functional/win32/registry_spec.rb +8 -8
  36. data/spec/unit/data_collector_spec.rb +24 -1
  37. data/spec/unit/dsl/reboot_pending_spec.rb +1 -1
  38. data/spec/unit/mixin/default_paths_spec.rb +1 -1
  39. data/spec/unit/mixin/securable_spec.rb +3 -3
  40. data/spec/unit/provider/cron_spec.rb +45 -0
  41. data/spec/unit/provider/package/rubygems_spec.rb +5 -5
  42. data/spec/unit/provider/package/windows_spec.rb +1 -1
  43. data/spec/unit/provider/registry_key_spec.rb +4 -4
  44. data/spec/unit/provider/service/windows_spec.rb +5 -5
  45. data/spec/unit/provider/subversion_spec.rb +4 -4
  46. data/spec/unit/provider/windows_env_spec.rb +1 -1
  47. data/spec/unit/provider/zypper_repository_spec.rb +1 -1
  48. data/spec/unit/resource/chocolatey_config_spec.rb +1 -1
  49. data/spec/unit/resource/chocolatey_feature_spec.rb +1 -1
  50. data/spec/unit/resource/chocolatey_source_spec.rb +1 -1
  51. data/spec/unit/resource/kernel_module_spec.rb +2 -1
  52. data/spec/unit/resource/macos_user_defaults_spec.rb +36 -96
  53. data/spec/unit/resource/registry_key_spec.rb +10 -10
  54. data/spec/unit/resource/windows_auto_run_spec.rb +1 -1
  55. data/spec/unit/resource/windows_feature_powershell_spec.rb +1 -1
  56. data/spec/unit/resource/windows_firewall_rule_spec.rb +2 -2
  57. data/spec/unit/resource/windows_task_spec.rb +3 -3
  58. data/spec/unit/resource_reporter_spec.rb +2 -2
  59. data/spec/unit/resource_spec.rb +5 -0
  60. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +99 -20
  61. data/spec/unit/util/backup_spec.rb +1 -1
  62. data/spec/unit/win32/registry_spec.rb +3 -3
  63. metadata +21 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59f5d3f142e80c94be749ef60ee943e69079238f55209a2a10741158c8816bce
4
- data.tar.gz: 48a22e1452ab3aa51e69f64144ccccff80790f9890e81c7ea3a781a151080da6
3
+ metadata.gz: 830ef86569d7fc3510b6428198eaf8f6befb9473f808af1f77ae7d1e95171fb7
4
+ data.tar.gz: 58d92cc9852026920805cb37699360c2f13edf4f8404839c8ab0ba5de1e54f21
5
5
  SHA512:
6
- metadata.gz: 28fb40af64c9a66d6e1d7ab487e88873b0eed7db8fc13f80c7e5fe5c191bbbe1b89da0d5fcf841072a12d1674ce2a5986d243dc41340ddb71508d337e804325e
7
- data.tar.gz: 24a4a408695c4c6283bcd7312b7f74c164fe2f4bb9b6eb3adce43c4182d398f86a02cbb2aa1a63df0ff0a1084961cba96f3c7a7b4fefb958b23a61c92f53a3a8
6
+ metadata.gz: f07a07a8726c05f0b967e65f391388b7206b6590d598360b2aac3d26e48c773573366153d58dcf1392cbffc4552ed1756096d243ed2d076820d10394999abdb3
7
+ data.tar.gz: 8c6a775624f533de9112b3c77cae54ba033e94faca6a87fd0c44c7772a64e2f4f981c550813f2deb6c8bf1326adc33877fc15e4fb1d16a65ab98ec6f20297bde
data/Gemfile CHANGED
@@ -39,6 +39,11 @@ group(:ruby_shadow) do
39
39
  gem "ruby-shadow", git: "https://github.com/chef/ruby-shadow", branch: "lcg/ruby-3.0", platforms: :ruby
40
40
  end
41
41
 
42
+ # deps that cannot be put in the knife gem because they require a compiler and fail on windows nodes
43
+ group(:knife_windows_deps) do
44
+ gem "ed25519", "~> 1.2" # ed25519 ssh key support
45
+ end
46
+
42
47
  group(:development, :test) do
43
48
  gem "rake"
44
49
  gem "rspec"
data/chef.gemspec CHANGED
@@ -52,6 +52,7 @@ Gem::Specification.new do |s|
52
52
  s.add_dependency "addressable"
53
53
  s.add_dependency "syslog-logger", "~> 1.6"
54
54
  s.add_dependency "uuidtools", ">= 2.1.5", "< 3.0" # osx_profile resource
55
+ s.add_dependency "corefoundation", "~> 0.3.4" # macos_userdefaults resource
55
56
 
56
57
  s.add_dependency "proxifier", "~> 1.0"
57
58
 
@@ -276,7 +276,7 @@ class Chef
276
276
  regexp << ".*"
277
277
  when "*"
278
278
  exact = nil
279
- regexp << '[^\/]*'
279
+ regexp << "[^\\/]*"
280
280
  when "?"
281
281
  exact = nil
282
282
  regexp << "."
@@ -58,7 +58,7 @@ class Chef
58
58
  end
59
59
 
60
60
  def self.regexp_path_separator
61
- ChefUtils.windows? ? '[\/\\\\]' : "/"
61
+ ChefUtils.windows? ? "[\\/\\\\]" : "/"
62
62
  end
63
63
 
64
64
  # Given a server path, determines if it is absolute.
@@ -128,7 +128,7 @@ class Chef
128
128
 
129
129
  if new_resource.cookbook_name
130
130
  hash["cookbook_name"] = new_resource.cookbook_name
131
- hash["cookbook_version"] = new_resource.cookbook_version.version
131
+ hash["cookbook_version"] = new_resource.cookbook_version&.version
132
132
  hash["recipe_name"] = new_resource.recipe_name
133
133
  end
134
134
 
@@ -37,7 +37,7 @@ class Chef
37
37
  # due to a file being in use (usually a temporary file and a system file)
38
38
  # \??\c:\temp\test.sys!\??\c:\winnt\system32\test.sys
39
39
  # http://technet.microsoft.com/en-us/library/cc960241.aspx
40
- registry_value_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager', { name: "PendingFileRenameOperations" }) ||
40
+ registry_value_exists?("HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager", { name: "PendingFileRenameOperations" }) ||
41
41
 
42
42
  # RebootRequired key contains Update IDs with a value of 1 if they require a reboot.
43
43
  # The existence of RebootRequired alone is sufficient on my Windows 8.1 workstation in Windows Update
@@ -308,6 +308,16 @@ class Chef
308
308
  super("No secret service provided. Supported services are: :#{fetcher_service_names.join(" :")}")
309
309
  end
310
310
  end
311
+
312
+ class Azure
313
+ class IdentityNotFound < RuntimeError
314
+ def initialize
315
+ super("The managed identity could not be found. This could mean one of the following things:\n\n" \
316
+ " 1. The VM has no system or user assigned identities.\n" \
317
+ " 2. The managed identity object_id or client_id that was specified is not assigned to the VM.\n")
318
+ end
319
+ end
320
+ end
311
321
  end
312
322
 
313
323
  # Exception class for collecting multiple failures. Used when running
@@ -100,7 +100,10 @@ class Chef
100
100
  newcron = get_crontab_entry
101
101
 
102
102
  if @cron_exists
103
- unless cron_different?
103
+ # Only compare the crontab if the current resource has a set command.
104
+ # This may not be set in cases where the Chef comment exists but the
105
+ # crontab command was commented out.
106
+ if current_resource.property_is_set?(:command) && !cron_different?
104
107
  logger.debug("#{new_resource}: Skipping existing cron entry")
105
108
  return
106
109
  end
@@ -28,7 +28,7 @@ class Chef
28
28
  extend Forwardable
29
29
  provides :git
30
30
 
31
- GIT_VERSION_PATTERN = Regexp.compile('git version (\d+\.\d+.\d+)')
31
+ GIT_VERSION_PATTERN = Regexp.compile("git version (\\d+\\.\\d+.\\d+)")
32
32
 
33
33
  def_delegator :new_resource, :destination, :cwd
34
34
 
@@ -87,7 +87,7 @@ iface <%= new_resource.device %> <%= new_resource.family %> static
87
87
  directory INTERFACES_DOT_D_DIR
88
88
 
89
89
  # roll our own file_edit resource, this will not get reported until we have a file_edit resource
90
- interfaces_dot_d_for_regexp = INTERFACES_DOT_D_DIR.gsub(/\./, '\.') # escape dots for the regexp
90
+ interfaces_dot_d_for_regexp = INTERFACES_DOT_D_DIR.gsub(/\./, "\\.") # escape dots for the regexp
91
91
  regexp = %r{^\s*source\s+#{interfaces_dot_d_for_regexp}/\*\s*$}
92
92
 
93
93
  return if ::File.exist?(INTERFACES_FILE) && regexp.match(IO.read(INTERFACES_FILE))
@@ -58,7 +58,7 @@ class Chef
58
58
  action :checkout, description: "Clone or check out the source. When a checkout is available, this provider does nothing." do
59
59
  if target_dir_non_existent_or_empty?
60
60
  converge_by("perform checkout of #{new_resource.repository} into #{new_resource.destination}") do
61
- shell_out!(checkout_command, run_options)
61
+ shell_out!(checkout_command, **run_options)
62
62
  end
63
63
  else
64
64
  logger.debug "#{new_resource} checkout destination #{new_resource.destination} already exists or is a non-empty directory - nothing to do"
@@ -75,7 +75,7 @@ class Chef
75
75
 
76
76
  action :force_export, description: "Export the source, excluding or removing any version control artifacts and force an export of the source that is overwriting the existing copy (if it exists)." do
77
77
  converge_by("export #{new_resource.repository} into #{new_resource.destination}") do
78
- shell_out!(export_command, run_options)
78
+ shell_out!(export_command, **run_options)
79
79
  end
80
80
  end
81
81
 
@@ -86,7 +86,7 @@ class Chef
86
86
  logger.trace "#{new_resource} current revision: #{current_rev} target revision: #{revision_int}"
87
87
  unless current_revision_matches_target_revision?
88
88
  converge_by("sync #{new_resource.destination} from #{new_resource.repository}") do
89
- shell_out!(sync_command, run_options)
89
+ shell_out!(sync_command, **run_options)
90
90
  logger.info "#{new_resource} updated to revision: #{revision_int}"
91
91
  end
92
92
  end
@@ -125,7 +125,7 @@ class Chef
125
125
  new_resource.revision
126
126
  else
127
127
  command = scm(:info, new_resource.repository, new_resource.svn_info_args, authentication, "-r#{new_resource.revision}")
128
- svn_info = shell_out!(command, run_options(cwd: cwd, returns: [0, 1])).stdout
128
+ svn_info = shell_out!(command, **run_options(cwd: cwd, returns: [0, 1])).stdout
129
129
 
130
130
  extract_revision_info(svn_info)
131
131
  end
@@ -137,7 +137,7 @@ class Chef
137
137
  return nil unless ::File.exist?(::File.join(new_resource.destination, ".svn"))
138
138
 
139
139
  command = scm(:info)
140
- svn_info = shell_out!(command, run_options(cwd: cwd, returns: [0, 1])).stdout
140
+ svn_info = shell_out!(command, **run_options(cwd: cwd, returns: [0, 1])).stdout
141
141
 
142
142
  extract_revision_info(svn_info)
143
143
  end
@@ -21,7 +21,7 @@ class Chef
21
21
 
22
22
  provides :chocolatey_config
23
23
 
24
- description "Use the **chocolatey_config** resource to add or remove Chocolatey configuration keys."
24
+ description "Use the **chocolatey_config** resource to add or remove Chocolatey configuration keys. Note: The Chocolatey package manager is not installed on Windows by default. You will need to install it prior to using this resource by adding the [Chocolatey cookbook](https://supermarket.chef.io/cookbooks/chocolatey/) to your node's run list."
25
25
  introduced "14.3"
26
26
  examples <<~DOC
27
27
  **Set the Chocolatey cacheLocation config**:
@@ -20,7 +20,7 @@ class Chef
20
20
  unified_mode true
21
21
  provides :chocolatey_feature
22
22
 
23
- description "Use the **chocolatey_feature** resource to enable and disable Chocolatey features."
23
+ description "Use the **chocolatey_feature** resource to enable and disable Chocolatey features. Note: The Chocolatey package manager is not installed on Windows by default. You will need to install it prior to using this resource by adding the [Chocolatey cookbook](https://supermarket.chef.io/cookbooks/chocolatey/) to your node's run list."
24
24
  introduced "15.1"
25
25
  examples <<~DOC
26
26
  **Enable the checksumFiles Chocolatey feature**
@@ -20,7 +20,7 @@ class Chef
20
20
  unified_mode true
21
21
  provides :chocolatey_source
22
22
 
23
- description "Use the **chocolatey_source** resource to add, remove, enable, or disable Chocolatey sources."
23
+ description "Use the **chocolatey_source** resource to add, remove, enable, or disable Chocolatey sources. Note: The Chocolatey package manager is not installed on Windows by default. You will need to install it prior to using this resource by adding the [Chocolatey cookbook](https://supermarket.chef.io/cookbooks/chocolatey/) to your node's run list."
24
24
  introduced "14.3"
25
25
  examples <<~DOC
26
26
  **Add a Chocolatey source**
@@ -63,6 +63,22 @@ class Chef
63
63
 
64
64
  property :disabled, [TrueClass, FalseClass], default: false, desired_state: false, skip_docs: true
65
65
 
66
+ property :username, String,
67
+ description: "The username to use when authenticating against the source",
68
+ introduced: "17.7"
69
+
70
+ property :password, String, sensitive: true, desired_state: false,
71
+ description: "The password to use when authenticating against the source",
72
+ introduced: "17.7"
73
+
74
+ property :cert, String,
75
+ description: "The certificate to use when authenticating against the source",
76
+ introduced: "17.7"
77
+
78
+ property :cert_password, String, sensitive: true, desired_state: false,
79
+ description: "The password for the certificate to use when authenticating against the source",
80
+ introduced: "17.7"
81
+
66
82
  load_current_value do
67
83
  element = fetch_source_element(source_name)
68
84
  current_value_does_not_exist! if element.nil?
@@ -74,6 +90,8 @@ class Chef
74
90
  allow_self_service element["selfService"] == "true"
75
91
  priority element["priority"].to_i
76
92
  disabled element["disabled"] == "true"
93
+ username element["user"]
94
+ cert element["certificate"]
77
95
  end
78
96
 
79
97
  # @param [String] id the source name
@@ -129,10 +147,14 @@ class Chef
129
147
  def choco_cmd(action)
130
148
  cmd = "#{ENV["ALLUSERSPROFILE"]}\\chocolatey\\bin\\choco source #{action} -n \"#{new_resource.source_name}\""
131
149
  if action == "add"
132
- cmd << " -s #{new_resource.source} --priority=#{new_resource.priority}"
150
+ cmd << " --source=\"#{new_resource.source}\" --priority=#{new_resource.priority}"
133
151
  cmd << " --bypassproxy" if new_resource.bypass_proxy
134
152
  cmd << " --allowselfservice" if new_resource.allow_self_service
135
153
  cmd << " --adminonly" if new_resource.admin_only
154
+ cmd << " --user=\"#{new_resource.username}\"" if new_resource.username
155
+ cmd << " --password=\"#{new_resource.password}\"" if new_resource.password
156
+ cmd << " --cert=\"#{new_resource.cert}\"" if new_resource.cert
157
+ cmd << " --certpassword=\"#{new_resource.cert_password}\"" if new_resource.cert_password
136
158
  end
137
159
  cmd
138
160
  end
@@ -46,7 +46,7 @@ class Chef
46
46
  description: "The path to the directory. Using a fully qualified path is recommended, but is not always required."
47
47
 
48
48
  property :recursive, [ TrueClass, FalseClass ],
49
- description: "Create or delete parent directories recursively. For the owner, group, and mode properties, the value of this property applies only to the leaf directory.",
49
+ description: "Create parent directories recursively, or delete directory and all children recursively. For the owner, group, and mode properties, the value of this property applies only to the leaf directory.",
50
50
  default: false
51
51
  end
52
52
  end
@@ -95,10 +95,10 @@ class Chef
95
95
  path habfile
96
96
  destination "#{Chef::Config[:file_cache_path]}/habitat"
97
97
  action :extract
98
- not_if { ::Dir.exist?('c:\habitat') }
98
+ not_if { ::Dir.exist?("c:\\habitat") }
99
99
  end
100
100
 
101
- directory 'c:\habitat' do
101
+ directory "c:\\habitat" do
102
102
  notifies :run, "powershell_script[installing from archive]", :immediately
103
103
  end
104
104
 
@@ -110,7 +110,7 @@ class Chef
110
110
  end
111
111
 
112
112
  # TODO: This won't self heal if missing until the next upgrade
113
- windows_path 'C:\habitat' do
113
+ windows_path "C:\\habitat" do
114
114
  action :add
115
115
  end
116
116
  else
@@ -116,7 +116,7 @@ class Chef
116
116
  description: "The expiration date of the waiver - provided in YYYY-MM-DD format",
117
117
  callbacks: {
118
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
119
+ re = Regexp.new("\\d{4}-\\d{2}-\\d{2}$").freeze
120
120
  if re.match?(e)
121
121
  Date.valid_date?(*e.split("-").map(&:to_i))
122
122
  else
@@ -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('\d{4}-\d{2}-\d{2}$').freeze
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: shelling out \"#{defaults_export_cmd(new_resource).join(" ")}\" to determine state"
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
- value plist_data[new_resource.key]
123
- end
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
- state_cmd.concat(["export", resource.domain, "-"])
140
- state_cmd
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
- cmd = defaults_modify_cmd
146
- Chef::Log.debug("Updating defaults value by shelling out: #{cmd.join(" ")}")
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 unless current_resource
126
+ return if current_resource.nil?
155
127
 
156
128
  converge_by("delete domain:#{new_resource.domain} key:#{new_resource.key}") do
157
-
158
- cmd = defaults_modify_cmd
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
- action_class do
166
- #
167
- # The command used to write or delete delete values from domains
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
- cmd.concat([action.to_s, new_resource.domain, new_resource.key])
181
- cmd.concat(processed_value) if action == :write
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
- # convert the provided value into the format defaults expects
188
- #
189
- # @return [array] array of values starting with the type if applicable
190
- #
191
- def processed_value
192
- type = new_resource.type || value_type(new_resource.value)
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
- cmd_values.concat([new_resource.value])
149
+ value
206
150
  end
207
-
208
- cmd_values
209
151
  end
210
152
 
211
- #
212
- # defaults booleans on the CLI must be 'TRUE' or 'FALSE' so convert various inputs to that
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 true, false
236
- "bool"
237
- when Integer
238
- "int"
239
- when Float
240
- "float"
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
@@ -88,7 +88,7 @@ class Chef
88
88
  # @return [String]
89
89
  def registry_path
90
90
  { machine: "HKLM", user: "HKCU" }[new_resource.root] + \
91
- '\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run'
91
+ "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"
92
92
  end
93
93
  end
94
94
  end
@@ -38,7 +38,7 @@ class Chef
38
38
 
39
39
  property :full_users, Array,
40
40
  description: "Determines which users should have full access to the share.",
41
- default: ['BUILTIN\\administrators']
41
+ default: ["BUILTIN\\administrators"]
42
42
 
43
43
  property :change_users, Array,
44
44
  description: "Determines which users should have change access to the share.",
@@ -50,7 +50,7 @@ class Chef
50
50
 
51
51
  property :root, String,
52
52
  description: "The root from which to create the DFS tree. Defaults to C:\\DFSRoots.",
53
- default: 'C:\\DFSRoots'
53
+ default: "C:\\DFSRoots"
54
54
 
55
55
  action :create, description: "Creates the dfs namespace on the server." do
56
56
  directory file_path do
@@ -145,7 +145,7 @@ class Chef
145
145
  action :set, description: "Set Windows Update settings." do
146
146
  actual_day = convert_day(new_resource.scheduled_install_day)
147
147
 
148
- registry_key 'HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate' do
148
+ registry_key "HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate" do
149
149
  recursive true
150
150
  values [{
151
151
  name: "DisableOSUpgrade",
@@ -180,7 +180,7 @@ class Chef
180
180
  action :create
181
181
  end
182
182
 
183
- registry_key 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer' do
183
+ registry_key "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" do
184
184
  recursive true
185
185
  values [{
186
186
  name: "NoWindowsUpdate",
@@ -190,7 +190,7 @@ class Chef
190
190
  action :create
191
191
  end
192
192
 
193
- registry_key 'HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU' do
193
+ registry_key "HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU" do
194
194
  recursive true
195
195
  values [{
196
196
  name: "AUOptions",
data/lib/chef/resource.rb CHANGED
@@ -1508,7 +1508,7 @@ class Chef
1508
1508
  # @return Chef::CookbookVersion The cookbook in which this Resource was defined.
1509
1509
  #
1510
1510
  def cookbook_version
1511
- if cookbook_name
1511
+ if cookbook_name && cookbook_name != "@recipe_files"
1512
1512
  run_context.cookbook_collection[cookbook_name]
1513
1513
  end
1514
1514
  end