chef 12.0.0.alpha.1-x86-mingw32 → 12.0.0.alpha.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/application.rb +8 -1
  3. data/lib/chef/application/apply.rb +4 -0
  4. data/lib/chef/application/client.rb +7 -7
  5. data/lib/chef/application/solo.rb +21 -13
  6. data/lib/chef/chef_fs/chef_fs_data_store.rb +60 -6
  7. data/lib/chef/chef_fs/config.rb +78 -4
  8. data/lib/chef/chef_fs/data_handler/acl_data_handler.rb +2 -2
  9. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  10. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  11. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  13. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +76 -2
  14. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  15. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  16. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  17. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +30 -0
  18. data/lib/chef/chef_fs/data_handler/organization_invites_data_handler.rb +17 -0
  19. data/lib/chef/chef_fs/data_handler/organization_members_data_handler.rb +17 -0
  20. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  21. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +2 -1
  22. data/lib/chef/chef_fs/file_system.rb +0 -1
  23. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +1 -1
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +5 -1
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +73 -13
  27. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +44 -5
  28. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -1
  29. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -3
  30. data/lib/chef/chef_fs/file_system/org_entry.rb +34 -0
  31. data/lib/chef/chef_fs/file_system/organization_invites_entry.rb +58 -0
  32. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +57 -0
  33. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +13 -4
  34. data/lib/chef/chef_fs/knife.rb +1 -1
  35. data/lib/chef/client.rb +8 -2
  36. data/lib/chef/config.rb +75 -57
  37. data/lib/chef/config_fetcher.rb +6 -21
  38. data/lib/chef/dsl/data_query.rb +48 -3
  39. data/lib/chef/dsl/platform_introspection.rb +42 -0
  40. data/lib/chef/dsl/reboot_pending.rb +6 -3
  41. data/lib/chef/encrypted_data_bag_item.rb +1 -1
  42. data/lib/chef/encrypted_data_bag_item/encryptor.rb +12 -0
  43. data/lib/chef/exceptions.rb +2 -0
  44. data/lib/chef/http/basic_client.rb +14 -0
  45. data/lib/chef/http/json_output.rb +7 -2
  46. data/lib/chef/knife.rb +36 -121
  47. data/lib/chef/knife/bootstrap.rb +68 -54
  48. data/lib/chef/knife/bootstrap/archlinux-gems.erb +6 -1
  49. data/lib/chef/knife/bootstrap/chef-aix.erb +5 -0
  50. data/lib/chef/knife/bootstrap/chef-full.erb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +70 -29
  52. data/lib/chef/knife/search.rb +56 -12
  53. data/lib/chef/knife/serve.rb +1 -1
  54. data/lib/chef/local_mode.rb +10 -4
  55. data/lib/chef/mixin/deep_merge.rb +6 -3
  56. data/lib/chef/mixin/shell_out.rb +33 -17
  57. data/lib/chef/null_logger.rb +72 -0
  58. data/lib/chef/platform.rb +2 -1
  59. data/lib/chef/platform/provider_mapping.rb +1 -1
  60. data/lib/chef/platform/rebooter.rb +54 -0
  61. data/lib/chef/provider/ifconfig.rb +15 -16
  62. data/lib/chef/provider/link.rb +1 -1
  63. data/lib/chef/provider/mount/mount.rb +1 -1
  64. data/lib/chef/provider/mount/solaris.rb +102 -64
  65. data/lib/chef/provider/package/aix.rb +4 -12
  66. data/lib/chef/provider/package/ips.rb +8 -12
  67. data/lib/chef/provider/package/macports.rb +4 -12
  68. data/lib/chef/provider/package/pacman.rb +2 -6
  69. data/lib/chef/provider/package/portage.rb +2 -6
  70. data/lib/chef/provider/package/rpm.rb +4 -12
  71. data/lib/chef/provider/package/solaris.rb +4 -12
  72. data/lib/chef/provider/reboot.rb +69 -0
  73. data/lib/chef/provider/service/debian.rb +10 -10
  74. data/lib/chef/provider/service/freebsd.rb +89 -73
  75. data/lib/chef/provider/service/gentoo.rb +2 -2
  76. data/lib/chef/provider/service/init.rb +6 -4
  77. data/lib/chef/provider/service/insserv.rb +3 -3
  78. data/lib/chef/provider/service/macosx.rb +2 -2
  79. data/lib/chef/provider/service/simple.rb +6 -4
  80. data/lib/chef/provider/service/solaris.rb +1 -1
  81. data/lib/chef/provider/service/systemd.rb +9 -9
  82. data/lib/chef/provider/service/upstart.rb +6 -6
  83. data/lib/chef/provider/subversion.rb +6 -6
  84. data/lib/chef/provider/user/dscl.rb +32 -28
  85. data/lib/chef/provider/user/windows.rb +6 -6
  86. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  87. data/lib/chef/providers.rb +1 -0
  88. data/lib/chef/recipe.rb +0 -1
  89. data/lib/chef/resource.rb +3 -5
  90. data/lib/chef/resource/mount.rb +9 -0
  91. data/lib/chef/resource/reboot.rb +48 -0
  92. data/lib/chef/resources.rb +1 -0
  93. data/lib/chef/run_context.rb +25 -0
  94. data/lib/chef/search/query.rb +122 -14
  95. data/lib/chef/util/path_helper.rb +54 -6
  96. data/lib/chef/util/windows/net_user.rb +4 -1
  97. data/lib/chef/version.rb +1 -1
  98. data/lib/chef/win32/api/file.rb +1 -5
  99. data/lib/chef/win32/api/net.rb +1 -0
  100. data/lib/chef/workstation_config_loader.rb +177 -0
  101. data/spec/functional/http/simple_spec.rb +57 -1
  102. data/spec/functional/mixin/shell_out_spec.rb +2 -2
  103. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +51 -0
  104. data/spec/functional/rebooter_spec.rb +105 -0
  105. data/spec/functional/resource/deploy_revision_spec.rb +0 -4
  106. data/spec/functional/resource/file_spec.rb +26 -3
  107. data/spec/functional/resource/group_spec.rb +5 -3
  108. data/spec/functional/resource/link_spec.rb +16 -16
  109. data/spec/functional/resource/reboot_spec.rb +103 -0
  110. data/spec/integration/client/client_spec.rb +4 -8
  111. data/spec/integration/client/ipv6_spec.rb +1 -1
  112. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -2
  113. data/spec/integration/knife/delete_spec.rb +39 -0
  114. data/spec/integration/knife/deps_spec.rb +30 -20
  115. data/spec/integration/knife/download_spec.rb +77 -1
  116. data/spec/integration/knife/list_spec.rb +221 -0
  117. data/spec/integration/knife/raw_spec.rb +1 -1
  118. data/spec/integration/knife/show_spec.rb +2 -2
  119. data/spec/integration/knife/upload_spec.rb +154 -1
  120. data/spec/support/pedant/run_pedant.rb +0 -1
  121. data/spec/support/shared/functional/http.rb +8 -1
  122. data/spec/support/shared/integration/integration_helper.rb +11 -19
  123. data/spec/support/shared/unit/platform_introspector.rb +22 -0
  124. data/spec/unit/application/apply.rb +11 -1
  125. data/spec/unit/application/solo_spec.rb +19 -3
  126. data/spec/unit/chef_fs/config_spec.rb +58 -0
  127. data/spec/unit/config_fetcher_spec.rb +1 -3
  128. data/spec/unit/config_spec.rb +247 -220
  129. data/spec/unit/dsl/data_query_spec.rb +165 -23
  130. data/spec/unit/dsl/reboot_pending_spec.rb +1 -7
  131. data/spec/unit/encrypted_data_bag_item_spec.rb +1 -1
  132. data/spec/unit/knife/bootstrap_spec.rb +354 -182
  133. data/spec/unit/knife/core/bootstrap_context_spec.rb +67 -30
  134. data/spec/unit/knife_spec.rb +3 -30
  135. data/spec/unit/mixin/deep_merge_spec.rb +14 -0
  136. data/spec/unit/mixin/shell_out_spec.rb +134 -64
  137. data/spec/unit/provider/ifconfig/debian_spec.rb +19 -9
  138. data/spec/unit/provider/ifconfig/redhat_spec.rb +16 -14
  139. data/spec/unit/provider/ifconfig_spec.rb +3 -3
  140. data/spec/unit/provider/link_spec.rb +5 -5
  141. data/spec/unit/provider/mount/mount_spec.rb +10 -1
  142. data/spec/unit/provider/mount/solaris_spec.rb +185 -11
  143. data/spec/unit/provider/package/aix_spec.rb +5 -17
  144. data/spec/unit/provider/package/ips_spec.rb +8 -21
  145. data/spec/unit/provider/package/macports_spec.rb +12 -12
  146. data/spec/unit/provider/package/pacman_spec.rb +4 -12
  147. data/spec/unit/provider/package/portage_spec.rb +5 -15
  148. data/spec/unit/provider/package/rpm_spec.rb +7 -22
  149. data/spec/unit/provider/package/solaris_spec.rb +5 -16
  150. data/spec/unit/provider/service/arch_service_spec.rb +8 -14
  151. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  152. data/spec/unit/provider/service/freebsd_service_spec.rb +457 -225
  153. data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
  154. data/spec/unit/provider/service/init_service_spec.rb +10 -10
  155. data/spec/unit/provider/service/insserv_service_spec.rb +3 -4
  156. data/spec/unit/provider/service/invokercd_service_spec.rb +8 -9
  157. data/spec/unit/provider/service/macosx_spec.rb +5 -5
  158. data/spec/unit/provider/service/simple_service_spec.rb +4 -6
  159. data/spec/unit/provider/service/solaris_smf_service_spec.rb +1 -3
  160. data/spec/unit/provider/service/systemd_service_spec.rb +20 -20
  161. data/spec/unit/provider/service/upstart_service_spec.rb +15 -17
  162. data/spec/unit/provider/subversion_spec.rb +5 -6
  163. data/spec/unit/provider/user/dscl_spec.rb +2 -1
  164. data/spec/unit/provider/user/windows_spec.rb +7 -0
  165. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  166. data/spec/unit/resource/mount_spec.rb +9 -0
  167. data/spec/unit/resource_spec.rb +0 -4
  168. data/spec/unit/rest_spec.rb +1 -1
  169. data/spec/unit/run_context_spec.rb +15 -0
  170. data/spec/unit/search/query_spec.rb +196 -40
  171. data/spec/unit/util/path_helper_spec.rb +111 -28
  172. data/spec/unit/workstation_config_loader_spec.rb +283 -0
  173. metadata +36 -20
  174. data/lib/chef/knife/bootstrap/centos5-gems.erb +0 -62
  175. data/lib/chef/knife/bootstrap/fedora13-gems.erb +0 -44
  176. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +0 -53
  177. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +0 -48
  178. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +0 -46
  179. data/spec/support/shared/integration/chef_zero_support.rb +0 -130
  180. data/spec/unit/knife/config_file_selection_spec.rb +0 -135
