chef 12.5.0.alpha.1 → 12.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +21 -25
  3. data/Gemfile +46 -0
  4. data/README.md +4 -4
  5. data/Rakefile +5 -110
  6. data/distro/common/html/knife_cookbook_site.html +18 -18
  7. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  8. data/lib/chef/application.rb +1 -1
  9. data/lib/chef/application/apply.rb +19 -1
  10. data/lib/chef/application/client.rb +11 -5
  11. data/lib/chef/application/knife.rb +2 -2
  12. data/lib/chef/application/windows_service_manager.rb +9 -7
  13. data/lib/chef/chef_class.rb +39 -0
  14. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  15. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  16. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  17. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  18. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  19. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  20. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  21. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  22. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  23. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  24. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  25. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
  26. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  27. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  28. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  29. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  30. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  31. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  32. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  33. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  35. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  36. data/lib/chef/client.rb +2 -3
  37. data/lib/chef/config.rb +34 -2
  38. data/lib/chef/cookbook/metadata.rb +25 -3
  39. data/lib/chef/cookbook/synchronizer.rb +1 -1
  40. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  41. data/lib/chef/cookbook_version.rb +3 -3
  42. data/lib/chef/deprecation/mixin/template.rb +1 -2
  43. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  44. data/lib/chef/deprecation/provider/file.rb +1 -1
  45. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  46. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  47. data/lib/chef/deprecation/provider/template.rb +1 -1
  48. data/lib/chef/deprecation/warnings.rb +3 -4
  49. data/lib/chef/dsl/reboot_pending.rb +3 -2
  50. data/lib/chef/dsl/recipe.rb +6 -5
  51. data/lib/chef/dsl/resources.rb +2 -2
  52. data/lib/chef/event_dispatch/base.rb +12 -7
  53. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  54. data/lib/chef/exceptions.rb +22 -0
  55. data/lib/chef/file_content_management/tempfile.rb +1 -1
  56. data/lib/chef/formatters/base.rb +3 -0
  57. data/lib/chef/formatters/doc.rb +53 -5
  58. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  59. data/lib/chef/formatters/minimal.rb +2 -2
  60. data/lib/chef/knife.rb +35 -55
  61. data/lib/chef/knife/bootstrap.rb +41 -0
  62. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  63. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  64. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  65. data/lib/chef/knife/cookbook_create.rb +1 -1
  66. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  67. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  68. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  69. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  70. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  71. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  72. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  73. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  74. data/lib/chef/knife/core/node_presenter.rb +24 -1
  75. data/lib/chef/knife/core/object_loader.rb +1 -0
  76. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  77. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  78. data/lib/chef/knife/null.rb +10 -0
  79. data/lib/chef/knife/rehash.rb +62 -0
  80. data/lib/chef/knife/search.rb +3 -3
  81. data/lib/chef/knife/ssh.rb +52 -30
  82. data/lib/chef/local_mode.rb +5 -0
  83. data/lib/chef/log.rb +5 -1
  84. data/lib/chef/mixin/deprecation.rb +8 -8
  85. data/lib/chef/mixin/params_validate.rb +2 -2
  86. data/lib/chef/mixin/template.rb +48 -0
  87. data/lib/chef/mixin/which.rb +1 -1
  88. data/lib/chef/mixin/wide_string.rb +72 -0
  89. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  90. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  91. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  92. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  93. data/lib/chef/node.rb +97 -3
  94. data/lib/chef/node_map.rb +2 -2
  95. data/lib/chef/platform/provider_mapping.rb +5 -6
  96. data/lib/chef/platform/query_helpers.rb +46 -4
  97. data/lib/chef/platform/service_helpers.rb +30 -32
  98. data/lib/chef/policy_builder.rb +1 -8
  99. data/lib/chef/policy_builder/dynamic.rb +186 -0
  100. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  101. data/lib/chef/policy_builder/policyfile.rb +155 -18
  102. data/lib/chef/property.rb +38 -9
  103. data/lib/chef/provider.rb +104 -12
  104. data/lib/chef/provider/batch.rb +8 -0
  105. data/lib/chef/provider/deploy.rb +2 -2
  106. data/lib/chef/provider/directory.rb +14 -2
  107. data/lib/chef/provider/dsc_resource.rb +5 -9
  108. data/lib/chef/provider/group/pw.rb +1 -1
  109. data/lib/chef/provider/ifconfig.rb +2 -2
  110. data/lib/chef/provider/mount.rb +7 -3
  111. data/lib/chef/provider/package/dpkg.rb +5 -11
  112. data/lib/chef/provider/package/rpm.rb +2 -2
  113. data/lib/chef/provider/package/rubygems.rb +1 -1
  114. data/lib/chef/provider/package/windows/msi.rb +2 -2
  115. data/lib/chef/provider/package/yum.rb +17 -5
  116. data/lib/chef/provider/powershell_script.rb +27 -4
  117. data/lib/chef/provider/remote_directory.rb +190 -102
  118. data/lib/chef/provider/service.rb +12 -2
  119. data/lib/chef/provider/service/aix.rb +1 -1
  120. data/lib/chef/provider/service/debian.rb +3 -5
  121. data/lib/chef/provider/service/freebsd.rb +1 -1
  122. data/lib/chef/provider/service/gentoo.rb +3 -3
  123. data/lib/chef/provider/service/init.rb +3 -3
  124. data/lib/chef/provider/service/insserv.rb +2 -4
  125. data/lib/chef/provider/service/invokercd.rb +2 -4
  126. data/lib/chef/provider/service/openbsd.rb +2 -1
  127. data/lib/chef/provider/service/redhat.rb +52 -16
  128. data/lib/chef/provider/service/simple.rb +2 -2
  129. data/lib/chef/provider/service/systemd.rb +3 -5
  130. data/lib/chef/provider/service/upstart.rb +4 -6
  131. data/lib/chef/provider/subversion.rb +13 -7
  132. data/lib/chef/provider/template/content.rb +16 -6
  133. data/lib/chef/provider/user/solaris.rb +32 -4
  134. data/lib/chef/provider/windows_script.rb +3 -5
  135. data/lib/chef/provider_resolver.rb +2 -2
  136. data/lib/chef/resource.rb +85 -27
  137. data/lib/chef/resource/action_class.rb +83 -0
  138. data/lib/chef/resource/chef_gem.rb +3 -3
  139. data/lib/chef/resource/deploy.rb +8 -2
  140. data/lib/chef/resource/dsc_script.rb +2 -0
  141. data/lib/chef/resource/file/verification.rb +1 -1
  142. data/lib/chef/resource/registry_key.rb +1 -1
  143. data/lib/chef/resource/service.rb +10 -2
  144. data/lib/chef/resource/subversion.rb +5 -0
  145. data/lib/chef/resource/windows_script.rb +6 -2
  146. data/lib/chef/resource/yum_package.rb +10 -1
  147. data/lib/chef/resource_resolver.rb +3 -3
  148. data/lib/chef/run_context.rb +6 -8
  149. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  150. data/lib/chef/run_lock.rb +30 -21
  151. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  152. data/lib/chef/util/windows.rb +0 -32
  153. data/lib/chef/util/windows/net_group.rb +85 -106
  154. data/lib/chef/util/windows/net_use.rb +35 -71
  155. data/lib/chef/util/windows/net_user.rb +0 -1
  156. data/lib/chef/util/windows/volume.rb +19 -19
  157. data/lib/chef/version.rb +3 -3
  158. data/lib/chef/win32/api.rb +1 -0
  159. data/lib/chef/win32/api/file.rb +20 -0
  160. data/lib/chef/win32/api/net.rb +163 -43
  161. data/lib/chef/win32/api/registry.rb +51 -0
  162. data/lib/chef/win32/api/system.rb +23 -0
  163. data/lib/chef/win32/api/unicode.rb +0 -43
  164. data/lib/chef/win32/crypto.rb +2 -1
  165. data/lib/chef/win32/file.rb +28 -3
  166. data/lib/chef/win32/mutex.rb +1 -2
  167. data/lib/chef/win32/net.rb +162 -8
  168. data/lib/chef/win32/process.rb +13 -0
  169. data/lib/chef/win32/registry.rb +25 -28
  170. data/lib/chef/win32/security.rb +1 -1
  171. data/lib/chef/win32/security/token.rb +1 -1
  172. data/lib/chef/win32/system.rb +62 -0
  173. data/lib/chef/win32/unicode.rb +7 -2
  174. data/lib/chef/win32/version.rb +0 -4
  175. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  176. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  177. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  178. data/spec/data/dsc_lcm.pfx +0 -0
  179. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  180. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  181. data/spec/functional/knife/ssh_spec.rb +16 -0
  182. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  183. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  184. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  185. data/spec/functional/resource/group_spec.rb +67 -44
  186. data/spec/functional/resource/powershell_script_spec.rb +104 -15
  187. data/spec/functional/resource/windows_service_spec.rb +1 -1
  188. data/spec/functional/run_lock_spec.rb +368 -189
  189. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
  190. data/spec/integration/client/client_spec.rb +51 -0
  191. data/spec/integration/knife/download_spec.rb +4 -0
  192. data/spec/integration/knife/list_spec.rb +8 -0
  193. data/spec/integration/knife/upload_spec.rb +1 -1
  194. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  195. data/spec/integration/recipes/remote_directory.rb +74 -0
  196. data/spec/integration/recipes/resource_action_spec.rb +42 -22
  197. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  198. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  199. data/spec/spec_helper.rb +8 -0
  200. data/spec/support/platform_helpers.rb +13 -0
  201. data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
  202. data/spec/support/shared/functional/windows_script.rb +63 -26
  203. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  204. data/spec/support/shared/unit/provider/file.rb +10 -4
  205. data/spec/unit/application/client_spec.rb +16 -3
  206. data/spec/unit/application/knife_spec.rb +2 -2
  207. data/spec/unit/chef_class_spec.rb +0 -4
  208. data/spec/unit/client_spec.rb +6 -1
  209. data/spec/unit/config_spec.rb +31 -0
  210. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  211. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  212. data/spec/unit/deprecation_spec.rb +3 -6
  213. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  214. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  215. data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
  216. data/spec/unit/formatters/doc_spec.rb +32 -0
  217. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  218. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  219. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  220. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  221. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  222. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  223. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  224. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  225. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  226. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  227. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  228. data/spec/unit/mixin/template_spec.rb +5 -1
  229. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  230. data/spec/unit/node_spec.rb +213 -0
  231. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  232. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  233. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  234. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  235. data/spec/unit/property/validation_spec.rb +5 -0
  236. data/spec/unit/property_spec.rb +152 -26
  237. data/spec/unit/provider/deploy_spec.rb +5 -5
  238. data/spec/unit/provider/directory_spec.rb +35 -0
  239. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  240. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  241. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  242. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  243. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  244. data/spec/unit/provider/mount_spec.rb +12 -1
  245. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  246. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  247. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  248. data/spec/unit/provider/package/yum_spec.rb +97 -24
  249. data/spec/unit/provider/powershell_script_spec.rb +52 -26
  250. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  251. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  252. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  253. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  254. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  255. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  256. data/spec/unit/provider/service/windows_spec.rb +211 -200
  257. data/spec/unit/provider/subversion_spec.rb +50 -31
  258. data/spec/unit/provider/template/content_spec.rb +93 -2
  259. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  260. data/spec/unit/provider_resolver_spec.rb +707 -650
  261. data/spec/unit/resource/deploy_spec.rb +7 -1
  262. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  263. data/spec/unit/resource/file/verification_spec.rb +1 -1
  264. data/spec/unit/resource/powershell_script_spec.rb +17 -13
  265. data/spec/unit/resource/service_spec.rb +4 -4
  266. data/spec/unit/resource/subversion_spec.rb +4 -0
  267. data/spec/unit/resource/yum_package_spec.rb +10 -1
  268. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  269. data/spec/unit/win32/registry_spec.rb +394 -0
  270. data/tasks/external_tests.rb +47 -23
  271. data/tasks/maintainers.rb +155 -14
  272. metadata +51 -26
  273. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  274. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  275. data/spec/unit/registry_helper_spec.rb +0 -390
