chef 0.10.8 → 0.10.10.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data/distro/arch/etc/rc.d/chef-client +15 -1
  2. data/distro/common/html/chef-client.8.html +4 -4
  3. data/distro/common/html/chef-expander.8.html +4 -4
  4. data/distro/common/html/chef-expanderctl.8.html +4 -4
  5. data/distro/common/html/chef-server-webui.8.html +4 -4
  6. data/distro/common/html/chef-server.8.html +4 -4
  7. data/distro/common/html/chef-solo.8.html +4 -4
  8. data/distro/common/html/chef-solr.8.html +4 -4
  9. data/distro/common/html/knife-bootstrap.1.html +6 -10
  10. data/distro/common/html/knife-client.1.html +4 -4
  11. data/distro/common/html/knife-configure.1.html +4 -4
  12. data/distro/common/html/knife-cookbook-site.1.html +6 -6
  13. data/distro/common/html/knife-cookbook.1.html +4 -4
  14. data/distro/common/html/knife-data-bag.1.html +4 -4
  15. data/distro/common/html/knife-environment.1.html +4 -4
  16. data/distro/common/html/knife-exec.1.html +4 -4
  17. data/distro/common/html/knife-index.1.html +4 -4
  18. data/distro/common/html/knife-node.1.html +5 -5
  19. data/distro/common/html/knife-role.1.html +4 -4
  20. data/distro/common/html/knife-search.1.html +4 -4
  21. data/distro/common/html/knife-ssh.1.html +5 -6
  22. data/distro/common/html/knife-status.1.html +4 -4
  23. data/distro/common/html/knife-tag.1.html +4 -4
  24. data/distro/common/html/knife.1.html +7 -8
  25. data/distro/common/html/shef.1.html +4 -4
  26. data/distro/common/man/man1/knife-bootstrap.1 +4 -4
  27. data/distro/common/man/man1/knife-client.1 +1 -1
  28. data/distro/common/man/man1/knife-configure.1 +1 -1
  29. data/distro/common/man/man1/knife-cookbook-site.1 +4 -4
  30. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  31. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  32. data/distro/common/man/man1/knife-environment.1 +1 -1
  33. data/distro/common/man/man1/knife-exec.1 +1 -1
  34. data/distro/common/man/man1/knife-index.1 +1 -1
  35. data/distro/common/man/man1/knife-node.1 +2 -2
  36. data/distro/common/man/man1/knife-role.1 +1 -1
  37. data/distro/common/man/man1/knife-search.1 +1 -1
  38. data/distro/common/man/man1/knife-ssh.1 +3 -7
  39. data/distro/common/man/man1/knife-status.1 +1 -1
  40. data/distro/common/man/man1/knife-tag.1 +1 -1
  41. data/distro/common/man/man1/knife.1 +5 -9
  42. data/distro/common/man/man1/shef.1 +1 -1
  43. data/distro/common/man/man8/chef-client.8 +1 -1
  44. data/distro/common/man/man8/chef-expander.8 +1 -1
  45. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  46. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  47. data/distro/common/man/man8/chef-server.8 +1 -1
  48. data/distro/common/man/man8/chef-solo.8 +1 -1
  49. data/distro/common/man/man8/chef-solr.8 +1 -1
  50. data/distro/common/markdown/man1/knife-bootstrap.mkd +3 -7
  51. data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
  52. data/distro/common/markdown/man1/knife-node.mkd +2 -2
  53. data/distro/common/markdown/man1/knife-ssh.mkd +2 -5
  54. data/distro/common/markdown/man1/knife.mkd +7 -9
  55. data/distro/debian/etc/init.d/chef-client +22 -1
  56. data/distro/redhat/etc/init.d/chef-client +12 -1
  57. data/distro/windows/service_manager.rb +164 -0
  58. data/lib/chef/application.rb +12 -6
  59. data/lib/chef/application/client.rb +4 -3
  60. data/lib/chef/application/knife.rb +7 -12
  61. data/lib/chef/application/solo.rb +2 -1
  62. data/lib/chef/application/windows_service.rb +224 -0
  63. data/lib/chef/checksum_cache.rb +1 -0
  64. data/lib/chef/client.rb +3 -16
  65. data/lib/chef/config.rb +42 -13
  66. data/lib/chef/cookbook/metadata.rb +1 -1
  67. data/lib/chef/cookbook/syntax_check.rb +2 -2
  68. data/lib/chef/cookbook_version.rb +5 -0
  69. data/lib/chef/daemon.rb +1 -1
  70. data/lib/chef/exceptions.rb +7 -1
  71. data/lib/chef/file_access_control.rb +13 -87
  72. data/lib/chef/file_access_control/unix.rb +119 -0
  73. data/lib/chef/file_access_control/windows.rb +257 -0
  74. data/lib/chef/handler/json_file.rb +7 -1
  75. data/lib/chef/knife.rb +10 -16
  76. data/lib/chef/knife/bootstrap.rb +15 -8
  77. data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
  78. data/lib/chef/knife/bootstrap/chef-full.erb +59 -0
  79. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -0
  80. data/lib/chef/knife/configure.rb +2 -2
  81. data/lib/chef/knife/cookbook_site_download.rb +60 -21
  82. data/lib/chef/knife/cookbook_site_install.rb +16 -21
  83. data/lib/chef/knife/cookbook_upload.rb +77 -48
  84. data/lib/chef/knife/core/bootstrap_context.rb +3 -1
  85. data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
  86. data/lib/chef/knife/core/node_editor.rb +1 -1
  87. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  88. data/lib/chef/knife/core/ui.rb +3 -2
  89. data/lib/chef/knife/help_topics.rb +1 -1
  90. data/lib/chef/knife/node_run_list_add.rb +14 -6
  91. data/lib/chef/knife/node_run_list_remove.rb +3 -3
  92. data/lib/chef/knife/ssh.rb +32 -13
  93. data/lib/chef/mash.rb +14 -0
  94. data/lib/chef/mixin/command.rb +1 -0
  95. data/lib/chef/mixin/command/unix.rb +5 -0
  96. data/lib/chef/mixin/convert_to_class_name.rb +2 -0
  97. data/lib/chef/mixin/deep_merge.rb +40 -18
  98. data/lib/chef/mixin/enforce_ownership_and_permissions.rb +39 -0
  99. data/lib/chef/mixin/language.rb +89 -3
  100. data/lib/chef/mixin/language_include_recipe.rb +8 -4
  101. data/lib/chef/mixin/path_sanity.rb +67 -0
  102. data/lib/chef/mixin/recipe_definition_dsl_core.rb +19 -11
  103. data/lib/chef/mixin/securable.rb +152 -0
  104. data/lib/chef/mixin/shell_out.rb +1 -1
  105. data/lib/chef/mixin/template.rb +8 -3
  106. data/lib/chef/mixins.rb +3 -0
  107. data/lib/chef/monkey_patches/moneta.rb +50 -0
  108. data/lib/chef/monkey_patches/string.rb +1 -1
  109. data/lib/chef/node.rb +2 -1
  110. data/lib/chef/platform.rb +34 -0
  111. data/lib/chef/provider.rb +23 -21
  112. data/lib/chef/provider/cron.rb +17 -12
  113. data/lib/chef/provider/cron/solaris.rb +6 -18
  114. data/lib/chef/provider/deploy.rb +14 -15
  115. data/lib/chef/provider/deploy/timestamped.rb +0 -1
  116. data/lib/chef/provider/directory.rb +1 -3
  117. data/lib/chef/provider/execute.rb +2 -2
  118. data/lib/chef/provider/file.rb +1 -75
  119. data/lib/chef/provider/git.rb +11 -9
  120. data/lib/chef/provider/group/gpasswd.rb +14 -9
  121. data/lib/chef/provider/link.rb +28 -59
  122. data/lib/chef/provider/mdadm.rb +2 -2
  123. data/lib/chef/provider/mount/mount.rb +1 -1
  124. data/lib/chef/provider/package.rb +10 -6
  125. data/lib/chef/provider/package/apt.rb +3 -1
  126. data/lib/chef/provider/package/dpkg.rb +1 -1
  127. data/lib/chef/provider/package/portage.rb +6 -3
  128. data/lib/chef/provider/package/rubygems.rb +75 -6
  129. data/lib/chef/provider/package/smartos.rb +84 -0
  130. data/lib/chef/provider/package/yum-dump.py +3 -2
  131. data/lib/chef/provider/package/yum.rb +51 -10
  132. data/lib/chef/provider/remote_directory.rb +24 -3
  133. data/lib/chef/provider/remote_file.rb +0 -6
  134. data/lib/chef/provider/route.rb +3 -3
  135. data/lib/chef/provider/service/debian.rb +2 -2
  136. data/lib/chef/provider/service/freebsd.rb +1 -1
  137. data/lib/chef/provider/service/macosx.rb +125 -0
  138. data/lib/chef/provider/service/windows.rb +5 -1
  139. data/lib/chef/provider/subversion.rb +10 -7
  140. data/lib/chef/providers.rb +3 -0
  141. data/lib/chef/resource.rb +181 -87
  142. data/lib/chef/resource/apt_package.rb +10 -1
  143. data/lib/chef/resource/chef_gem.rb +53 -0
  144. data/lib/chef/resource/conditional.rb +3 -0
  145. data/lib/chef/resource/cookbook_file.rb +12 -6
  146. data/lib/chef/resource/cron.rb +9 -0
  147. data/lib/chef/resource/directory.rb +14 -31
  148. data/lib/chef/resource/execute.rb +11 -9
  149. data/lib/chef/resource/file.rb +9 -33
  150. data/lib/chef/resource/link.rb +13 -8
  151. data/lib/chef/resource/mdadm.rb +10 -1
  152. data/lib/chef/resource/remote_directory.rb +13 -2
  153. data/lib/chef/resource/remote_file.rb +14 -7
  154. data/lib/chef/resource/smartos_package.rb +36 -0
  155. data/lib/chef/resource/template.rb +12 -5
  156. data/lib/chef/resource_platform_map.rb +153 -0
  157. data/lib/chef/resources.rb +2 -0
  158. data/lib/chef/rest.rb +55 -10
  159. data/lib/chef/rest/auth_credentials.rb +1 -0
  160. data/lib/chef/rest/rest_request.rb +24 -8
  161. data/lib/chef/role.rb +8 -2
  162. data/lib/chef/run_list.rb +1 -1
  163. data/lib/chef/run_list/run_list_expansion.rb +2 -2
  164. data/lib/chef/run_list/run_list_item.rb +7 -0
  165. data/lib/chef/runner.rb +4 -0
  166. data/lib/chef/shef.rb +2 -2
  167. data/lib/chef/shef/shef_session.rb +4 -5
  168. data/lib/chef/shell_out.rb +2 -245
  169. data/lib/chef/util/file_edit.rb +99 -89
  170. data/lib/chef/version.rb +1 -1
  171. data/lib/chef/win32/api.rb +349 -0
  172. data/lib/chef/win32/api/error.rb +921 -0
  173. data/lib/chef/win32/api/file.rb +289 -0
  174. data/lib/chef/win32/api/memory.rb +105 -0
  175. data/lib/chef/win32/api/process.rb +40 -0
  176. data/lib/chef/win32/api/psapi.rb +51 -0
  177. data/lib/chef/win32/api/security.rb +341 -0
  178. data/lib/chef/win32/api/system.rb +192 -0
  179. data/lib/chef/win32/api/unicode.rb +178 -0
  180. data/lib/chef/win32/error.rb +73 -0
  181. data/lib/chef/win32/file.rb +117 -0
  182. data/lib/chef/win32/file/info.rb +100 -0
  183. data/lib/chef/win32/handle.rb +48 -0
  184. data/lib/chef/win32/memory.rb +101 -0
  185. data/lib/chef/win32/process.rb +84 -0
  186. data/lib/chef/win32/security.rb +489 -0
  187. data/lib/chef/win32/security/ace.rb +125 -0
  188. data/lib/chef/win32/security/acl.rb +101 -0
  189. data/lib/chef/win32/security/securable_object.rb +109 -0
  190. data/lib/chef/win32/security/security_descriptor.rb +93 -0
  191. data/lib/chef/win32/security/sid.rb +199 -0
  192. data/lib/chef/win32/security/token.rb +64 -0
  193. data/lib/chef/win32/unicode.rb +43 -0
  194. data/lib/chef/win32/version.rb +119 -0
  195. metadata +104 -158
  196. data/lib/chef/shell_out/unix.rb +0 -223
  197. data/lib/chef/shell_out/windows.rb +0 -588
