chef 11.14.0.alpha.4 → 11.14.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/CONTRIBUTING.md +0 -4
  2. data/README.md +1 -1
  3. data/distro/common/man/man1/chef-shell.1 +4 -4
  4. data/distro/common/man/man1/knife-bootstrap.1 +14 -11
  5. data/distro/common/man/man1/knife-client.1 +14 -11
  6. data/distro/common/man/man1/knife-configure.1 +7 -7
  7. data/distro/common/man/man1/knife-cookbook-site.1 +23 -23
  8. data/distro/common/man/man1/knife-cookbook.1 +23 -23
  9. data/distro/common/man/man1/knife-data-bag.1 +13 -13
  10. data/distro/common/man/man1/knife-delete.1 +9 -9
  11. data/distro/common/man/man1/knife-deps.1 +9 -9
  12. data/distro/common/man/man1/knife-diff.1 +10 -10
  13. data/distro/common/man/man1/knife-download.1 +9 -9
  14. data/distro/common/man/man1/knife-edit.1 +7 -7
  15. data/distro/common/man/man1/knife-environment.1 +10 -10
  16. data/distro/common/man/man1/knife-exec.1 +7 -7
  17. data/distro/common/man/man1/knife-index-rebuild.1 +1 -1
  18. data/distro/common/man/man1/knife-list.1 +12 -12
  19. data/distro/common/man/man1/knife-node.1 +12 -9
  20. data/distro/common/man/man1/knife-raw.1 +7 -7
  21. data/distro/common/man/man1/knife-recipe-list.1 +1 -1
  22. data/distro/common/man/man1/knife-role.1 +8 -8
  23. data/distro/common/man/man1/knife-search.1 +9 -9
  24. data/distro/common/man/man1/knife-serve.1 +109 -0
  25. data/distro/common/man/man1/knife-show.1 +8 -8
  26. data/distro/common/man/man1/knife-ssh.1 +9 -9
  27. data/distro/common/man/man1/knife-ssl-check.1 +9 -9
  28. data/distro/common/man/man1/knife-ssl-fetch.1 +10 -10
  29. data/distro/common/man/man1/knife-status.1 +9 -9
  30. data/distro/common/man/man1/knife-tag.1 +7 -7
  31. data/distro/common/man/man1/knife-upload.1 +10 -10
  32. data/distro/common/man/man1/knife-user.1 +9 -9
  33. data/distro/common/man/man1/knife-xargs.1 +7 -7
  34. data/distro/common/man/man1/knife.1 +118 -14
  35. data/distro/common/man/man8/chef-client.8 +13 -10
  36. data/distro/common/man/man8/chef-solo.8 +13 -14
  37. data/distro/common/markdown/man1/knife.mkd +1 -1
  38. data/lib/chef/application/knife.rb +1 -1
  39. data/lib/chef/application/windows_service.rb +0 -1
  40. data/lib/chef/chef_fs/file_system.rb +6 -2
  41. data/lib/chef/config.rb +3 -2
  42. data/lib/chef/config_fetcher.rb +1 -1
  43. data/lib/chef/cookbook/metadata.rb +20 -14
  44. data/lib/chef/cookbook/synchronizer.rb +24 -13
  45. data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
  46. data/lib/chef/encrypted_data_bag_item/encryptor.rb +2 -2
  47. data/lib/chef/exceptions.rb +1 -0
  48. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  49. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +1 -1
  50. data/lib/chef/http.rb +6 -1
  51. data/lib/chef/http/http_request.rb +9 -1
  52. data/lib/chef/http/simple.rb +2 -1
  53. data/lib/chef/json_compat.rb +5 -16
  54. data/lib/chef/knife/bootstrap.rb +2 -0
  55. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  56. data/lib/chef/knife/core/object_loader.rb +3 -1
  57. data/lib/chef/knife/ssh.rb +14 -7
  58. data/lib/chef/mixin/convert_to_class_name.rb +1 -0
  59. data/lib/chef/mixin/windows_architecture_helper.rb +24 -4
  60. data/lib/chef/platform/provider_mapping.rb +13 -0
  61. data/lib/chef/provider/env/windows.rb +3 -6
  62. data/lib/chef/provider/git.rb +1 -2
  63. data/lib/chef/provider/log.rb +15 -1
  64. data/lib/chef/provider/package/apt.rb +3 -3
  65. data/lib/chef/provider/package/dpkg.rb +35 -16
  66. data/lib/chef/provider/package/paludis.rb +91 -0
  67. data/lib/chef/provider/package/rpm.rb +3 -2
  68. data/lib/chef/provider/package/yum-dump.py +6 -6
  69. data/lib/chef/provider/package/yum.rb +2 -0
  70. data/lib/chef/provider/registry_key.rb +4 -5
  71. data/lib/chef/provider/remote_file/cache_control_data.rb +1 -1
  72. data/lib/chef/provider/service/solaris.rb +1 -1
  73. data/lib/chef/provider/service/upstart.rb +2 -1
  74. data/lib/chef/provider/service/windows.rb +37 -9
  75. data/lib/chef/provider/user/pw.rb +1 -1
  76. data/lib/chef/provider/user/useradd.rb +1 -1
  77. data/lib/chef/provider/windows_script.rb +2 -1
  78. data/lib/chef/providers.rb +1 -0
  79. data/lib/chef/resource.rb +10 -0
  80. data/lib/chef/resource/file.rb +0 -9
  81. data/lib/chef/resource/package.rb +14 -4
  82. data/lib/chef/resource/paludis_package.rb +33 -0
  83. data/lib/chef/resource/registry_key.rb +62 -3
  84. data/lib/chef/resource/service.rb +21 -4
  85. data/lib/chef/resource_reporter.rb +10 -0
  86. data/lib/chef/resources.rb +1 -0
  87. data/lib/chef/role.rb +14 -10
  88. data/lib/chef/shell.rb +8 -0
  89. data/lib/chef/shell/shell_session.rb +3 -3
  90. data/lib/chef/user.rb +12 -11
  91. data/lib/chef/util/selinux.rb +1 -1
  92. data/lib/chef/version.rb +1 -1
  93. data/lib/chef/version_constraint.rb +6 -5
  94. data/lib/chef/win32/api/process.rb +1 -0
  95. data/lib/chef/win32/api/system.rb +14 -0
  96. data/lib/chef/win32/error.rb +1 -1
  97. data/lib/chef/win32/security.rb +5 -5
  98. data/lib/chef/win32/version.rb +6 -2
  99. data/spec/data/trusted_certs/opscode.pem +57 -35
  100. data/spec/functional/application_spec.rb +2 -2
  101. data/spec/functional/resource/mount_spec.rb +3 -1
  102. data/spec/functional/shell_spec.rb +10 -0
  103. data/spec/functional/tiny_server_spec.rb +2 -2
  104. data/spec/support/chef_helpers.rb +1 -1
  105. data/spec/support/shared/functional/securable_resource.rb +11 -2
  106. data/spec/support/shared/functional/securable_resource_with_reporting.rb +13 -2
  107. data/spec/tiny_server.rb +1 -1
  108. data/spec/unit/config_spec.rb +5 -0
  109. data/spec/unit/cookbook/metadata_spec.rb +24 -0
  110. data/spec/unit/environment_spec.rb +6 -0
  111. data/spec/unit/http/http_request_spec.rb +91 -0
  112. data/spec/unit/http_spec.rb +23 -0
  113. data/spec/unit/knife/bootstrap_spec.rb +2 -2
  114. data/spec/unit/knife/ssh_spec.rb +7 -13
  115. data/spec/unit/knife_spec.rb +1 -1
  116. data/spec/unit/mixin/convert_to_class_name_spec.rb +4 -0
  117. data/spec/unit/provider/git_spec.rb +2 -2
  118. data/spec/unit/provider/log_spec.rb +18 -0
  119. data/spec/unit/provider/mount/solaris_spec.rb +3 -1
  120. data/spec/unit/provider/package/apt_spec.rb +85 -40
  121. data/spec/unit/provider/package/dpkg_spec.rb +24 -48
  122. data/spec/unit/provider/package/paludis_spec.rb +135 -0
  123. data/spec/unit/provider/package/rpm_spec.rb +40 -32
  124. data/spec/unit/provider/package/yum_spec.rb +11 -4
  125. data/spec/unit/provider/registry_key_spec.rb +67 -53
  126. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +10 -1
  127. data/spec/unit/provider/service/solaris_smf_service_spec.rb +23 -2
  128. data/spec/unit/provider/service/upstart_service_spec.rb +7 -0
  129. data/spec/unit/provider/service/windows_spec.rb +72 -0
  130. data/spec/unit/provider/user/pw_spec.rb +21 -4
  131. data/spec/unit/provider/user/useradd_spec.rb +10 -0
  132. data/spec/unit/resource/package_spec.rb +26 -18
  133. data/spec/unit/resource/registry_key_spec.rb +28 -0
  134. data/spec/unit/resource/service_spec.rb +14 -0
  135. data/spec/unit/resource_reporter_spec.rb +37 -12
  136. data/spec/unit/resource_spec.rb +41 -6
  137. data/spec/unit/rest_spec.rb +2 -2
  138. data/spec/unit/role_spec.rb +46 -28
  139. data/spec/unit/shell/shell_session_spec.rb +42 -2
  140. data/spec/unit/shell_spec.rb +1 -1
  141. data/spec/unit/user_spec.rb +12 -0
  142. data/spec/unit/util/selinux_spec.rb +4 -4
  143. data/spec/unit/version_constraint_spec.rb +14 -2
  144. metadata +195 -161
  145. checksums.yaml +0 -7