@@ -0,0 +1,58 @@
1
+ require 'chef/chef_fs/file_system/rest_list_entry'
2
+ require 'chef/chef_fs/data_handler/organization_invites_data_handler'
3
+
4
+ class Chef
5
+ module ChefFS
6
+ module FileSystem
7
+ # /organizations/NAME/invitations.json
8
+ # read data from:
9
+ # - GET /organizations/NAME/association_requests
10
+ # write data to:
11
+ # - remove from list: DELETE /organizations/NAME/association_requests/id
12
+ # - add to list: POST /organizations/NAME/association_requests
13
+ class OrganizationInvitesEntry < RestListEntry
14
+ def initialize(name, parent, exists = nil)
15
+ super(name, parent)
16
+ @exists = exists
17
+ end
18
+
19
+ def data_handler
20
+ Chef::ChefFS::DataHandler::OrganizationInvitesDataHandler.new
21
+ end
22
+
23
+ # /organizations/foo/invites.json -> /organizations/foo/association_requests
24
+ def api_path
25
+ File.join(parent.api_path, 'association_requests')
26
+ end
27
+
28
+ def exists?
29
+ parent.exists?
30
+ end
31
+
32
+ def delete(recurse)
33
+ raise Chef::ChefFS::FileSystem::OperationNotAllowedError.new(:delete, self)
34
+ end
35
+
36
+ def write(contents)
37
+ desired_invites = minimize_value(JSON.parse(contents, :create_additions => false))
38
+ actual_invites = _read_json.inject({}) { |h,val| h[val['username']] = val['id']; h }
39
+ invites = actual_invites.keys
40
+ (desired_invites - invites).each do |invite|
41
+ begin
42
+ rest.post(api_path, { 'user' => invite })
43
+ rescue Net::HTTPServerException => e
44
+ if e.response.code == '409'
45
+ Chef::Log.warn("Could not invite #{invite} to organization #{org}: #{api_error_text(e.response)}")
46
+ else
47
+ raise
48
+ end
49
+ end
50
+ end
51
+ (invites - desired_invites).each do |invite|
52
+ rest.delete(File.join(api_path, actual_invites[invite]))
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,57 @@
1
+ require 'chef/chef_fs/file_system/rest_list_entry'
2
+ require 'chef/chef_fs/data_handler/organization_members_data_handler'
3
+
4
+ class Chef
5
+ module ChefFS
6
+ module FileSystem
7
+ # /organizations/NAME/members.json
8
+ # reads data from:
9
+ # - GET /organizations/NAME/users
10
+ # writes data to:
11
+ # - remove from list: DELETE /organizations/NAME/users/name
12
+ # - add to list: POST /organizations/NAME/users/name
13
+ class OrganizationMembersEntry < RestListEntry
14
+ def initialize(name, parent, exists = nil)
15
+ super(name, parent)
16
+ @exists = exists
17
+ end
18
+
19
+ def data_handler
20
+ Chef::ChefFS::DataHandler::OrganizationMembersDataHandler.new
21
+ end
22
+
23
+ # /organizations/foo/members.json -> /organizations/foo/users
24
+ def api_path
25
+ File.join(parent.api_path, 'users')
26
+ end
27
+
28
+ def exists?
29
+ parent.exists?
30
+ end
31
+
32
+ def delete(recurse)
33
+ raise Chef::ChefFS::FileSystem::OperationNotAllowedError.new(:delete, self)
34
+ end
35
+
36
+ def write(contents)
37
+ desired_members = minimize_value(JSON.parse(contents, :create_additions => false))
38
+ members = minimize_value(_read_json)
39
+ (desired_members - members).each do |member|
40
+ begin
41
+ rest.post(File.join(api_path, member), {})
42
+ rescue Net::HTTPServerException => e
43
+ if e.response.code == '404'
44
+ raise "Chef server at #{api_path} does not allow you to directly add members. Please either upgrade your Chef server or move the users you want into invitations.json instead of members.json."
45
+ else
46
+ raise
47
+ end
48
+ end
49
+ end
50
+ (members - desired_members).each do |member|
51
+ rest.delete(File.join(api_path, member))
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -80,13 +80,13 @@ class Chef
80
80
  end