@@ -19,19 +19,13 @@
19
19
 
20
20
  require 'chef/exceptions'
21
21
  require 'chef/platform/query_helpers'
22
- require 'win32/api' if Chef::Platform.windows?
23
- require 'chef/win32/api/process' if Chef::Platform.windows?
24
- require 'chef/win32/api/error' if Chef::Platform.windows?
22
+ require 'chef/win32/process' if Chef::Platform.windows?
23
+ require 'chef/win32/system' if Chef::Platform.windows?
25
24
 
26
25
  class Chef
27
26
  module Mixin
28
27
  module WindowsArchitectureHelper
29
28
 
30
- if Chef::Platform.windows?
31
- include Chef::ReservedNames::Win32::API::Process
32
- include Chef::ReservedNames::Win32::API::Error
33
- end
34
-
35
29
  def node_windows_architecture(node)
36
30
  node[:kernel][:machine].to_sym
37
31
  end
@@ -42,6 +36,16 @@ class Chef
42
36
  is_i386_process_on_x86_64_windows?
43
37
  end
44
38
 
39
+ def forced_32bit_override_required?(node, desired_architecture)
40
+ desired_architecture == :i386 &&
41
+ node_windows_architecture(node) == :x86_64 &&
42
+ !is_i386_process_on_x86_64_windows?
43
+ end
44
+
45
+ def wow64_directory
46
+ Chef::ReservedNames::Win32::System.get_system_wow64_directory
47
+ end
48
+
45
49
  def with_os_architecture(node, architecture: nil)
