chef 13.6.4 → 13.7.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/acceptance/Gemfile +2 -2
  4. data/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb +1 -6
  5. data/distro/powershell/chef/chef.psm1 +1 -5
  6. data/lib/chef/api_client.rb +5 -5
  7. data/lib/chef/api_client_v1.rb +6 -6
  8. data/lib/chef/application.rb +3 -2
  9. data/lib/chef/application/knife.rb +4 -0
  10. data/lib/chef/chef_class.rb +2 -2
  11. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +2 -4
  13. data/lib/chef/client.rb +3 -3
  14. data/lib/chef/cookbook/chefignore.rb +4 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +2 -2
  16. data/lib/chef/cookbook/metadata.rb +2 -2
  17. data/lib/chef/data_bag.rb +1 -1
  18. data/lib/chef/deprecated.rb +10 -0
  19. data/lib/chef/event_dispatch/base.rb +2 -2
  20. data/lib/chef/http.rb +10 -10
  21. data/lib/chef/knife.rb +16 -15
  22. data/lib/chef/knife/configure.rb +12 -36
  23. data/lib/chef/knife/cookbook_upload.rb +4 -4
  24. data/lib/chef/knife/core/bootstrap_context.rb +1 -1
  25. data/lib/chef/knife/core/status_presenter.rb +6 -2
  26. data/lib/chef/knife/core/ui.rb +1 -1
  27. data/lib/chef/knife/data_bag_secret_options.rb +1 -1
  28. data/lib/chef/knife/data_bag_show.rb +1 -1
  29. data/lib/chef/knife/edit.rb +1 -1
  30. data/lib/chef/knife/ssh.rb +47 -35
  31. data/lib/chef/knife/user_create.rb +2 -0
  32. data/lib/chef/knife/user_delete.rb +2 -0
  33. data/lib/chef/knife/user_edit.rb +2 -0
  34. data/lib/chef/knife/user_reregister.rb +2 -0
  35. data/lib/chef/knife/user_show.rb +2 -0
  36. data/lib/chef/mixin/powershell_out.rb +1 -1
  37. data/lib/chef/node/attribute.rb +46 -70
  38. data/lib/chef/node/attribute_collections.rb +5 -5
  39. data/lib/chef/node/common_api.rb +1 -1
  40. data/lib/chef/node/immutable_collections.rb +180 -23
  41. data/lib/chef/node/mixin/state_tracking.rb +6 -6
  42. data/lib/chef/node_map.rb +63 -45
  43. data/lib/chef/property.rb +8 -8
  44. data/lib/chef/provider.rb +9 -3
  45. data/lib/chef/provider/apt_preference.rb +1 -1
  46. data/lib/chef/provider/apt_repository.rb +1 -1
  47. data/lib/chef/provider/apt_update.rb +1 -1
  48. data/lib/chef/provider/file.rb +1 -1
  49. data/lib/chef/provider/group/dscl.rb +6 -2
  50. data/lib/chef/provider/ifconfig.rb +96 -34
  51. data/lib/chef/provider/launchd.rb +0 -1
  52. data/lib/chef/provider/log.rb +3 -13
  53. data/lib/chef/provider/package/dnf.rb +1 -1
  54. data/lib/chef/provider/package/smartos.rb +2 -2
  55. data/lib/chef/provider/reboot.rb +12 -0
  56. data/lib/chef/provider/remote_directory.rb +1 -1
  57. data/lib/chef/provider/remote_file/http.rb +3 -2
  58. data/lib/chef/provider/service/solaris.rb +6 -2
  59. data/lib/chef/provider/systemd_unit.rb +34 -33
  60. data/lib/chef/provider/user/dscl.rb +1 -1
  61. data/lib/chef/provider/windows_path.rb +6 -7
  62. data/lib/chef/provider/windows_task.rb +89 -33
  63. data/lib/chef/provider/yum_repository.rb +24 -9
  64. data/lib/chef/resource/apt_package.rb +1 -0
  65. data/lib/chef/resource/apt_preference.rb +4 -0
  66. data/lib/chef/resource/apt_repository.rb +4 -0
  67. data/lib/chef/resource/apt_update.rb +3 -0
  68. data/lib/chef/resource/bash.rb +4 -0
  69. data/lib/chef/resource/batch.rb +5 -0
  70. data/lib/chef/resource/bff_package.rb +4 -0
  71. data/lib/chef/resource/breakpoint.rb +6 -0
  72. data/lib/chef/resource/cab_package.rb +6 -6
  73. data/lib/chef/resource/chef_gem.rb +13 -0
  74. data/lib/chef/resource/chocolatey_package.rb +4 -6
  75. data/lib/chef/resource/cookbook_file.rb +13 -15
  76. data/lib/chef/resource/cron.rb +2 -0
  77. data/lib/chef/resource/csh.rb +4 -0
  78. data/lib/chef/resource/directory.rb +8 -26
  79. data/lib/chef/resource/dnf_package.rb +5 -0
  80. data/lib/chef/resource/dpkg_package.rb +2 -0
  81. data/lib/chef/resource/dsc_resource.rb +5 -0
  82. data/lib/chef/resource/dsc_script.rb +6 -0
  83. data/lib/chef/resource/env.rb +3 -0
  84. data/lib/chef/resource/erl_call.rb +5 -0
  85. data/lib/chef/resource/execute.rb +5 -1
  86. data/lib/chef/resource/file.rb +2 -1
  87. data/lib/chef/resource/file/verification.rb +10 -0
  88. data/lib/chef/resource/freebsd_package.rb +10 -2
  89. data/lib/chef/resource/gem_package.rb +2 -0
  90. data/lib/chef/resource/git.rb +2 -0
  91. data/lib/chef/resource/group.rb +1 -0
  92. data/lib/chef/resource/homebrew_package.rb +3 -0
  93. data/lib/chef/resource/http_request.rb +2 -0
  94. data/lib/chef/resource/ifconfig.rb +23 -150
  95. data/lib/chef/resource/ips_package.rb +1 -0
  96. data/lib/chef/resource/ksh.rb +6 -0
  97. data/lib/chef/resource/launchd.rb +5 -4
  98. data/lib/chef/resource/link.rb +10 -0
  99. data/lib/chef/resource/log.rb +19 -46
  100. data/lib/chef/resource/macports_package.rb +1 -0
  101. data/lib/chef/resource/mdadm.rb +4 -0
  102. data/lib/chef/resource/mount.rb +1 -0
  103. data/lib/chef/resource/msu_package.rb +7 -8
  104. data/lib/chef/resource/ohai.rb +2 -0
  105. data/lib/chef/resource/openbsd_package.rb +3 -0
  106. data/lib/chef/resource/osx_profile.rb +10 -40
  107. data/lib/chef/resource/package.rb +6 -0
  108. data/lib/chef/resource/pacman_package.rb +1 -0
  109. data/lib/chef/resource/paludis_package.rb +3 -0
  110. data/lib/chef/resource/perl.rb +4 -0
  111. data/lib/chef/resource/portage_package.rb +1 -0
  112. data/lib/chef/resource/powershell_package.rb +5 -0
  113. data/lib/chef/resource/powershell_script.rb +8 -0
  114. data/lib/chef/resource/python.rb +4 -0
  115. data/lib/chef/resource/reboot.rb +14 -20
  116. data/lib/chef/resource/registry_key.rb +1 -0
  117. data/lib/chef/resource/remote_directory.rb +3 -0
  118. data/lib/chef/resource/remote_file.rb +2 -0
  119. data/lib/chef/resource/resource_notification.rb +17 -0
  120. data/lib/chef/resource/route.rb +1 -0
  121. data/lib/chef/resource/rpm_package.rb +1 -0
  122. data/lib/chef/resource/ruby.rb +4 -0
  123. data/lib/chef/resource/ruby_block.rb +3 -0
  124. data/lib/chef/resource/script.rb +4 -0
  125. data/lib/chef/resource/service.rb +1 -0
  126. data/lib/chef/resource/smartos_package.rb +1 -0
  127. data/lib/chef/resource/solaris_package.rb +1 -0
  128. data/lib/chef/resource/subversion.rb +1 -0
  129. data/lib/chef/resource/systemd_unit.rb +6 -0
  130. data/lib/chef/resource/template.rb +9 -0
  131. data/lib/chef/resource/user.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +2 -0
  133. data/lib/chef/resource/windows_path.rb +5 -10
  134. data/lib/chef/resource/windows_service.rb +3 -0
  135. data/lib/chef/resource/windows_task.rb +66 -87
  136. data/lib/chef/resource/yum_repository.rb +26 -22
  137. data/lib/chef/resource/zypper_package.rb +2 -0
  138. data/lib/chef/resource/zypper_repository.rb +6 -1
  139. data/lib/chef/run_context.rb +8 -2
  140. data/lib/chef/server_api.rb +1 -0
  141. data/lib/chef/util/selinux.rb +5 -4
  142. data/lib/chef/version.rb +1 -1
  143. data/lib/chef/version/platform.rb +18 -0
  144. data/lib/chef/version_constraint/platform.rb +2 -0
  145. data/spec/data/client.d_00/02-strings.rb +2 -0
  146. data/spec/functional/assets/chefinittest +6 -4
  147. data/spec/functional/knife/ssh_spec.rb +54 -7
  148. data/spec/functional/resource/bff_spec.rb +3 -3
  149. data/spec/functional/resource/ifconfig_spec.rb +1 -1
  150. data/spec/functional/resource/mount_spec.rb +7 -3
  151. data/spec/functional/resource/user/useradd_spec.rb +4 -4
  152. data/spec/functional/resource/windows_task_spec.rb +6 -6
  153. data/spec/functional/win32/security_spec.rb +7 -33
  154. data/spec/integration/knife/data_bag_show_spec.rb +1 -1
  155. data/spec/integration/recipes/noop_resource_spec.rb +1 -1
  156. data/spec/integration/recipes/recipe_dsl_spec.rb +30 -30
  157. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  158. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +71 -15
  159. data/spec/spec_helper.rb +19 -0
  160. data/spec/support/shared/functional/execute_resource.rb +1 -1
  161. data/spec/support/shared/unit/application_dot_d.rb +2 -0
  162. data/spec/support/shared/unit/execute_resource.rb +8 -1
  163. data/spec/support/shared/unit/provider/file.rb +9 -1
  164. data/spec/unit/chef_fs/data_handler/data_bag_item_data_handler.rb +10 -7
  165. data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +2 -2
  166. data/spec/unit/client_spec.rb +1 -1
  167. data/spec/unit/deprecated_spec.rb +4 -4
  168. data/spec/unit/http_spec.rb +9 -0
  169. data/spec/unit/knife/bootstrap_spec.rb +5 -0
  170. data/spec/unit/knife/configure_spec.rb +10 -60
  171. data/spec/unit/knife/data_bag_create_spec.rb +40 -2
  172. data/spec/unit/knife/data_bag_show_spec.rb +16 -2
  173. data/spec/unit/knife/ssh_spec.rb +85 -39
  174. data/spec/unit/knife_spec.rb +2 -0
  175. data/spec/unit/lwrp_spec.rb +5 -3
  176. data/spec/unit/mixin/powershell_type_coercions_spec.rb +7 -6
  177. data/spec/unit/node/attribute_spec.rb +55 -24
  178. data/spec/unit/node/immutable_collections_spec.rb +28 -14
  179. data/spec/unit/node/vivid_mash_spec.rb +27 -10
  180. data/spec/unit/node_map_spec.rb +34 -0
  181. data/spec/unit/property_spec.rb +13 -13
  182. data/spec/unit/provider/group/dscl_spec.rb +14 -5
  183. data/spec/unit/provider/ifconfig_spec.rb +10 -3
  184. data/spec/unit/provider/remote_file/http_spec.rb +23 -19
  185. data/spec/unit/provider/service/solaris_smf_service_spec.rb +6 -5
  186. data/spec/unit/provider/user/dscl_spec.rb +26 -0
  187. data/spec/unit/provider/windows_task_spec.rb +148 -4
  188. data/spec/unit/provider_spec.rb +1 -1
  189. data/spec/unit/resource/apt_package_spec.rb +1 -1
  190. data/spec/unit/resource/bash_spec.rb +8 -10
  191. data/spec/unit/resource/batch_spec.rb +1 -1
  192. data/spec/unit/resource/cab_package_spec.rb +19 -1
  193. data/spec/unit/resource/chef_gem_spec.rb +3 -3
  194. data/spec/unit/resource/chocolatey_package_spec.rb +10 -10
  195. data/spec/unit/resource/conditional_spec.rb +2 -2
  196. data/spec/unit/resource/cookbook_file_spec.rb +24 -30
  197. data/spec/unit/resource/cron_spec.rb +79 -82
  198. data/spec/unit/resource/csh_spec.rb +8 -10
  199. data/spec/unit/resource/deploy_spec.rb +1 -1
  200. data/spec/unit/resource/directory_spec.rb +28 -31
  201. data/spec/unit/resource/dnf_package_spec.rb +9 -9
  202. data/spec/unit/resource/env_spec.rb +7 -7
  203. data/spec/unit/resource/erl_call_spec.rb +9 -9
  204. data/spec/unit/resource/execute_spec.rb +6 -6
  205. data/spec/unit/resource/file/verification_spec.rb +18 -4
  206. data/spec/unit/resource/file_spec.rb +53 -56
  207. data/spec/unit/resource/freebsd_package_spec.rb +7 -7
  208. data/spec/unit/resource/gem_package_spec.rb +1 -1
  209. data/spec/unit/resource/git_spec.rb +7 -9
  210. data/spec/unit/resource/group_spec.rb +60 -70
  211. data/spec/unit/resource/http_request_spec.rb +16 -19
  212. data/spec/unit/resource/ifconfig_spec.rb +3 -3
  213. data/spec/unit/resource/ips_package_spec.rb +3 -5
  214. data/spec/unit/resource/ksh_spec.rb +8 -10
  215. data/spec/unit/resource/launchd_spec.rb +17 -10
  216. data/spec/unit/resource/link_spec.rb +53 -53
  217. data/spec/unit/resource/log_spec.rb +24 -28
  218. data/spec/unit/resource/mdadm_spec.rb +42 -44
  219. data/spec/unit/resource/mount_spec.rb +97 -99
  220. data/spec/unit/resource/msu_package_spec.rb +14 -8
  221. data/spec/unit/resource/ohai_spec.rb +15 -17
  222. data/spec/unit/resource/openbsd_package_spec.rb +3 -3
  223. data/spec/unit/resource/osx_profile_spec.rb +7 -7
  224. data/spec/unit/resource/package_spec.rb +36 -40
  225. data/spec/unit/resource/perl_spec.rb +8 -11
  226. data/spec/unit/resource/portage_package_spec.rb +8 -10
  227. data/spec/unit/resource/powershell_package_spec.rb +9 -9
  228. data/spec/unit/resource/python_spec.rb +8 -11
  229. data/spec/unit/resource/reboot_spec.rb +50 -0
  230. data/spec/unit/resource/registry_key_spec.rb +84 -98
  231. data/spec/unit/resource/remote_directory_spec.rb +40 -42
  232. data/spec/unit/resource/remote_file_spec.rb +78 -80
  233. data/spec/unit/resource/route_spec.rb +42 -44
  234. data/spec/unit/resource/rpm_package_spec.rb +5 -7
  235. data/spec/unit/resource/ruby_block_spec.rb +14 -16
  236. data/spec/unit/resource/ruby_spec.rb +8 -12
  237. data/spec/unit/resource/scm_spec.rb +66 -69
  238. data/spec/unit/resource/script_spec.rb +1 -1
  239. data/spec/unit/resource/service_spec.rb +80 -83
  240. data/spec/unit/resource/smartos_package_spec.rb +5 -0
  241. data/spec/unit/resource/solaris_package_spec.rb +3 -5
  242. data/spec/unit/resource/subversion_spec.rb +18 -16
  243. data/spec/unit/resource/systemd_unit_spec.rb +50 -54
  244. data/spec/unit/resource/template_spec.rb +56 -61
  245. data/spec/unit/resource/user_spec.rb +47 -53
  246. data/spec/unit/resource/windows_package_spec.rb +1 -1
  247. data/spec/unit/resource/windows_path_spec.rb +11 -8
  248. data/spec/unit/resource/windows_task_spec.rb +129 -33
  249. data/spec/unit/resource/yum_package_spec.rb +1 -1
  250. data/spec/unit/resource/yum_repository_spec.rb +61 -8
  251. data/spec/unit/resource/zypper_repository_spec.rb +17 -18
  252. data/spec/unit/util/selinux_spec.rb +3 -6
  253. data/tasks/dependencies.rb +0 -5
  254. data/tasks/rspec.rb +1 -1
  255. metadata +6 -6
  256. data/acceptance/top-cookbooks/.kitchen.docker.yml +0 -13
  257. data/acceptance/top-cookbooks/.kitchen.git.yml +0 -11
