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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bb8885d8fef5b3f1c25e60b31dc41f6fbcfd4ec
4
- data.tar.gz: 0ab23b2bb4e32bf69fe731661e4103d11ad65315
3
+ metadata.gz: 3c86d339c90f91e7424eb62914aa079c88147bbf
4
+ data.tar.gz: e46377e3e8d217dde44e76fcdad337c5dc905363
5
5
  SHA512:
6
- metadata.gz: d4bea571104aeba2611fd707005da1f8848eae843aed7e9bf18a3cf6250fdc8c3036c0f0a7c7f480e64df4079056ff863230a9732c1a89cdfe4d44fbf62d5ce2
7
- data.tar.gz: 258176206b6d683e50011f7d7d3deaf304b4bce98cc5ad96763d4a7ac4588de7699d227dcbae2e4a82f1ff0328d150c259ff7c69a92868dbf959ab676066746c
6
+ metadata.gz: 10a7da378604081a93c7ce8b70cffe9c9e93379ffdbc1dcef15e7ffb0f5069c3b001db3de5c0063f8b1120622292a05a29daec093e207604c1f56b79b2d70579
7
+ data.tar.gz: d2430bf003d81db3206c0f9bf74695a9b42118ce733c3a13a129dd53b7221fabd5c75b645dfaa7da5083a5536b156a824cca0535d5054212454971377af27df5
data/Rakefile CHANGED
@@ -24,6 +24,7 @@ require 'rubygems/package_task'
24
24
  require 'rdoc/task'
25
25
  require_relative 'tasks/rspec'
26
26
  require_relative 'tasks/external_tests'
27
+ require_relative 'tasks/maintainers'
27
28
 
28
29
  GEM_NAME = "chef"
29
30
 
@@ -108,9 +109,19 @@ Dir[File.expand_path("../*gemspec", __FILE__)].reverse.each do |gemspec_path|
108
109
  Gem::PackageTask.new(gemspec).define
109
110
  end
110
111
 
112
+ def with_clean_env(&block)
113
+ if defined?(Bundler)
114
+ Bundler.with_clean_env(&block)
115
+ else
116
+ block.call
117
+ end
118
+ end
119
+
111
120
  desc "Build and install a chef gem"
112
121
  task :install => [:package] do
113
- sh %{gem install pkg/#{GEM_NAME}-#{VERSION}.gem --no-rdoc --no-ri}
122
+ with_clean_env do
123
+ sh %{gem install pkg/#{GEM_NAME}-#{VERSION}.gem --no-rdoc --no-ri}
124
+ end
114
125
  end
115
126
 
116
127
  task :uninstall do
@@ -1,7 +1,7 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Author:: Nuo Yan (<nuo@opscode.com>)
4
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Author:: Nuo Yan (<nuo@chef.io>)
4
+ # Copyright:: Copyright (c) 2008, 2015 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,12 +23,18 @@ require 'chef/mixin/from_file'
23
23
  require 'chef/mash'
24
24
  require 'chef/json_compat'
25
25
  require 'chef/search/query'
26
+ require 'chef/exceptions'
27
+ require 'chef/mixin/api_version_request_handling'
28
+ require 'chef/server_api'
26
29
 
27
30
  class Chef
28
31
  class ApiClient
29
32
 
30
33
  include Chef::Mixin::FromFile
31
34
  include Chef::Mixin::ParamsValidate
35
+ include Chef::Mixin::ApiVersionRequestHandling
36
+
37
+ SUPPORTED_API_VERSIONS = [0,1]
32
38
 
33
39
  # Create a new Chef::ApiClient object.
34
40
  def initialize
@@ -37,6 +43,25 @@ class Chef
37
43
  @private_key = nil
38
44
  @admin = false
39
45
  @validator = false
46
+ @create_key = nil
47
+ end
48
+
49
+ def chef_rest_v0
50
+ @chef_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], {:api_version => "0"})
51
+ end
52
+
53
+ def chef_rest_v1
54
+ @chef_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], {:api_version => "1"})
55
+ end
56
+
57
+ # will default to the current version (Chef::Authenticator::DEFAULT_SERVER_API_VERSION)
58
+ def http_api
59
+ @http_api ||= Chef::REST.new(Chef::Config[:chef_server_url])
60
+ end
61
+
62
+ # will default to the current version (Chef::Authenticator::DEFAULT_SERVER_API_VERSION)
63
+ def self.http_api
64
+ Chef::REST.new(Chef::Config[:chef_server_url])
40
65
  end