46
50
  node ||= begin
47
51
  os_arch = ENV['PROCESSOR_ARCHITEW6432'] ||
@@ -88,49 +92,21 @@ class Chef
88
92
 
89
93
  def is_i386_process_on_x86_64_windows?
90
94
  if Chef::Platform.windows?
91
- is_64_bit_process_result = FFI::MemoryPointer.new(:int)
92
-
93
- # The return value of IsWow64Process is nonzero value if the API call succeeds.
94
- # The result data are returned in the last parameter, not the return value.
95
- call_succeeded = IsWow64Process(GetCurrentProcess(), is_64_bit_process_result)
96
-
97
- # The result is nonzero if IsWow64Process's calling process, in the case here
98
- # this process, is running under WOW64, i.e. the result is nonzero if this
99
- # process is 32-bit (aka :i386).
100
- result = (call_succeeded != 0) && (is_64_bit_process_result.get_int(0) != 0)
95
+ Chef::ReservedNames::Win32::Process.is_wow64_process
101
96
  else
102
97
  false
103
98
  end
104
99
  end
105
100
 
106
101
  def disable_wow64_file_redirection( node )
107
- original_redirection_state = ['0'].pack('P')
108
-
109
102
  if ( ( node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?)
110
- win32_wow_64_disable_wow_64_fs_redirection =
111
- ::Win32::API.new('Wow64DisableWow64FsRedirection', 'P', 'L', 'kernel32')
112
-
113
- succeeded = win32_wow_64_disable_wow_64_fs_redirection.call(original_redirection_state)
114
-
115
- if succeeded == 0
116
- raise Win32APIError "Failed to disable Wow64 file redirection"
117
- end
118
-
103
+ Chef::ReservedNames::Win32::System.wow64_disable_wow64_fs_redirection
119
104
  end
120
-
121
- original_redirection_state
122
105
  end
123
106
 
124
107
  def restore_wow64_file_redirection( node, original_redirection_state )
125
108
  if ( (node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?)
126
- win32_wow_64_revert_wow_64_fs_redirection =
127
- ::Win32::API.new('Wow64RevertWow64FsRedirection', 'P', 'L', 'kernel32')
128
-
129
- succeeded = win32_wow_64_revert_wow_64_fs_redirection.call(original_redirection_state)
130
-
131
- if succeeded == 0
132
- raise Win32APIError "Failed to revert Wow64 file redirection"
133
- end
109
+ Chef::ReservedNames::Win32::System.wow64_revert_wow64_fs_redirection(original_redirection_state)
134
110
  end
135
111
  end
136
112
 
@@ -18,6 +18,7 @@
18
18
 
19
19
 
20
20
  require 'chef/exceptions'
21
+ require 'chef/mixin/wide_string'
21
22
  require 'chef/platform/query_helpers'
22
23
  require 'chef/win32/error' if Chef::Platform.windows?
23
24
  require 'chef/win32/api/system' if Chef::Platform.windows?
@@ -26,6 +27,8 @@ require 'chef/win32/api/unicode' if Chef::Platform.windows?
26
27
  class Chef
27
28
  module Mixin
28
29
  module WindowsEnvHelper
30
+ include Chef::Mixin::WideString
31
+
29
32
  if Chef::Platform.windows?
30
33
  include Chef::ReservedNames::Win32::API::System
31
34
  end
@@ -45,7 +48,7 @@ class Chef
45
48
  Chef::ReservedNames::Win32::Error.raise!
46
49
  end
47
50
  if ( SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string(
48
- Chef::ReservedNames::Win32::Unicode.utf8_to_wide('Environment')
51
+ utf8_to_wide('Environment')
49
52
  ).address, flags, 5000, nil) == 0 )
50
53
  Chef::ReservedNames::Win32::Error.raise!
51
54
  end
@@ -0,0 +1,51 @@
1
+ require 'webrick/utils'
2
+
3
+ module WEBrick
4
+ module Utils
5
+ ##
6
+ # Creates TCP server sockets bound to +address+:+port+ and returns them.
7
+ #
8
+ # It will create IPV4 and IPV6 sockets on all interfaces.
9
+ #
10
+ # NOTE: We need to monkey patch this method because
11
+ # create_listeners on Windows with Ruby > 2.0.0 does not
12
+ # raise an error if we're already listening on a port.
13
+ #
14
+ def create_listeners(address, port, logger=nil)
15
+ #
16
+ # utils.rb -- Miscellaneous utilities
17
+ #
18
+ # Author: IPR -- Internet Programming with Ruby -- writers
19
+ # Copyright (c) 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
20
+ # Copyright (c) 2002 Internet Programming with Ruby writers. All rights
21
+ # reserved.
22
+ #
23
+ # $IPR: utils.rb,v 1.10 2003/02/16 22:22:54 gotoyuzo Exp $
24
+ unless port
25
+ raise ArgumentError, "must specify port"
26
+ end
27
+ res = Socket::getaddrinfo(address, port,
28
+ Socket::AF_UNSPEC, # address family
29
+ Socket::SOCK_STREAM, # socket type
30
+ 0, # protocol
31
+ Socket::AI_PASSIVE) # flag
32
+ last_error = nil
33
+ sockets = []
34
+ res.each{|ai|
35
+ begin
36
+ logger.debug("TCPServer.new(#{ai[3]}, #{port})") if logger
37
+ sock = TCPServer.new(ai[3], port)
38
+ port = sock.addr[1] if port == 0
39
+ Utils::set_close_on_exec(sock)
40
+ sockets << sock
41
+ rescue => ex
42
+ logger.warn("TCPServer Error: #{ex}") if logger
43
+ last_error = ex
44
+ end
45
+ }
46
+ raise last_error if sockets.empty?
47
+ return sockets
48
+ end
49
+ module_function :create_listeners
50
+ end
51
+ end
@@ -0,0 +1,72 @@
1
+ #
2
+ # Copyright:: Copyright 2015 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/win32/api/registry'
19
+ require 'chef/win32/unicode'
20
+ require 'win32/registry'
21
+
22
+ module Win32
23
+ class Registry
24
+
25
+ module API
26
+
27
+ extend Chef::ReservedNames::Win32::API::Registry
28
+
29
+ module_function
30
+
31
+ if RUBY_VERSION =~ /^2\.1/
32
+ # ::Win32::Registry#delete_value is broken in Ruby 2.1 (up to Ruby 2.1.6).
33
+ # This should be resolved in a later release (see note #9 in link below).
34
+ # https://bugs.ruby-lang.org/issues/10820
35
+ def DeleteValue(hkey, name)
36
+ check RegDeleteValueW(hkey, name.to_wstring)
37
+ end
38
+ end
39
+
40
+ # ::Win32::Registry#delete_key uses RegDeleteKeyW. We need to use
41
+ # RegDeleteKeyExW to properly support WOW64 systems.
42
+ def DeleteKey(hkey, name)
43
+ check RegDeleteKeyExW(hkey, name.to_wstring, 0, 0)
44
+ end
45
+
46
+ end
47
+
48
+ if RUBY_VERSION =~ /^2.1/
49
+ # ::Win32::Registry#write does not correctly handle data in Ruby 2.1 (up to Ruby 2.1.6).
50
+ # https://bugs.ruby-lang.org/issues/11439
51
+ def write(name, type, data)
52
+ case type
53
+ when REG_SZ, REG_EXPAND_SZ
54
+ data = data.to_s.encode(WCHAR) + WCHAR_NUL
55
+ when REG_MULTI_SZ
56
+ data = data.to_a.map {|s| s.encode(WCHAR)}.join(WCHAR_NUL) << WCHAR_NUL << WCHAR_NUL
57
+ when REG_BINARY
58
+ data = data.to_s
59
+ when REG_DWORD
60
+ data = API.packdw(data.to_i)
61
+ when REG_DWORD_BIG_ENDIAN
62
+ data = [data.to_i].pack('N')
63
+ when REG_QWORD
64
+ data = API.packqw(data.to_i)
65
+ else
66
+ raise TypeError, "Unsupported type #{type}"
67
+ end
68
+ API.SetValue(@hkey, name, type, data, data.bytesize)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -63,6 +63,8 @@ class Chef
63
63
 
64
64
  include Chef::Mixin::ParamsValidate
65
65
 
66
+ NULL_ARG = Object.new
67
+
66
68
  # Create a new Chef::Node object.
67
69
  def initialize(chef_server_rest: nil)
68
70
  @chef_server_rest = chef_server_rest
@@ -72,6 +74,9 @@ class Chef
72
74
  @primary_runlist = Chef::RunList.new
73
75
  @override_runlist = Chef::RunList.new
74
76
 
77
+ @policy_name = nil
78
+ @policy_group = nil
79
+
75
80
  @attributes = Chef::Node::Attribute.new({}, {}, {}, {})
76
81
 
77
82
  @run_state = {}
@@ -132,6 +137,50 @@ class Chef
132
137
 
133
138
  alias :environment :chef_environment
134
139
 
140
+ # The `policy_name` for this node. Setting this to a non-nil value will
141
+ # enable policyfile mode when `chef-client` is run. If set in the config
142
+ # file or in node json, running `chef-client` will update this value.
143
+ #
144
+ # @see Chef::PolicyBuilder::Dynamic
145
+ # @see Chef::PolicyBuilder::Policyfile
146
+ #
147
+ # @param arg [String] the new policy_name value
148
+ # @return [String] the current policy_name, or the one you just set
149
+ def policy_name(arg=NULL_ARG)
150
+ return @policy_name if arg.equal?(NULL_ARG)
151
+ validate({policy_name: arg}, { policy_name: { kind_of: [ String, NilClass ], regex: /^[\-:.[:alnum:]_]+$/ } })
152
+ @policy_name = arg
153
+ end
154
+
155
+ # A "non-DSL-style" setter for `policy_name`
156
+ #
157
+ # @see #policy_name
158
+ def policy_name=(policy_name)
159
+ policy_name(policy_name)
160
+ end
161
+
162
+ # The `policy_group` for this node. Setting this to a non-nil value will
163
+ # enable policyfile mode when `chef-client` is run. If set in the config
164
+ # file or in node json, running `chef-client` will update this value.
165
+ #
166
+ # @see Chef::PolicyBuilder::Dynamic
167
+ # @see Chef::PolicyBuilder::Policyfile
168
+ #
169
+ # @param arg [String] the new policy_group value
170
+ # @return [String] the current policy_group, or the one you just set
171
+ def policy_group(arg=NULL_ARG)
172
+ return @policy_group if arg.equal?(NULL_ARG)
173
+ validate({policy_group: arg}, { policy_group: { kind_of: [ String, NilClass ], regex: /^[\-:.[:alnum:]_]+$/ } })
174
+ @policy_group = arg
175
+ end
176
+
177
+ # A "non-DSL-style" setter for `policy_group`
178
+ #
179
+ # @see #policy_group
180
+ def policy_group=(policy_group)
181
+ policy_group(policy_group)
182
+ end
183
+
135
184
  def attributes
136
185
  @attributes
137
186
  end
@@ -391,7 +440,7 @@ class Chef
391
440
 
392
441
  self.tags # make sure they're defined
393
442
 
394
- automatic_attrs[:recipes] = expansion.recipes.with_fully_qualified_names_and_version_constraints
443
+ automatic_attrs[:recipes] = expansion.recipes.with_duplicate_names
395
444
  automatic_attrs[:expanded_run_list] = expansion.recipes.with_fully_qualified_names_and_version_constraints
396
445
  automatic_attrs[:roles] = expansion.roles
397
446
 
@@ -461,6 +510,14 @@ class Chef
461
510
  #Render correctly for run_list items so malformed json does not result
462
511
  "run_list" => @primary_runlist.run_list.map { |item| item.to_s }
463
512
  }