@@ -80,7 +80,9 @@ CONFIG
80
80
  end
81
81
 
82
82
  def start_chef
83
- s = "/usr/bin/chef-client -j /etc/chef/first-boot.json"
83
+ # If the user doesn't have a client path configure, let bash use the PATH for what it was designed for
84
+ client_path = @chef_config[:chef_client_path] || 'chef-client'
85
+ s = "#{client_path} -j /etc/chef/first-boot.json"
84
86
  s << " -E #{bootstrap_environment}" if chef_version.to_f != 0.9 # only use the -E option on Chef 0.10+
85
87
  s
86
88
  end
@@ -84,7 +84,7 @@ class Chef
84
84
  if update_count = updated?(cookbook_name)
85
85
  ui.info "#{update_count} files updated, committing changes"
86
86
  git("add #{cookbook_name}")
87
- git("commit -m 'Import #{cookbook_name} version #{version}' -- #{cookbook_name}")
87
+ git("commit -m \"Import #{cookbook_name} version #{version}\" -- #{cookbook_name}")
88
88
  ui.info("Creating tag cookbook-site-imported-#{cookbook_name}-#{version}")
89
89
  git("tag -f cookbook-site-imported-#{cookbook_name}-#{version}")
90
90
  true
@@ -32,7 +32,7 @@ class Chef
32
32
  end