41
66
 
42
67
  # Gets or sets the client name.
@@ -88,7 +113,8 @@ class Chef
88
113
  )
89
114
  end
90
115
 
91
- # Gets or sets the private key.
116
+ # Private key. The server will return it as a string.
117
+ # Set to true under API V0 to have the server regenerate the default key.
92
118
  #
93
119
  # @params [Optional String] The string representation of the private key.
94
120
  # @return [String] The current value.
@@ -96,7 +122,19 @@ class Chef
96
122
  set_or_return(
97
123
  :private_key,
98
124
  arg,
99
- :kind_of => [String, FalseClass]
125
+ :kind_of => [String, TrueClass, FalseClass]
126
+ )
127
+ end
128
+
129
+ # Used to ask server to generate key pair under api V1
130
+ #
131
+ # @params [Optional True/False] Should be true or false - default is false.
132
+ # @return [True/False] The current value
133
+ def create_key(arg=nil)
134
+ set_or_return(
135
+ :create_key,
136
+ arg,
137
+ :kind_of => [ TrueClass, FalseClass ]
100
138
  )
101
139
  end
102
140
 
@@ -107,13 +145,14 @@ class Chef
107
145
  def to_hash
108
146
  result = {
109
147
  "name" => @name,
110
- "public_key" => @public_key,
111
148
  "validator" => @validator,
112
149
  "admin" => @admin,
113
150
  'json_class' => self.class.name,
114
151
  "chef_type" => "client"
115
152
  }
116
- result["private_key"] = @private_key if @private_key
153
+ result["private_key"] = @private_key unless @private_key.nil?
154
+ result["public_key"] = @public_key unless @public_key.nil?
155
+ result["create_key"] = @create_key unless @create_key.nil?
117
156
  result
118
157
  end
119
158
 
@@ -127,10 +166,11 @@ class Chef
127
166
  def self.from_hash(o)
128
167
  client = Chef::ApiClient.new
129
168
  client.name(o["name"] || o["clientname"])
130
- client.private_key(o["private_key"]) if o.key?("private_key")
131
- client.public_key(o["public_key"])
132
169
  client.admin(o["admin"])
133
170
  client.validator(o["validator"])
171
+ client.private_key(o["private_key"]) if o.key?("private_key")
172
+ client.public_key(o["public_key"]) if o.key?("public_key")
173
+ client.create_key(o["create_key"]) if o.key?("create_key")
134
174
  client
135
175
  end
136
176
 
@@ -142,10 +182,6 @@ class Chef
142
182
  from_hash(Chef::JSONCompat.parse(j))
143
183
  end
144
184
 
145
- def self.http_api
146
- Chef::REST.new(Chef::Config[:chef_server_url])
147
- end
148
-
149
185
  def self.reregister(name)
150
186
  api_client = load(name)
151
187
  api_client.reregister
@@ -182,11 +218,11 @@ class Chef
182
218
  # Save this client via the REST API, returns a hash including the private key
183
219
  def save
184
220
  begin
185
- http_api.put("clients/#{name}", { :name => self.name, :admin => self.admin, :validator => self.validator})
221
+ update
186
222
  rescue Net::HTTPServerException => e
187
223
  # If that fails, go ahead and try and update it
188
224
  if e.response.code == "404"
189
- http_api.post("clients", {:name => self.name, :admin => self.admin, :validator => self.validator })
225
+ create
190
226
  else
