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
@@ -42,7 +42,18 @@ class Chef
42
42
  entries = @name_args[1].split(',').map { |e| e.strip }
43
43
  end
44
44
 
45
- entries.each { |e| node.run_list.remove(e) }
45
+ # iterate over the list of things to remove,
46
+ # warning if one of them was not found
47
+ entries.each do |e|
48
+ if node.run_list.find { |rli| e == rli.to_s }
49
+ node.run_list.remove(e)
50
+ else
51
+ ui.warn "#{e} is not in the run list"
52
+ unless e =~ /^(recipe|role)\[/
53
+ ui.warn '(did you forget recipe[] or role[] around it?)'
54
+ end
55
+ end
56
+ end
46
57
 
47
58
  node.save
48
59
 
@@ -0,0 +1,10 @@
1
+ class Chef
2
+ class Knife
3
+ class Null < Chef::Knife
4
+ banner "knife null"
5
+
6
+ def run
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,62 @@
1
+ #
2
+ # Author:: Steven Danna <steve@chef.io>
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife'
20
+ require 'chef/knife/core/subcommand_loader'
21
+
22
+ class Chef
23
+ class Knife
24
+ class Rehash < Chef::Knife
25
+ banner "knife rehash"
26
+
27
+ def run
28
+ if ! Chef::Knife::SubcommandLoader.autogenerated_manifest?
29
+ ui.msg "Using knife-rehash will speed up knife's load time by caching the location of subcommands on disk."
30
+ ui.msg "However, you will need to update the cache by running `knife rehash` anytime you install a new knife plugin."
31
+ else
32
+ reload_plugins
33
+ end
34
+ write_hash(generate_hash)
35
+ end
36
+
37
+ def reload_plugins
38
+ Chef::Knife::SubcommandLoader::GemGlobLoader.new(@@chef_config_dir).load_commands
39
+ end
40
+
41
+ def generate_hash
42
+ output = if Chef::Knife::SubcommandLoader.plugin_manifest?
43
+ Chef::Knife::SubcommandLoader.plugin_manifest
44
+ else
45
+ { Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY => {}}
46
+ end
47
+ output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]['plugins_paths'] = Chef::Knife.subcommand_files
48
+ output[Chef::Knife::SubcommandLoader::HashedCommandLoader::KEY]['plugins_by_category'] = Chef::Knife.subcommands_by_category
49
+ output
50
+ end
51
+
52
+ def write_hash(data)
53
+ plugin_manifest_dir = File.expand_path('..', Chef::Knife::SubcommandLoader.plugin_manifest_path)
54
+ FileUtils.mkdir_p(plugin_manifest_dir) unless File.directory?(plugin_manifest_dir)
55
+ File.open(Chef::Knife::SubcommandLoader.plugin_manifest_path, 'w') do |f|
56
+ f.write(Chef::JSONCompat.to_json_pretty(data))
57
+ ui.msg "Knife subcommands are cached in #{Chef::Knife::SubcommandLoader.plugin_manifest_path}. Delete this file to disable the caching."
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -136,7 +136,7 @@ class Chef
136
136
  def read_cli_args
137
137
  if config[:query]
138
138
  if @name_args[1]
139
- ui.error "please specify query as an argument or an option via -q, not both"
139
+ ui.error "Please specify query as an argument or an option via -q, not both"
140
140
  ui.msg opt_parser
141
141
  exit 1
142
142
  end
@@ -145,7 +145,7 @@ class Chef
145
145
  else
146
146
  case name_args.size
147
147
  when 0
148
- ui.error "no query specified"
148
+ ui.error "No query specified"
149
149
  ui.msg opt_parser
150
150
  exit 1
151
151
  when 1
@@ -160,7 +160,7 @@ class Chef
160
160
 
161
161
  def fuzzify_query
162
162
  if @query !~ /:/
163
- @query = "tags:*#{@query}* OR roles:*#{@query}* OR fqdn:*#{@query}* OR addresses:*#{@query}*"
163
+ @query = "tags:*#{@query}* OR roles:*#{@query}* OR fqdn:*#{@query}* OR addresses:*#{@query}* OR policy_name:*#{@query}* OR policy_group:*#{@query}*"
164
164
  end
165
165
  end
166
166
 
@@ -132,15 +132,19 @@ class Chef
132
132
  if config[:ssh_gateway]
133
133
  gw_host, gw_user = config[:ssh_gateway].split('@').reverse
134
134
  gw_host, gw_port = gw_host.split(':')