@@ -17,6 +17,7 @@
17
17
  #
18
18
 
19
19
  require "chef/knife"
20
+ require "chef/util/path_helper"
20
21
 
21
22
  class Chef
22
23
  class Knife
@@ -67,24 +68,22 @@ class Chef
67
68
  end
68
69
 
69
70
  def run
70
- ask_user_for_config_path
71
-
72
71
  FileUtils.mkdir_p(chef_config_path)
72
+ config_file = File.join(chef_config_path, "credentials")
73
73
 
74
74
  ask_user_for_config
75
75
 
76
- ::File.open(config[:config_file], "w") do |f|
76
+ config_file = File.expand_path(config_file)
77
+ if File.exist?(config_file)
78
+ confirm("Overwrite #{config_file}?")
79
+ end
80
+ ::File.open(config_file, "w") do |f|
77
81
  f.puts <<-EOH
78
- node_name '#{new_client_name}'
79
- client_key '#{new_client_key}'
80
- validation_client_name '#{validation_client_name}'
81
- validation_key '#{validation_key}'
82
- chef_server_url '#{chef_server}'
83
- syntax_check_cache_path '#{File.join(chef_config_path, "syntax_check_cache")}'
82
+ [default]
83
+ client_name = '#{new_client_name}'
84
+ client_key = '#{new_client_key}'
85
+ chef_server_url = '#{chef_server}'
84
86
  EOH