33
33
 
34
34
  def edit_node
35
- abort "You specified the --no-editor option, nothing to edit" if config[:no_editor]
35
+ abort "You specified the --disable_editing option, nothing to edit" if config[:disable_editing]
36
36
  assert_editor_set!
37
37
 
38
38
  updated_node_data = edit_data(view)
@@ -48,7 +48,7 @@ class Chef
48
48
  end
49
49
 
50
50
  # finally search ~/.chef/plugins/knife/*.rb
51
- user_specific_files.concat Dir.glob(File.join(env['HOME'], '.chef', 'plugins', 'knife', '*.rb'))
51
+ user_specific_files.concat Dir.glob(File.join(env['HOME'], '.chef', 'plugins', 'knife', '*.rb')) if env['HOME']
52
52
 
53
53
  user_specific_files
54
54
  end
@@ -19,6 +19,7 @@
19
19
  #
20
20
 
21
21
  require 'forwardable'
22
+ require 'chef/platform'
22
23
  require 'chef/knife/core/generic_presenter'
23
24
 
24
25
  class Chef
@@ -98,7 +99,7 @@ class Chef
98
99
  # determined by the value of `config[:color]`. When output is not to a
99
100
  # terminal, colored output is never used
100
101
  def color?
101
- Chef::Config[:color] && stdout.tty? && (RUBY_PLATFORM !~ /mswin|mingw32|windows/)
102
+ Chef::Config[:color] && stdout.tty? && !Chef::Platform.windows?
102
103
  end