135
- gw_opts = gw_port ? { :port => gw_port } : {}
135
+ gw_opts = session_options(gw_host, gw_port, gw_user)
136
+ user = gw_opts.delete(:user)
136
137
 
137
- session.via(gw_host, gw_user || config[:ssh_user], gw_opts)
138
+ begin
139
+ # Try to connect with a key.
140
+ session.via(gw_host, user, gw_opts)
141
+ rescue Net::SSH::AuthenticationFailed
142
+ prompt = "Enter the password for #{user}@#{gw_host}: "
143
+ gw_opts[:password] = prompt_for_password(prompt)
144
+ # Try again with a password.
145
+ session.via(gw_host, user, gw_opts)
146
+ end
138
147
  end
139
- rescue Net::SSH::AuthenticationFailed
140
- user = gw_user || config[:ssh_user]
141
- prompt = "Enter the password for #{user}@#{gw_host}: "
142
- gw_opts.merge!(:password => prompt_for_password(prompt))
143
- session.via(gw_host, user, gw_opts)
144
148
  end
145
149
 
146
150
  def configure_session
@@ -204,32 +208,50 @@ class Chef
204
208
  list
205
209
  end
206
210
 
207
- def session_from_list(list)
208
- list.each do |item|
209
- host, ssh_port = item
210
- Chef::Log.debug("Adding #{host}")
211
- session_opts = {}
212
-
213
- ssh_config = Net::SSH.configuration_for(host)
214
-
211
+ # Net::SSH session options hash for global options. These should be
212
+ # options that will apply to the gateway connection in addition to the
213
+ # main one.
214
+ #
215
+ # @since 12.5.0
216
+ # @param host [String] Hostname for this session.
217
+ # @param port [String] SSH port for this session.
218
+ # @param user [String] Optional username for this session.
219
+ # @return [Hash<Symbol, Object>]
220
+ def session_options(host, port, user=nil)
221
+ ssh_config = Net::SSH.configuration_for(host)
222
+ {}.tap do |opts|
215
223
  # Chef::Config[:knife][:ssh_user] is parsed in #configure_user and written to config[:ssh_user]
216
- user = config[:ssh_user] || ssh_config[:user]
217
- hostspec = user ? "#{user}@#{host}" : host
218
- session_opts[:keys] = File.expand_path(config[:identity_file]) if config[:identity_file]
219
- session_opts[:keys_only] = true if config[:identity_file]
220
- session_opts[:password] = config[:ssh_password] if config[:ssh_password]
221
- session_opts[:forward_agent] = config[:forward_agent]
222
- session_opts[:port] = config[:ssh_port] ||
223
- ssh_port || # Use cloud port if available
224
- Chef::Config[:knife][:ssh_port] ||
225
- ssh_config[:port]
226
- session_opts[:logger] = Chef::Log.logger if Chef::Log.level == :debug
227
-
224
+ opts[:user] = user || config[:ssh_user] || ssh_config[:user]
225
+ if config[:identity_file]
226
+ opts[:keys] = File.expand_path(config[:identity_file])
227
+ opts[:keys_only] = true
228
+ elsif config[:ssh_password]
229
+ opts[:password] = config[:ssh_password]
230
+ end
231
+ # Don't set the keys to nil if we don't have them.
232
+ forward_agent = config[:forward_agent] || ssh_config[:forward_agent]
233
+ opts[:forward_agent] = forward_agent unless forward_agent.nil?
234
+ port ||= ssh_config[:port]
235
+ opts[:port] = port unless port.nil?
236
+ opts[:logger] = Chef::Log.logger if Chef::Log.level == :debug
228
237
  if !config[:host_key_verify]
229
- session_opts[:paranoid] = false
230
- session_opts[:user_known_hosts_file] = "/dev/null"
238
+ opts[:paranoid] = false
239
+ opts[:user_known_hosts_file] = '/dev/null'
231
240
  end
241
+ end
242
+ end
232
243
 
244
+ def session_from_list(list)
245
+ list.each do |item|
246
+ host, ssh_port = item
247
+ Chef::Log.debug("Adding #{host}")
248
+ session_opts = session_options(host, ssh_port)
249
+ # Handle port overrides for the main connection.
250
+ session_opts[:port] = Chef::Config[:knife][:ssh_port] if Chef::Config[:knife][:ssh_port]
251
+ session_opts[:port] = config[:ssh_port] if config[:ssh_port]
252
+ # Create the hostspec.
253
+ hostspec = session_opts[:user] ? "#{session_opts.delete(:user)}@#{host}" : host
254
+ # Connect a new session on the multi.
233
255
  session.use(hostspec, session_opts)