81
81
 
82
82
  def read
83
- Chef::JSONCompat.to_json_pretty(_read_hash)
83
+ Chef::JSONCompat.to_json_pretty(minimize_value(_read_json))
84
84
  end
85
85
 
86
- def _read_hash
86
+ def _read_json
87
87
  begin
88
88
  # Minimize the value (get rid of defaults) so the results don't look terrible
89
- minimize_value(root.get_json(api_path))
89
+ root.get_json(api_path)
90
90
  rescue Timeout::Error => e
91
91
  raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e), "Timeout reading: #{e}"
92
92
  rescue Net::HTTPServerException => e
@@ -119,7 +119,7 @@ class Chef
119
119
 
120
120
  # Grab this value
121
121
  begin
122
- value = _read_hash
122
+ value = _read_json
123
123
  rescue Chef::ChefFS::FileSystem::NotFoundError
124
124
  return [ false, :none, other_value_json ]
125
125
  end
@@ -169,7 +169,16 @@ class Chef
169
169
  end
170
170
  end
171
171
  end
172
+
173
+ def api_error_text(response)
174
+ begin
175
+ JSON.parse(response.body)['error'].join("\n")
176
+ rescue
177
+ response.body
178
+ end
179
+ end
172
180
  end
181
+
173
182
  end