191
227
  raise e
192
228
  end
@@ -194,18 +230,95 @@ class Chef
194
230
  end
195
231
 
196
232
  def reregister
197
- reregistered_self = http_api.put("clients/#{name}", { :name => name, :admin => admin, :validator => validator, :private_key => true })
233
+ # Try API V0 and if it fails due to V0 not being supported, raise the proper error message.
234
+ # reregister only supported in API V0 or lesser.
235
+ reregistered_self = chef_rest_v0.put("clients/#{name}", { :name => name, :admin => admin, :validator => validator, :private_key => true })
198
236
  if reregistered_self.respond_to?(:[])
199
237
  private_key(reregistered_self["private_key"])
200
238
  else
201
239
  private_key(reregistered_self.private_key)
202
240
  end
203
241
  self
242
+ rescue Net::HTTPServerException => e
243
+ # if there was a 406 related to versioning, give error explaining that
244
+ # only API version 0 is supported for reregister command
245
+ if e.response.code == "406" && e.response["x-ops-server-api-version"]
246
+ version_header = Chef::JSONCompat.from_json(e.response["x-ops-server-api-version"])
247
+ min_version = version_header["min_version"]
248
+ max_version = version_header["max_version"]
249
+ error_msg = reregister_only_v0_supported_error_msg(max_version, min_version)
250
+ raise Chef::Exceptions::OnlyApiVersion0SupportedForAction.new(error_msg)
251
+ else
252
+ raise e
253
+ end
254
+ end
255
+
256
+ # Updates the client via the REST API
257
+ def update
258
+ # NOTE: API V1 dropped support for updating client keys via update (aka PUT),
259
+ # but this code never supported key updating in the first place. Since
260
+ # it was never implemented, we will simply ignore that functionality
261
+ # as it is being deprecated.
262
+ # Delete this comment after V0 support is dropped.
263
+ payload = { :name => name }
264
+ payload[:validator] = validator unless validator.nil?
265
+
266
+ # DEPRECATION
267
+ # This field is ignored in API V1, but left for backwards-compat,
268
+ # can remove after API V0 is no longer supported.
269
+ payload[:admin] = admin unless admin.nil?
270
+
271
+ begin
272
+ new_client = chef_rest_v1.put("clients/#{name}", payload)
273
+ rescue Net::HTTPServerException => e
274
+ # rescue API V0 if 406 and the server supports V0
275
+ supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS)
276
+ raise e unless supported_versions && supported_versions.include?(0)
277
+ new_client = chef_rest_v0.put("clients/#{name}", payload)
278
+ end
279
+
280
+ new_client
204
281
  end
205
282
 
206
283
  # Create the client via the REST API
207
284
  def create
208
- http_api.post("clients", self)
285
+ payload = {
286
+ :name => name,
287
+ :validator => validator,
288
+ # this field is ignored in API V1, but left for backwards-compat,
289
+ # can remove after OSC 11 support is finished?
290
+ :admin => admin
291
+ }
292
+ begin
293
+ # try API V1
294
+ raise Chef::Exceptions::InvalidClientAttribute, "You cannot set both public_key and create_key for create." if !create_key.nil? && !public_key.nil?
295
+
296
+ payload[:public_key] = public_key unless public_key.nil?
297
+ payload[:create_key] = create_key unless create_key.nil?
298
+
299
+ new_client = chef_rest_v1.post("clients", payload)
300
+
301
+ # get the private_key out of the chef_key hash if it exists
302
+ if new_client['chef_key']
303
+ if new_client['chef_key']['private_key']
304
+ new_client['private_key'] = new_client['chef_key']['private_key']
305
+ end
306
+ new_client['public_key'] = new_client['chef_key']['public_key']
307
+ new_client.delete('chef_key')
308
+ end
309
+
310
+ rescue Net::HTTPServerException => e
311
+ # rescue API V0 if 406 and the server supports V0
312
+ supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS)
313
+ raise e unless supported_versions && supported_versions.include?(0)
314
+
315
+ # under API V0, a key pair will always be created unless public_key is
316
+ # passed on initial POST
317
+ payload[:public_key] = public_key unless public_key.nil?
318
+
319
+ new_client = chef_rest_v0.post("clients", payload)
320
+ end
321
+ Chef::ApiClient.from_hash(self.to_hash.merge(new_client))
209
322
  end