234
256
 
235
257
  @longest = host.length if host.length > @longest
@@ -405,7 +427,7 @@ class Chef
405
427
  begin
406
428
  require 'appscript'
407
429
  rescue LoadError
408
- STDERR.puts "you need the rb-appscript gem to use knife ssh macterm. `(sudo) gem install rb-appscript` to install"
430
+ STDERR.puts "You need the rb-appscript gem to use knife ssh macterm. `(sudo) gem install rb-appscript` to install"
409
431
  raise
410
432
  end
411
433
 
@@ -15,6 +15,11 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  require 'chef/config'
18
+ if Chef::Platform.windows?
19
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.1')
20
+ require 'chef/monkey_patches/webrick-utils'
21
+ end
22
+ end
18
23
 
19
24
  class Chef
20
25
  module LocalMode
@@ -37,7 +37,11 @@ class Chef
37
37
  end
38
38
  end
39
39
 
40
- def self.deprecation(msg=nil, &block)
40
+ def self.deprecation(msg=nil, location=caller(2..2)[0], &block)
41
+ if msg
42
+ msg << " at #{Array(location).join("\n")}"
43
+ msg = msg.join("") if msg.respond_to?(:join)
44
+ end
41
45
  if Chef::Config[:treat_deprecation_warnings_as_errors]
42
46
  error(msg, &block)
43
47
  raise Chef::Exceptions::DeprecatedFeatureError.new(msg)
@@ -102,20 +102,20 @@ class Chef
102
102
 
103
103
  def deprecated_attr_reader(name, alternative, level=:warn)
104
104
  define_method(name) do
105
- Chef::Log.deprecation("#{self.class}.#{name} is deprecated. Support will be removed in a future release.")
106
- Chef::Log.deprecation(alternative)
107
- Chef::Log.deprecation("Called from:")
108
- caller[0..3].each {|c| Chef::Log.deprecation(c)}
105
+ Chef.log_deprecation("#{self.class}.#{name} is deprecated. Support will be removed in a future release.")
106
+ Chef.log_deprecation(alternative)
107
+ Chef.log_deprecation("Called from:")
108
+ caller[0..3].each {|c| Chef.log_deprecation(c)}
109
109
  instance_variable_get("@#{name}")
110
110
  end
111
111
  end
112
112
 
113
113
  def deprecated_attr_writer(name, alternative, level=:warn)
114
114
  define_method("#{name}=") do |value|
115
- Chef::Log.deprecation("Writing to #{self.class}.#{name} with #{name}= is deprecated. Support will be removed in a future release.")
116
- Chef::Log.deprecation(alternative)
117
- Chef::Log.deprecation("Called from:")
118
- caller[0..3].each {|c| Chef::Log.deprecation(c)}
115
+ Chef.log_deprecation("Writing to #{self.class}.#{name} with #{name}= is deprecated. Support will be removed in a future release.")
116
+ Chef.log_deprecation(alternative)
117
+ Chef.log_deprecation("Called from:")
118
+ caller[0..3].each {|c| Chef.log_deprecation(c)}
119
119
  instance_variable_set("@#{name}", value)
120
120
  end
121
121
  end
@@ -291,7 +291,7 @@ class Chef
291
291
  def _pv_regex(opts, key, regex)
292
292
  value = _pv_opts_lookup(opts, key)
293
293
  if !value.nil?
294
- Array(regex).each do |r|
294
+ Array(regex).flatten.each do |r|
295
295
  return true if r.match(value.to_s)
296
296
  end
297
297
  raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} does not match regular expression #{regex.inspect}"
@@ -315,7 +315,7 @@ class Chef
315
315
  value = _pv_opts_lookup(opts, key)
316
316
  if !value.nil?
317
317
  callbacks.each do |message, zeproc|
318
- if zeproc.call(value) != true
318
+ unless zeproc.call(value)
319
319
  raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} #{message}!"
320
320
  end
321
321
  end
@@ -44,6 +44,52 @@ class Chef
44
44
 
45
45
  attr_reader :_extension_modules
46
46
 