174
183
  end
175
184
  end
@@ -68,7 +68,7 @@ class Chef
68
68
  end
69
69
  end
70
70
 
71
- @chef_fs_config = Chef::ChefFS::Config.new(Chef::Config, Dir.pwd, config)
71
+ @chef_fs_config = Chef::ChefFS::Config.new(Chef::Config, Dir.pwd, config, ui)
72
72
 
73
73
  Chef::ChefFS::Parallelizer.threads = (Chef::Config[:concurrency] || 10) - 1
74
74
  end
data/lib/chef/client.rb CHANGED
@@ -25,7 +25,6 @@ require 'chef/log'
25
25
  require 'chef/rest'
26
26
  require 'chef/api_client'
27
27
  require 'chef/api_client/registration'
28
- require 'chef/platform/query_helpers'
29
28
  require 'chef/node'
30
29
  require 'chef/role'
31
30
  require 'chef/file_cache'
@@ -45,6 +44,7 @@ require 'chef/resource_reporter'
45
44
  require 'chef/run_lock'
46
45
  require 'chef/policy_builder'
47
46
  require 'chef/request_id'
47
+ require 'chef/platform/rebooter'
48
48
  require 'ohai'
49
49
  require 'rbconfig'
50
50
 
@@ -428,7 +428,9 @@ class Chef
428
428
 