@@ -704,6 +704,8 @@ class Chef
704
704
  opts << " #{@extra_repo_control}"
705
705
  end
706
706
 
707
+ opts << " --yum-lock-timeout #{Chef::Config[:yum_lock_timeout]}"
708
+
707
709
  one_line = false
708
710
  error = nil
709
711
 
@@ -54,7 +54,7 @@ class Chef
54
54
  if registry.key_exists?(@new_resource.key)
55
55
  @current_resource.values(registry.get_values(@new_resource.key))
56
56
  end
57
- values_to_hash(@current_resource.values)
57
+ values_to_hash(@current_resource.unscrubbed_values)
58
58
  @current_resource
59
59
  end
60
60
 
@@ -99,7 +99,7 @@ class Chef
99
99
  registry.create_key(@new_resource.key, @new_resource.recursive)
100
100
  end
101
101
  end
102
- @new_resource.values.each do |value|
102
+ @new_resource.unscrubbed_values.each do |value|
103
103
  if @name_hash.has_key?(value[:name])
104
104
  current_value = @name_hash[value[:name]]
105
105
  unless current_value[:type] == value[:type] && current_value[:data] == value[:data]
@@ -121,7 +121,7 @@ class Chef
121
121
  registry.create_key(@new_resource.key, @new_resource.recursive)