47
+ #
48
+ # Helpers for adding context of which resource is rendering the template (CHEF-5012)
49
+ #
50
+
51
+ # name of the cookbook containing the template resource, e.g.:
52
+ # test
53
+ #
54
+ # @return [String] cookbook name
55
+ attr_reader :cookbook_name
56
+
57
+ # name of the recipe containing the template resource, e.g.:
58
+ # default
59
+ #
60
+ # @return [String] recipe name
61
+ attr_reader :recipe_name
62
+
63
+ # string representation of the line in the recipe containing the template resource, e.g.:
64
+ # /Users/lamont/solo/cookbooks/test/recipes/default.rb:2:in `from_file'
65
+ #
66
+ # @return [String] recipe line
67
+ attr_reader :recipe_line_string
68
+
69
+ # path to the recipe containing the template resource, e.g.:
70
+ # /Users/lamont/solo/cookbooks/test/recipes/default.rb
71
+ #
72
+ # @return [String] recipe path
73
+ attr_reader :recipe_path
74
+
75
+ # line in the recipe containing the template reosurce, e.g.:
76
+ # 2
77
+ #
78
+ # @return [String] recipe line
79
+ attr_reader :recipe_line
80
+
81
+ # name of the template source itself, e.g.:
82
+ # foo.erb
83
+ #
84
+ # @return [String] template name
85
+ attr_reader :template_name
86
+
87
+ # path to the template source itself, e.g.:
88
+ # /Users/lamont/solo/cookbooks/test/templates/default/foo.erb
89
+ #
90
+ # @return [String] template path
91
+ attr_reader :template_path
92
+
47
93
  def initialize(variables)
48
94
  super
49
95
  @_extension_modules = []
@@ -62,6 +108,7 @@ class Chef
62
108
  "include a node variable if you plan to use it."
63
109
  end
64
110
 
111
+
65
112
  #
66
113
  # Takes the name of the partial, plus a hash of options. Returns a
67
114
  # string that contains the result of the evaluation of the partial.
@@ -89,6 +136,7 @@ class Chef
89
136
  raise "You cannot render partials in this context" unless @template_finder
90
137
 
91
138
  partial_variables = options.delete(:variables) || _public_instance_variables
139
+ partial_variables[:template_finder] = @template_finder
92
140
  partial_context = self.class.new(partial_variables)
93
141
  partial_context._extend_modules(@_extension_modules)
94
142
 
@@ -28,7 +28,7 @@ class Chef
28
28
  paths = ENV['PATH'].split(File::PATH_SEPARATOR) + extra_path
29
29
  paths.each do |path|
30
30
  filename = File.join(path, cmd)
31
- return filename if File.executable?(filename)
31
+ return filename if File.executable?(Chef.path_to(filename))
32
32
  end
33
33
  false
34
34
  end
@@ -0,0 +1,72 @@
1
+ #
2
+ # Author:: Jay Mundrawala(<jdm@chef.io>)
3
+ # Copyright:: Copyright 2015 Chef Software
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class Chef
20
+ module Mixin
21
+ module WideString
22
+
23
+ def wstring(str)
24
+ if str.nil? || str.encoding == Encoding::UTF_16LE
25
+ str
26
+ else
27
+ utf8_to_wide(str)
28
+ end
29
+ end
30
+
31
+ def utf8_to_wide(ustring)
32
+ # ensure it is actually UTF-8
33
+ # Ruby likes to mark binary data as ASCII-8BIT
34
+ ustring = (ustring + "").force_encoding('UTF-8') if ustring.respond_to?(:force_encoding) && ustring.encoding.name != "UTF-8"
35
+
36
+ # ensure we have the double-null termination Windows Wide likes
37
+ ustring = ustring + "\000\000" if ustring.length == 0 or ustring[-1].chr != "\000"
38
+
39
+ # encode it all as UTF-16LE AKA Windows Wide Character AKA Windows Unicode
40
+ ustring = begin
41
+ if ustring.respond_to?(:encode)
42
+ ustring.encode('UTF-16LE')
43
+ else
44
+ require 'iconv'
45
+ Iconv.conv("UTF-16LE", "UTF-8", ustring)
46
+ end
47
+ end
48
+ ustring
49
+ end
50
+
51
+ def wide_to_utf8(wstring)
52
+ # ensure it is actually UTF-16LE
53
+ # Ruby likes to mark binary data as ASCII-8BIT
54
+ wstring = wstring.force_encoding('UTF-16LE') if wstring.respond_to?(:force_encoding)
55
+
56
+ # encode it all as UTF-8
57
+ wstring = begin
58
+ if wstring.respond_to?(:encode)
59
+ wstring.encode('UTF-8')
60
+ else
61
+ require 'iconv'
62
+ Iconv.conv("UTF-8", "UTF-16LE", wstring)
63
+ end
64
+ end
65
+ # remove trailing CRLF and NULL characters
66
+ wstring.strip!
67
+ wstring
68
+ end
69
+
70
+ end
71
+ end
72
+ end