429
429
  run_context = setup_run_context
430
430
 
431
- converge(run_context)
431
+ catch (:end_client_run_early) do
432
+ converge(run_context)
433
+ end
432
434
 
433
435
  save_updated_node
434
436
 
@@ -436,6 +438,10 @@ class Chef
436
438
  Chef::Log.info("Chef Run complete in #{run_status.elapsed_time} seconds")
437
439
  run_completed_successfully
438
440
  @events.run_completed(node)
441
+
442
+ # rebooting has to be the last thing we do, no exceptions.
443
+ Chef::Platform::Rebooter.reboot_if_needed!(node)
444
+
439
445
  true
440
446
  rescue Exception => e
441
447
  # CHEF-3336: Send the error first in case something goes wrong below and we don't know why
data/lib/chef/config.rb CHANGED
@@ -23,6 +23,7 @@ require 'chef/log'
23
23
  require 'chef/exceptions'
24
24
  require 'mixlib/config'
25
25
  require 'chef/util/selinux'
26
+ require 'chef/util/path_helper'
26
27
  require 'pathname'
27
28
 
28
29
  class Chef
@@ -30,6 +31,8 @@ class Chef
30
31
 
31
32
  extend Mixlib::Config
32
33
 
34
+ PathHelper = Chef::Util::PathHelper
35
+
33
36
  # Evaluates the given string as config.
34
37
  #
35
38
  # +filename+ is used for context in stacktraces, but doesn't need to be the name of an actual file.
@@ -58,37 +61,13 @@ class Chef
58
61
  configuration.inspect
59
62
  end
60
63
 
61
- def self.on_windows?
62
- RUBY_PLATFORM =~ /mswin|mingw|windows/
63
- end
64
-
65
- BACKSLASH = '\\'.freeze
66
-
67
- def self.platform_path_separator
68
- if on_windows?
69
- File::ALT_SEPARATOR || BACKSLASH
70
- else
71
- File::SEPARATOR
72
- end
73
- end
74
-
75
- def self.path_join(*args)
76
- args = args.flatten
77
- args.inject do |joined_path, component|
78
- unless joined_path[-1,1] == platform_path_separator
79
- joined_path += platform_path_separator
80
- end
81
- joined_path += component
82
- end
83
- end
84
-
85
64
  def self.platform_specific_path(path)