513
+ # Chef Server rejects node JSON with extra keys; prior to 12.3,
514
+ # "policy_name" and "policy_group" are unknown; after 12.3 they are
515
+ # optional, therefore only including them in the JSON if present
516
+ # maximizes compatibility for most people.
517
+ unless policy_group.nil? && policy_name.nil?
518
+ result["policy_name"] = policy_name
519
+ result["policy_group"] = policy_group
520
+ end
464
521
  result
465
522
  end
466
523
 
@@ -492,6 +549,10 @@ class Chef
492
549
  else
493
550
  o["recipes"].each { |r| node.recipes << r }
494
551
  end
552
+
553
+ node.policy_name = o["policy_name"] if o.has_key?("policy_name")
554
+ node.policy_group = o["policy_group"] if o.has_key?("policy_group")
555
+
495
556
  node
496
557
  end
497
558
 
@@ -553,8 +614,16 @@ class Chef
553
614
  chef_server_rest.put_rest("nodes/#{name}", data_for_save)
554
615
  end
555
616
  rescue Net::HTTPServerException => e
556
- raise e unless e.response.code == "404"
557
- chef_server_rest.post_rest("nodes", data_for_save)
617
+ if e.response.code == "404"
618
+ chef_server_rest.post_rest("nodes", data_for_save)
619
+ # Chef Server before 12.3 rejects node JSON with 'policy_name' or
620
+ # 'policy_group' keys, but 'policy_name' will be detected first.
621
+ # Backcompat can be removed in 13.0
622
+ elsif e.response.code == "400" && e.response.body.include?("Invalid key policy_name")
623
+ save_without_policyfile_attrs
624
+ else
625
+ raise
626
+ end
558
627
  end