210
323
 
211
324
  # As a string
@@ -213,14 +326,5 @@ class Chef
213
326
  "client[#{@name}]"
214
327
  end
215
328
 
216
- def inspect
217
- "Chef::ApiClient name:'#{name}' admin:'#{admin.inspect}' validator:'#{validator}' " +
218
- "public_key:'#{public_key}' private_key:'#{private_key}'"
219
- end
220
-
221
- def http_api
222
- @http_api ||= Chef::REST.new(Chef::Config[:chef_server_url])
223
- end
224
-
225
329
  end
226
330
  end
@@ -93,7 +93,6 @@ class Chef
93
93
  if config[:config_file].nil?
94
94
  Chef::Log.warn("No config file found or specified on command line, using command line options.")
95
95
  elsif config_fetcher.config_missing?
96
- pp config_missing: true
97
96
  Chef::Log.warn("*****************************************")
98
97
  Chef::Log.warn("Did not find config file: #{config[:config_file]}, using command line options.")
99
98
  Chef::Log.warn("*****************************************")
@@ -279,6 +279,12 @@ class Chef::Application::Client < Chef::Application
279
279
  Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url
280
280
 
281
281
  Chef::Config.local_mode = config[:local_mode] if config.has_key?(:local_mode)
282
+
283
+ if Chef::Config.has_key?(:chef_repo_path) && Chef::Config.chef_repo_path.nil?
284
+ Chef::Config.delete(:chef_repo_path)
285
+ Chef::Log.warn "chef_repo_path was set in a config file but was empty. Assuming #{Chef::Config.chef_repo_path}"
286
+ end
287
+
282
288
  if Chef::Config.local_mode && !Chef::Config.has_key?(:cookbook_path) && !Chef::Config.has_key?(:chef_repo_path)
283
289
  Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
284
290
  end
@@ -320,12 +326,6 @@ class Chef::Application::Client < Chef::Application
320
326
  unless expected_modes.include?(mode)
321
327
  Chef::Application.fatal!(unrecognized_audit_mode(mode))
322
328
  end
323
-
324
- unless mode == :disabled
325
- # This should be removed when audit-mode is enabled by default/no longer
326
- # an experimental feature.
327
- Chef::Log.warn(audit_mode_experimental_message)
328
- end
329
329
  end
330
330
  end
331
331
 
@@ -448,7 +448,7 @@ class Chef::Application::Client < Chef::Application
448
448
  "\nEnable chef-client interval runs by setting `:client_fork = true` in your config file or adding `--fork` to your command line options."
449
449
  end
450
450
 
451
- def audit_mode_settings_explaination
451
+ def audit_mode_settings_explanation
452
452
  "\n* To enable audit mode after converge, use command line option `--audit-mode enabled` or set `:audit_mode = :enabled` in your config file." +
453
453
  "\n* To disable audit mode, use command line option `--audit-mode disabled` or set `:audit_mode = :disabled` in your config file." +
454
454
  "\n* To only run audit mode, use command line option `--audit-mode audit-only` or set `:audit_mode = :audit_only` in your config file." +
@@ -456,18 +456,7 @@ class Chef::Application::Client < Chef::Application
456
456
  end
457
457
 
458
458
  def unrecognized_audit_mode(mode)
459
- "Unrecognized setting #{mode} for audit mode." + audit_mode_settings_explaination
460
- end
461
-
462
- def audit_mode_experimental_message
463
- msg = if Chef::Config[:audit_mode] == :audit_only
464
- "Chef-client has been configured to skip converge and only audit."
465
- else
466
- "Chef-client has been configured to audit after it converges."
467
- end
468
- msg += " Audit mode is an experimental feature currently under development. API changes may occur. Use at your own risk."
469
- msg += audit_mode_settings_explaination
470
- return msg
459
+ "Unrecognized setting #{mode} for audit mode." + audit_mode_settings_explanation
471
460
  end
