chef 12.5.1-universal-mingw32 → 12.6.0-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 (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/README.md +6 -4
  4. data/Rakefile +1 -4
  5. data/chef-windows.gemspec +21 -0
  6. data/chef.gemspec +58 -0
  7. data/lib/chef/api_client/registration.rb +9 -4
  8. data/lib/chef/application.rb +3 -84
  9. data/lib/chef/application/apply.rb +9 -2
  10. data/lib/chef/application/client.rb +8 -3
  11. data/lib/chef/application/solo.rb +7 -1
  12. data/lib/chef/application/windows_service.rb +21 -6
  13. data/lib/chef/application/windows_service_manager.rb +2 -3
  14. data/lib/chef/audit/runner.rb +1 -0
  15. data/lib/chef/chef_class.rb +1 -11
  16. data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
  17. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
  18. data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
  19. data/lib/chef/client.rb +28 -1
  20. data/lib/chef/cookbook/cookbook_collection.rb +14 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +115 -9
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +6 -2
  25. data/lib/chef/data_bag.rb +1 -1
  26. data/lib/chef/data_bag_item.rb +1 -1
  27. data/lib/chef/digester.rb +5 -1
  28. data/lib/chef/dsl/chef_provisioning.rb +57 -0
  29. data/lib/chef/dsl/cheffish.rb +64 -0
  30. data/lib/chef/dsl/declare_resource.rb +108 -0
  31. data/lib/chef/dsl/platform_introspection.rb +3 -3
  32. data/lib/chef/dsl/recipe.rb +3 -73
  33. data/lib/chef/dsl/resources.rb +27 -1
  34. data/lib/chef/event_dispatch/base.rb +3 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +5 -0
  36. data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
  37. data/lib/chef/exceptions.rb +21 -1
  38. data/lib/chef/file_access_control/unix.rb +12 -12
  39. data/lib/chef/file_content_management/deploy/cp.rb +2 -2
  40. data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
  41. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  42. data/lib/chef/formatters/base.rb +7 -0
  43. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  44. data/lib/chef/formatters/indentable_output_stream.rb +5 -0
  45. data/lib/chef/http.rb +19 -3
  46. data/lib/chef/http/decompressor.rb +2 -2
  47. data/lib/chef/json_compat.rb +1 -0
  48. data/lib/chef/knife.rb +16 -2
  49. data/lib/chef/knife/bootstrap.rb +55 -10
  50. data/lib/chef/knife/cookbook_site_install.rb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +2 -1
  52. data/lib/chef/knife/core/node_presenter.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +30 -16
  54. data/lib/chef/knife/ssl_check.rb +4 -2
  55. data/lib/chef/knife/ssl_fetch.rb +3 -2
  56. data/lib/chef/knife/status.rb +14 -1
  57. data/lib/chef/log.rb +14 -0
  58. data/lib/chef/mixin/get_source_from_package.rb +7 -2
  59. data/lib/chef/mixin/properties.rb +302 -0
  60. data/lib/chef/mixin/proxified_socket.rb +38 -0
  61. data/lib/chef/mixin/subclass_directive.rb +37 -0
  62. data/lib/chef/node.rb +13 -5
  63. data/lib/chef/platform/query_helpers.rb +14 -3
  64. data/lib/chef/platform/service_helpers.rb +20 -38
  65. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  66. data/lib/chef/policy_builder/policyfile.rb +1 -0
  67. data/lib/chef/property.rb +51 -12
  68. data/lib/chef/provider.rb +40 -35
  69. data/lib/chef/provider/deploy.rb +1 -1
  70. data/lib/chef/provider/dsc_resource.rb +54 -20
  71. data/lib/chef/provider/execute.rb +25 -4
  72. data/lib/chef/provider/group.rb +1 -1
  73. data/lib/chef/provider/lwrp_base.rb +1 -0
  74. data/lib/chef/provider/package.rb +76 -30
  75. data/lib/chef/provider/package/dpkg.rb +152 -69
  76. data/lib/chef/provider/package/openbsd.rb +6 -8
  77. data/lib/chef/provider/package/solaris.rb +2 -0
  78. data/lib/chef/provider/package/windows.rb +95 -14
  79. data/lib/chef/provider/package/windows/exe.rb +129 -0
  80. data/lib/chef/provider/package/windows/msi.rb +37 -13
  81. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
  82. data/lib/chef/provider/package/yum.rb +13 -3
  83. data/lib/chef/provider/powershell_script.rb +3 -0
  84. data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
  85. data/lib/chef/provider/remote_file/http.rb +1 -1
  86. data/lib/chef/provider/script.rb +1 -0
  87. data/lib/chef/provider/service.rb +13 -10
  88. data/lib/chef/provider/service/solaris.rb +43 -17
  89. data/lib/chef/provider/service/upstart.rb +3 -3
  90. data/lib/chef/provider/user.rb +1 -1
  91. data/lib/chef/provider/user/dscl.rb +111 -100
  92. data/lib/chef/provider/user/windows.rb +5 -3
  93. data/lib/chef/recipe.rb +3 -5
  94. data/lib/chef/resource.rb +77 -320
  95. data/lib/chef/resource/action_class.rb +4 -0
  96. data/lib/chef/resource/dpkg_package.rb +4 -3
  97. data/lib/chef/resource/dsc_resource.rb +40 -2
  98. data/lib/chef/resource/execute.rb +9 -1
  99. data/lib/chef/resource/ksh.rb +32 -0
  100. data/lib/chef/resource/lwrp_base.rb +6 -10
  101. data/lib/chef/resource/package.rb +8 -9
  102. data/lib/chef/resource/registry_key.rb +1 -1
  103. data/lib/chef/resource/resource_notification.rb +14 -1
  104. data/lib/chef/resource/script.rb +1 -1
  105. data/lib/chef/resource/windows_package.rb +1 -1
  106. data/lib/chef/resource_builder.rb +14 -7
  107. data/lib/chef/resource_reporter.rb +6 -0
  108. data/lib/chef/resources.rb +1 -7
  109. data/lib/chef/rest.rb +1 -1
  110. data/lib/chef/run_context.rb +45 -2
  111. data/lib/chef/run_list/run_list_expansion.rb +47 -0
  112. data/lib/chef/runner.rb +25 -0
  113. data/lib/chef/search/query.rb +16 -2
  114. data/lib/chef/util/diff.rb +2 -2
  115. data/lib/chef/util/powershell/ps_credential.rb +2 -3
  116. data/lib/chef/version.rb +1 -1
  117. data/lib/chef/win32/api/file.rb +51 -1
  118. data/lib/chef/win32/file.rb +5 -0
  119. data/lib/chef/win32/file/version_info.rb +93 -0
  120. data/lib/chef/win32/mutex.rb +1 -1
  121. data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
  122. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
  123. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
  124. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
  125. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
  126. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
  127. data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
  128. data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
  129. data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
  130. data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
  131. data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
  132. data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
  133. data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
  134. data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
  135. data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
  136. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
  137. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
  138. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
  139. data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
  140. data/spec/functional/application_spec.rb +1 -1
  141. data/spec/functional/audit/runner_spec.rb +4 -0
  142. data/spec/functional/knife/ssh_spec.rb +5 -5
  143. data/spec/functional/notifications_spec.rb +74 -4
  144. data/spec/functional/resource/aix_service_spec.rb +2 -2
  145. data/spec/functional/resource/dpkg_package_spec.rb +339 -0
  146. data/spec/functional/resource/ifconfig_spec.rb +3 -1
  147. data/spec/functional/resource/mount_spec.rb +5 -2
  148. data/spec/functional/resource/package_spec.rb +1 -1
  149. data/spec/functional/resource/user/windows_spec.rb +8 -0
  150. data/spec/functional/resource/windows_package_spec.rb +177 -0
  151. data/spec/functional/win32/version_info_spec.rb +50 -0
  152. data/spec/integration/client/client_spec.rb +80 -0
  153. data/spec/integration/knife/download_spec.rb +9 -0
  154. data/spec/integration/knife/upload_spec.rb +28 -1
  155. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
  156. data/spec/integration/recipes/resource_action_spec.rb +211 -116
  157. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
  158. data/spec/integration/solo/solo_spec.rb +34 -0
  159. data/spec/spec_helper.rb +11 -1
  160. data/spec/support/platform_helpers.rb +8 -0
  161. data/spec/support/shared/integration/integration_helper.rb +6 -0
  162. data/spec/support/shared/unit/execute_resource.rb +5 -0
  163. data/spec/support/shared/unit/platform_introspector.rb +7 -0
  164. data/spec/tiny_server.rb +6 -2
  165. data/spec/unit/api_client/registration_spec.rb +5 -4
  166. data/spec/unit/application_spec.rb +1 -181
  167. data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
  168. data/spec/unit/cookbook/metadata_spec.rb +122 -2
  169. data/spec/unit/http_spec.rb +102 -0
  170. data/spec/unit/knife/bootstrap_spec.rb +55 -13
  171. data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
  172. data/spec/unit/knife/ssl_check_spec.rb +7 -3
  173. data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
  174. data/spec/unit/knife/status_spec.rb +13 -13
  175. data/spec/unit/knife_spec.rb +26 -2
  176. data/spec/unit/lwrp_spec.rb +1 -1
  177. data/spec/unit/mixin/properties_spec.rb +97 -0
  178. data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
  179. data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
  180. data/spec/unit/node_spec.rb +9 -1
  181. data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
  182. data/spec/unit/property/validation_spec.rb +14 -12
  183. data/spec/unit/property_spec.rb +56 -0
  184. data/spec/unit/provider/deploy_spec.rb +1 -1
  185. data/spec/unit/provider/dsc_resource_spec.rb +63 -24
  186. data/spec/unit/provider/execute_spec.rb +95 -28
  187. data/spec/unit/provider/package/dpkg_spec.rb +185 -96
  188. data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
  189. data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
  190. data/spec/unit/provider/package/windows_spec.rb +227 -26
  191. data/spec/unit/provider/package/yum_spec.rb +6 -0
  192. data/spec/unit/provider/package_spec.rb +495 -366
  193. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
  194. data/spec/unit/provider/script_spec.rb +2 -2
  195. data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
  196. data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
  197. data/spec/unit/provider/user/dscl_spec.rb +14 -0
  198. data/spec/unit/provider/user/windows_spec.rb +2 -2
  199. data/spec/unit/provider/user_spec.rb +9 -0
  200. data/spec/unit/provider_resolver_spec.rb +6 -30
  201. data/spec/unit/recipe_spec.rb +46 -20
  202. data/spec/unit/resource/chef_gem_spec.rb +1 -1
  203. data/spec/unit/resource/dsc_resource_spec.rb +14 -3
  204. data/spec/unit/resource/ksh_spec.rb +40 -0
  205. data/spec/unit/resource/registry_key_spec.rb +2 -2
  206. data/spec/unit/resource/resource_notification_spec.rb +44 -45
  207. data/spec/unit/resource_reporter_spec.rb +7 -0
  208. data/spec/unit/resource_spec.rb +268 -253
  209. data/spec/unit/rest_spec.rb +2 -2
  210. data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
  211. data/spec/unit/search/query_spec.rb +19 -1
  212. data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
  213. data/spec/unit/windows_service_spec.rb +83 -38
  214. data/tasks/external_tests.rb +19 -9
  215. data/tasks/rspec.rb +1 -1
  216. metadata +70 -21
  217. data/spec/support/pedant/Gemfile +0 -3
  218. data/spec/support/pedant/pedant_config.rb +0 -129
  219. data/spec/support/pedant/run_pedant.rb +0 -63
  220. data/spec/support/pedant/stickywicket.pem +0 -27
  221. data/spec/unit/provider/package_spec.rbe +0 -0
@@ -142,7 +142,11 @@ class Chef
142
142
  def extract_cookbook(upstream_file, version)
143
143
  ui.info("Uncompressing #{@cookbook_name} version #{version}.")
144
144
  # FIXME: Detect if we have the bad tar from git on Windows: https://github.com/opscode/chef/issues/1753
145
- shell_out!("tar zxvf #{convert_path upstream_file}", :cwd => @install_path)
145
+ extract_command="tar zxvf \"#{convert_path upstream_file}\""
146
+ if Chef::Platform.windows?
147
+ extract_command << " --force-local"
148
+ end
149
+ shell_out!(extract_command, :cwd => @install_path)
146
150
  end
147
151
 
148
152
  def clear_existing_files(cookbook_path)
@@ -40,7 +40,7 @@ class Chef
40
40
  end
41
41
 
42
42
  def bootstrap_environment
43
- @chef_config[:environment]
43
+ @config[:environment]
44
44
  end
45
45
 
46
46
  def validation_key
@@ -129,6 +129,7 @@ CONFIG
129
129
  s = "#{client_path} -j /etc/chef/first-boot.json"
130
130
  s << ' -l debug' if @config[:verbosity] and @config[:verbosity] >= 2
131
131
  s << " -E #{bootstrap_environment}" unless bootstrap_environment.nil?
132
+ s << " --no-color" unless @config[:color]
132
133
  s
133
134
  end
134
135
 
@@ -125,7 +125,7 @@ ROLES
125
125
  summarized << <<-SUMMARY
126
126
  #{key('Recipes:')} #{Array(node[:recipes]).join(', ')}
127
127
  #{key('Platform:')} #{node[:platform]} #{node[:platform_version]}
128
- #{key('Tags:')} #{Array(node[:tags]).join(', ')}
128
+ #{key('Tags:')} #{node.tags.join(', ')}
129
129
  SUMMARY
130
130
  if config[:medium_output] || config[:long_output]
131
131
  summarized +=<<-MORE
@@ -16,6 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require 'chef/mixin/shell_out'
19
20
  require 'chef/knife'
20
21
 
21
22
  class Chef
@@ -29,7 +30,6 @@ class Chef
29
30
  require 'readline'
30
31
  require 'chef/exceptions'
31
32
  require 'chef/search/query'
32
- require 'chef/mixin/shell_out'
33
33
  require 'chef/mixin/command'
34
34
  require 'chef/util/path_helper'
35
35
  require 'mixlib/shellout'
@@ -72,7 +72,7 @@ class Chef
72
72
  :description => "The ssh password - will prompt if flag is specified but no password is given",
73
73
  # default to a value that can not be a password (boolean)
74
74
  # so we can effectively test if this parameter was specified
75
- # without a vlaue
75
+ # without a value
76
76
  :default => false
77
77
 
78
78
  option :ssh_port,
@@ -94,8 +94,12 @@ class Chef
94
94
  :boolean => true
95
95
 
96
96
  option :identity_file,
97
- :short => "-i IDENTITY_FILE",
98
97
  :long => "--identity-file IDENTITY_FILE",
98
+ :description => "The SSH identity file used for authentication. [DEPRECATED] Use --ssh-identity-file instead."
99
+
100
+ option :ssh_identity_file,
101
+ :short => "-i IDENTITY_FILE",
102
+ :long => "--ssh-identity-file IDENTITY_FILE",
99
103
  :description => "The SSH identity file used for authentication"
100
104
 
101
105
  option :host_key_verify,
@@ -111,6 +115,12 @@ class Chef
111
115
  :boolean => true,
112
116
  :proc => Proc.new { :raise }
113
117
 
118
+ option :tmux_split,
119
+ :long => "--tmux-split",
120
+ :description => "Split tmux window.",
121
+ :boolean => true,
122
+ :default => false
123
+
114
124
  def session
115
125
  config[:on_error] ||= :skip
116
126
  ssh_error_handler = Proc.new do |server|
@@ -222,8 +232,8 @@ class Chef
222
232
  {}.tap do |opts|
223
233
  # Chef::Config[:knife][:ssh_user] is parsed in #configure_user and written to config[:ssh_user]
224
234
  opts[:user] = user || config[:ssh_user] || ssh_config[:user]
225
- if config[:identity_file]
226
- opts[:keys] = File.expand_path(config[:identity_file])
235
+ if config[:ssh_identity_file]
236
+ opts[:keys] = File.expand_path(config[:ssh_identity_file])
227
237
  opts[:keys_only] = true
228
238
  elsif config[:ssh_password]
229
239
  opts[:password] = config[:ssh_password]
@@ -386,7 +396,7 @@ class Chef
386
396
  window = 0
387
397
  session.servers_for.each do |server|
388
398
  tf.print("screen -t \"#{server.host}\" #{window} ssh ")
389
- tf.print("-i #{config[:identity_file]} ") if config[:identity_file]
399
+ tf.print("-i #{config[:ssh_identity_file]} ") if config[:ssh_identity_file]
390
400
  server.user ? tf.puts("#{server.user}@#{server.host}") : tf.puts(server.host)
391
401
  window += 1
392
402
  end
@@ -396,7 +406,7 @@ class Chef
396
406
 
397
407
  def tmux
398
408
  ssh_dest = lambda do |server|
399
- identity = "-i #{config[:identity_file]} " if config[:identity_file]
409
+ identity = "-i #{config[:ssh_identity_file]} " if config[:ssh_identity_file]
400
410
  prefix = server.user ? "#{server.user}@" : ""
401
411
  "'ssh #{identity}#{prefix}#{server.host}'"
402
412
  end
@@ -404,7 +414,11 @@ class Chef
404
414
  new_window_cmds = lambda do
405
415
  if session.servers_for.size > 1
406
416
  [""] + session.servers_for[1..-1].map do |server|
407
- "new-window -a -n '#{server.host}' #{ssh_dest.call(server)}"
417
+ if config[:tmux_split]
418
+ "split-window #{ssh_dest.call(server)}; tmux select-layout tiled"
419
+ else
420
+ "new-window -a -n '#{server.host}' #{ssh_dest.call(server)}"
421
+ end
408
422
  end
409
423
  else
410
424
  []
@@ -459,15 +473,15 @@ class Chef
459
473
  end
460
474
  raise Chef::Exceptions::Exec, "no command found for cssh" unless cssh_cmd
461
475
 
462
- # pass in the consolidated itentity file option to cssh(X)
463
- if config[:identity_file]
464
- cssh_cmd << " --ssh_args '-i #{File.expand_path(config[:identity_file])}'"
476
+ # pass in the consolidated identity file option to cssh(X)
477
+ if config[:ssh_identity_file]
478
+ cssh_cmd << " --ssh_args '-i #{File.expand_path(config[:ssh_identity_file])}'"
465
479
  end
466
480
 
467
481
  session.servers_for.each do |server|
468
482
  cssh_cmd << " #{server.user ? "#{server.user}@#{server.host}" : server.host}"
469
483
  end
470
- Chef::Log.debug("starting cssh session with command: #{cssh_cmd}")
484
+ Chef::Log.debug("Starting cssh session with command: #{cssh_cmd}")
471
485
  exec(cssh_cmd)
472
486
  end
473
487
 
@@ -506,9 +520,9 @@ class Chef
506
520
  end
507
521
  end
508
522
 
509
- def configure_identity_file
510
- config[:identity_file] = get_stripped_unfrozen_value(config[:identity_file] ||
511
- Chef::Config[:knife][:ssh_identity_file])
523
+ def configure_ssh_identity_file
524
+ # config[:identity_file] is DEPRECATED in favor of :ssh_identity_file
525
+ config[:ssh_identity_file] = get_stripped_unfrozen_value(config[:ssh_identity_file] || config[:identity_file] || Chef::Config[:knife][:ssh_identity_file])
512
526
  end
513
527
 
514
528
  def extract_nested_value(data_structure, path_spec)
@@ -522,7 +536,7 @@ class Chef
522
536
 
523
537
  configure_user
524
538
  configure_password
525
- configure_identity_file
539
+ configure_ssh_identity_file
526
540
  configure_gateway
527
541
  configure_session
528
542
 
@@ -29,6 +29,8 @@ class Chef
29
29
  require 'uri'
30
30
  require 'chef/http/ssl_policies'
31
31
  require 'openssl'
32
+ require 'chef/mixin/proxified_socket'
33
+ include Chef::Mixin::ProxifiedSocket
32
34
  end
33
35
 
34
36
  banner "knife ssl check [URL] (options)"
@@ -75,7 +77,7 @@ class Chef
75
77
 
76
78
  def verify_peer_socket
77
79
  @verify_peer_socket ||= begin
78
- tcp_connection = TCPSocket.new(host, port)
80
+ tcp_connection = proxified_socket(host, port)
79
81
  ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_connection, verify_peer_ssl_context)
