chef 17.6.18-universal-mingw32 → 17.7.22-universal-mingw32

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: 0ff701d08b25d18128b8e0b6180c5fa376fb3016e99f35530cb56de54fa570ce
4
- data.tar.gz: db08c621aa2c52c80ff0528ff2ab7df3eff56b40ad9f1aa0813652835239b220
3
+ metadata.gz: de3500fef9fe640bfe7197594dcf426e223aa7f2780c7672abad2f307596236a
4
+ data.tar.gz: 4b30b19efeea5d20d3b039dd2a04e8a1b478750676961a92d25f2e5041c5cac6
5
5
  SHA512:
6
- metadata.gz: 3f570c574fdee1879e1db8e882239d1d09474715ef315769f7769d295b6e74d91f8cd5f207e4eb298f32ae96efdcb51c650450d1dc0d895388ae851d4a0047f5
7
- data.tar.gz: 1d1ca95e861d92dffba948cbd0fb9fcdeee94b98c851f2fe015bd4d472387a7c276f04716b67f72124b31b2af092755d14d6eb2fc16f214c12726aa233d41679
6
+ metadata.gz: 203a3046e662b1ecd6584e6d82284da42053787cdc133dba3fc859c642008d16f82a58f3ee97e75621cca97cb8d2d3f246927905de54697b1729f5c52b4c7d90
7
+ data.tar.gz: 6b4faa047fdfe94f1223716980e5399e8a3343eb9d00305d65e05414a8957f1ba42fcf29b327123aff5b293f28c3b86cb92992ea2961811a25ddb1d31898bb62
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