472
461
 
473
462
  def fetch_recipe_tarball(url, path)
@@ -34,6 +34,7 @@ class Chef
34
34
  @rest_client = rest_client
35
35
  # Ruby 1.9.3 and above "enumerate their values in the order that the corresponding keys were inserted."
36
36
  @ordered_control_groups = Hash.new
37
+ @audit_phase_error = nil
37
38
  end
38
39
 
39
40
  def run_context
@@ -46,7 +47,7 @@ class Chef
46
47
  @run_status = run_status
47
48
  end
48
49
 
49
- def audit_phase_complete
50
+ def audit_phase_complete(audit_output)
50
51
  Chef::Log.debug("Audit Reporter completed successfully without errors.")
51
52
  ordered_control_groups.each do |name, control_group|
52
53
  audit_data.add_control_group(control_group)
@@ -57,8 +58,9 @@ class Chef
57
58
  # that runs tests - normal errors are interpreted as EXAMPLE failures and captured.
58
59
  # We still want to send available audit information to the server so we process the
59
60
  # known control groups.
60
- def audit_phase_failed(error)
61
+ def audit_phase_failed(error, audit_output)
61
62
  # The stacktrace information has already been logged elsewhere
63
+ @audit_phase_error = error
62
64
  Chef::Log.debug("Audit Reporter failed.")
63
65
  ordered_control_groups.each do |name, control_group|
64
66
  audit_data.add_control_group(control_group)
@@ -70,7 +72,9 @@ class Chef
70
72
  end
71
73
 
72
74
  def run_failed(error)
73
- post_auditing_data(error)
75
+ # Audit phase errors are captured when audit_phase_failed gets called.
76
+ # The error passed here isn't relevant to auditing, so we ignore it.
77
+ post_auditing_data
74
78
  end
75
79
 
76
80
  def control_group_started(name)
@@ -98,7 +102,7 @@ class Chef
98
102
 
99
103
  private
100
104
 
101
- def post_auditing_data(error = nil)
105
+ def post_auditing_data
102
106
  unless auditing_enabled?
103
107
  Chef::Log.debug("Audit Reports are disabled. Skipping sending reports.")
104
108
  return
@@ -116,8 +120,10 @@ class Chef
116
120
  Chef::Log.debug("Sending audit report (run-id: #{audit_data.run_id})")
117
121
  run_data = audit_data.to_hash
118
122
 
119
- if error
120
- run_data[:error] = "#{error.class.to_s}: #{error.message}\n#{error.backtrace.join("\n")}"
123
+ if @audit_phase_error
124
+ error_info = "#{@audit_phase_error.class}: #{@audit_phase_error.message}"
125
+ error_info << "\n#{@audit_phase_error.backtrace.join("\n")}" if @audit_phase_error.backtrace
126
+ run_data[:error] = error_info
121
127
  end
122
128
 
123
129
  Chef::Log.debug "Audit Report:\n#{Chef::JSONCompat.to_json_pretty(run_data)}"
@@ -163,7 +169,6 @@ class Chef
163
169
  def iso8601ify(time)
164
170
  time.utc.iso8601.to_s
165
171
  end
166
-
167
172
  end
168
173
  end
169
174
  end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 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 'stringio'
19
+
20
+ class Chef
21
+ class Audit
22
+ class Logger
23
+ def self.puts(message="")
24
+ @buffer ||= StringIO.new
25
+ @buffer.puts(message)
26
+
27
+ Chef::Log.info(message)
28
+ end
29
+
30
+ def self.read_buffer
31
+ return "" if @buffer.nil?
32
+ @buffer.string
33
+ end
34
+ end
35
+ end
36
+ end