chef 12.4.0.rc.0-universal-mingw32 → 12.4.0.rc.2-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +12 -1
  3. data/lib/chef/api_client.rb +130 -26
  4. data/lib/chef/application.rb +0 -1
  5. data/lib/chef/application/client.rb +8 -19
  6. data/lib/chef/audit/audit_reporter.rb +12 -7
  7. data/lib/chef/audit/logger.rb +36 -0
  8. data/lib/chef/audit/runner.rb +4 -2
  9. data/lib/chef/chef_class.rb +62 -11
  10. data/lib/chef/client.rb +587 -207
  11. data/lib/chef/config.rb +0 -1
  12. data/lib/chef/dsl/recipe.rb +45 -56
  13. data/lib/chef/dsl/resources.rb +3 -2
  14. data/lib/chef/event_dispatch/base.rb +7 -2
  15. data/lib/chef/exceptions.rb +4 -1
  16. data/lib/chef/file_content_management/deploy/mv_windows.rb +16 -6
  17. data/lib/chef/formatters/doc.rb +15 -7
  18. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +10 -7
  19. data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -0
  20. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +4 -1
  21. data/lib/chef/http/authenticator.rb +7 -2
  22. data/lib/chef/knife.rb +16 -4
  23. data/lib/chef/knife/client_create.rb +55 -31
  24. data/lib/chef/knife/core/generic_presenter.rb +1 -1
  25. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  26. data/lib/chef/knife/osc_user_create.rb +97 -0
  27. data/lib/chef/knife/osc_user_delete.rb +51 -0
  28. data/lib/chef/knife/osc_user_edit.rb +58 -0
  29. data/lib/chef/knife/osc_user_list.rb +47 -0
  30. data/lib/chef/knife/osc_user_reregister.rb +64 -0
  31. data/lib/chef/knife/osc_user_show.rb +54 -0
  32. data/lib/chef/knife/user_create.rb +95 -36
  33. data/lib/chef/knife/user_delete.rb +52 -2
  34. data/lib/chef/knife/user_edit.rb +37 -7
  35. data/lib/chef/knife/user_list.rb +3 -0
  36. data/lib/chef/knife/user_reregister.rb +39 -8
  37. data/lib/chef/knife/user_show.rb +30 -1
  38. data/lib/chef/mixin/api_version_request_handling.rb +66 -0
  39. data/lib/chef/mixin/convert_to_class_name.rb +10 -4
  40. data/lib/chef/mixin/deprecation.rb +24 -0
  41. data/lib/chef/mixin/powershell_out.rb +98 -0
  42. data/lib/chef/mixin/provides.rb +5 -18
  43. data/lib/chef/mixin/uris.rb +11 -0
  44. data/lib/chef/mixin/windows_architecture_helper.rb +5 -2
  45. data/lib/chef/mixin/windows_env_helper.rb +11 -2
  46. data/lib/chef/node_map.rb +130 -75
  47. data/lib/chef/osc_user.rb +194 -0
  48. data/lib/chef/platform/provider_mapping.rb +2 -269
  49. data/lib/chef/platform/provider_priority_map.rb +6 -69
  50. data/lib/chef/platform/query_helpers.rb +5 -0
  51. data/lib/chef/platform/resource_priority_map.rb +12 -15
  52. data/lib/chef/policy_builder/policyfile.rb +1 -0
  53. data/lib/chef/provider.rb +19 -0
  54. data/lib/chef/provider/directory.rb +3 -0
  55. data/lib/chef/provider/dsc_resource.rb +8 -1
  56. data/lib/chef/provider/file.rb +1 -0
  57. data/lib/chef/provider/group/aix.rb +1 -0
  58. data/lib/chef/provider/group/dscl.rb +1 -1
  59. data/lib/chef/provider/group/gpasswd.rb +1 -0
  60. data/lib/chef/provider/group/groupmod.rb +1 -1
  61. data/lib/chef/provider/group/pw.rb +1 -0
  62. data/lib/chef/provider/group/suse.rb +2 -0
  63. data/lib/chef/provider/group/usermod.rb +2 -1
  64. data/lib/chef/provider/group/windows.rb +1 -1
  65. data/lib/chef/provider/ifconfig.rb +2 -0
  66. data/lib/chef/provider/ifconfig/aix.rb +1 -0
  67. data/lib/chef/provider/ifconfig/debian.rb +2 -0
  68. data/lib/chef/provider/ifconfig/redhat.rb +1 -0
  69. data/lib/chef/provider/lwrp_base.rb +4 -0
  70. data/lib/chef/provider/mount.rb +0 -1
  71. data/lib/chef/provider/mount/aix.rb +1 -0
  72. data/lib/chef/provider/mount/mount.rb +2 -0
  73. data/lib/chef/provider/mount/solaris.rb +2 -0
  74. data/lib/chef/provider/package.rb +55 -0
  75. data/lib/chef/provider/package/aix.rb +7 -7
  76. data/lib/chef/provider/package/apt.rb +3 -3
  77. data/lib/chef/provider/package/dpkg.rb +4 -4
  78. data/lib/chef/provider/package/easy_install.rb +5 -5
  79. data/lib/chef/provider/package/freebsd/base.rb +2 -2
  80. data/lib/chef/provider/package/freebsd/pkg.rb +6 -6
  81. data/lib/chef/provider/package/freebsd/pkgng.rb +5 -5
  82. data/lib/chef/provider/package/freebsd/port.rb +4 -4
  83. data/lib/chef/provider/package/homebrew.rb +2 -2
  84. data/lib/chef/provider/package/ips.rb +4 -4
  85. data/lib/chef/provider/package/macports.rb +5 -6
  86. data/lib/chef/provider/package/openbsd.rb +4 -5
  87. data/lib/chef/provider/package/pacman.rb +4 -4
  88. data/lib/chef/provider/package/portage.rb +2 -0
  89. data/lib/chef/provider/package/rpm.rb +7 -8
  90. data/lib/chef/provider/package/rubygems.rb +5 -12
  91. data/lib/chef/provider/package/smartos.rb +4 -4
  92. data/lib/chef/provider/package/solaris.rb +7 -7
  93. data/lib/chef/provider/package/windows/msi.rb +1 -1
  94. data/lib/chef/provider/package/yum.rb +4 -6
  95. data/lib/chef/provider/package/zypper.rb +16 -14
  96. data/lib/chef/provider/powershell_script.rb +129 -47
  97. data/lib/chef/provider/remote_file/content.rb +4 -1
  98. data/lib/chef/provider/remote_file/local_file.rb +10 -4
  99. data/lib/chef/provider/service.rb +44 -0
  100. data/lib/chef/provider/service/freebsd.rb +1 -1
  101. data/lib/chef/provider/service/init.rb +1 -0
  102. data/lib/chef/provider/service/macosx.rb +1 -1
  103. data/lib/chef/provider/service/windows.rb +0 -1
  104. data/lib/chef/provider/user.rb +1 -1
  105. data/lib/chef/provider/user/aix.rb +3 -2
  106. data/lib/chef/provider/user/pw.rb +1 -0
  107. data/lib/chef/provider/user/solaris.rb +2 -0
  108. data/lib/chef/provider/user/useradd.rb +1 -0
  109. data/lib/chef/provider_resolver.rb +87 -134
  110. data/lib/chef/resource.rb +274 -68
  111. data/lib/chef/resource/apt_package.rb +0 -2
  112. data/lib/chef/resource/bash.rb +0 -2
  113. data/lib/chef/resource/batch.rb +1 -1
  114. data/lib/chef/resource/bff_package.rb +0 -7
  115. data/lib/chef/resource/breakpoint.rb +3 -6
  116. data/lib/chef/resource/chef_gem.rb +0 -3
  117. data/lib/chef/resource/cookbook_file.rb +1 -3
  118. data/lib/chef/resource/cron.rb +2 -4
  119. data/lib/chef/resource/csh.rb +0 -2
  120. data/lib/chef/resource/deploy.rb +9 -6
  121. data/lib/chef/resource/deploy_revision.rb +0 -14
  122. data/lib/chef/resource/directory.rb +2 -4
  123. data/lib/chef/resource/dpkg_package.rb +0 -5
  124. data/lib/chef/resource/dsc_resource.rb +2 -3
  125. data/lib/chef/resource/dsc_script.rb +2 -3
  126. data/lib/chef/resource/easy_install_package.rb +0 -7
  127. data/lib/chef/resource/env.rb +3 -3
  128. data/lib/chef/resource/erl_call.rb +2 -5
  129. data/lib/chef/resource/execute.rb +2 -4
  130. data/lib/chef/resource/file.rb +2 -4
  131. data/lib/chef/resource/freebsd_package.rb +0 -5
  132. data/lib/chef/resource/gem_package.rb +0 -3
  133. data/lib/chef/resource/git.rb +0 -3
  134. data/lib/chef/resource/group.rb +2 -4
  135. data/lib/chef/resource/homebrew_package.rb +0 -2
  136. data/lib/chef/resource/http_request.rb +3 -4
  137. data/lib/chef/resource/ifconfig.rb +3 -4
  138. data/lib/chef/resource/ips_package.rb +2 -2
  139. data/lib/chef/resource/link.rb +3 -5
  140. data/lib/chef/resource/log.rb +2 -4
  141. data/lib/chef/resource/lwrp_base.rb +10 -61
  142. data/lib/chef/resource/macosx_service.rb +1 -2
  143. data/lib/chef/resource/macports_package.rb +0 -7
  144. data/lib/chef/resource/mdadm.rb +2 -5
  145. data/lib/chef/resource/mount.rb +2 -4
  146. data/lib/chef/resource/ohai.rb +2 -4
  147. data/lib/chef/resource/openbsd_package.rb +0 -6
  148. data/lib/chef/resource/package.rb +9 -6
  149. data/lib/chef/resource/pacman_package.rb +0 -7
  150. data/lib/chef/resource/paludis_package.rb +2 -3
  151. data/lib/chef/resource/perl.rb +0 -3
  152. data/lib/chef/resource/portage_package.rb +0 -3
  153. data/lib/chef/resource/powershell_script.rb +1 -2
  154. data/lib/chef/resource/python.rb +0 -3
  155. data/lib/chef/resource/reboot.rb +1 -3
  156. data/lib/chef/resource/registry_key.rb +3 -5
  157. data/lib/chef/resource/remote_directory.rb +3 -5
  158. data/lib/chef/resource/remote_file.rb +4 -5
  159. data/lib/chef/resource/route.rb +3 -5
  160. data/lib/chef/resource/rpm_package.rb +0 -2
  161. data/lib/chef/resource/ruby.rb +0 -4
  162. data/lib/chef/resource/ruby_block.rb +2 -4
  163. data/lib/chef/resource/scm.rb +3 -5
  164. data/lib/chef/resource/script.rb +0 -3
  165. data/lib/chef/resource/service.rb +3 -5
  166. data/lib/chef/resource/smartos_package.rb +0 -9
  167. data/lib/chef/resource/solaris_package.rb +0 -10
  168. data/lib/chef/resource/subversion.rb +1 -3
  169. data/lib/chef/resource/template.rb +0 -4
  170. data/lib/chef/resource/timestamped_deploy.rb +0 -4
  171. data/lib/chef/resource/user.rb +2 -5
  172. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -7
  173. data/lib/chef/resource/windows_package.rb +3 -3
  174. data/lib/chef/resource/windows_script.rb +2 -2
  175. data/lib/chef/resource/windows_service.rb +3 -3
  176. data/lib/chef/resource/yum_package.rb +0 -3
  177. data/lib/chef/resource/zypper_package.rb +27 -0
  178. data/lib/chef/resource_builder.rb +7 -0
  179. data/lib/chef/resource_reporter.rb +1 -1
  180. data/lib/chef/resource_resolver.rb +108 -62
  181. data/lib/chef/resources.rb +1 -0
  182. data/lib/chef/rest.rb +1 -0
  183. data/lib/chef/server_api.rb +2 -0
  184. data/lib/chef/user.rb +193 -42
  185. data/lib/chef/util/backup.rb +9 -1
  186. data/lib/chef/util/path_helper.rb +0 -1
  187. data/lib/chef/version.rb +1 -1
  188. data/spec/functional/audit/runner_spec.rb +22 -42
  189. data/spec/functional/mixin/powershell_out_spec.rb +43 -0
  190. data/spec/functional/resource/execute_spec.rb +9 -2
  191. data/spec/functional/resource/file_spec.rb +25 -0
  192. data/spec/functional/resource/group_spec.rb +5 -0
  193. data/spec/functional/resource/link_spec.rb +5 -11
  194. data/spec/functional/resource/powershell_spec.rb +40 -5
  195. data/spec/functional/resource/user/useradd_spec.rb +10 -18
  196. data/spec/integration/recipes/lwrp_spec.rb +57 -0
  197. data/spec/integration/recipes/provider_choice.rb +2 -7
  198. data/spec/integration/recipes/recipe_dsl_spec.rb +517 -19
  199. data/spec/spec_helper.rb +1 -1
  200. data/spec/support/lib/chef/provider/openldap_includer.rb +29 -0
  201. data/spec/support/lib/chef/resource/cat.rb +0 -2
  202. data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -6
  203. data/spec/support/lib/chef/resource/openldap_includer.rb +27 -0
  204. data/spec/support/lib/chef/resource/with_state.rb +0 -9
  205. data/spec/support/lib/chef/resource/zen_follower.rb +0 -6
  206. data/spec/support/lib/chef/resource/zen_master.rb +1 -6
  207. data/spec/support/shared/context/client.rb +277 -0
  208. data/spec/support/shared/examples/client.rb +53 -0
  209. data/spec/support/shared/functional/file_resource.rb +0 -4
  210. data/spec/support/shared/functional/securable_resource.rb +0 -24
  211. data/spec/support/shared/functional/securable_resource_with_reporting.rb +4 -4
  212. data/spec/support/shared/functional/windows_script.rb +1 -1
  213. data/spec/support/shared/unit/api_versioning.rb +77 -0
  214. data/spec/support/shared/unit/knife_shared.rb +40 -0
  215. data/spec/support/shared/unit/user_and_client_shared.rb +115 -0
  216. data/spec/unit/api_client_spec.rb +189 -14
  217. data/spec/unit/application/client_spec.rb +0 -5
  218. data/spec/unit/audit/audit_reporter_spec.rb +58 -14
  219. data/spec/unit/audit/logger_spec.rb +42 -0
  220. data/spec/unit/audit/runner_spec.rb +2 -2
  221. data/spec/unit/chef_fs/file_pattern_spec.rb +3 -15
  222. data/spec/unit/client_spec.rb +58 -374
  223. data/spec/unit/cookbook_spec.rb +0 -9
  224. data/spec/unit/cookbook_version_spec.rb +0 -20
  225. data/spec/unit/deprecation_spec.rb +55 -0
  226. data/spec/unit/dsl/resources_spec.rb +85 -0
  227. data/spec/unit/exceptions_spec.rb +2 -2
  228. data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +60 -0
  229. data/spec/unit/formatters/doc_spec.rb +46 -0
  230. data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +12 -10
  231. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +8 -0
  232. data/spec/unit/http/authenticator_spec.rb +11 -2
  233. data/spec/unit/knife/client_create_spec.rb +122 -51
  234. data/spec/unit/knife/core/subcommand_loader_spec.rb +19 -3
  235. data/spec/unit/knife/core/ui_spec.rb +14 -0
  236. data/spec/unit/knife/osc_user_create_spec.rb +93 -0
  237. data/spec/unit/knife/osc_user_delete_spec.rb +44 -0
  238. data/spec/unit/knife/osc_user_edit_spec.rb +52 -0
  239. data/spec/unit/knife/osc_user_list_spec.rb +37 -0
  240. data/spec/unit/knife/osc_user_reregister_spec.rb +58 -0
  241. data/spec/unit/knife/osc_user_show_spec.rb +46 -0
  242. data/spec/unit/knife/user_create_spec.rb +177 -51
  243. data/spec/unit/knife/user_delete_spec.rb +34 -8
  244. data/spec/unit/knife/user_edit_spec.rb +31 -12
  245. data/spec/unit/knife/user_list_spec.rb +7 -3
  246. data/spec/unit/knife/user_reregister_spec.rb +38 -17
  247. data/spec/unit/knife/user_show_spec.rb +35 -11
  248. data/spec/unit/knife_spec.rb +10 -4
  249. data/spec/unit/lwrp_spec.rb +228 -54
  250. data/spec/unit/mixin/api_version_request_handling_spec.rb +127 -0
  251. data/spec/unit/mixin/command_spec.rb +1 -2
  252. data/spec/unit/mixin/powershell_out_spec.rb +70 -0
  253. data/spec/unit/mixin/uris_spec.rb +23 -11
  254. data/spec/unit/node_map_spec.rb +4 -1
  255. data/spec/unit/osc_user_spec.rb +276 -0
  256. data/spec/unit/platform_spec.rb +0 -60
  257. data/spec/unit/provider/deploy_spec.rb +1 -1
  258. data/spec/unit/provider/directory_spec.rb +199 -135
  259. data/spec/unit/provider/ifconfig/debian_spec.rb +0 -10
  260. data/spec/unit/provider/package/aix_spec.rb +16 -16
  261. data/spec/unit/provider/package/dpkg_spec.rb +2 -2
  262. data/spec/unit/provider/package/freebsd/pkg_spec.rb +13 -13
  263. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
  264. data/spec/unit/provider/package/freebsd/port_spec.rb +7 -7
  265. data/spec/unit/provider/package/ips_spec.rb +22 -22
  266. data/spec/unit/provider/package/macports_spec.rb +10 -10
  267. data/spec/unit/provider/package/openbsd_spec.rb +4 -26
  268. data/spec/unit/provider/package/pacman_spec.rb +5 -5
  269. data/spec/unit/provider/package/rpm_spec.rb +14 -14
  270. data/spec/unit/provider/package/rubygems_spec.rb +10 -44
  271. data/spec/unit/provider/package/smartos_spec.rb +4 -4
  272. data/spec/unit/provider/package/solaris_spec.rb +11 -11
  273. data/spec/unit/provider/package/zypper_spec.rb +125 -90
  274. data/spec/unit/provider/package_spec.rb +34 -0
  275. data/spec/unit/provider/powershell_spec.rb +53 -11
  276. data/spec/unit/provider/remote_directory_spec.rb +2 -2
  277. data/spec/unit/provider/remote_file/local_file_spec.rb +25 -6
  278. data/spec/unit/provider/service/freebsd_service_spec.rb +0 -12
  279. data/spec/unit/provider/user_spec.rb +3 -3
  280. data/spec/unit/provider_resolver_spec.rb +463 -327
  281. data/spec/unit/recipe_spec.rb +42 -15
  282. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  283. data/spec/unit/resource/erl_call_spec.rb +1 -1
  284. data/spec/unit/resource/file_spec.rb +1 -1
  285. data/spec/unit/resource/ifconfig_spec.rb +10 -6
  286. data/spec/unit/resource/remote_file_spec.rb +5 -0
  287. data/spec/unit/resource/route_spec.rb +1 -1
  288. data/spec/unit/resource/ruby_block_spec.rb +2 -2
  289. data/spec/unit/resource/template_spec.rb +1 -1
  290. data/spec/unit/resource/timestamped_deploy_spec.rb +1 -2
  291. data/spec/unit/resource/windows_service_spec.rb +1 -1
  292. data/spec/unit/resource_spec.rb +99 -13
  293. data/spec/unit/rest_spec.rb +5 -5
  294. data/spec/unit/run_context_spec.rb +41 -0
  295. data/spec/unit/runner_spec.rb +2 -2
  296. data/spec/unit/user_spec.rb +406 -93
  297. data/tasks/maintainers.rb +69 -0
  298. metadata +37 -4