103
104
 
104
105
  def ask(*args, &block)
@@ -146,7 +147,7 @@ class Chef
146
147
  def edit_data(data, parse_output=true)
147
148
  output = Chef::JSONCompat.to_json_pretty(data)
148
149
 
149
- if (!config[:no_editor])
150
+ if (!config[:disable_editing])
150
151
  filename = "knife-edit-"
151
152
  0.upto(20) { filename += rand(9).to_s }
152
153
  filename << ".js"
@@ -1,4 +1,4 @@
1
1
  # Do not edit this file by hand
2
2
  # This file is autogenerated by the docs:list rake task from the available manpages
3
3
 
4
- HELP_TOPICS = ["knife-ssh", "knife-environment", "knife-bootstrap", "knife-cookbook", "knife-exec", "knife-tag", "knife-status", "knife", "knife-data-bag", "knife-index", "knife-configure", "knife-search", "knife-node", "knife-client", "shef", "knife-role", "knife-cookbook-site"]
4
+ HELP_TOPICS = ["knife-bootstrap", "knife-client", "knife-configure", "knife-cookbook-site", "knife-cookbook", "knife-data-bag", "knife-environment", "knife-exec", "knife-index", "knife-node", "knife-role", "knife-search", "knife-ssh", "knife-status", "knife-tag", "knife", "shef"]
@@ -27,7 +27,7 @@ class Chef
27
27
  require 'chef/json_compat'
28
28
  end
29
29
 
30
- banner "knife node run_list add [NODE] [ENTRY] (options)"
30
+ banner "knife node run_list add [NODE] [ENTRY[,ENTRY]] (options)"
31
31
 
32
32
  option :after,