559
628
  self
560
629
  end
@@ -563,6 +632,15 @@ class Chef
563
632
  def create
564
633
  chef_server_rest.post_rest("nodes", data_for_save)
565
634
  self
635
+ rescue Net::HTTPServerException => e
636
+ # Chef Server before 12.3 rejects node JSON with 'policy_name' or
637
+ # 'policy_group' keys, but 'policy_name' will be detected first.
638
+ # Backcompat can be removed in 13.0
639
+ if e.response.code == "400" && e.response.body.include?("Invalid key policy_name")
640
+ chef_server_rest.post_rest("nodes", data_for_save_without_policyfile_attrs)
641
+ else
642
+ raise
643
+ end
566
644
  end
567
645
 
568
646
  def to_s
@@ -575,6 +653,22 @@ class Chef
575
653
 
576
654
  private
577
655
 
656
+ def save_without_policyfile_attrs
657
+ trimmed_data = data_for_save_without_policyfile_attrs
658
+
659
+ chef_server_rest.put_rest("nodes/#{name}", trimmed_data)
660
+ rescue Net::HTTPServerException => e
661
+ raise e unless e.response.code == "404"
662
+ chef_server_rest.post_rest("nodes", trimmed_data)
663
+ end
664
+
665
+ def data_for_save_without_policyfile_attrs
666
+ data_for_save.tap do |trimmed_data|
667
+ trimmed_data.delete("policy_name")
668
+ trimmed_data.delete("policy_group")
669
+ end
670
+ end
671
+
578
672
  def data_for_save