85
- unless chef_repo.empty?
86
- f.puts "cookbook_path [ '#{chef_repo}/cookbooks' ]"
87
- end
88
87
  end
89
88
 
90
89
  if config[:initial]
@@ -109,26 +108,11 @@ EOH
109
108
  ui.msg("Before running commands with Knife")
110
109
  ui.msg("")
111
110
  ui.msg("*****")
112
- ui.msg("")
113
- ui.msg("You must place your validation key in:")
114
- ui.msg(" #{validation_key}")
115
- ui.msg("Before generating instance data with Knife")
116
- ui.msg("")
117
- ui.msg("*****")
118
111
  end
119
112
 
120
113
  ui.msg("Configuration file written to #{config[:config_file]}")
121
114
  end
122
115
 
123
- def ask_user_for_config_path
124
- config[:config_file] ||= ask_question("Where should I put the config file? ", :default => "#{Chef::Config[:user_home]}/.chef/knife.rb")
125
- # have to use expand path to expand the tilde character to the user's home
126
- config[:config_file] = File.expand_path(config[:config_file])
127
- if File.exists?(config[:config_file])
128
- confirm("Overwrite #{config[:config_file]}")
129
- end
130
- end
131
-
132
116
  def ask_user_for_config
133
117
  server_name = guess_servername