122
122
  end
123
123
  end
124
- @new_resource.values.each do |value|
124
+ @new_resource.unscrubbed_values.each do |value|
125
125
  unless @name_hash.has_key?(value[:name])
126
126
  converge_by("create value #{value}") do
127
127
  registry.set_value(@new_resource.key, value)
@@ -132,7 +132,7 @@ class Chef
132
132
 
133
133
  def action_delete
134
134
  if registry.key_exists?(@new_resource.key)
135
- @new_resource.values.each do |value|
135
+ @new_resource.unscrubbed_values.each do |value|
136
136
  if @name_hash.has_key?(value[:name])
137
137
  converge_by("delete value #{value}") do
138
138
  registry.delete_value(@new_resource.key, value)
@@ -153,4 +153,3 @@ class Chef
153
153
  end
154
154
  end
155
155
  end
156
-
@@ -140,7 +140,7 @@ class Chef
140
140
 
141
141
  def load_data
142
142
  Chef::JSONCompat.from_json(load_json_data)
143
- rescue Chef::Exceptions::FileNotFound, Yajl::ParseError
143
+ rescue Chef::Exceptions::FileNotFound, FFI_Yajl::ParseError, JSON::ParserError
144
144
  false
145
145
  end
146
146
 
@@ -69,7 +69,7 @@ class Chef
69
69
  end