33
33
  :short => "-a ITEM",
@@ -36,9 +36,17 @@ class Chef
36
36
 
37
37
  def run
38
38
  node = Chef::Node.load(@name_args[0])
39
- entry = @name_args[1]
39
+ if @name_args.size > 2
40
+ # Check for nested lists and create a single plain one
41
+ entries = @name_args[1..-1].map do |entry|
42
+ entry.split(',').map { |e| e.strip }
43
+ end.flatten
44
+ else
45
+ # Convert to array and remove the extra spaces
46
+ entries = @name_args[1].split(',').map { |e| e.strip }
47
+ end
40
48
 
41
- add_to_run_list(node, entry, config[:after])
49
+ add_to_run_list(node, entries, config[:after])
42
50
 
43
51
  node.save
44
52
 
@@ -47,18 +55,18 @@ class Chef
47
55
  output(format_for_display(node))
48
56
  end
49
57
 
50
- def add_to_run_list(node, new_value, after=nil)
58
+ def add_to_run_list(node, entries, after=nil)
51
59
  if after
52
60
  nlist = []
53
61
  node.run_list.each do |entry|
54
62
  nlist << entry
55
63
  if entry == after
56
- nlist << new_value
64
+ entries.each { |e| nlist << e }
57
65
  end
58
66
  end
59
67
  node.run_list.reset!(nlist)
60
68
  else
61
- node.run_list << new_value
69
+ entries.each { |e| node.run_list << e }
62
70
  end
63
71
  end
64
72
 
@@ -27,13 +27,13 @@ class Chef
27
27
  require 'chef/json_compat'
28
28
  end
29
29
 
30
- banner "knife node run_list remove [NODE] [ENTRY] (options)"
30
+ banner "knife node run_list remove [NODE] [ENTRIES] (options)"
31
31
 
32
32
  def run
33
33
  node = Chef::Node.load(@name_args[0])
34
- entry = @name_args[1]
34
+ entries = @name_args[1].split(',')
35
35
 
36
- node.run_list.remove(entry)
36
+ entries.each { |e| node.run_list.remove(e) }
37
37
 
38
38
  node.save
39
39
 
@@ -45,7 +45,7 @@ class Chef
45
45
  :short => "-a ATTR",
46
46
  :long => "--attribute ATTR",
47
47
  :description => "The attribute to use for opening the connection - default is fqdn",
48
- :default => "fqdn"
48
+ :proc => Proc.new { |key| Chef::Config[:knife][:ssh_attribute] = key }
49
49
 
50
50
  option :manual,
51
51
  :short => "-m",
@@ -71,16 +71,22 @@ class Chef
71
71
  :default => "22",
72
72
  :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
73
73
 
74
+ option :ssh_gateway,
75
+ :short => "-G GATEWAY",
76
+ :long => "--ssh-gateway GATEWAY",
77
+ :description => "The ssh gateway",
78
+ :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gatewa] = key }
79
+
74
80
  option :identity_file,
75
81
  :short => "-i IDENTITY_FILE",
76
82
  :long => "--identity-file IDENTITY_FILE",
77
83
  :description => "The SSH identity file used for authentication"
78
84
 
79
- option :no_host_key_verify,
80
- :long => "--no-host-key-verify",
81
- :description => "Disable host key verification",
85
+ option :host_key_verify,
86
+ :long => "--[no-]host-key-verify",
87
+ :description => "Verify host key, enabled by default.",
82
88
  :boolean => true,
83
- :default => false
89
+ :default => true
84
90
 
85
91
  def session
86
92
  config[:on_error] ||= :skip
@@ -124,17 +130,27 @@ class Chef
124
130
  end
125
131
 
126
132
  def session_from_list(list)
133
+ config[:ssh_gateway] ||= Chef::Config[:knife][:ssh_gateway]
134
+ if config[:ssh_gateway]
135
+ gw_host, gw_user = config[:ssh_gateway].split('@').reverse
136
+ gw_host, gw_port = gw_host.split(':')
137
+ gw_opts = gw_port ? { :port => gw_port } : {}
138
+
139
+ session.via(gw_host, gw_user || config[:ssh_user], gw_opts)
140
+ end
141
+
127
142
  list.each do |item|
128
143
  Chef::Log.debug("Adding #{item}")
129
144
 