86
- if on_windows?
87
- # turns /etc/chef/client.rb into C:/chef/client.rb
88
- system_drive = env['SYSTEMDRIVE'] ? env['SYSTEMDRIVE'] : ""
89
- path = File.join(system_drive, path.split('/')[2..-1])
90
- # ensure all forward slashes are backslashes
91
- path.gsub!(File::SEPARATOR, (File::ALT_SEPARATOR || '\\'))
65
+ path = PathHelper.cleanpath(path)
66
+ if Chef::Platform.windows?
67
+ # turns \etc\chef\client.rb and \var\chef\client.rb into C:/chef/client.rb
68
+ if env['SYSTEMDRIVE'] && path[0] == '\\' && path.split('\\')[2] == 'chef'
69
+ path = PathHelper.join(env['SYSTEMDRIVE'], path.split('\\', 3)[2])
70
+ end
92
71
  end
93
72
  path
94
73
  end
@@ -101,17 +80,13 @@ class Chef
101
80
  configurable(:config_file)
102
81
 
103
82
  default(:config_dir) do
104
- if local_mode
105
- path_join(user_home, ".chef#{platform_path_separator}")
83
+ if config_file
84
+ PathHelper.dirname(config_file)
106
85
  else
107
- config_file && ::File.dirname(config_file)
86
+ PathHelper.join(user_home, ".chef", "")
108
87
  end
109
88
  end
110
89
 
111
- # No config file (client.rb / knife.rb / etc.) will be loaded outside this path.
112
- # Major use case is tests, where we don't want to load the user's config files.
113
- configurable(:config_file_jail)
114
-
115
90
  default :formatters, []
116
91
 
117
92
  # Override the config dispatch to set the value of multiple server options simultaneously
@@ -119,7 +94,7 @@ class Chef
119
94
  # === Parameters
120
95
  # url<String>:: String to be set for all of the chef-server-api URL's
121
96
  #
122
- configurable(:chef_server_url).writes_value { |url| url.strip }
97
+ configurable(:chef_server_url).writes_value { |url| url.to_s.strip }
123
98
 
124
99
  # When you are using ActiveSupport, they monkey-patch 'daemonize' into Kernel.
125
100
  # So while this is basically identical to what method_missing would do, we pull
@@ -150,7 +125,7 @@ class Chef
150
125
  # In local mode, we auto-discover the repo root by looking for a path with "cookbooks" under it.
151
126
  # This allows us to run config-free.
152
127
  path = cwd
153
- until File.directory?(path_join(path, "cookbooks"))
128
+ until File.directory?(PathHelper.join(path, "cookbooks"))
154
129
  new_path = File.expand_path('..', path)
155
130
  if new_path == path
156
131
  Chef::Log.warn("No cookbooks directory found at or above current directory. Assuming #{Dir.pwd}.")
@@ -164,9 +139,9 @@ class Chef
164
139
 
165
140
  def self.derive_path_from_chef_repo_path(child_path)
166
141
  if chef_repo_path.kind_of?(String)
167
- path_join(chef_repo_path, child_path)
142
+ PathHelper.join(chef_repo_path, child_path)
168
143
  else
169
- chef_repo_path.map { |path| path_join(path, child_path)}
144
+ chef_repo_path.map { |path| PathHelper.join(path, child_path)}
170
145
  end
171
146
  end
172
147
 
@@ -238,7 +213,7 @@ class Chef
238
213
  # this is under the user's home directory.
239
214
  default(:cache_path) do
240
215
  if local_mode
241
- "#{config_dir}local-mode-cache"
216
+ PathHelper.join(config_dir, 'local-mode-cache')
242
217
  else
243
218
  primary_cache_root = platform_specific_path("/var")
244
219
  primary_cache_path = platform_specific_path("/var/chef")
@@ -247,8 +222,7 @@ class Chef
247
222
  # Otherwise, we'll create .chef under the user's home directory and use that as
248
223
  # the cache path.
249
224
  unless path_accessible?(primary_cache_path) || path_accessible?(primary_cache_root)
250
- secondary_cache_path = File.join(user_home, '.chef')
251
- secondary_cache_path.gsub!(File::SEPARATOR, platform_path_separator) # Safety, mainly for Windows...
225
+ secondary_cache_path = PathHelper.join(user_home, '.chef')
252
226
  Chef::Log.info("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}")