579
673
  data = for_json
580
674
  ["automatic", "default", "normal", "override"].each do |level|
@@ -32,8 +32,8 @@ class Chef
32
32
  # @return [NodeMap] Returns self for possible chaining
33
33
  #
34
34
  def set(key, value, platform: nil, platform_version: nil, platform_family: nil, os: nil, on_platform: nil, on_platforms: nil, canonical: nil, override: nil, &block)
35
- Chef::Log.deprecation "The on_platform option to node_map has been deprecated" if on_platform
36
- Chef::Log.deprecation "The on_platforms option to node_map has been deprecated" if on_platforms
35
+ Chef.log_deprecation("The on_platform option to node_map has been deprecated") if on_platform
36
+ Chef.log_deprecation("The on_platforms option to node_map has been deprecated") if on_platforms
37
37
  platform ||= on_platform || on_platforms
38
38
  filters = {}
39
39
  filters[:platform] = platform if platform
@@ -200,14 +200,13 @@ class Chef
200
200
  class_name = resource_type.class.name ? resource_type.class.name.split('::').last :
201
201
  convert_to_class_name(resource_type.resource_name.to_s)
202
202
 
203
- begin
204
- result = Chef::Provider.const_get(class_name)
205
- Chef::Log.warn("Class Chef::Provider::#{class_name} does not declare 'resource_name #{convert_to_snake_case(class_name).to_sym.inspect}'.")
206
- Chef::Log.warn("This will no longer work in Chef 13: you must use 'resource_name' to provide DSL.")
207
- rescue NameError
203
+ if Chef::Provider.const_defined?(class_name)
204
+ Chef::Log.warn("Class Chef::Provider::#{class_name} does not declare 'provides #{convert_to_snake_case(class_name).to_sym.inspect}'.")
205
+ Chef::Log.warn("This will no longer work in Chef 13: you must use 'provides' to use the resource's DSL.")
206
+ return Chef::Provider.const_get(class_name)
208
207
  end