130
145
  hostspec = config[:ssh_user] ? "#{config[:ssh_user]}@#{item}" : item
131
146
  session_opts = {}
132
147
  session_opts[:keys] = File.expand_path(config[:identity_file]) if config[:identity_file]
148
+ session_opts[:keys_only] = true if config[:identity_file]
133
149
  session_opts[:password] = config[:ssh_password] if config[:ssh_password]
134
150
  session_opts[:port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port]
135
151
  session_opts[:logger] = Chef::Log.logger if Chef::Log.level == :debug
136
152
 
137
- if config[:no_host_key_verify]
153
+ if !config[:host_key_verify]
138
154
  session_opts[:paranoid] = false
139
155
  session_opts[:user_known_hosts_file] = "/dev/null"
140
156
  end
@@ -309,9 +325,8 @@ class Chef
309
325
  end
310
326
 
311
327
  def configure_attribute
312
- config[:attribute] = (config[:attribute] ||
313
- Chef::Config[:knife][:ssh_attribute] ||
314
- "fqdn").strip
328
+ config[:attribute] = (Chef::Config[:knife][:ssh_attribute] ||
329
+ config[:attribute]).strip
315
330
  end
316
331
 
317
332
  def csshx
@@ -322,15 +337,19 @@ class Chef
322
337
  exec(csshx_cmd)
323
338
  end
324
339
 
340
+ def get_stripped_unfrozen_value(value)
341
+ return nil if value.nil?
342
+ value.strip
343
+ end
344
+
325
345
  def configure_user