@@ -51,4 +51,3 @@ class Chef
51
51
 
52
52
  end
53
53
  end
54
-
@@ -21,8 +21,10 @@ require 'chef/mixin/convert_to_class_name'
21
21
  require 'chef/exceptions'
22
22
  require 'chef/resource_builder'
23
23
  require 'chef/mixin/shell_out'
24
+ require 'chef/mixin/powershell_out'
24
25
  require 'chef/dsl/resources'
25
26
  require 'chef/dsl/definitions'
27
+ require 'chef/resource'
26
28
 
27
29
  class Chef
28
30
  module DSL
@@ -33,58 +35,7 @@ class Chef
33
35
  module Recipe
34
36
 
35
37
  include Chef::Mixin::ShellOut
36
-
37
- # method_missing must live for backcompat purposes until Chef 13.
38
- def method_missing(method_symbol, *args, &block)
39
- #
40
- # If there is already DSL for this, someone must have called
41
- # method_missing manually. Not a fan. Not. A. Fan.
42
- #
43
- if respond_to?(method_symbol)
44
- Chef::Log.deprecation("Calling method_missing(#{method_symbol.inspect}) directly is deprecated in Chef 12 and will be removed in Chef 13.")
45
- Chef::Log.deprecation("Use public_send() or send() instead.")
46
- return send(method_symbol, *args, &block)
47
- end
48
-
49
- #
50
- # If a definition exists, then Chef::DSL::Definitions.add_definition was
51
- # never called. DEPRECATED.
52
- #
53
- if run_context.definitions.has_key?(method_symbol.to_sym)
54
- Chef::Log.deprecation("Definition #{method_symbol} (#{run_context.definitions[method_symbol.to_sym]}) was added to the run_context without calling Chef::DSL::Definitions.add_definition(#{method_symbol.to_sym.inspect}). This will become required in Chef 13.")
55
- Chef::DSL::Definitions.add_definition(method_symbol)
56
- return send(method_symbol, *args, &block)
57
- end
58
-
59
- #
60
- # See if the resource exists anyway. If the user had set
61
- # Chef::Resource::Blah = <resource>, a deprecation warning will be
62
- # emitted and the DSL method 'blah' will be added to the DSL.
63
- #
64
- resource_class = Chef::ResourceResolver.new(run_context ? run_context.node : nil, method_symbol).resolve
65
- if resource_class
66
- #
67
- # If the DSL method was *not* added, this is the case where the
68
- # matching class implements 'provides?' and matches resources that it
69
- # never declared "provides" for (which means we would never have
70
- # created DSL). Anything where we don't create DSL is deprecated.
71
- #
72
- if !respond_to?(method_symbol)
73
- Chef::Log.deprecation("#{resource_class} is marked as providing DSL #{method_symbol}, but provides #{method_symbol.inspect} was never called!")
74
- Chef::Log.deprecation("In Chef 13, this will break: you must call provides to mark the names you provide, even if you also override provides? yourself.")
75
- Chef::DSL::Resources.add_resource_dsl(method_symbol)
76
- end
77
- return send(method_symbol, *args, &block)
78
- end
79
-
80
- begin
81
- super
82
- rescue NoMethodError
83
- raise NoMethodError, "No resource or method named `#{method_symbol}' for #{describe_self_for_error}"
84
- rescue NameError
85
- raise NameError, "No resource, method, or local variable named `#{method_symbol}' for #{describe_self_for_error}"
86
- end
87
- end
38
+ include Chef::Mixin::PowershellOut
88
39
 