253
227
  secondary_cache_path
254
228
  else
@@ -263,20 +237,20 @@ class Chef
263
237
  end
264
238
 
265
239
  # Where cookbook files are stored on the server (by content checksum)
266
- default(:checksum_path) { path_join(cache_path, "checksums") }
240
+ default(:checksum_path) { PathHelper.join(cache_path, "checksums") }
267
241
 
268
242
  # Where chef's cache files should be stored
269
- default(:file_cache_path) { path_join(cache_path, "cache") }
243
+ default(:file_cache_path) { PathHelper.join(cache_path, "cache") }
270
244
 
271
245
  # Where backups of chef-managed files should go
272
- default(:file_backup_path) { path_join(cache_path, "backup") }
246
+ default(:file_backup_path) { PathHelper.join(cache_path, "backup") }
273
247
 
274
248
  # The chef-client (or solo) lockfile.
275
249
  #
276
250
  # If your `file_cache_path` resides on a NFS (or non-flock()-supporting
277
251
  # fs), it's recommended to set this to something like
278
252
  # '/tmp/chef-client-running.pid'
279
- default(:lockfile) { path_join(file_cache_path, "chef-client-running.pid") }
253
+ default(:lockfile) { PathHelper.join(file_cache_path, "chef-client-running.pid") }
280
254
 
281
255
  ## Daemonization Settings ##
282
256
  # What user should Chef run as?
@@ -372,7 +346,7 @@ class Chef
372
346
  # Path to the default CA bundle files.
373
347
  default :ssl_ca_path, nil
374
348
  default(:ssl_ca_file) do
375
- if on_windows? and embedded_path = embedded_dir
349
+ if Chef::Platform.windows? and embedded_path = embedded_dir
376
350
  cacert_path = File.join(embedded_path, "ssl/certs/cacert.pem")
377
351
  cacert_path if File.exist?(cacert_path)
378
352
  else
@@ -384,7 +358,7 @@ class Chef
384
358
  # certificates in this directory will be added to whatever CA bundle ruby
385
359
  # is using. Use this to add self-signed certs for your Chef Server or local
386
360
  # HTTP file servers.
387
- default(:trusted_certs_dir) { config_dir && path_join(config_dir, "trusted_certs") }
361
+ default(:trusted_certs_dir) { PathHelper.join(config_dir, "trusted_certs") }
388
362
 
389
363
  # Where should chef-solo download recipes from?
390
364
  default :recipe_url, nil
@@ -417,10 +391,6 @@ class Chef
417
391
 
418
392
  # This secret is used to decrypt encrypted data bag items.
419
393
  default(:encrypted_data_bag_secret) do
420
- # We have to check for the existence of the default file before setting it
421
- # since +Chef::Config[:encrypted_data_bag_secret]+ is read by older
422
- # bootstrap templates to determine if the local secret should be uploaded to
423
- # node being bootstrapped. This should be removed in Chef 12.
424
394
  if File.exist?(platform_specific_path("/etc/chef/encrypted_data_bag_secret"))
425
395
  platform_specific_path("/etc/chef/encrypted_data_bag_secret")
426
396
  else
@@ -492,7 +462,7 @@ class Chef
492
462
  default(:syntax_check_cache_path) { cache_options[:path] }
493
463
 
494
464
  # Deprecated:
495
- default(:cache_options) { { :path => path_join(file_cache_path, "checksums") } }
465
+ default(:cache_options) { { :path => PathHelper.join(file_cache_path, "checksums") } }
496
466
 
497
467
  # Set to false to silence Chef 11 deprecation warnings:
498
468
  default :chef11_deprecation_warnings, true
@@ -505,6 +475,9 @@ class Chef
505
475
  default :ssh_gateway, nil
506
476
  default :bootstrap_version, nil
507
477
  default :bootstrap_proxy, nil
478
+ default :bootstrap_template, "chef-full"
479
+ default :secret, nil
480
+ default :secret_file, nil
508
481
  default :identity_file, nil