209
208
  end
210
- result
209
+ nil
211
210
  end
212
211
 
213
212
  end
@@ -25,13 +25,10 @@ class Chef
25
25
  end
26
26
 
27
27
  def windows_server_2003?
28
+ # WMI startup shouldn't be performed unless we're on Windows.
28
29
  return false unless windows?
29
30
  require 'wmi-lite/wmi'
30
31
 
31
- # CHEF-4888: Work around ruby #2618, expected to be fixed in Ruby 2.1.0
32
- # https://github.com/ruby/ruby/commit/588504b20f5cc880ad51827b93e571e32446e5db
33
- # https://github.com/ruby/ruby/commit/27ed294c7134c0de582007af3c915a635a6506cd
34
-
35
32
  wmi = WmiLite::Wmi.new
36
33
  host = wmi.first_of('Win32_OperatingSystem')
37
34
  is_server_2003 = (host['version'] && host['version'].start_with?("5.2"))
@@ -39,6 +36,44 @@ class Chef
39
36
  is_server_2003
40
37
  end
41
38
 
39
+ def windows_nano_server?
40
+ return false unless windows?
41
+ require 'win32/registry'
42
+
43
+ # This method may be called before ohai runs (e.g., it may be used to
44
+ # determine settings in config.rb). Chef::Win32::Registry.new uses
45
+ # node attributes to verify the machine architecture which aren't
46
+ # accessible before ohai runs.
47
+ nano = nil
48
+ key = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Server\\ServerLevels"
49
+ access = ::Win32::Registry::KEY_QUERY_VALUE | 0x0100 # nano is 64-bit only
50
+ begin
51
+ ::Win32::Registry::HKEY_LOCAL_MACHINE.open(key, access) do |reg|
52
+ nano = reg["NanoServer"]
53
+ end
54
+ rescue ::Win32::Registry::Error
55
+ # If accessing the registry key failed, then we're probably not on
56
+ # nano. Fail through.
57
+ end
58
+ return nano == 1
59
+ end
60
+
61
+ def supports_msi?
62
+ return false unless windows?
63
+ require 'win32/registry'
64
+
65
+ key = "System\\CurrentControlSet\\Services\\msiserver"
66
+ access = ::Win32::Registry::KEY_QUERY_VALUE
67
+
68
+ begin
69
+ ::Win32::Registry::HKEY_LOCAL_MACHINE.open(key, access) do |reg|
70
+ true
71
+ end
72
+ rescue ::Win32::Registry::Error
73
+ false
74
+ end
75
+ end
76
+
42
77
  def supports_powershell_execution_bypass?(node)
43
78
  node[:languages] && node[:languages][:powershell] &&
44
79
  node[:languages][:powershell][:version].to_i >= 3
@@ -55,6 +90,13 @@ class Chef
55
90
  Gem::Version.new(node[:languages][:powershell][:version]) >=
56
91
  Gem::Version.new("5.0.10018.0")
57
92
  end
93
+
94
+ def dsc_refresh_mode_disabled?(node)
95
+ require 'chef/util/powershell/cmdlet'
96
+ cmdlet = Chef::Util::Powershell::Cmdlet.new(node, "Get-DscLocalConfigurationManager", :object)
97
+ metadata = cmdlet.run!.return_value
98
+ metadata['RefreshMode'] == 'Disabled'
99
+ end
58
100
  end
59
101
  end
60
102
  end