70
70
 
71
71
  def service_status
72
- status = shell_out!("#{@status_command} #{@current_resource.service_name}")
72
+ status = shell_out!("#{@status_command} #{@current_resource.service_name}", :returns => [0, 1])
73
73
  status.stdout.each_line do |line|
74
74
  case line
75
75
  when /state\s+online/
@@ -43,7 +43,8 @@ class Chef
43
43
 
44
44
  run_context.node
45
45
 
46
- @job = @new_resource.service_name
46
+ # dup so we can mutate @job
47
+ @job = @new_resource.service_name.dup
47
48
 
48
49
  if @new_resource.parameters
49
50
  @new_resource.parameters.each do |key, value|
@@ -28,11 +28,21 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
28
28
 
29
29
  include Chef::Mixin::ShellOut
30
30
 
31
- RUNNING = 'running'
32
- STOPPED = 'stopped'
31
+ #Win32::Service.get_start_type
33
32
  AUTO_START = 'auto start'
34
33
  DISABLED = 'disabled'
35
34
 
35
+ #Win32::Service.get_current_state
36
+ RUNNING = 'running'
37
+ STOPPED = 'stopped'
38
+ CONTINUE_PENDING = 'continue pending'
39
+ PAUSE_PENDING = 'pause pending'
40
+ PAUSED = 'paused'
41
+ START_PENDING = 'start pending'
42
+ STOP_PENDING = 'stop pending'
43
+
44
+ TIMEOUT = 60
45
+
36
46
  def whyrun_supported?
37
47
  false
38
48
  end
@@ -49,9 +59,15 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
49
59
 
50
60
  def start_service
51
61
  if Win32::Service.exists?(@new_resource.service_name)
52
- if current_state == RUNNING
62
+ state = current_state
63
+ if state == RUNNING
53
64
  Chef::Log.debug "#{@new_resource} already started - nothing to do"
54
- else
65
+ elsif state == START_PENDING
66
+ Chef::Log.debug "#{@new_resource} already sent start signal - waiting for start"
67
+ spawn_command_thread do
68
+ wait_for_state(RUNNING)
69
+ end
70
+ elsif state == STOPPED
55
71
  if @new_resource.start_command
56
72
  Chef::Log.debug "#{@new_resource} starting service using the given start_command"
57
73
  shell_out!(@new_resource.start_command)
@@ -62,15 +78,18 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
62
78
  end
63
79
  end
64
80
  @new_resource.updated_by_last_action(true)
81
+ else
82
+ raise Chef::Exceptions::Service, "Service #{@new_resource} can't be started from state [#{state}]"
65
83
  end
66
84
  else
67
- Chef::Log.debug "#{@new_resource} does not exist - nothing to do"
85
+ Chef::Log.debug "#{@new_resource} does not exist - nothing to do"
68
86
  end
69
87
  end
70
88
 
71
89
  def stop_service
72
90
  if Win32::Service.exists?(@new_resource.service_name)
73
- if current_state == RUNNING
91
+ state = current_state
92
+ if state == RUNNING
74
93
  if @new_resource.stop_command