509
482
  default :host_key_verify, nil
510
483
  default :forward_agent, nil
@@ -537,7 +510,7 @@ class Chef
537
510
 
538
511
  # Those lists of regular expressions define what chef considers a
539
512
  # valid user and group name
540
- if on_windows?
513
+ if Chef::Platform.windows?
541
514
  set_defaults_for_windows
542
515
  else
543
516
  set_defaults_for_nix
@@ -550,7 +523,7 @@ class Chef
550
523
  end
551
524
 
552
525
  def self.windows_home_path
553
- windows_home_path = env['SYSTEMDRIVE'] + env['HOMEPATH'] if env['SYSTEMDRIVE'] && env['HOMEPATH']
526
+ env['SYSTEMDRIVE'] + env['HOMEPATH'] if env['SYSTEMDRIVE'] && env['HOMEPATH']
554
527
  end
555
528
 
556
529
  # returns a platform specific path to the user home dir if set, otherwise default to current directory.
@@ -614,6 +587,51 @@ class Chef
614
587
  default :normal_attribute_whitelist, nil
615
588
  default :override_attribute_whitelist, nil
616
589
 
590
+ # Chef requires an English-language UTF-8 locale to function properly. We attempt
591
+ # to use the 'locale -a' command and search through a list of preferences until we
592
+ # find one that we can use. On Ubuntu systems we should find 'C.UTF-8' and be
593
+ # able to use that even if there is no English locale on the server, but Mac, Solaris,
594
+ # AIX, etc do not have that locale. We then try to find an English locale and fall
595
+ # back to 'C' if we do not. The choice of fallback is pick-your-poison. If we try
596
+ # to do the work to return a non-US UTF-8 locale then we fail inside of providers when
597
+ # things like 'svn info' return Japanese and we can't parse them. OTOH, if we pick 'C' then
598
+ # we will blow up on UTF-8 characters. Between the warn we throw and the Encoding
599
+ # exception that ruby will throw it is more obvious what is broken if we drop UTF-8 by
600
+ # default rather than drop English.
601
+ #
602
+ # If there is no 'locale -a' then we return 'en_US.UTF-8' since that is the most commonly
603
+ # available English UTF-8 locale. However, all modern POSIXen should support 'locale -a'.
604
+ default :internal_locale do
605
+ begin
606
+ locales = `locale -a`.split
607
+ case
608
+ when locales.include?('C.UTF-8')
609
+ 'C.UTF-8'
610
+ when locales.include?('en_US.UTF-8')
611
+ 'en_US.UTF-8'
612
+ when locales.include?('en.UTF-8')
613
+ 'en.UTF-8'
614
+ when guesses = locales.select { |l| l =~ /^en_.*UTF-8$'/ }
615
+ guesses.first
616
+ else
617
+ Chef::Log.warn "Please install an English UTF-8 locale for Chef to use, falling back to C locale and disabling UTF-8 support."
618
+ 'C'
619
+ end
620
+ rescue
621
+ Chef::Log.warn "No usable locale -a command found, assuming you have en_US.UTF-8 installed."
622
+ 'en_US.UTF-8'
623
+ end
624
+ end
625
+
626
+ # Force UTF-8 Encoding, for when we fire up in the 'C' locale or other strange locales (e.g.
627
+ # japanese windows encodings). If we do not do this, then knife upload will fail when a cookbook's
628
+ # README.md has UTF-8 characters that do not encode in whatever surrounding encoding we have been
629
+ # passed. Effectively, the Chef Ecosystem is globally UTF-8 by default. Anyone who wants to be
630
+ # able to upload Shift_JIS or ISO-8859-1 files needs to mark *those* files explicitly with
631
+ # magic tags to make ruby correctly identify the encoding being used. Changing this default will
632
+ # break Chef community cookbooks and is very highly discouraged.
633
+ default :ruby_encoding, Encoding::UTF_8
634
+
617
635
  # If installed via an omnibus installer, this gives the path to the
618
636
  # "embedded" directory which contains all of the software packaged with
619
637
  # omnibus. This is used to locate the cacert.pem file on windows.