134
118
  @chef_server = config[:chef_server_url] || ask_question("Please enter the chef server URL: ", :default => "https://#{server_name}/organizations/myorg")
@@ -140,10 +124,6 @@ EOH
140
124
  else
141
125
  @new_client_name = config[:node_name] || ask_question("Please enter an existing username or clientname for the API: ", :default => Etc.getlogin)
142
126
  end
143
- @validation_client_name = config[:validation_client_name] || ask_question("Please enter the validation clientname: ", :default => "chef-validator")
144
- @validation_key = config[:validation_key] || ask_question("Please enter the location of the validation key: ", :default => "/etc/chef-server/chef-validator.pem")
145
- @validation_key = File.expand_path(@validation_key)
146
- @chef_repo = config[:repository] || ask_question("Please enter the path to a chef repository (or leave blank): ")
147
127
 
148
128
  @new_client_key = config[:client_key] || File.join(chef_config_path, "#{@new_client_name}.pem")
149
129
  @new_client_key = File.expand_path(@new_client_key)
@@ -157,12 +137,8 @@ EOH
157
137
  o[:fqdn] || o[:machinename] || o[:hostname] || "localhost"
158
138
  end
159
139
 
160
- def config_file
161
- config[:config_file]
162
- end
163
-
164
140
  def chef_config_path
165
- File.dirname(config_file)
141
+ Chef::Util::PathHelper.home(".chef")
166
142
  end
167
143
  end
168
144
  end
@@ -146,12 +146,12 @@ class Chef
146
146
  end
147
147
 
148
148
  if upload_failures == 0
149
- ui.info "Uploaded #{upload_ok} cookbook#{upload_ok > 1 ? "s" : ""}."
149
+ ui.info "Uploaded #{upload_ok} cookbook#{upload_ok == 1 ? "" : "s"}."
150
150
  elsif upload_failures > 0 && upload_ok > 0