75
94
  Chef::Log.debug "#{@new_resource} stopping service using the given stop_command"
76
95
  shell_out!(@new_resource.stop_command)
@@ -81,8 +100,15 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
81
100
  end
82
101
  end
83
102
  @new_resource.updated_by_last_action(true)
84
- else
103
+ elsif state == STOPPED
85
104
  Chef::Log.debug "#{@new_resource} already stopped - nothing to do"
105
+ elsif state == STOP_PENDING
106
+ Chef::Log.debug "#{@new_resource} already sent stop signal - waiting for stop"
107
+ spawn_command_thread do
108
+ wait_for_state(STOPPED)
109
+ end
110
+ else
111
+ raise Chef::Exceptions::Service, "Service #{@new_resource} can't be stopped from state [#{state}]"
86
112
  end
87
113
  else
88
114
  Chef::Log.debug "#{@new_resource} does not exist - nothing to do"
@@ -151,12 +177,14 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
151
177
  sleep 1 until current_state == desired_state
152
178
  end
153
179
 
154
- # There ain't no party like a thread party...
155
180
  def spawn_command_thread
156
181
  worker = Thread.new do
157
182
  yield
158
183
  end
159
- Timeout.timeout(60) do
184
+
185
+ resource_timeout = @new_resource.timeout if @new_resource.timeout
186
+ resource_timeout ||= TIMEOUT
187
+ Timeout.timeout(resource_timeout) do
160
188
  worker.join
161
189
  end
162
190
  end
@@ -93,7 +93,7 @@ class Chef
93
93
  end
94
94
 
95
95
  def modify_password
96
- if @current_resource.password != @new_resource.password
96
+ if (not @new_resource.password.nil?) && (@current_resource.password != @new_resource.password)
97
97
  Chef::Log.debug("#{new_resource} updating password")
98
98
  command = "pw usermod #{@new_resource.username} -H 0"
99
99
  status = popen4(command, :waitlast => true) do |pid, stdin, stdout, stderr|
@@ -38,7 +38,7 @@ class Chef
38
38
  end
39
39
 
40
40
  def manage_user
41
- if universal_options != ""
41
+ unless universal_options.empty?
42
42
  command = compile_command("usermod") do |u|
43
43
  u.concat(universal_options)
44
44
  end
@@ -36,7 +36,8 @@ class Chef
36
36
 
37
37
  @is_wow64 = wow64_architecture_override_required?(run_context.node, target_architecture)
38
38
 
39
- if ( target_architecture == :i386 ) && ! is_i386_windows_process?
39
+ # if the user wants to run the script 32 bit && we are on a 64bit windows system && we are running a 64bit ruby ==> fail
40
+ if ( target_architecture == :i386 ) && node_windows_architecture(run_context.node) == :x86_64 && !is_i386_process_on_x86_64_windows?
40
41
  raise Chef::Exceptions::Win32ArchitectureIncorrect,
41
42
  "Support for the i386 architecture from a 64-bit Ruby runtime is not yet implemented"
42
43
  end
@@ -62,6 +62,7 @@ require 'chef/provider/package/ips'
62
62
  require 'chef/provider/package/macports'
63
63
  require 'chef/provider/package/pacman'
64
64
  require 'chef/provider/package/portage'
65
+ require 'chef/provider/package/paludis'
65
66
  require 'chef/provider/package/rpm'
66
67
  require 'chef/provider/package/rubygems'
67
68
  require 'chef/provider/package/yum'
@@ -253,6 +253,7 @@ F
253
253
  @source_line = nil
254
254
  @guard_interpreter = :default
255
255
  @elapsed_time = 0
256
+ @sensitive = false
256
257
 
257
258
  @node = run_context ? deprecated_ivar(run_context.node, :node, :warn) : nil
258
259
  end
@@ -400,6 +401,14 @@ F
400
401
  )
401
402
  end
402
403
 