80
82
  ssl_client.hostname = host
81
83
  ssl_client
@@ -93,7 +95,7 @@ class Chef
93
95
 
94
96
  def noverify_socket
95
97
  @noverify_socket ||= begin
96
- tcp_connection = TCPSocket.new(host, port)
98
+ tcp_connection = proxified_socket(host, port)
97
99
  OpenSSL::SSL::SSLSocket.new(tcp_connection, noverify_peer_ssl_context)
98
100
  end
99
101
  end
@@ -28,6 +28,8 @@ class Chef
28
28
  require 'socket'
29
29
  require 'uri'
30
30
  require 'openssl'
31
+ require 'chef/mixin/proxified_socket'
32
+ include Chef::Mixin::ProxifiedSocket
31
33
  end
32
34
 
33
35
  banner "knife ssl fetch [URL] (options)"
@@ -71,7 +73,7 @@ class Chef
71
73
  end
72
74
 
73
75
  def remote_cert_chain
74
- tcp_connection = TCPSocket.new(host, port)
76
+ tcp_connection = proxified_socket(host, port)
75
77
  shady_ssl_connection = OpenSSL::SSL::SSLSocket.new(tcp_connection, noverify_peer_ssl_context)
76
78
  shady_ssl_connection.connect
77
79
  shady_ssl_connection.peer_cert_chain