89
40
  include Chef::DSL::Resources
90
41
  include Chef::DSL::Definitions
@@ -183,14 +134,52 @@ class Chef
183
134
  raise Chef::Exceptions::ResourceNotFound, "exec was called, but you probably meant to use an execute resource. If not, please call Kernel#exec explicitly. The exec block called was \"#{args}\""
184
135
  end
185
136
 
137
+ # DEPRECATED:
138
+ # method_missing must live for backcompat purposes until Chef 13.
139
+ def method_missing(method_symbol, *args, &block)
140
+ #
141
+ # If there is already DSL for this, someone must have called
142
+ # method_missing manually. Not a fan. Not. A. Fan.
143
+ #
144
+ if respond_to?(method_symbol)
145
+ Chef::Log.deprecation("Calling method_missing(#{method_symbol.inspect}) directly is deprecated in Chef 12 and will be removed in Chef 13.")
146
+ Chef::Log.deprecation("Use public_send() or send() instead.")
147
+ return send(method_symbol, *args, &block)
148
+ end
149
+
150
+ #
151
+ # If a definition exists, then Chef::DSL::Definitions.add_definition was
152
+ # never called. DEPRECATED.
153
+ #
154
+ if run_context.definitions.has_key?(method_symbol.to_sym)
155
+ Chef::Log.deprecation("Definition #{method_symbol} (#{run_context.definitions[method_symbol.to_sym]}) was added to the run_context without calling Chef::DSL::Definitions.add_definition(#{method_symbol.to_sym.inspect}). This will become required in Chef 13.")
156
+ Chef::DSL::Definitions.add_definition(method_symbol)
157
+ return send(method_symbol, *args, &block)
158
+ end
159
+
160
+ #
161
+ # See if the resource exists anyway. If the user had set
162
+ # Chef::Resource::Blah = <resource>, a deprecation warning will be
163
+ # emitted and the DSL method 'blah' will be added to the DSL.
164
+ #
165
+ resource_class = Chef::ResourceResolver.resolve(method_symbol, node: run_context ? run_context.node : nil)
166
+ if resource_class
167
+ Chef::DSL::Resources.add_resource_dsl(method_symbol)
168
+ return send(method_symbol, *args, &block)
169
+ end
170
+
171
+ begin
172
+ super
173
+ rescue NoMethodError
174
+ raise NoMethodError, "No resource or method named `#{method_symbol}' for #{describe_self_for_error}"
175
+ rescue NameError
176
+ raise NameError, "No resource, method, or local variable named `#{method_symbol}' for #{describe_self_for_error}"
177
+ end
178
+ end
186
179
  end
