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.
- data/CONTRIBUTING.md +0 -4
- data/README.md +1 -1
- data/distro/common/man/man1/chef-shell.1 +4 -4
- data/distro/common/man/man1/knife-bootstrap.1 +14 -11
- data/distro/common/man/man1/knife-client.1 +14 -11
- data/distro/common/man/man1/knife-configure.1 +7 -7
- data/distro/common/man/man1/knife-cookbook-site.1 +23 -23
- data/distro/common/man/man1/knife-cookbook.1 +23 -23
- data/distro/common/man/man1/knife-data-bag.1 +13 -13
- data/distro/common/man/man1/knife-delete.1 +9 -9
- data/distro/common/man/man1/knife-deps.1 +9 -9
- data/distro/common/man/man1/knife-diff.1 +10 -10
- data/distro/common/man/man1/knife-download.1 +9 -9
- data/distro/common/man/man1/knife-edit.1 +7 -7
- data/distro/common/man/man1/knife-environment.1 +10 -10
- data/distro/common/man/man1/knife-exec.1 +7 -7
- data/distro/common/man/man1/knife-index-rebuild.1 +1 -1
- data/distro/common/man/man1/knife-list.1 +12 -12
- data/distro/common/man/man1/knife-node.1 +12 -9
- data/distro/common/man/man1/knife-raw.1 +7 -7
- data/distro/common/man/man1/knife-recipe-list.1 +1 -1
- data/distro/common/man/man1/knife-role.1 +8 -8
- data/distro/common/man/man1/knife-search.1 +9 -9
- data/distro/common/man/man1/knife-serve.1 +109 -0
- data/distro/common/man/man1/knife-show.1 +8 -8
- data/distro/common/man/man1/knife-ssh.1 +9 -9
- data/distro/common/man/man1/knife-ssl-check.1 +9 -9
- data/distro/common/man/man1/knife-ssl-fetch.1 +10 -10
- data/distro/common/man/man1/knife-status.1 +9 -9
- data/distro/common/man/man1/knife-tag.1 +7 -7
- data/distro/common/man/man1/knife-upload.1 +10 -10
- data/distro/common/man/man1/knife-user.1 +9 -9
- data/distro/common/man/man1/knife-xargs.1 +7 -7
- data/distro/common/man/man1/knife.1 +118 -14
- data/distro/common/man/man8/chef-client.8 +13 -10
- data/distro/common/man/man8/chef-solo.8 +13 -14
- data/distro/common/markdown/man1/knife.mkd +1 -1
- data/lib/chef/application/knife.rb +1 -1
- data/lib/chef/application/windows_service.rb +0 -1
- data/lib/chef/chef_fs/file_system.rb +6 -2
- data/lib/chef/config.rb +3 -2
- data/lib/chef/config_fetcher.rb +1 -1
- data/lib/chef/cookbook/metadata.rb +20 -14
- data/lib/chef/cookbook/synchronizer.rb +24 -13
- data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
- data/lib/chef/encrypted_data_bag_item/encryptor.rb +2 -2
- data/lib/chef/exceptions.rb +1 -0
- data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
- data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +1 -1
- data/lib/chef/http.rb +6 -1
- data/lib/chef/http/http_request.rb +9 -1
- data/lib/chef/http/simple.rb +2 -1
- data/lib/chef/json_compat.rb +5 -16
- data/lib/chef/knife/bootstrap.rb +2 -0
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
- data/lib/chef/knife/core/object_loader.rb +3 -1
- data/lib/chef/knife/ssh.rb +14 -7
- data/lib/chef/mixin/convert_to_class_name.rb +1 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +24 -4
- data/lib/chef/platform/provider_mapping.rb +13 -0
- data/lib/chef/provider/env/windows.rb +3 -6
- data/lib/chef/provider/git.rb +1 -2
- data/lib/chef/provider/log.rb +15 -1
- data/lib/chef/provider/package/apt.rb +3 -3
- data/lib/chef/provider/package/dpkg.rb +35 -16
- data/lib/chef/provider/package/paludis.rb +91 -0
- data/lib/chef/provider/package/rpm.rb +3 -2
- data/lib/chef/provider/package/yum-dump.py +6 -6
- data/lib/chef/provider/package/yum.rb +2 -0
- data/lib/chef/provider/registry_key.rb +4 -5
- data/lib/chef/provider/remote_file/cache_control_data.rb +1 -1
- data/lib/chef/provider/service/solaris.rb +1 -1
- data/lib/chef/provider/service/upstart.rb +2 -1
- data/lib/chef/provider/service/windows.rb +37 -9
- data/lib/chef/provider/user/pw.rb +1 -1
- data/lib/chef/provider/user/useradd.rb +1 -1
- data/lib/chef/provider/windows_script.rb +2 -1
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +10 -0
- data/lib/chef/resource/file.rb +0 -9
- data/lib/chef/resource/package.rb +14 -4
- data/lib/chef/resource/paludis_package.rb +33 -0
- data/lib/chef/resource/registry_key.rb +62 -3
- data/lib/chef/resource/service.rb +21 -4
- data/lib/chef/resource_reporter.rb +10 -0
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/role.rb +14 -10
- data/lib/chef/shell.rb +8 -0
- data/lib/chef/shell/shell_session.rb +3 -3
- data/lib/chef/user.rb +12 -11
- data/lib/chef/util/selinux.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/lib/chef/version_constraint.rb +6 -5
- data/lib/chef/win32/api/process.rb +1 -0
- data/lib/chef/win32/api/system.rb +14 -0
- data/lib/chef/win32/error.rb +1 -1
- data/lib/chef/win32/security.rb +5 -5
- data/lib/chef/win32/version.rb +6 -2
- data/spec/data/trusted_certs/opscode.pem +57 -35
- data/spec/functional/application_spec.rb +2 -2
- data/spec/functional/resource/mount_spec.rb +3 -1
- data/spec/functional/shell_spec.rb +10 -0
- data/spec/functional/tiny_server_spec.rb +2 -2
- data/spec/support/chef_helpers.rb +1 -1
- data/spec/support/shared/functional/securable_resource.rb +11 -2
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +13 -2
- data/spec/tiny_server.rb +1 -1
- data/spec/unit/config_spec.rb +5 -0
- data/spec/unit/cookbook/metadata_spec.rb +24 -0
- data/spec/unit/environment_spec.rb +6 -0
- data/spec/unit/http/http_request_spec.rb +91 -0
- data/spec/unit/http_spec.rb +23 -0
- data/spec/unit/knife/bootstrap_spec.rb +2 -2
- data/spec/unit/knife/ssh_spec.rb +7 -13
- data/spec/unit/knife_spec.rb +1 -1
- data/spec/unit/mixin/convert_to_class_name_spec.rb +4 -0
- data/spec/unit/provider/git_spec.rb +2 -2
- data/spec/unit/provider/log_spec.rb +18 -0
- data/spec/unit/provider/mount/solaris_spec.rb +3 -1
- data/spec/unit/provider/package/apt_spec.rb +85 -40
- data/spec/unit/provider/package/dpkg_spec.rb +24 -48
- data/spec/unit/provider/package/paludis_spec.rb +135 -0
- data/spec/unit/provider/package/rpm_spec.rb +40 -32
- data/spec/unit/provider/package/yum_spec.rb +11 -4
- data/spec/unit/provider/registry_key_spec.rb +67 -53
- data/spec/unit/provider/remote_file/cache_control_data_spec.rb +10 -1
- data/spec/unit/provider/service/solaris_smf_service_spec.rb +23 -2
- data/spec/unit/provider/service/upstart_service_spec.rb +7 -0
- data/spec/unit/provider/service/windows_spec.rb +72 -0
- data/spec/unit/provider/user/pw_spec.rb +21 -4
- data/spec/unit/provider/user/useradd_spec.rb +10 -0
- data/spec/unit/resource/package_spec.rb +26 -18
- data/spec/unit/resource/registry_key_spec.rb +28 -0
- data/spec/unit/resource/service_spec.rb +14 -0
- data/spec/unit/resource_reporter_spec.rb +37 -12
- data/spec/unit/resource_spec.rb +41 -6
- data/spec/unit/rest_spec.rb +2 -2
- data/spec/unit/role_spec.rb +46 -28
- data/spec/unit/shell/shell_session_spec.rb +42 -2
- data/spec/unit/shell_spec.rb +1 -1
- data/spec/unit/user_spec.rb +12 -0
- data/spec/unit/util/selinux_spec.rb +4 -4
- data/spec/unit/version_constraint_spec.rb +14 -2
- metadata +195 -161
- checksums.yaml +0 -7
@@ -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.
|
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.
|
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.
|
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.
|
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
|
-
|
@@ -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/
|
@@ -28,11 +28,21 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
|
|
28
28
|
|
29
29
|
include Chef::Mixin::ShellOut
|
30
30
|
|
31
|
-
|
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
|
-
|
62
|
+
state = current_state
|
63
|
+
if state == RUNNING
|
53
64
|
Chef::Log.debug "#{@new_resource} already started - nothing to do"
|
54
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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|
|
@@ -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
|
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
|
data/lib/chef/providers.rb
CHANGED
@@ -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'
|
data/lib/chef/resource.rb
CHANGED
@@ -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"
|
data/lib/chef/resource/file.rb
CHANGED
@@ -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
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
66
|
-
|
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
|