@@ -155,4 +157,3 @@ TRUST_TRUST
155
157
  end
156
158
  end
157
159
  end
158
-
@@ -44,7 +44,11 @@ class Chef
44
44
  option :hide_healthy,
45
45
  :short => "-H",
46
46
  :long => "--hide-healthy",
47
- :description => "Hide nodes that have run chef in the last hour"
47
+ :description => "Hide nodes that have run chef in the last hour. [DEPRECATED] Use --hide-by-mins MINS instead"
48
+
49
+ option :hide_by_mins,
50
+ :long => "--hide-by-mins MINS",
51
+ :description => "Hide nodes that have run chef in the last MINS minutes"
48
52
 
49
53
  def append_to_query(term)
50
54
  @query << " AND " unless @query.empty?
@@ -68,12 +72,21 @@ class Chef
68
72
  append_to_query("chef_environment:#{config[:environment]}") if config[:environment]
69
73
 
70
74
  if config[:hide_healthy]
75
+ ui.warn("-H / --hide-healthy is deprecated. Use --hide-by-mins MINS instead")
71
76
  time = Time.now.to_i
72
77
  # AND NOT is not valid lucene syntax, so don't use append_to_query
73
78
  @query << " " unless @query.empty?
74
79
  @query << "NOT ohai_time:[#{(time - 60*60).to_s} TO #{time.to_s}]"