151
- ui.warn "Uploaded #{upload_ok} cookbook#{upload_ok > 1 ? "s" : ""} ok but #{upload_failures} " +
152
- "cookbook#{upload_failures > 1 ? "s" : ""} upload failed."
151
+ ui.warn "Uploaded #{upload_ok} cookbook#{upload_ok == 1 ? "" : "s"} ok but #{upload_failures} " +
152
+ "cookbook#{upload_failures == 1 ? "" : "s"} upload failed."
153
153
  elsif upload_failures > 0 && upload_ok == 0
154
- ui.error "Failed to upload #{upload_failures} cookbook#{upload_failures > 1 ? "s" : ""}."
154
+ ui.error "Failed to upload #{upload_failures} cookbook#{upload_failures == 1 ? "" : "s"}."
155
155
  exit 1
156
156
  end
157
157
  end
@@ -255,7 +255,7 @@ validation_client_name "#{@chef_config[:validation_client_name]}"
255
255
  content << "mkdir #{file_on_node}\n"
256
256
  else
257
257
  content << "cat > #{file_on_node} <<'EOP'\n" +
258
- f.read + "\nEOP\n"
258
+ f.read.gsub("'", "'\\\\''") + "\nEOP\n"
259
259
  end
260
260
  end
261
261
  end
@@ -101,9 +101,10 @@ class Chef
101
101
  fqdn = (node[:ec2] && node[:ec2][:public_hostname]) || node[:fqdn]
102
102
  name = node["name"] || node.name
103
103
 
104
- hours, minutes, = time_difference_in_hms(node["ohai_time"])
104
+ hours, minutes, seconds = time_difference_in_hms(node["ohai_time"])
105
105
  hours_text = "#{hours} hour#{hours == 1 ? ' ' : 's'}"
106
106
  minutes_text = "#{minutes} minute#{minutes == 1 ? ' ' : 's'}"
107
+ seconds_text = "#{seconds} second#{seconds == 1 ? ' ' : 's'}"
107
108
  run_list = "#{node['run_list']}" if config[:run_list]
108
109
  if hours > 24
109
110
  color = :red
@@ -111,9 +112,12 @@ class Chef
111
112
  elsif hours >= 1
112
113
  color = :yellow
113
114
  text = hours_text
114
- else
115
+ elsif minutes >= 1
115
116
  color = :green
116
117
  text = minutes_text
118
+ else
119
+ color = :green
120
+ text = seconds_text
117
121
  end
118
122
 
119
123
  line_parts = Array.new
@@ -172,7 +172,7 @@ class Chef
172
172
  tf.sync = true
173
173
  tf.puts output
174
174
  tf.close
175
- raise "Please set EDITOR environment variable. See https://docs.chef.io/knife_using.html for details." unless system("#{config[:editor]} #{tf.path}")
175
+ raise "Please set EDITOR environment variable. See https://docs.chef.io/knife_setup.html for details." unless system("#{config[:editor]} #{tf.path}")
176
176
 
177
177
  output = IO.read(tf.path)
178
178
  end
@@ -95,7 +95,7 @@ class Chef
95
95
 
96
96
  ##
97
97
  # Determine if the user has specified an appropriate secret for encrypting data bag items.
98
- # @returns boolean
98
+ # @return boolean
99
99
  def base_encryption_secret_provided?(need_encrypt_flag = true)
100
100
  validate_secrets
101
101
 
@@ -51,7 +51,7 @@ class Chef
51
51
  ui.warn("Encrypted data bag detected, but no secret provided for decoding. Displaying encrypted data.")
52
52
  format_for_display(raw_data)
53
53
  else
54
- ui.warn("Unencrypted data bag detected, ignoring any provided secret options.")
54
+ ui.warn("Unencrypted data bag detected, ignoring any provided secret options.") if secret
55
55
  format_for_display(raw_data)
56
56
  end
57
57
 
@@ -58,7 +58,7 @@ class Chef
58
58
 
59
59
  # Let the user edit the temporary file
60
60
  if !system("#{config[:editor]} #{file.path}")
61
- raise "Please set EDITOR environment variable. See https://docs.chef.io/knife_using.html for details."
61
+ raise "Please set EDITOR environment variable. See https://docs.chef.io/knife_setup.html for details."
62
62
  end
63
63
 
64
64
  result_text = IO.read(file.path)
@@ -46,11 +46,10 @@ class Chef
46
46
  :default => nil,
47
47
  :proc => lambda { |o| o.to_i }
48
48
 
49
- option :attribute,
49
+ option :ssh_attribute,
50
50
  :short => "-a ATTR",
51
51
  :long => "--attribute ATTR",
52
- :description => "The attribute to use for opening the connection - default depends on the context",
53
- :proc => Proc.new { |key| Chef::Config[:knife][:ssh_attribute] = key.strip }
52
+ :description => "The attribute to use for opening the connection - default depends on the context"
54
53
 
55
54
  option :manual,
56
55
  :short => "-m",
@@ -59,6 +58,10 @@ class Chef
59
58
  :description => "QUERY is a space separated list of servers",
60
59
  :default => false
61
60
 
61
+ option :prefix_attribute,
62
+ :long => "--prefix-attribute ATTR",
63
+ :description => "The attribute to use for prefixing the ouput - default depends on the context"
64
+
62
65
  option :ssh_user,
63
66
  :short => "-x USERNAME",
64
67
  :long => "--ssh-user USERNAME",