404
+ def sensitive(arg=nil)
405
+ set_or_return(
406
+ :sensitive,
407
+ arg,
408
+ :kind_of => [ TrueClass, FalseClass ]
409
+ )
410
+ end
411
+
403
412
  def epic_fail(arg=nil)
404
413
  ignore_failure(arg)
405
414
  end
@@ -494,6 +503,7 @@ F
494
503
  end
495
504
 
496
505
  def to_text
506
+ return "suppressed sensitive resource output" if sensitive
497
507
  ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS
498
508
  text = "# Declared in #{@source_line}\n\n"
499
509
  text << self.class.dsl_name + "(\"#{name}\") do\n"
@@ -52,7 +52,6 @@ class Chef
52
52
  @force_unlink = false
53
53
  @manage_symlink_source = nil
54
54
  @diff = nil
55
- @sensitive = false
56
55
  end
57
56
 
58
57
  def content(arg=nil)
@@ -118,14 +117,6 @@ class Chef
118
117
  :kind_of => [ TrueClass, FalseClass ]
119
118
  )
120
119
  end
121
-
122
- def sensitive(arg=nil)
123
- set_or_return(
124
- :sensitive,
125
- arg,
126
- :kind_of => [ TrueClass, FalseClass ]
127
- )
128
- end
129
120
  end
130
121
  end
131
122
  end
@@ -39,6 +39,7 @@ class Chef
39
39
  @response_file_variables = Hash.new
40
40
  @source = nil
41
41
  @version = nil
42
+ @timeout = 900
42
43
  end
43
44
 
44
45
  def package_name(arg=nil)
@@ -83,11 +84,20 @@ class Chef
83
84
 
84
85
  def options(arg=nil)
85
86
  set_or_return(
86
- :options,
87
- arg,
88
- :kind_of => [ String ]
89
- )
87
+ :options,
88
+ arg,
89
+ :kind_of => [ String ]
90
+ )
90
91
  end
92
+
93
+ def timeout(arg=nil)
94
+ set_or_return(
95
+ :timeout,
96
+ arg,
97
+ :kind_of => [String, Integer]
98
+ )
99
+ end
100
+
91
101
  end
92
102
  end
93
103
  end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Author:: Vasiliy Tolstov (<v.tolstov@selfip.ru>)
3
+ # Copyright:: Copyright (c) 2014 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/resource/package'
20
+ require 'chef/provider/package/paludis'
21
+
22
+ class Chef
23
+ class Resource
24
+ class PaludisPackage < Chef::Resource::Package
25
+ def initialize(name, run_context=nil)
26
+ super(name, run_context)
27
+ @resource_name = :paludis_package
28
+ @provider = Chef::Provider::Package::Paludis
29
+ @allowed_actions = [ :install, :remove, :upgrade ]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -17,6 +17,7 @@
17
17
  #
18
18
  require 'chef/provider/registry_key'
19
19
  require 'chef/resource'
20
+ require 'chef/digester'
20
21
 
21
22
  class Chef
22
23
  class Resource
@@ -25,6 +26,37 @@ class Chef
25
26
  identity_attr :key
26
27
  state_attrs :values
27
28
 