75
80
  end
76
81
 
82
+ if config[:hide_by_mins]
83
+ hidemins = config[:hide_by_mins].to_i
84
+ time = Time.now.to_i
85
+ # AND NOT is not valid lucene syntax, so don't use append_to_query
86
+ @query << " " unless @query.empty?
87
+ @query << "NOT ohai_time:[#{(time - hidemins*60).to_s} TO #{time.to_s}]"
88
+ end
89
+
77
90
  @query = @query.empty? ? "*:*" : @query
78
91
 
79
92
  all_nodes = []
@@ -37,6 +37,20 @@ class Chef
37
37
  end
38
38
  end
39
39
 
40
+ #
41
+ # Get the location of the caller (from the recipe). Grabs the first caller
42
+ # that is *not* in the chef gem proper (allowing us to weed out internal
43
+ # calls and give the user a more useful perspective).
44
+ #
45
+ # @return [String] The location of the caller (file:line#) from caller(0..20), or nil if no non-chef caller is found.
46
+ #
47
+ def self.caller_location
48
+ # Pick the first caller that is *not* part of the Chef gem, that's the
49
+ # thing the user wrote.
50
+ chef_gem_path = File.expand_path("../..", __FILE__)
51
+ caller(0..20).select { |c| !c.start_with?(chef_gem_path) }.first
52
+ end
53
+
40
54
  def self.deprecation(msg=nil, location=caller(2..2)[0], &block)