@@ -181,27 +184,34 @@ class Chef
181
184
  session_from_list(list)
182
185
  end
183
186
 
184
- def get_ssh_attribute(node)
187
+ def get_prefix_attribute(item)
188
+ # Order of precedence for prefix
189
+ # 1) config value (cli or knife config)
190
+ # 2) nil
191
+ msg = "Using node attribute '%s' as the prefix: %s"
192
+ if item["prefix"]
193
+ Chef::Log.debug(sprintf(msg, config[:prefix_attribute], item["prefix"]))
194
+ item["prefix"]
195
+ else
196
+ nil
197
+ end
198
+ end
199
+
200
+ def get_ssh_attribute(item)
185
201
  # Order of precedence for ssh target
186
- # 1) command line attribute
187
- # 2) configuration file
188
- # 3) cloud attribute
189
- # 4) fqdn
190
- if node["config"]
191
- Chef::Log.debug("Using node attribute '#{config[:attribute]}' as the ssh target: #{node["config"]}")
192
- node["config"]
193
- elsif Chef::Config[:knife][:ssh_attribute]
194
- Chef::Log.debug("Using node attribute #{Chef::Config[:knife][:ssh_attribute]}: #{node["knife_config"]}")
195
- node["knife_config"]
196
- elsif node["cloud"] &&
197
- node["cloud"]["public_hostname"] &&
198
- !node["cloud"]["public_hostname"].empty?
199
- Chef::Log.debug("Using node attribute 'cloud[:public_hostname]' automatically as the ssh target: #{node["cloud"]["public_hostname"]}")
200
- node["cloud"]["public_hostname"]
202
+ # 1) config value (cli or knife config)
203
+ # 2) cloud attribute
204
+ # 3) fqdn
205
+ msg = "Using node attribute '%s' as the ssh target: %s"
206
+ if item["target"]
207
+ Chef::Log.debug(sprintf(msg, config[:ssh_attribute], item["target"]))
208
+ item["target"]
209
+ elsif !item.dig("cloud", "public_hostname").to_s.empty?
210
+ Chef::Log.debug(sprintf(msg, "cloud.public_hostname", item["cloud"]["public_hostname"]))
211
+ item["cloud"]["public_hostname"]
201
212
  else
202
- # falling back to default of fqdn
203
- Chef::Log.debug("Using node attribute 'fqdn' as the ssh target: #{node["fqdn"]}")
204
- node["fqdn"]
213
+ Chef::Log.debug(sprintf(msg, "fqdn", item["fqdn"]))
214
+ item["fqdn"]
205
215
  end
206
216
  end
207
217
 
@@ -212,14 +222,12 @@ class Chef
212
222
 
213
223
  separator = ui.presenter.attribute_field_separator
214
224
 
215
- # if we've set an attribute to use on the command line
216
- if config[:attribute]
217
- required_attributes[:config] = config[:attribute].split(separator)
225
+ if config[:prefix_attribute]
226
+ required_attributes[:prefix] = config[:prefix_attribute].split(separator)
218
227
  end
219
228
 
220
- # if we've configured an attribute in our config
221
- if Chef::Config[:knife][:ssh_attribute]
222
- required_attributes[:knife_config] = Chef::Config[:knife][:ssh_attribute].split(separator)
229
+ if config[:ssh_attribute]
230
+ required_attributes[:target] = config[:ssh_attribute].split(separator)
223
231
  end
224
232
 
225
233
  @search_count = 0
@@ -232,8 +240,9 @@ class Chef
232
240
  # returned node object
233
241
  host = get_ssh_attribute(item)
234
242
  next if host.nil?
235
- ssh_port = item[:cloud].nil? ? nil : item[:cloud][:public_ssh_port]
236
- srv = [host, ssh_port]
243
+ prefix = get_prefix_attribute(item)
244
+ ssh_port = item.dig("cloud", "public_ssh_port")
245
+ srv = [host, ssh_port, prefix]
237
246
  list.push(srv)
238
247
  end
239
248
 
@@ -282,7 +291,8 @@ class Chef
282
291
 
283
292
  def session_from_list(list)
284
293
  list.each do |item|
285
- host, ssh_port = item
294
+ host, ssh_port, prefix = item
295
+ prefix = host unless prefix
286
296
  Chef::Log.debug("Adding #{host}")
287
297
  session_opts = session_options(host, ssh_port)
288
298
  # Handle port overrides for the main connection.
@@ -291,12 +301,14 @@ class Chef
291
301
  # Handle connection timeout
292
302
  session_opts[:timeout] = Chef::Config[:knife][:ssh_timeout] if Chef::Config[:knife][:ssh_timeout]
293
303
  session_opts[:timeout] = config[:ssh_timeout] if config[:ssh_timeout]
304
+ # Handle session prefix
305
+ session_opts[:properties] = { prefix: prefix }
294
306
  # Create the hostspec.
295
307
  hostspec = session_opts[:user] ? "#{session_opts.delete(:user)}@#{host}" : host
296
308
  # Connect a new session on the multi.
297
309
  session.use(hostspec, session_opts)
298
310
 
299
- @longest = host.length if host.length > @longest
311
+ @longest = prefix.length if prefix.length > @longest
300
312
  end
301
313
 
302
314
  session
@@ -342,9 +354,9 @@ class Chef
342
354
  chan.exec command do |ch, success|
343
355
  raise ArgumentError, "Cannot execute #{command}" unless success
344
356
  ch.on_data do |ichannel, data|