326
- config[:ssh_user] = (config[:ssh_user] ||
346
+ config[:ssh_user] = get_stripped_unfrozen_value(config[:ssh_user] ||
327
347
  Chef::Config[:knife][:ssh_user])
328
- config[:ssh_user].strip! unless config[:ssh_user].nil?
329
348
  end
330
349
 
331
350
  def configure_identity_file
332
- config[:identity_file] = (config[:identity_file] || Chef::Config[:knife][:ssh_identity_file])
333
- config[:identity_file].strip! unless config[:identity_file].nil?
351
+ config[:identity_file] = get_stripped_unfrozen_value(config[:identity_file] ||
352
+ Chef::Config[:knife][:ssh_identity_file])
334
353
  end
335
354
 
336
355
  def run
@@ -65,6 +65,20 @@ class Mash < Hash
65
65
  end
66
66
  end
67
67
 
68
+ # @param orig<Object> Mash being copied
69
+ #
70
+ # @return [Object] A new copied Mash
71
+ def initialize_copy(orig)
72
+ super
73
+ # Handle nested values
74
+ each do |k,v|
75
+ if v.kind_of?(Mash) || v.is_a?(Array)
76
+ self[k] = v.dup
77
+ end
78
+ end
79
+ self
80
+ end
81
+
68
82
  # @param key<Object> The default value for the mash. Defaults to nil.
69
83
  #
70
84
  # @details [Alternatives]
@@ -27,6 +27,7 @@ class Chef
27
27
  module Command
28
28
  extend self
29
29
 
30
+ # NOTE: run_command is deprecated in favor of using Chef::Shellout which now comes from the mixlib-shellout gem. NOTE #
30
31
 
31
32
  if RUBY_PLATFORM =~ /mswin|mingw32|windows/
32
33
  require 'chef/mixin/command/windows'
@@ -28,6 +28,9 @@ class Chef
28
28
  #
29
29
  # Thanks Ara!
30
30
  def popen4(cmd, args={}, &b)
31
+ # Ruby 1.8 suffers from intermittent segfaults believed to be due to GC while IO.select
32
+ # See CHEF-2916 / CHEF-1305
33
+ GC.disable
31
34
 
32
35
  # Waitlast - this is magic.
33
36
  #
@@ -207,6 +210,8 @@ class Chef
207
210
  else
208
211
  [cid, pw.last, pr.first, pe.first]
209
212
  end
213
+ ensure
214
+ GC.enable
210
215
  end
211
216
 
212
217
  end
@@ -23,6 +23,8 @@ class Chef
23
23
  extend self
24
24
 
25
25
  def convert_to_class_name(str)
26
+ str = str.dup
27
+ str.gsub!(/[^A-Za-z0-9_]/,'_')
26
28
  rname = nil
27
29
  regexp = %r{^(.+?)(_(.+))?$}
28
30
 
@@ -22,21 +22,30 @@ class Chef
22
22
  # == Chef::Mixin::DeepMerge
23
23
  # Implements a deep merging algorithm for nested data structures.
24
24
  # ==== Notice:
25
- # This code is imported from deep_merge by Steve Midgley. deep_merge is
26
- # available under the MIT license from
25
+ # This code was originally imported from deep_merge by Steve Midgley.
26
+ # deep_merge is available under the MIT license from
27
27
  # http://trac.misuse.org/science/wiki/DeepMerge
28
28
  module DeepMerge
29
- def self.merge(first, second)
29
+ extend self
30
+
31
+ def merge(first, second)
30
32
  first = Mash.new(first) unless first.kind_of?(Mash)
31
33
  second = Mash.new(second) unless second.kind_of?(Mash)
32
34
 
33
- DeepMerge.deep_merge!(second, first, {:knockout_prefix => "!merge:", :preserve_unmergeables => false})
35
+ DeepMerge.deep_merge(second, first, {:preserve_unmergeables => false})
36
+ end
37
+
38
+ # Inherited roles use the knockout_prefix array subtraction functionality
39
+ # This is likely to go away in Chef >= 0.11
40
+ def role_merge(first, second)
41
+ first = Mash.new(first) unless first.kind_of?(Mash)
42
+ second = Mash.new(second) unless second.kind_of?(Mash)
43
+
44
+ DeepMerge.deep_merge(second, first, {:knockout_prefix => "!merge", :preserve_unmergeables => false})
34
45
  end
35
46
 
36
47
  class InvalidParameter < StandardError; end
37
48
 
38
- DEFAULT_FIELD_KNOCKOUT_PREFIX = '--' unless defined?(DEFAULT_FIELD_KNOCKOUT_PREFIX)
39
-
40
49
  # Deep Merge core documentation.
41
50
  # deep_merge! method permits merging of arbitrary child elements. The two top level
42
51
  # elements must be hashes. These hashes can contain unlimited (to stack limit) levels
@@ -54,11 +63,13 @@ class Chef
54
63
  #
55
64
  # Options:
56
65
  # Options are specified in the last parameter passed, which should be in hash format:
57
- # hash.deep_merge!({:x => [1,2]}, {:knockout_prefix => '--'})
66
+ # hash.deep_merge!({:x => [1,2]}, {:knockout_prefix => '!merge'})
58
67
  # :preserve_unmergeables DEFAULT: false
59
68
  # Set to true to skip any unmergeable elements from source
60
69
  # :knockout_prefix DEFAULT: nil
61
70
  # Set to string value to signify prefix which deletes elements from existing element
71
+ # A colon is appended when indicating a specific value, eg:
72
+ # :knockout_prefix => "dontmerge", is referenced as "dontmerge:foobar" in an array
62
73
  # :sort_merged_arrays DEFAULT: false
63
74
  # Set to true to sort all arrays that are merged together
64
75
  # :unpack_arrays DEFAULT: nil
@@ -69,13 +80,13 @@ class Chef
69
80
  # Selected Options Details:
70
81
  # :knockout_prefix => The purpose of this is to provide a way to remove elements
71
82
  # from existing Hash by specifying them in a special way in incoming hash
72
- # source = {:x => ['--1', '2']}
83
+ # source = {:x => ['!merge:1', '2']}
73
84
  # dest = {:x => ['1', '3']}
74
85
  # dest.ko_deep_merge!(source)
75
86
  # Results: {:x => ['2','3']}
76
87
  # Additionally, if the knockout_prefix is passed alone as a string, it will cause
77
88
  # the entire element to be removed:
78
- # source = {:x => '--'}
89
+ # source = {:x => '!merge'}
79
90
  # dest = {:x => [1,2,3]}
80
91
  # dest.ko_deep_merge!(source)
81
92
  # Results: {:x => ""}
@@ -90,7 +101,7 @@ class Chef
90
101
  #
91
102
  # There are many tests for this library - and you can learn more about the features
92
103
  # and usages of deep_merge! by just browsing the test examples
93
- def self.deep_merge!(source, dest, options = {})
104
+ def deep_merge!(source, dest, options = {})
94
105
  # turn on this line for stdout debugging text
95
106
  merge_debug = options[:merge_debug] || false
96
107
  overwrite_unmergeable = !options[:preserve_unmergeables]
@@ -108,7 +119,7 @@ class Chef
108
119
  if dest.nil? && overwrite_unmergeable
109
120
  dest = source; return dest
110
121
  end
111
-
122
+
112
123
  puts "#{di}Source class: #{source.class.inspect} :: Dest class: #{dest.class.inspect}" if merge_debug
113
124
  if source.kind_of?(Hash)
114
125
  puts "#{di}Hashes: #{source.inspect} :: #{dest.inspect}" if merge_debug
@@ -146,8 +157,11 @@ class Chef
146
157
  end
147
158
  end
148
159
  # if there's a naked knockout_prefix in source, that means we are to truncate dest
149
- if source.index(knockout_prefix)
150
- dest = clear_or_nil(dest); source.delete(knockout_prefix)
160
+ ko_variants = [ knockout_prefix, "#{knockout_prefix}:" ]
161
+ ko_variants.each do |ko|
162
+ if source.index(ko)
163
+ dest = clear_or_nil(dest); source.delete(ko)
164
+ end
151
165
  end
152
166
  if dest.kind_of?(Array)
153
167
  if knockout_prefix
@@ -155,7 +169,7 @@ class Chef
155
169
  # remove knockout prefix items from both source and dest
156
170
  source.delete_if do |ko_item|
157
171
  retval = false
158
- item = ko_item.respond_to?(:gsub) ? ko_item.gsub(%r{^#{knockout_prefix}}, "") : ko_item
172
+ item = ko_item.respond_to?(:gsub) ? ko_item.gsub(%r{^#{knockout_prefix}:}, "") : ko_item
159
173
  if item != ko_item
160
174
  print "#{ko_item} - " if merge_debug
161
175
  dest.delete(item)
@@ -182,16 +196,20 @@ class Chef
182
196
  end # deep_merge!
183
197
 
184
198
  # allows deep_merge! to uniformly handle overwriting of unmergeable entities
185
- def self.overwrite_unmergeables(source, dest, options)
199
+ def overwrite_unmergeables(source, dest, options)
186
200
  merge_debug = options[:merge_debug] || false
187
201
  overwrite_unmergeable = !options[:preserve_unmergeables]
188
202
  knockout_prefix = options[:knockout_prefix] || false
189
203
  di = options[:debug_indent] || ''
190
204
  if knockout_prefix && overwrite_unmergeable
191
205
  if source.kind_of?(String) # remove knockout string from source before overwriting dest
192
- src_tmp = source.gsub(%r{^#{knockout_prefix}},"")
206
+ if source == knockout_prefix
207
+ src_tmp = ""
208
+ else
209
+ src_tmp = source.gsub(%r{^#{knockout_prefix}:},"")
210
+ end
193
211
  elsif source.kind_of?(Array) # remove all knockout elements before overwriting dest
194
- src_tmp = source.delete_if {|ko_item| ko_item.kind_of?(String) && ko_item.match(%r{^#{knockout_prefix}}) }
212
+ src_tmp = source.delete_if {|ko_item| ko_item.kind_of?(String) && ko_item.match(%r{^#{knockout_prefix}:}) }
195
213
  else
196
214
  src_tmp = source
197
215
  end
@@ -207,8 +225,12 @@ class Chef
207
225
  end
208
226
  dest
209
227
  end
228
+
229
+ def deep_merge(source, dest, options = {})
230
+ deep_merge!(source.dup, dest.dup, options)
231
+ end
210
232
 
211
- def self.clear_or_nil(obj)
233
+ def clear_or_nil(obj)
212
234
  if obj.respond_to?(:clear)
213
235
  obj.clear
214
236
  else
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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/file_access_control'
20
+
21
+ class Chef
22
+ module Mixin
23
+ module EnforceOwnershipAndPermissions
24
+
25
+ # will set the proper user, group and
26
+ # permissions using a platform specific
27
+ # version of Chef::FileAccessControl
28
+ def enforce_ownership_and_permissions(path=nil)
29
+ if path.nil? and new_resource.respond_to?(:path)
30
+ path = new_resource.path
31
+ end
32
+ access_controls = Chef::FileAccessControl.new(new_resource, path)
33
+ access_controls.set_all
34
+ new_resource.updated_by_last_action(access_controls.modified?)
35
+ end
36
+
37
+ end
38
+ end
39
+ end