41
55
  if msg
42
56
  msg << " at #{Array(location).join("\n")}"
@@ -1,5 +1,5 @@
1
1
  # Author:: Lamont Granquist (<lamont@opscode.com>)
2
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
2
+ # Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,6 +27,12 @@
27
27
  class Chef
28
28
  module Mixin
29
29
  module GetSourceFromPackage
30
+ # FIXME: this is some bad code that I wrote a long time ago.
31
+ # - it does too much in the initializer
32
+ # - it mutates the new_resource
33
+ # - it does not support multipackage arrays
34
+ # this code is deprecated, check out the :use_package_names_for_source
35
+ # subclass directive instead
30
36
  def initialize(new_resource, run_context)
31
37
  super
32
38
  return if new_resource.package_name.is_a?(Array)
@@ -40,4 +46,3 @@ class Chef
40
46
  end
41
47
  end
42
48
  end
43
-
@@ -0,0 +1,302 @@
1
+ require 'chef/delayed_evaluator'
2
+ require 'chef/mixin/params_validate'
3
+ require 'chef/property'
4
+
5
+ class Chef
6
+ module Mixin
7
+ module Properties
8
+ module ClassMethods
9
+ #
10
+ # The list of properties defined on this resource.
11
+ #
12
+ # Everything defined with `property` is in this list.
13
+ #
14
+ # @param include_superclass [Boolean] `true` to include properties defined
15
+ # on superclasses; `false` or `nil` to return the list of properties
16
+ # directly on this class.
17
+ #
18
+ # @return [Hash<Symbol,Property>] The list of property names and types.
19
+ #
20
+ def properties(include_superclass=true)
21
+ if include_superclass
22
+ result = {}
23
+ ancestors.reverse_each { |c| result.merge!(c.properties(false)) if c.respond_to?(:properties) }
24
+ result
25
+ else
26
+ @properties ||= {}
27
+ end
28
+ end
29
+
30
+ #
31
+ # Create a property on this resource class.
32
+ #
33
+ # If a superclass has this property, or if this property has already been
34
+ # defined by this resource, this will *override* the previous value.
35
+ #
36
+ # @param name [Symbol] The name of the property.
37
+ # @param type [Object,Array<Object>] The type(s) of this property.
38
+ # If present, this is prepended to the `is` validation option.
39
+ # @param options [Hash<Symbol,Object>] Validation options.
40
+ # @option options [Object,Array] :is An object, or list of
41
+ # objects, that must match the value using Ruby's `===` operator
42
+ # (`options[:is].any? { |v| v === value }`).
43
+ # @option options [Object,Array] :equal_to An object, or list
44
+ # of objects, that must be equal to the value using Ruby's `==`
45
+ # operator (`options[:is].any? { |v| v == value }`)
46
+ # @option options [Regexp,Array<Regexp>] :regex An object, or
47
+ # list of objects, that must match the value with `regex.match(value)`.
48
+ # @option options [Class,Array<Class>] :kind_of A class, or
49
+ # list of classes, that the value must be an instance of.
50
+ # @option options [Hash<String,Proc>] :callbacks A hash of
51
+ # messages -> procs, all of which match the value. The proc must
52
+ # return a truthy or falsey value (true means it matches).
53
+ # @option options [Symbol,Array<Symbol>] :respond_to A method
54
+ # name, or list of method names, the value must respond to.
55
+ # @option options [Symbol,Array<Symbol>] :cannot_be A property,
56
+ # or a list of properties, that the value cannot have (such as `:nil` or
57
+ # `:empty`). The method with a questionmark at the end is called on the
58
+ # value (e.g. `value.empty?`). If the value does not have this method,
59
+ # it is considered valid (i.e. if you don't respond to `empty?` we
60
+ # assume you are not empty).
61
+ # @option options [Proc] :coerce A proc which will be called to
62
+ # transform the user input to canonical form. The value is passed in,
63
+ # and the transformed value returned as output. Lazy values will *not*
64
+ # be passed to this method until after they are evaluated. Called in the
65
+ # context of the resource (meaning you can access other properties).
66
+ # @option options [Boolean] :required `true` if this property
67
+ # must be present; `false` otherwise. This is checked after the resource
68
+ # is fully initialized.
69
+ # @option options [Boolean] :name_property `true` if this
70
+ # property defaults to the same value as `name`. Equivalent to
71
+ # `default: lazy { name }`, except that #property_is_set? will
72
+ # return `true` if the property is set *or* if `name` is set.
73
+ # @option options [Boolean] :name_attribute Same as `name_property`.
74
+ # @option options [Object] :default The value this property
75
+ # will return if the user does not set one. If this is `lazy`, it will
76
+ # be run in the context of the instance (and able to access other
77
+ # properties).
78
+ # @option options [Boolean] :desired_state `true` if this property is
79
+ # part of desired state. Defaults to `true`.
80
+ # @option options [Boolean] :identity `true` if this property
81
+ # is part of object identity. Defaults to `false`.
82
+ #
83
+ # @example Bare property
84
+ # property :x
85
+ #
86
+ # @example With just a type
87
+ # property :x, String
88
+ #
89
+ # @example With just options
90
+ # property :x, default: 'hi'
91
+ #
92
+ # @example With type and options
93
+ # property :x, String, default: 'hi'
94
+ #
95
+ def property(name, type=NOT_PASSED, **options)
96
+ name = name.to_sym
97
+
98
+ options.each { |k,v| options[k.to_sym] = v if k.is_a?(String) }
99
+
100
+ options[:instance_variable_name] = :"@#{name}" if !options.has_key?(:instance_variable_name)
101
+ options.merge!(name: name, declared_in: self)
102
+
103
+ if type == NOT_PASSED
104
+ # If a type is not passed, the property derives from the
105
+ # superclass property (if any)
106
+ if properties.has_key?(name)
107
+ property = properties[name].derive(**options)
108
+ else
109
+ property = property_type(**options)
110
+ end
111
+
112
+ # If a Property is specified, derive a new one from that.
113
+ elsif type.is_a?(Property) || (type.is_a?(Class) && type <= Property)
114
+ property = type.derive(**options)
115
+
116
+ # If a primitive type was passed, combine it with "is"
117
+ else
118
+ if options[:is]
119
+ options[:is] = ([ type ] + [ options[:is] ]).flatten(1)
120
+ else
121
+ options[:is] = type
122
+ end
123
+ property = property_type(**options)
124
+ end
125
+
126
+ local_properties = properties(false)
127
+ local_properties[name] = property
128
+
129
+ property.emit_dsl
130
+ end
131
+
132
+ #
133
+ # Create a reusable property type that can be used in multiple properties
134
+ # in different resources.
135
+ #
136
+ # @param options [Hash<Symbol,Object>] Validation options. see #property for
137
+ # the list of options.
138
+ #
139
+ # @example
140
+ # property_type(default: 'hi')
141
+ #
142
+ def property_type(**options)
143
+ Property.derive(**options)
144
+ end
145
+
146
+ #
147
+ # Create a lazy value for assignment to a default value.
148
+ #
149
+ # @param block The block to run when the value is retrieved.
150
+ #
151
+ # @return [Chef::DelayedEvaluator] The lazy value
152
+ #
153
+ def lazy(&block)
154
+ DelayedEvaluator.new(&block)
155
+ end
156
+
157
+ #
158
+ # Get or set the list of desired state properties for this resource.
159
+ #
160
+ # State properties are properties that describe the desired state
161
+ # of the system, such as file permissions or ownership.
162
+ # In general, state properties are properties that could be populated by
163
+ # examining the state of the system (e.g., File.stat can tell you the
164
+ # permissions on an existing file). Contrarily, properties that are not
165
+ # "state properties" usually modify the way Chef itself behaves, for example
166
+ # by providing additional options for a package manager to use when
167
+ # installing a package.
168
+ #
169
+ # This list is used by the Chef client auditing system to extract
170
+ # information from resources to describe changes made to the system.
171
+ #
172
+ # This method is unnecessary when declaring properties with `property`;
173
+ # properties are added to state_properties by default, and can be turned off
174
+ # with `desired_state: false`.
175
+ #
176
+ # ```ruby
177
+ # property :x # part of desired state
178
+ # property :y, desired_state: false # not part of desired state
179
+ # ```
180
+ #
181
+ # @param names [Array<Symbol>] A list of property names to set as desired
182
+ # state.
183
+ #
184
+ # @return [Array<Property>] All properties in desired state.
185
+ #
186
+ def state_properties(*names)
187
+ if !names.empty?
188
+ names = names.map { |name| name.to_sym }.uniq
189
+
190
+ local_properties = properties(false)
191
+ # Add new properties to the list.
192
+ names.each do |name|
193
+ property = properties[name]
194
+ if !property
195
+ self.property name, instance_variable_name: false, desired_state: true
196
+ elsif !property.desired_state?
197
+ self.property name, desired_state: true
198
+ end
199
+ end
200
+
201
+ # If state_attrs *excludes* something which is currently desired state,
202
+ # mark it as desired_state: false.
203
+ local_properties.each do |name,property|
204
+ if property.desired_state? && !names.include?(name)
205
+ self.property name, desired_state: false
206
+ end
207
+ end
208
+ end
209
+
210
+ properties.values.select { |property| property.desired_state? }
211
+ end
212
+
213
+ #
214
+ # Set the identity of this resource to a particular set of properties.
215
+ #
216
+ # This drives #identity, which returns data that uniquely refers to a given
217
+ # resource on the given node (in such a way that it can be correlated
218
+ # across Chef runs).
219
+ #
220
+ # This method is unnecessary when declaring properties with `property`;
221
+ # properties can be added to identity during declaration with
222
+ # `identity: true`.
223
+ #
224
+ # ```ruby
225
+ # property :x, identity: true # part of identity
226
+ # property :y # not part of identity
227
+ # ```
228
+ #
229
+ # If no properties are marked as identity, "name" is considered the identity.
230
+ #
231
+ # @param names [Array<Symbol>] A list of property names to set as the identity.
232
+ #
233
+ # @return [Array<Property>] All identity properties.
234
+ #
235
+ def identity_properties(*names)
236
+ if !names.empty?
237
+ names = names.map { |name| name.to_sym }
238
+
239
+ # Add or change properties that are not part of the identity.
240
+ names.each do |name|
241
+ property = properties[name]
242
+ if !property
243
+ self.property name, instance_variable_name: false, identity: true
244
+ elsif !property.identity?
245
+ self.property name, identity: true
246
+ end
247
+ end
248
+
249
+ # If identity_properties *excludes* something which is currently part of
250
+ # the identity, mark it as identity: false.
251
+ properties.each do |name,property|
252
+ if property.identity? && !names.include?(name)
253
+
254
+ self.property name, identity: false
255
+ end
256
+ end
257
+ end
258
+
259
+ result = properties.values.select { |property| property.identity? }
260
+ result = [ properties[:name] ] if result.empty?
261
+ result
262
+ end
263
+
264
+ def included(other)
265
+ other.extend ClassMethods
266
+ end
267
+ end
268
+
269
+ def self.included(other)
270
+ other.extend ClassMethods
271
+ end
272
+
273
+ include Chef::Mixin::ParamsValidate
274
+
275
+ #
276
+ # Whether this property has been set (or whether it has a default that has
277
+ # been retrieved).
278
+ #
279
+ # @param name [Symbol] The name of the property.
280
+ # @return [Boolean] `true` if the property has been set.
281
+ #
282
+ def property_is_set?(name)
283
+ property = self.class.properties[name.to_sym]
284
+ raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
285
+ property.is_set?(self)
286
+ end
287
+
288
+ #
289
+ # Clear this property as if it had never been set. It will thereafter return
290
+ # the default.
291
+ # been retrieved).
292
+ #
293
+ # @param name [Symbol] The name of the property.
294
+ #
295
+ def reset_property(name)
296
+ property = self.class.properties[name.to_sym]
297
+ raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
298
+ property.reset(self)
299
+ end
300
+ end
301
+ end
302
+ end