345
- print_data(ichannel[:host], data)
357
+ print_data(ichannel.connection[:prefix], data)
346
358
  if data =~ /^knife sudo password: /
347
- print_data(ichannel[:host], "\n")
359
+ print_data(ichannel.connection[:prefix], "\n")
348
360
  ichannel.send_data("#{get_password}\n")
349
361
  end
350
362
  end
@@ -461,7 +473,7 @@ class Chef
461
473
  end.join(" \\; ")
462
474
  end
463
475
 
464
- tmux_name = "'knife ssh #{@name_args[0].tr(':', '=')}'"
476
+ tmux_name = "'knife ssh #{@name_args[0].tr(':.', '=-')}'"
465
477
  begin
466
478
  server = session.servers_for.first
467
479
  cmd = ["tmux new-session -d -s #{tmux_name}",
@@ -78,6 +78,8 @@ knife user create for Open Source 11 Server is being deprecated.
78
78
  Open Source 11 Server user commands now live under the knife osc_user namespace.
79
79
  For backwards compatibility, we will forward this request to knife osc_user create.
80
80
  If you are using an Open Source 11 Server, please use that command to avoid this warning.
81
+ NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed
82
+ in Chef 15 which will be released April 2019.
81
83
  EOF
82
84
  end
83
85
 
@@ -37,6 +37,8 @@ knife user delete for Open Source 11 Server is being deprecated.
37
37
  Open Source 11 Server user commands now live under the knife osc_user namespace.
38
38
  For backwards compatibility, we will forward this request to knife osc_user delete.
39
39
  If you are using an Open Source 11 Server, please use that command to avoid this warning.
40
+ NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed
41
+ in Chef 15 which will be released April 2019.
40
42
  EOF
41
43
  end
42
44
 
@@ -37,6 +37,8 @@ knife user edit for Open Source 11 Server is being deprecated.
37
37
  Open Source 11 Server user commands now live under the knife oc_user namespace.
38
38
  For backwards compatibility, we will forward this request to knife osc_user edit.
39
39
  If you are using an Open Source 11 Server, please use that command to avoid this warning.
40
+ NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed
41
+ in Chef 15 which will be released April 2019.
40
42
  EOF
41
43
  end
42
44
 
@@ -37,6 +37,8 @@ knife user reregister for Open Source 11 Server is being deprecated.
37
37
  Open Source 11 Server user commands now live under the knife osc_user namespace.
38
38
  For backwards compatibility, we will forward this request to knife osc_user reregister.
39
39
  If you are using an Open Source 11 Server, please use that command to avoid this warning.
40
+ NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed
41
+ in Chef 15 which will be released April 2019.
40
42
  EOF
41
43
  end
42
44
 
@@ -39,6 +39,8 @@ knife user show for Open Source 11 Server is being deprecated.
39
39
  Open Source 11 Server user commands now live under the knife osc_user namespace.
40
40
  For backwards compatibility, we will forward this request to knife osc_user show.
41
41
  If you are using an Open Source 11 Server, please use that command to avoid this warning.
42
+ NOTE: Backwards compatibility for Open Source 11 Server in these commands will be removed
43
+ in Chef 15 which will be released April 2019.
42
44
  EOF
43
45
  end
44
46
 
@@ -74,7 +74,7 @@ class Chef
74
74
  # Helper to build a powershell command around the script to run.
75
75
  #
76
76
  # @param script [String] script to run
77
- # @retrurn [String] powershell command to execute
77
+ # @return [String] powershell command to execute
78
78
  def build_powershell_command(script)
79
79
  flags = [
80
80
  # Hides the copyright banner at startup.
@@ -17,7 +17,6 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require "chef/node/mixin/deep_merge_cache"
21
20
  require "chef/node/mixin/immutablize_hash"
22
21
  require "chef/node/mixin/state_tracking"
23
22
  require "chef/node/immutable_collections"
@@ -45,7 +44,6 @@ class Chef
45
44
  # expects. This include should probably be deleted?
46
45
  include Enumerable
47
46
 
48
- include Chef::Node::Mixin::DeepMergeCache
49
47
  include Chef::Node::Mixin::StateTracking
50
48
  include Chef::Node::Mixin::ImmutablizeHash
51
49
 
@@ -187,6 +185,9 @@ class Chef
187
185
  # return the automatic level attribute component
188
186
  attr_reader :automatic
189
187
 
188
+ # return the immutablemash deep merge cache
189
+ attr_reader :deep_merge_cache
190
+
190
191
  def initialize(normal, default, override, automatic, node = nil)
191
192
  @default = VividMash.new(default, self, node, :default)
192
193
  @env_default = VividMash.new({}, self, node, :env_default)
@@ -202,7 +203,8 @@ class Chef
202
203
 
203
204
  @automatic = VividMash.new(automatic, self, node, :automatic)
204
205
 
205
- super(nil, self, node, :merged)
206
+ @deep_merge_cache = ImmutableMash.new({}, self, node, :merged)
207
+ @__node__ = node
206
208
  end
207
209
 
208
210
  # Debug what's going on with an attribute. +args+ is a path spec to the
@@ -226,6 +228,22 @@ class Chef
226
228
  end
227
229
  end
228
230
 
231
+ def reset
232
+ @deep_merge_cache = ImmutableMash.new({}, self, @__node__, :merged)
233
+ end
234
+
235
+ def reset_cache(*path)
236
+ if path.empty?
237
+ reset
238
+ else
239
+ container = read(*path)
240
+ case container
241
+ when Hash, Array
242
+ container.reset
243
+ end
244
+ end
245
+ end
246
+
229
247
  # Set the cookbook level default attribute component to +new_data+.
230
248
  def default=(new_data)
231
249
  reset
@@ -290,7 +308,7 @@ class Chef
290
308
 
291
309
  # clears attributes from all precedence levels
292
310
  def rm(*args)
293
- with_deep_merged_return_value(self, *args) do
311
+ with_deep_merged_return_value(combined_all, *args) do
294
312
  rm_default(*args)
295
313
  rm_normal(*args)
296
314
  rm_override(*args)
@@ -337,6 +355,9 @@ class Chef
337
355
  def with_deep_merged_return_value(obj, *path, last)
338
356
  hash = obj.read(*path)
339
357
  return nil unless hash.is_a?(Hash)
358
+ # coerce from immutablemash/vividmash to plain-old Hash
359
+ # also de-immutablizes and dup's the return value correctly in chef-13
360
+ hash = hash.to_hash
340
361
  ret = hash[last]
341
362
  yield
342
363
  ret
@@ -398,16 +419,16 @@ class Chef
398
419
  # all of node['foo'] even if the user only requires node['foo']['bar']['baz'].
399
420
  #
400
421
 
401
- def merged_attributes(*path)
402
- merge_all(path)
422
+ def combined_override(*path)
423
+ merge_overrides(path)
403
424
  end
404
425
 
405
- def combined_override(*path)
406
- immutablize(merge_overrides(path))
426
+ def combined_all(*path)
427
+ path.empty? ? self : read(*path)
407
428
  end
408
429
 
409
430
  def combined_default(*path)
410
- immutablize(merge_defaults(path))
431
+ merge_defaults(path)
411
432
  end
412
433
 
413
434
  def normal_unless(*args)
@@ -476,6 +497,14 @@ class Chef
476
497
  merged_attributes.to_s
477
498
  end
478
499
 
500
+ def [](key)
501
+ @deep_merge_cache[key]
502
+ end
503
+
504
+ def merged_attributes
505
+ @deep_merge_cache
506
+ end
507
+
479
508
  def inspect
480
509
  "#<#{self.class} " << (COMPONENTS + [:@merged_attributes, :@properties]).map do |iv|
481
510
  "#{iv}=#{instance_variable_get(iv).inspect}"
@@ -484,7 +513,14 @@ class Chef
484
513
 
485
514
  private
486
515
 
487
- # Helper method for merge_all/merge_defaults/merge_overrides.
516
+ # For elements like Fixnums, true, nil...
517
+ def safe_dup(e)
518
+ e.dup
519
+ rescue TypeError
520
+ e
521
+ end
522
+
523
+ # Helper method for merge_defaults/merge_overrides.
488
524
  #
489
525
  # apply_path(thing, [ "foo", "bar", "baz" ]) = thing["foo"]["bar"]["baz"]
490
526
  #
@@ -514,34 +550,6 @@ class Chef
514
550
  end
515
551
  end
516
552
 
517
- # For elements like Fixnums, true, nil...
518
- def safe_dup(e)
519
- e.dup
520
- rescue TypeError
521
- e
522
- end
523
-
524
- # Deep merge all attribute levels using hash-only merging between different precidence
525
- # levels (so override arrays completely replace arrays set at any default level).
526
- #
527
- # The path allows for selectively deep-merging a subtree of the node object.
528
- #
529
- # @param path [Array] Array of args to method chain to descend into the node object
530
- # @return [attr] Deep Merged values (may be VividMash, Hash, Array, etc) from the node object
531
- def merge_all(path)
532
- components = [
533
- merge_defaults(path),
534
- apply_path(@normal, path),
535
- merge_overrides(path),
536
- apply_path(@automatic, path),
537
- ]
538
-
539
- ret = components.inject(NIL) do |merged, component|
540
- hash_only_merge!(merged, component)
541
- end
542
- ret == NIL ? nil : ret
543
- end
544
-
545
553
  # Deep merge the default attribute levels with array merging.
546
554
  #
547
555
  # The path allows for selectively deep-merging a subtree of the node object.
@@ -613,38 +621,6 @@ class Chef
613
621
  end
614
622
  end
615
623
 
616
- # @api private
617
- def hash_only_merge!(merge_onto, merge_with)
618
- # If there are two Hashes, recursively merge.
619
- if merge_onto.kind_of?(Hash) && merge_with.kind_of?(Hash)
620
- merge_with.each do |key, merge_with_value|
621
- value =
622
- if merge_onto.has_key?(key)
623
- hash_only_merge!(safe_dup(merge_onto[key]), merge_with_value)
624
- else
625
- merge_with_value
626
- end
627
-
628
- # internal_set bypasses converting keys, does convert values and allows writing to immutable mashes
629
- merge_onto.internal_set(key, value)
630
- end
631
- merge_onto
632
-
633
- # If merge_with is nil, don't replace merge_onto
634
- elsif merge_with.nil?
635
- merge_onto
636
-
637
- # In all other cases, replace merge_onto with merge_with
638
- else
639
- if merge_with.kind_of?(Hash)
640
- Chef::Node::ImmutableMash.new(merge_with)
641
- elsif merge_with.kind_of?(Array)
642
- Chef::Node::ImmutableArray.new(merge_with)
643
- else
644
- merge_with
645
- end
646
- end
647
- end
648
624
  end
649
625
  end
650
626
  end