187
180
  end
188
181
  end
189
182
 
190
- # We require this at the BOTTOM of this file to avoid circular requires (it is used
191
- # at runtime but not load time)
192
- require 'chef/resource'
193
-
194
183
  # **DEPRECATED**
195
184
  # This used to be part of chef/mixin/recipe_definition_dsl_core. Load the file to activate the deprecation code.
196
185
  require 'chef/mixin/recipe_definition_dsl_core'
@@ -10,12 +10,13 @@ class Chef
10
10
  def self.add_resource_dsl(dsl_name)
11
11
  begin
12
12
  module_eval(<<-EOM, __FILE__, __LINE__+1)
13
- def #{dsl_name}(name, created_at=nil, &block)
13
+ def #{dsl_name}(name=nil, created_at=nil, &block)
14
14
  declare_resource(#{dsl_name.inspect}, name, created_at || caller[0], &block)
15
15
  end
16
16
  EOM
17
17
  rescue SyntaxError
18
- define_method(dsl_name.to_sym) do |name, created_at=nil, &block|
18
+ # Handle the case where dsl_name has spaces, etc.
19
+ define_method(dsl_name.to_sym) do |name=nil, created_at=nil, &block|
19
20
  declare_resource(dsl_name, name, created_at || caller[0], &block)
20
21
  end
21
22
  end
@@ -82,6 +82,11 @@ class Chef
82
82
  def node_load_completed(node, expanded_run_list, config)
83
83
  end
84
84
 
85
+ # Called after the Policyfile was loaded. This event only occurs when
86
+ # chef is in policyfile mode.
87
+ def policyfile_loaded(policy)
88
+ end
89
+
85
90
  # Called before the cookbook collection is fetched from the server.
86
91
  def cookbook_resolution_start(expanded_run_list)
87
92
  end
@@ -239,13 +244,13 @@ class Chef
239
244
  end
240
245
 
241
246
  # Called when audit phase successfully finishes
242
- def audit_phase_complete
247
+ def audit_phase_complete(audit_output)
243
248
  end
244
249
 
245
250
  # Called if there is an uncaught exception during the audit phase. The audit runner should
246
251
  # be catching and handling errors from the examples, so this is only uncaught errors (like
247
252
  # bugs in our handling code)
248
- def audit_phase_failed(exception)
253
+ def audit_phase_failed(exception, audit_output)
249
254
  end
250
255
 
251
256
  # Signifies the start of a `control_group` block with a defined name
@@ -73,10 +73,13 @@ class Chef
73
73
  class KeyCommandInputError < ArgumentError; end
74
74
  class InvalidKeyArgument < ArgumentError; end
75
75
  class InvalidKeyAttribute < ArgumentError; end
76
+ class InvalidUserAttribute < ArgumentError; end
77
+ class InvalidClientAttribute < ArgumentError; end
76
78
  class RedirectLimitExceeded < RuntimeError; end
77
79
  class AmbiguousRunlistSpecification < ArgumentError; end
78
80
  class CookbookFrozen < ArgumentError; end
79
81
  class CookbookNotFound < RuntimeError; end
82
+ class OnlyApiVersion0SupportedForAction < RuntimeError; end
80
83
  # Cookbook loader used to raise an argument error when cookbook not found.
81
84
  # for back compat, need to raise an error that inherits from ArgumentError
82
85
  class CookbookNotFoundInRepo < ArgumentError; end
@@ -435,7 +438,7 @@ class Chef
435
438
  wrapped_errors.each_with_index do |e,i|
436
439
  backtrace << "#{i+1}) #{e.class} - #{e.message}"
437
440
  backtrace += e.backtrace if e.backtrace
438
- backtrace << ""
441
+ backtrace << "" unless i == wrapped_errors.length - 1
439
442
  end
440
443
  set_backtrace(backtrace)
441
444
  end
@@ -63,12 +63,22 @@ class Chef
63
63
  raise Chef::Exceptions::WindowsNotAdmin, "can not get the security information for '#{dst}' due to missing Administrator privileges."
64
64
  end
65
65
 
66
- if dst_sd.dacl_present?
67
- apply_dacl = ACL.create(dst_sd.dacl.select { |ace| !ace.inherited? })
66
+ dacl_present = dst_sd.dacl_present?
67
+ if dacl_present
68
+ if dst_sd.dacl.nil?
69
+ apply_dacl = nil
70
+ else
71
+ apply_dacl = ACL.create(dst_sd.dacl.select { |ace| !ace.inherited? })
72
+ end
68
73
  end
69
74
 
70
- if dst_sd.sacl_present?
71
- apply_sacl = ACL.create(dst_sd.sacl.select { |ace| !ace.inherited? })
75
+ sacl_present = dst_sd.sacl_present?
76
+ if sacl_present
77
+ if dst_sd.sacl.nil?
78
+ apply_sacl = nil
79
+ else
80
+ apply_sacl = ACL.create(dst_sd.sacl.select { |ace| !ace.inherited? })
81
+ end
72
82
  end
73
83
 
74
84
  #
@@ -84,8 +94,8 @@ class Chef
84
94
  dst_so = Security::SecurableObject.new(dst)
85
95
  dst_so.group = dst_sd.group
86
96
  dst_so.owner = dst_sd.owner
87
- dst_so.set_dacl(apply_dacl, dst_sd.dacl_inherits?) if dst_sd.dacl_present?
88
- dst_so.set_sacl(apply_sacl, dst_sd.sacl_inherits?) if dst_sd.sacl_present?
97
+ dst_so.set_dacl(apply_dacl, dst_sd.dacl_inherits?) if dacl_present
98
+ dst_so.set_sacl(apply_sacl, dst_sd.sacl_inherits?) if sacl_present
89
99
 
90
100
  end
91
101
  end
@@ -3,9 +3,9 @@ require 'chef/config'
3
3
 
4
4
  class Chef
5
5
  module Formatters
6
- #--
7
- # TODO: not sold on the name, but the output is similar to what rspec calls
8
- # "specdoc"
6
+
7
+ # Formatter similar to RSpec's documentation formatter. Uses indentation to
8
+ # show context.
9
9
  class Doc < Formatters::Base
10
10
 
11
11
  attr_reader :start_time, :end_time, :successful_audits, :failed_audits
@@ -93,6 +93,10 @@ class Chef
93
93
  def node_load_completed(node, expanded_run_list, config)
94
94
  end
95
95
 
96
+ def policyfile_loaded(policy)
97
+ puts_line "Using policy '#{policy["name"]}' at revision '#{policy["revision_id"]}'"
98
+ end
99
+
96
100
  # Called before the cookbook collection is fetched from the server.
97
101
  def cookbook_resolution_start(expanded_run_list)
98
102
  puts_line "resolving cookbooks for run list: #{expanded_run_list.inspect}"
@@ -175,17 +179,21 @@ class Chef
175
179
  puts_line "Starting audit phase"
176
180
  end
177
181
 
178
- def audit_phase_complete
182
+ def audit_phase_complete(audit_output)
183
+ puts_line audit_output
179
184
  puts_line "Auditing complete"
180
185
  end
181
186
 
182
- def audit_phase_failed(error)
187
+ def audit_phase_failed(error, audit_output)
188
+ puts_line audit_output
183
189
  puts_line ""
184
190
  puts_line "Audit phase exception:"
185
191
  indent
186
192
  puts_line "#{error.message}"
187
- error.backtrace.each do |l|
188
- puts_line l
193
+ if error.backtrace
194
+ error.backtrace.each do |l|
195
+ puts_line l
196
+ end
189
197
  end
190
198
  end
191
199
 
@@ -68,14 +68,17 @@ E
68
68
  end
69
69
 
70
70
  def describe_406_error(error_description, response)
71
- if Chef::JSONCompat.from_json(response.body)["error"] == "invalid-x-ops-server-api-version"
72
- min_version = Chef::JSONCompat.from_json(response.body)["min_version"]
73
- max_version = Chef::JSONCompat.from_json(response.body)["max_version"]
71
+ if response["x-ops-server-api-version"]
72
+ version_header = Chef::JSONCompat.from_json(response["x-ops-server-api-version"])
73
+ client_api_version = version_header["request_version"]
74
+ min_server_version = version_header["min_version"]
75
+ max_server_version = version_header["max_version"]
76
+
74
77
  error_description.section("Incompatible server API version:",<<-E)
75
- This version of Chef is not supported by the Chef server you sent this request to
76
- This version of Chef requires a server API version of #{Chef::HTTP::Authenticator::SERVER_API_VERSION}
77
- The Chef server you sent the request to supports a min API version of #{min_version} and a max API version of #{max_version}
78
- Please either update your Chef client or server to be a compatible set
78
+ This version of the API that this Chef request specified is not supported by the Chef server you sent this request to.
79
+ The server supports a min API version of #{min_server_version} and a max API version of #{max_server_version}.
80
+ Chef just made a request with an API version of #{client_api_version}.
81
+ Please either update your Chef client or server to be a compatible set.
79
82
  E
80
83
  else
81
84
  describe_http_error(error_description)
@@ -16,6 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require 'chef/mixin/shell_out'
20
+
19
21
  class Chef
20
22
  class GuardInterpreter
21
23
  class DefaultGuardInterpreter
@@ -92,8 +92,11 @@ class Chef
92
92
  raise ArgumentError, "Specified guard interpreter class #{resource_class} must be a kind of Chef::Resource::Execute resource"
93
93
  end
94
94
 
95
+ # Duplicate the node below because the new RunContext
96
+ # overwrites the state of Node instances passed to it.
97
+ # See https://github.com/chef/chef/issues/3485.
95
98
  empty_events = Chef::EventDispatch::Dispatcher.new
96
- anonymous_run_context = Chef::RunContext.new(parent_resource.node, {}, empty_events)
99
+ anonymous_run_context = Chef::RunContext.new(parent_resource.node.dup, {}, empty_events)
97
100
  interpreter_resource = resource_class.new('Guard resource', anonymous_run_context)
98
101
  interpreter_resource.is_guard_interpreter = true
99
102
 
@@ -24,7 +24,7 @@ class Chef
24
24
  class HTTP
25
25
  class Authenticator
26
26
 
27
- SERVER_API_VERSION = "0"
27
+ DEFAULT_SERVER_API_VERSION = "1"
28
28
 
29
29
  attr_reader :signing_key_filename
30
30
  attr_reader :raw_key
@@ -39,11 +39,16 @@ class Chef
39
39
  @signing_key_filename = opts[:signing_key_filename]
40
40
  @key = load_signing_key(opts[:signing_key_filename], opts[:raw_key])
41
41
  @auth_credentials = AuthCredentials.new(opts[:client_name], @key)
42
+ if opts[:api_version]
43
+ @api_version = opts[:api_version]
44
+ else
45
+ @api_version = DEFAULT_SERVER_API_VERSION
46
+ end
42
47
  end
43
48
 
44
49
  def handle_request(method, url, headers={}, data=false)
45
50
  headers.merge!(authentication_headers(method, url, data)) if sign_requests?
46
- headers.merge!({'X-Ops-Server-API-Version' => SERVER_API_VERSION})
51
+ headers.merge!({'X-Ops-Server-API-Version' => @api_version})
47
52
  [method, url, headers, data]
48
53
  end
49
54
 
@@ -487,11 +487,13 @@ class Chef
487
487
  ui.error "Service temporarily unavailable"
488
488
  ui.info "Response: #{format_rest_error(response)}"
489
489
  when Net::HTTPNotAcceptable
490
- min_version = Chef::JSONCompat.from_json(response.body)["min_version"]
491
- max_version = Chef::JSONCompat.from_json(response.body)["max_version"]
490
+ version_header = Chef::JSONCompat.from_json(response["x-ops-server-api-version"])
491
+ client_api_version = version_header["request_version"]
492
+ min_server_version = version_header["min_version"]
493
+ max_server_version = version_header["max_version"]
492
494
  ui.error "The version of Chef that Knife is using is not supported by the Chef server you sent this request to"
493
- ui.info "This version of Chef requires a server API version of #{Chef::HTTP::Authenticator::SERVER_API_VERSION}"
494
- ui.info "The Chef server you sent the request to supports a min API verson of #{min_version} and a max API version of #{max_version}"
495
+ ui.info "The request that Knife sent was using API version #{client_api_version}"
496
+ ui.info "The Chef server you sent the request to supports a min API verson of #{min_server_version} and a max API version of #{max_server_version}"
495
497
  ui.info "Please either update your Chef client or server to be a compatible set"
496
498
  else
497
499
  ui.error response.message
@@ -549,6 +551,16 @@ class Chef
549
551
  self.msg("Deleted #{obj_name}")
550
552
  end
551
553
 
554
+ # helper method for testing if a field exists
555
+ # and returning the usage and proper error if not
556
+ def test_mandatory_field(field, fieldname)
557
+ if field.nil?
558
+ show_usage
559
+ ui.fatal("You must specify a #{fieldname}")
560
+ exit 1
561
+ end
562
+ end
563
+
552
564
  def rest
553
565
  @rest ||= begin
554
566
  require 'chef/rest'
@@ -28,58 +28,82 @@ class Chef
28
28
  end
29
29
 
30
30
  option :file,
31
- :short => "-f FILE",
32
- :long => "--file FILE",
33
- :description => "Write the key to a file"
31
+ :short => "-f FILE",
32
+ :long => "--file FILE",
33
+ :description => "Write the private key to a file if the server generated one."
34
34
 
35
35
  option :admin,
36
- :short => "-a",
37
- :long => "--admin",
38
- :description => "Create the client as an admin",
39
- :boolean => true
36
+ :short => "-a",
37
+ :long => "--admin",
38
+ :description => "Open Source Chef 11 only. Create the client as an admin.",
39
+ :boolean => true
40
40
 
41
41
  option :validator,
42
- :long => "--validator",
43
- :description => "Create the client as a validator",
44
- :boolean => true
42
+ :long => "--validator",
43
+ :description => "Create the client as a validator.",
44
+ :boolean => true
45
45
 
46
- banner "knife client create CLIENT (options)"
46
+ option :public_key,
47
+ :short => "-p FILE",
48
+ :long => "--public-key",
49
+ :description => "Set the initial default key for the client from a file on disk (cannot pass with --prevent-keygen)."
50
+
51
+ option :prevent_keygen,
52
+ :short => "-k",
53
+ :long => "--prevent-keygen",
54
+ :description => "API V1 only. Prevent server from generating a default key pair for you. Cannot be passed with --public-key.",
55
+ :boolean => true
56
+
57
+ banner "knife client create CLIENTNAME (options)"
58
+
59
+ def client
60
+ @client_field ||= Chef::ApiClient.new
61
+ end
62
+
63
+ def create_client(client)
64
+ # should not be using save :( bad behavior
65
+ client.save
66
+ end
47
67
 
48
68
  def run
49
- @client_name = @name_args[0]
69
+ test_mandatory_field(@name_args[0], "client name")
70
+ client.name @name_args[0]
50
71
 
51
- if @client_name.nil?
72
+ if config[:public_key] && config[:prevent_keygen]
52
73
  show_usage
53
- ui.fatal("You must specify a client name")
74
+ ui.fatal("You cannot pass --public-key and --prevent-keygen")
54
75
  exit 1
55
76
  end
56
77
 
57
- client_hash = {
58
- "name" => @client_name,
59
- "admin" => !!config[:admin],
60
- "validator" => !!config[:validator]
61
- }
78
+ if !config[:prevent_keygen] && !config[:public_key]
79
+ client.create_key(true)
80
+ end
81
+
82
+ if config[:admin]
83
+ client.admin(true)
84
+ end
62
85
 
63
- output = Chef::ApiClient.from_hash(edit_hash(client_hash))
86
+ if config[:validator]
87
+ client.validator(true)
88
+ end
64
89
 
65
- # Chef::ApiClient.save will try to create a client and if it
66
- # exists will update it instead silently.
67
- client = output.save
90
+ if config[:public_key]
91
+ client.public_key File.read(File.expand_path(config[:public_key]))
92
+ end
68
93
 
69
- # We only get a private_key on client creation, not on client update.
70
- if client['private_key']
71
- ui.info("Created #{output}")
94
+ output = edit_data(client)
95
+ final_client = create_client(output)
96
+ ui.info("Created #{output}")
72
97
 
98
+ # output private_key if one
99
+ if final_client.private_key
73
100
  if config[:file]
74
101
  File.open(config[:file], "w") do |f|
75
- f.print(client['private_key'])
102
+ f.print(final_client.private_key)
76
103
  end
77
104
  else
78
- puts client['private_key']
105
+ puts final_client.private_key
79
106
  end
80
- else
81
- ui.error "Client '#{client['name']}' already exists"
82
- exit 1
83
107
  end
84
108
  end
85
109
  end