29
+ # Some registry key data types may not be safely reported as json.
30
+ # Example (CHEF-5323):
31
+ #
32
+ # registry_key 'HKEY_CURRENT_USER\\ChefTest2014' do
33
+ # values [{
34
+ # :name => "ValueWithBadData",
35
+ # :type => :binary,
36
+ # :data => 255.chr * 1
37
+ # }]
38
+ # action :create
39
+ # end
40
+ #
41
+ # will raise Encoding::UndefinedConversionError: "\xFF" from ASCII-8BIT to UTF-8.
42
+ #
43
+ # To avoid sending data that cannot be nicely converted for json, we have
44
+ # the values method return "safe" data if the data type is "unsafe". Known "unsafe"
45
+ # data types are :binary, :dword, :dword-big-endian, and :qword. If other
46
+ # criteria generate data that cannot reliably be sent as json, add that criteria
47
+ # to the needs_checksum? method. When unsafe data is detected, the values method
48
+ # returns an md5 checksum of the listed data.
49
+ #
50
+ # :unscrubbed_values returns the values exactly as provided in the resource (i.e.,
51
+ # data is not checksummed, regardless of the data type/"unsafe" criteria).
52
+ #
53
+ # Future:
54
+ # If we have conflicts with other resources reporting json incompatible state, we
55
+ # may want to extend the state_attrs API with the ability to rename POST'd attrs.
56
+ #
57
+ # See lib/chef/resource_reporter.rb for more information.
58
+ attr_reader :unscrubbed_values
59
+
28
60
  def initialize(name, run_context=nil)
29
61
  super
30
62
  @resource_name = :registry_key
@@ -32,7 +64,7 @@ class Chef
32
64
  @architecture = :machine
33
65
  @recursive = false
34
66
  @key = name
35
- @values = []
67
+ @values, @unscrubbed_values = [], []
36
68
  @allowed_actions.push(:create, :create_if_missing, :delete, :delete_key)
37
69
  end
38
70
 
@@ -43,6 +75,7 @@ class Chef
43
75
  :kind_of => String
44
76
  )
45
77
  end
78
+
46
79
  def values(arg=nil)
47
80
  if not arg.nil?
48
81
  if arg.is_a?(Hash)
@@ -52,6 +85,7 @@ class Chef
52
85
  else
53
86
  raise ArgumentError, "Bad type for RegistryKey resource, use Hash or Array"
54
87
  end
88
+
55
89
  @values.each do |v|
56
90
  raise ArgumentError, "Missing name key in RegistryKey values hash" unless v.has_key?(:name)
57
91
  raise ArgumentError, "Missing type key in RegistryKey values hash" unless v.has_key?(:type)
@@ -62,10 +96,12 @@ class Chef
62
96
  raise ArgumentError, "Type of name => #{v[:name]} should be string" unless v[:name].is_a?(String)
63
97
  raise Argument Error "Type of type => #{v[:name]} should be symbol" unless v[:type].is_a?(Symbol)
64
98
  end
65
- elsif self.instance_variable_defined?(:@values) == true
66
- @values
99
+ @unscrubbed_values = @values
100
+ elsif self.instance_variable_defined?(:@values)
101
+ scrub_values(@values)
67
102
  end
68
103
  end
104
+
69
105
  def recursive(arg=nil)
70
106
  set_or_return(
71
107
  :recursive,
@@ -73,6 +109,7 @@ class Chef
73
109
  :kind_of => [TrueClass, FalseClass]
74
110
  )
75
111
  end
112
+
76
113
  def architecture(arg=nil)
77
114
  set_or_return(
78
115
  :architecture,
@@ -81,6 +118,28 @@ class Chef
81
118
  )
82
119
  end
83
120
 
121
+ private
122
+
123
+ def scrub_values(values)
124
+ scrubbed = []
125
+ values.each do |value|
126
+ scrubbed_value = value.dup
127
+ if needs_checksum?(scrubbed_value)
128
+ data_io = StringIO.new(scrubbed_value[:data].to_s)
129
+ scrubbed_value[:data] = Chef::Digester.instance.generate_md5_checksum(data_io)
130
+ end
131
+ scrubbed << scrubbed_value
132
+ end
133
+ scrubbed
134
+ end
135
+
136
+ # Some data types may raise errors when sent as json. Returns true if this
137
+ # value's data may need to be converted to a checksum.
138
+ def needs_checksum?(value)
139
+ unsafe_types = [:binary, :dword, :dword_big_endian, :qword]
140
+ unsafe_types.include?(value[:type])
141
+ end
142
+
84
143
  end
85
144
  end
86
145
  end