chef-config 16.2.44 → 16.4.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f95d6cbee8afbc2b5b6ceda9c6c18a75f542c545b9f01587f0f216c2d4cb735f
4
- data.tar.gz: b373dd5fdf065d4b4cc9287d7d4254ba3b340b8b4ded5334c33939b596c6db8d
3
+ metadata.gz: 51f20c3e7f57cf6748f609f9bbf456889aeff48a3ce3457adecc63c2c4686085
4
+ data.tar.gz: 449f8768c9f289352682f34cd242d11509a789804d70e291fd7034667a3fb9f3
5
5
  SHA512:
6
- metadata.gz: cd07d4b433d12ec1f9361c2d69ec07ecc3558aa5316ce07b546e8ee2b208247441621263045d0f5613c22e89f753eae817423d9036c8ca4b785322b4adeb665d
7
- data.tar.gz: cbbb118a11769451ee5e40277e975465e43f49ca532deaea6521d2823982cf70a20468b5e348c7240514d312e4846d2fb77b295d95fb6d8fdd5270a53bee45fe
6
+ metadata.gz: bb7293d322062c30c48ed4a4d62f5310e91ce2c60f7f71ae6c31d7bf51fa868142ad42f01019805a7b998963744e98127b554ed6d47a1de4be42d86972688296
7
+ data.tar.gz: 9adbb97999cedcc8efb039ccbc413724baa64ddb2bd97b764f8f49cb65b01f39a19e59f71ea9fe3e3960120d52afb217898a12571535d5fe9574094c26f686de
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "chef-config/version"
5
4
 
@@ -74,42 +74,66 @@ module ChefConfig
74
74
  path
75
75
  end
76
76
 
77
- # On *nix, /etc/chef
78
- def self.etc_chef_dir(is_windows = ChefUtils.windows?)
79
- path = is_windows ? c_chef_dir : PathHelper.join("/etc", ChefConfig::Dist::DIR_SUFFIX)
80
- PathHelper.cleanpath(path)
77
+ # On *nix, /etc/chef, on Windows C:\chef
78
+ #
79
+ # @param windows [Boolean] optional flag to force to windows or unix-style
80
+ # @return [String] the platform-specific path
81
+ #
82
+ def self.etc_chef_dir(windows: ChefUtils.windows?)
83
+ path = windows ? c_chef_dir : PathHelper.join("/etc", ChefConfig::Dist::DIR_SUFFIX, windows: windows)
84
+ PathHelper.cleanpath(path, windows: windows)
81
85
  end
82
86
 
83
- # On *nix, /var/chef
84
- def self.var_chef_dir(is_windows = ChefUtils.windows?)
85
- path = is_windows ? c_chef_dir : PathHelper.join("/var", ChefConfig::Dist::DIR_SUFFIX)
86
- PathHelper.cleanpath(path)
87
+ # On *nix, /var/chef, on Windows C:\chef
88
+ #
89
+ # @param windows [Boolean] optional flag to force to windows or unix-style
90
+ # @return [String] the platform-specific path
91
+ #
92
+ def self.var_chef_dir(windows: ChefUtils.windows?)
93
+ path = windows ? c_chef_dir : PathHelper.join("/var", ChefConfig::Dist::DIR_SUFFIX, windows: windows)
94
+ PathHelper.cleanpath(path, windows: windows)
87
95
  end
88
96
 
89
- # On *nix, the root of /var/, used to test if we can create and write in /var/chef
90
- def self.var_root_dir(is_windows = ChefUtils.windows?)
91
- path = is_windows ? c_chef_dir : "/var"
92
- PathHelper.cleanpath(path)
97
+ # On *nix, /var, on Windows C:\
98
+ #
99
+ # @param windows [Boolean] optional flag to force to windows or unix-style
100
+ # @return [String] the platform-specific path
101
+ #
102
+ def self.var_root_dir(windows: ChefUtils.windows?)
103
+ path = windows ? "C:\\" : "/var"
104
+ PathHelper.cleanpath(path, windows: windows)
93
105
  end
94
106
 
95
107
  # On windows, C:/chef/
96
- def self.c_chef_dir
108
+ #
109
+ # (should only be called in a windows-context)
110
+ #
111
+ # @return [String] the platform-specific path
112
+ #
113
+ def self.c_chef_dir(windows: ChefUtils.windows?)
97
114
  drive = windows_installation_drive || "C:"
98
- path = PathHelper.join(drive, ChefConfig::Dist::DIR_SUFFIX)
99
- PathHelper.cleanpath(path)
115
+ PathHelper.join(drive, ChefConfig::Dist::DIR_SUFFIX, windows: windows)
100
116
  end
101
117
 
102
- def self.c_opscode_dir
118
+ # On windows, C:/opscode
119
+ #
120
+ # (should only be called in a windows-context)
121
+ #
122
+ # @return [String] the platform-specific path
123
+ #
124
+ def self.c_opscode_dir(windows: ChefUtils.windows?)
103
125
  drive = windows_installation_drive || "C:"
104
- path = PathHelper.join(drive, ChefConfig::Dist::LEGACY_CONF_DIR, ChefConfig::Dist::DIR_SUFFIX)
105
- PathHelper.cleanpath(path)
126
+ PathHelper.join(drive, ChefConfig::Dist::LEGACY_CONF_DIR, ChefConfig::Dist::DIR_SUFFIX, windows: windows)
106
127
  end
107
128
 
108
129
  # the drive where Chef is installed on a windows host. This is determined
109
130
  # either by the drive containing the current file or by the SYSTEMDRIVE ENV
110
131
  # variable
111
132
  #
133
+ # (should only be called in a windows-context)
134
+ #
112
135
  # @return [String] the drive letter
136
+ #
113
137
  def self.windows_installation_drive
114
138
  if ChefUtils.windows?
115
139
  drive = File.expand_path(__FILE__).split("/", 2)[0]
@@ -313,9 +337,12 @@ module ChefConfig
313
337
  # Defaults to <chef_repo_path>/users.
314
338
  default(:user_path) { derive_path_from_chef_repo_path("users") }.writes_value { |path| expand_relative_paths(path) }
315
339
 
316
- # Turn on "path sanity" by default.
340
+ # DEPRECATED
317
341
  default :enforce_path_sanity, false
318
342
 
343
+ # Enforce default paths by default for all APIs, not just the default internal shell_out
344
+ default :enforce_default_paths, false
345
+
319
346
  # Formatted Chef Client output is a beta feature, disabled by default:
320
347
  default :formatter, "null"
321
348
 
@@ -339,11 +366,11 @@ module ChefConfig
339
366
  # the cache path.
340
367
  unless path_accessible?(primary_cache_path) || path_accessible?(primary_cache_root)
341
368
  secondary_cache_path = PathHelper.join(user_home, ChefConfig::Dist::USER_CONF_DIR)
342
- secondary_cache_path = target_mode? ? "#{secondary_cache_path}/#{target_mode.host}" : secondary_cache_path
369
+ secondary_cache_path = target_mode? ? PathHelper.join(secondary_cache_path, target_mode.host) : secondary_cache_path
343
370
  ChefConfig.logger.trace("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}")
344
371
  secondary_cache_path
345
372
  else
346
- target_mode? ? "#{primary_cache_path}/#{target_mode.host}" : primary_cache_path
373
+ target_mode? ? PathHelper.join(primary_cache_path, target_mode.host) : primary_cache_path
347
374
  end
348
375
  end
349
376
  end
@@ -352,7 +379,7 @@ module ChefConfig
352
379
  #
353
380
  # @param path [String]
354
381
  def self.path_accessible?(path)
355
- File.exists?(path) && File.readable?(path) && File.writable?(path)
382
+ File.exist?(path) && File.readable?(path) && File.writable?(path)
356
383
  end
357
384
 
358
385
  # Where cookbook files are stored on the server (by content checksum)
@@ -959,23 +986,32 @@ module ChefConfig
959
986
  #
960
987
  default :no_lazy_load, true
961
988
 
962
- # A whitelisted array of attributes you want sent over the wire when node
963
- # data is saved. The default setting is nil, which collects all data. Setting
964
- # to [] will not collect any data for save.
965
- #
966
- default :automatic_attribute_whitelist, nil
967
- default :default_attribute_whitelist, nil
968
- default :normal_attribute_whitelist, nil
969
- default :override_attribute_whitelist, nil
989
+ # A array of attributes you want sent over the wire when node
990
+ # data is saved. The default setting is nil, which collects all data.
991
+ # NOTE: Setting to [] will not collect ANY data to save.
992
+ default :allowed_automatic_attributes, nil
993
+ default :allowed_default_attributes, nil
994
+ default :allowed_normal_attributes, nil
995
+ default :allowed_override_attributes, nil
970
996
 
971
- # A blacklisted array of attributes you do not want to send over the
997
+ # An array of attributes you do not want to send over the
972
998
  # wire when node data is saved
973
- # The default setting is nil, which collects all data. Setting to [] will
974
- # still collect all data for save
999
+ # The default setting is nil, which collects all data.
1000
+ # NOTE: Setting to [] will still collect all data to save
1001
+ default :blocked_automatic_attributes, nil
1002
+ default :blocked_default_attributes, nil
1003
+ default :blocked_normal_attributes, nil
1004
+ default :blocked_override_attributes, nil
1005
+
1006
+ # deprecated config options that will be removed in Chef Infra Client 17
975
1007
  default :automatic_attribute_blacklist, nil
976
1008
  default :default_attribute_blacklist, nil
977
1009
  default :normal_attribute_blacklist, nil
978
1010
  default :override_attribute_blacklist, nil
1011
+ default :automatic_attribute_whitelist, nil
1012
+ default :default_attribute_whitelist, nil
1013
+ default :normal_attribute_whitelist, nil
1014
+ default :override_attribute_whitelist, nil
979
1015
 
980
1016
  # Pull down all the rubygems versions from rubygems and cache them the first time we do a gem_package or
981
1017
  # chef_gem install. This is memory-expensive and will grow without bounds, but will reduce network
@@ -19,5 +19,15 @@ module ChefConfig
19
19
  # The legacy conf folder: C:/opscode/chef. Specifically the "opscode" part
20
20
  # DIR_SUFFIX is appended to it in code where relevant
21
21
  LEGACY_CONF_DIR = "opscode".freeze
22
+
23
+ # Enable forcing Chef EULA
24
+ ENFORCE_LICENSE = true
25
+
26
+ # The servers's alias (chef-server)
27
+ SERVER = "chef-server".freeze
28
+
29
+ # The server's configuration utility
30
+ SERVER_CTL = "chef-server-ctl".freeze
31
+
22
32
  end
23
33
  end
@@ -0,0 +1,55 @@
1
+ #
2
+ # Author:: Jon Morrow (jmorrow@chef.io)
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require_relative "../path_helper"
19
+
20
+ module ChefConfig
21
+ module Mixin
22
+ module ChefCloud
23
+ CHEF_CLOUD_CLIENT_CONFIG = "/Library/Managed Preferences/io.chef.chef_client.plist"
24
+
25
+ def cloud_config?
26
+ File.file?(CHEF_CLOUD_CLIENT_CONFIG)
27
+ end
28
+ module_function :cloud_config?
29
+
30
+ def parse_cloud_config(path)
31
+ return nil unless cloud_config?
32
+
33
+ begin
34
+ plist_cmd = Mixlib::ShellOut.new("plutil -convert json '" + CHEF_CLOUD_CLIENT_CONFIG + "' -o -")
35
+ plist_cmd.run_command
36
+ plist_cmd.error!
37
+ JSON.parse(plist_cmd.stdout)
38
+ rescue => e
39
+ # TOML's error messages are mostly rubbish, so we'll just give a generic one
40
+ message = "Unable to parse chef client cloud config.\n"
41
+ message << e.message
42
+ raise ChefConfig::ConfigurationError, message
43
+ end
44
+ end
45
+
46
+ # Load chef client cloud config configuration.
47
+ #
48
+ # @api internal
49
+ # @return [void]
50
+ def load_cloud_config
51
+ Config.merge!(Hash[parse_cloud_config.map { |k, v| [k.to_sym, v] }])
52
+ end
53
+ end
54
+ end
55
+ end
@@ -26,14 +26,14 @@ module ChefConfig
26
26
  # Maximum characters in a standard Windows path (260 including drive letter and NUL)
27
27
  WIN_MAX_PATH = 259
28
28
 
29
- def self.dirname(path)
30
- if ChefUtils.windows?
29
+ def self.dirname(path, windows: ChefUtils.windows?)
30
+ if windows
31
31
  # Find the first slash, not counting trailing slashes
32
32
  end_slash = path.size
33
33
  loop do
34
- slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]/, end_slash - 1)
34
+ slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator(windows: windows))}]/, end_slash - 1)
35
35
  if !slash
36
- return end_slash == path.size ? "." : path_separator
36
+ return end_slash == path.size ? "." : path_separator(windows: windows)
37
37
  elsif slash == end_slash - 1
38
38
  end_slash = slash
39
39
  else
@@ -47,32 +47,28 @@ module ChefConfig
47
47
 
48
48
  BACKSLASH = '\\'.freeze
49
49
 
50
- def self.path_separator
51
- if ChefUtils.windows?
52
- File::ALT_SEPARATOR || BACKSLASH
50
+ def self.path_separator(windows: ChefUtils.windows?)
51
+ if windows
52
+ BACKSLASH
53
53
  else
54
54
  File::SEPARATOR
55
55
  end
56
56
  end
57
57
 
58
- def self.join(*args)
59
- path_separator_regex = Regexp.escape(File::SEPARATOR)
60
- unless path_separator == File::SEPARATOR
61
- path_separator_regex << Regexp.escape(path_separator)
62
- end
63
-
64
- trailing_slashes = /[#{path_separator_regex}]+$/
65
- leading_slashes = /^[#{path_separator_regex}]+/
58
+ def self.join(*args, windows: ChefUtils.windows?)
59
+ path_separator_regex = Regexp.escape(windows ? "#{File::SEPARATOR}#{BACKSLASH}" : File::SEPARATOR)
60
+ trailing_slashes_regex = /[#{path_separator_regex}]+$/.freeze
61
+ leading_slashes_regex = /^[#{path_separator_regex}]+/.freeze
66
62
 
67
63
  args.flatten.inject do |joined_path, component|
68
- joined_path = joined_path.sub(trailing_slashes, "")
69
- component = component.sub(leading_slashes, "")
70
- joined_path + "#{path_separator}#{component}"
64
+ joined_path = joined_path.sub(trailing_slashes_regex, "")
65
+ component = component.sub(leading_slashes_regex, "")
66
+ joined_path + "#{path_separator(windows: windows)}#{component}"
71
67
  end
72
68
  end
73
69
 
74
- def self.validate_path(path)
75
- if ChefUtils.windows?
70
+ def self.validate_path(path, windows: ChefUtils.windows?)
71
+ if windows
76
72
  unless printable?(path)
77
73
  msg = "Path '#{path}' contains non-printable characters. Check that backslashes are escaped with another backslash (e.g. C:\\\\Windows) in double-quoted strings."
78
74
  ChefConfig.logger.error(msg)
@@ -111,14 +107,14 @@ module ChefConfig
111
107
  end
112
108
 
113
109
  # Produces a comparable path.
114
- def self.canonical_path(path, add_prefix = true)
110
+ def self.canonical_path(path, add_prefix = true, windows: ChefUtils.windows?)
115
111
  # First remove extra separators and resolve any relative paths
116
112
  abs_path = File.absolute_path(path)
117
113
 
118
- if ChefUtils.windows?
114
+ if windows
119
115
  # Add the \\?\ API prefix on Windows unless add_prefix is false
120
116
  # Downcase on Windows where paths are still case-insensitive
121
- abs_path.gsub!(::File::SEPARATOR, path_separator)
117
+ abs_path.gsub!(::File::SEPARATOR, path_separator(windows: windows))
122
118
  if add_prefix && abs_path !~ /^\\\\?\\/
123
119
  abs_path.insert(0, "\\\\?\\")
124
120
  end
@@ -129,36 +125,67 @@ module ChefConfig
129
125
  abs_path
130
126
  end
131
127
 
132
- # This is the INVERSE of Pathname#cleanpath, it converts forward
133
- # slashes to backslashes for Windows. Since the Ruby API and the
134
- # Windows APIs all consume forward slashes, this helper function
135
- # should only be used for *DISPLAY* logic to send strings back
136
- # to the user with backslashes. Internally, filename paths should
137
- # generally be stored with forward slashes for consistency. It is
138
- # not necessary or desired to blindly convert pathnames to have
139
- # backslashes on Windows.
128
+ # The built in ruby Pathname#cleanpath method does not clean up forward slashes and
129
+ # backslashes. This is a wrapper around that which does. In general this is NOT
130
+ # recommended for internal use within ruby/chef since ruby does not care about forward slashes
131
+ # vs. backslashes, even on Windows. Where this generally matters is when being rendered
132
+ # to the user, or being rendered into things like the windows PATH or to commands that
133
+ # are being executed. In some cases it may be easier on windows to render paths to
134
+ # unix-style for being eventually eval'd by ruby in the future (templates being rendered
135
+ # with code to be consumed by ruby) where forcing unix-style forward slashes avoids the
136
+ # issue of needing to escape the backslashes in rendered strings. This has a boolean
137
+ # operator to force windows-style or non-windows style operation, where the default is
138
+ # determined by the underlying node['platform'] value.
139
+ #
140
+ # In general if you don't know if you need this routine, do not use it, best practice
141
+ # within chef/ruby itself is not to care. Only use it to force windows or unix style
142
+ # when it really matters.
143
+ #
144
+ # @param path [String] the path to clean
145
+ # @param windows [Boolean] optional flag to force to windows or unix-style
146
+ # @return [String] cleaned path
140
147
  #
141
- # Generally, if the user isn't going to be seeing it, you should be
142
- # using Pathname#cleanpath instead of this function.
143
- def self.cleanpath(path)
148
+ def self.cleanpath(path, windows: ChefUtils.windows?)
144
149
  path = Pathname.new(path).cleanpath.to_s
145
- # ensure all forward slashes are backslashes
146
- if ChefUtils.windows?
147
- path = path.gsub(File::SEPARATOR, path_separator)
150
+ if windows
151
+ # ensure all forward slashes are backslashes
152
+ path.gsub(File::SEPARATOR, path_separator(windows: windows))
153
+ else
154
+ # ensure all backslashes are forward slashes
155
+ path.gsub(BACKSLASH, File::SEPARATOR)
148
156
  end
149
- path
150
157
  end
151
158
 
152
- def self.paths_eql?(path1, path2)
153
- canonical_path(path1) == canonical_path(path2)
159
+ # This is not just escaping for something like use in Regexps, or in globs. For the former
160
+ # just use Regexp.escape. For the latter, use escape_glob_dir below.
161
+ #
162
+ # This is escaping where the path to be rendered is being put into a ruby file which will
163
+ # later be read back by ruby (or something similar) so we need quadruple backslashes.
164
+ #
165
+ # In order to print:
166
+ #
167
+ # file_cache_path "C:\\chef"
168
+ #
169
+ # We need to convert "C:\chef" to "C:\\\\chef" to interpolate into a string which is rendered
170
+ # into the output file with that line in it.
171
+ #
172
+ # @param path [String] the path to escape
173
+ # @return [String] the escaped path
174
+ #
175
+ def self.escapepath(path)
176
+ path.gsub(BACKSLASH, BACKSLASH * 4)
177
+ end
178
+
179
+ def self.paths_eql?(path1, path2, windows: ChefUtils.windows?)
180
+ canonical_path(path1, windows: windows) == canonical_path(path2, windows: windows)
154
181
  end
155
182
 
156
183
  # @deprecated this method is deprecated. Please use escape_glob_dirs
157
184
  # Paths which may contain glob-reserved characters need
158
185
  # to be escaped before globbing can be done.
159
186
  # http://stackoverflow.com/questions/14127343
160
- def self.escape_glob(*parts)
161
- path = cleanpath(join(*parts))
187
+ def self.escape_glob(*parts, windows: ChefUtils.windows?)
188
+ path = cleanpath(join(*parts, windows: windows), windows: windows)
162
189
  path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\" + x }
163
190
  end
164
191
 
@@ -169,8 +196,8 @@ module ChefConfig
169
196
  path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\" + x }
170
197
  end
171
198
 
172
- def self.relative_path_from(from, to)
173
- Pathname.new(cleanpath(to)).relative_path_from(Pathname.new(cleanpath(from)))
199
+ def self.relative_path_from(from, to, windows: ChefUtils.windows?)
200
+ Pathname.new(cleanpath(to, windows: windows)).relative_path_from(Pathname.new(cleanpath(from, windows: windows)))
174
201
  end
175
202
 
176
203
  # Set the project-specific home directory environment variable.
@@ -216,11 +243,11 @@ module ChefConfig
216
243
  #
217
244
  # The return is a list of all the returned values from each block invocation or a list of paths
218
245
  # if no block is provided.
219
- def self.all_homes(*args)
246
+ def self.all_homes(*args, windows: ChefUtils.windows?)
220
247
  paths = []
221
248
  paths << ENV[@@per_tool_home_environment] if defined?(@@per_tool_home_environment) && @@per_tool_home_environment && ENV[@@per_tool_home_environment]
222
249
  paths << ENV["CHEF_HOME"] if ENV["CHEF_HOME"]
223
- if ChefUtils.windows?
250
+ if windows
224
251
  # By default, Ruby uses the the following environment variables to determine Dir.home:
225
252
  # HOME
226
253
  # HOMEDRIVE HOMEPATH
@@ -249,7 +276,7 @@ module ChefConfig
249
276
  # Note: Maybe this is a bad idea on some unixy systems where \ might be a valid character depending on
250
277
  # the particular brand of kool-aid you consume. This code assumes that \ and / are both
251
278
  # path separators on any system being used.
252
- paths = paths.map { |home_path| home_path.gsub(path_separator, ::File::SEPARATOR) if home_path }
279
+ paths = paths.map { |home_path| home_path.gsub(path_separator(windows: windows), ::File::SEPARATOR) if home_path }
253
280
 
254
281
  # Filter out duplicate paths and paths that don't exist.
255
282
  valid_paths = paths.select { |home_path| home_path && Dir.exist?(home_path.force_encoding("utf-8")) }
@@ -14,6 +14,6 @@
14
14
  # limitations under the License.
15
15
 
16
16
  module ChefConfig
17
- CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__)
18
- VERSION = "16.2.44".freeze
17
+ CHEFCONFIG_ROOT = File.expand_path("..", __dir__)
18
+ VERSION = "16.4.35".freeze
19
19
  end
@@ -140,13 +140,11 @@ module ChefConfig
140
140
  end
141
141
 
142
142
  def working_directory
143
- a = if ChefUtils.windows?
144
- env["CD"]
145
- else
146
- env["PWD"]
147
- end || Dir.pwd
148
-
149
- a
143
+ if ChefUtils.windows?
144
+ env["CD"]
145
+ else
146
+ env["PWD"]
147
+ end || Dir.pwd
150
148
  end
151
149
 
152
150
  def apply_credentials(creds, profile)
@@ -222,13 +222,70 @@ RSpec.describe ChefConfig::Config do
222
222
  ChefConfig::Config.add_formatter(:doc, "/var/log/formatter.log")
223
223
  expect(ChefConfig::Config.formatters).to eq([[:doc, "/var/log/formatter.log"]])
224
224
  end
225
+ end
226
+
227
+ describe "#var_chef_path" do
228
+ let (:dirname) { ChefConfig::Dist::DIR_SUFFIX }
229
+
230
+ context "on unix", :unix_only do
231
+ it "var_chef_dir is /var/chef" do
232
+ expect(ChefConfig::Config.var_chef_dir).to eql("/var/#{dirname}")
233
+ end
234
+
235
+ it "var_root_dir is /var" do
236
+ expect(ChefConfig::Config.var_root_dir).to eql("/var")
237
+ end
238
+
239
+ it "etc_chef_dir is /etc/chef" do
240
+ expect(ChefConfig::Config.etc_chef_dir).to eql("/etc/#{dirname}")
241
+ end
242
+ end
243
+
244
+ context "on windows", :windows_only do
245
+ it "var_chef_dir is C:\\chef" do
246
+ expect(ChefConfig::Config.var_chef_dir).to eql("C:\\#{dirname}")
247
+ end
248
+
249
+ it "var_root_dir is C:\\" do
250
+ expect(ChefConfig::Config.var_root_dir).to eql("C:\\")
251
+ end
252
+
253
+ it "etc_chef_dir is C:\\chef" do
254
+ expect(ChefConfig::Config.etc_chef_dir).to eql("C:\\#{dirname}")
255
+ end
256
+ end
225
257
 
258
+ context "when forced to unix" do
259
+ it "var_chef_dir is /var/chef" do
260
+ expect(ChefConfig::Config.var_chef_dir(windows: false)).to eql("/var/#{dirname}")
261
+ end
262
+
263
+ it "var_root_dir is /var" do
264
+ expect(ChefConfig::Config.var_root_dir(windows: false)).to eql("/var")
265
+ end
266
+
267
+ it "etc_chef_dir is /etc/chef" do
268
+ expect(ChefConfig::Config.etc_chef_dir(windows: false)).to eql("/etc/#{dirname}")
269
+ end
270
+ end
271
+
272
+ context "when forced to windows" do
273
+ it "var_chef_dir is C:\\chef" do
274
+ expect(ChefConfig::Config.var_chef_dir(windows: true)).to eql("C:\\#{dirname}")
275
+ end
276
+
277
+ it "var_root_dir is C:\\" do
278
+ expect(ChefConfig::Config.var_root_dir(windows: true)).to eql("C:\\")
279
+ end
280
+
281
+ it "etc_chef_dir is C:\\chef" do
282
+ expect(ChefConfig::Config.etc_chef_dir(windows: true)).to eql("C:\\#{dirname}")
283
+ end
284
+ end
226
285
  end
227
286
 
228
287
  [ false, true ].each do |is_windows|
229
-
230
288
  context "On #{is_windows ? "Windows" : "Unix"}" do
231
-
232
289
  before :each do
233
290
  allow(ChefUtils).to receive(:windows?).and_return(is_windows)
234
291
  end
@@ -430,8 +487,8 @@ RSpec.describe ChefConfig::Config do
430
487
 
431
488
  describe "ChefConfig::Config[:cache_path]" do
432
489
  let(:target_mode_host) { "fluffy.kittens.org" }
433
- let(:target_mode_primary_cache_path) { "#{primary_cache_path}/#{target_mode_host}" }
434
- let(:target_mode_secondary_cache_path) { "#{secondary_cache_path}/#{target_mode_host}" }
490
+ let(:target_mode_primary_cache_path) { ChefUtils.windows? ? "#{primary_cache_path}\\#{target_mode_host}" : "#{primary_cache_path}/#{target_mode_host}" }
491
+ let(:target_mode_secondary_cache_path) { ChefUtils.windows? ? "#{secondary_cache_path}\\#{target_mode_host}" : "#{secondary_cache_path}/#{target_mode_host}" }
435
492
 
436
493
  before do
437
494
  if is_windows
@@ -23,9 +23,8 @@ RSpec.describe ChefConfig::PathHelper do
23
23
 
24
24
  let(:path_helper) { described_class }
25
25
 
26
- shared_examples_for "common_functionality" do
27
- describe "join" do
28
-
26
+ context "common functionality" do
27
+ context "join" do
29
28
  it "joins starting with '' resolve to absolute paths" do
30
29
  expect(path_helper.join("", "a", "b")).to eq("#{path_helper.path_separator}a#{path_helper.path_separator}b")
31
30
  end
@@ -33,10 +32,9 @@ RSpec.describe ChefConfig::PathHelper do
33
32
  it "joins ending with '' add a / to the end" do
34
33
  expect(path_helper.join("a", "b", "")).to eq("a#{path_helper.path_separator}b#{path_helper.path_separator}")
35
34
  end
36
-
37
35
  end
38
36
 
39
- describe "dirname" do
37
+ context "dirname" do
40
38
  it "dirname('abc') is '.'" do
41
39
  expect(path_helper.dirname("abc")).to eq(".")
42
40
  end
@@ -55,42 +53,109 @@ RSpec.describe ChefConfig::PathHelper do
55
53
  end
56
54
  end
57
55
 
58
- context "on windows" do
56
+ context "forcing windows/non-windows" do
57
+ context "forcing windows" do
58
+ it "path_separator is \\" do
59
+ expect(path_helper.path_separator(windows: true)).to eq('\\')
60
+ end
61
+
62
+ context "platform-specific #join behavior" do
63
+ it "joins components on Windows when some end with unix separators" do
64
+ expected = "C:\\foo\\bar\\baz"
65
+ expect(path_helper.join('C:\\foo/', "bar", "baz", windows: true)).to eq(expected)
66
+ end
67
+
68
+ it "joins components when some end with separators" do
69
+ expected = "C:\\foo\\bar\\baz"
70
+ expect(path_helper.join('C:\\foo\\', "bar", "baz", windows: true)).to eq(expected)
71
+ end
72
+
73
+ it "joins components when some end and start with separators" do
74
+ expected = "C:\\foo\\bar\\baz"
75
+ expect(path_helper.join('C:\\foo\\', "bar/", "/baz", windows: true)).to eq(expected)
76
+ end
77
+
78
+ it "joins components that don't end in separators" do
79
+ expected = "C:\\foo\\bar\\baz"
80
+ expect(path_helper.join('C:\\foo', "bar", "baz", windows: true)).to eq(expected)
81
+ end
82
+ end
83
+
84
+ it "cleanpath changes slashes into backslashes and leaves backslashes alone" do
85
+ expect(path_helper.cleanpath('/a/b\\c/d/', windows: true)).to eq('\\a\\b\\c\\d')
86
+ end
87
+
88
+ it "cleanpath does not remove leading double backslash" do
89
+ expect(path_helper.cleanpath('\\\\a/b\\c/d/', windows: true)).to eq('\\\\a\\b\\c\\d')
90
+ end
91
+ end
92
+
93
+ context "forcing unix" do
94
+ it "path_separator is /" do
95
+ expect(path_helper.path_separator(windows: false)).to eq("/")
96
+ end
97
+
98
+ it "cleanpath removes extra slashes alone" do
99
+ expect(path_helper.cleanpath("/a///b/c/d/", windows: false)).to eq("/a/b/c/d")
100
+ end
101
+
102
+ context "platform-specific #join behavior" do
103
+ it "joins components when some end with separators" do
104
+ expected = "/foo/bar/baz"
105
+ expect(path_helper.join("/foo/", "bar", "baz", windows: false)).to eq(expected)
106
+ end
107
+
108
+ it "joins components when some end and start with separators" do
109
+ expected = "/foo/bar/baz"
110
+ expect(path_helper.join("/foo/", "bar/", "/baz", windows: false)).to eq(expected)
111
+ end
112
+
113
+ it "joins components that don't end in separators" do
114
+ expected = "/foo/bar/baz"
115
+ expect(path_helper.join("/foo", "bar", "baz", windows: false)).to eq(expected)
116
+ end
117
+ end
118
+
119
+ it "cleanpath changes backslashes into slashes and leaves slashes alone" do
120
+ expect(path_helper.cleanpath('/a/b\\c/d/', windows: false)).to eq("/a/b/c/d")
121
+ end
122
+
123
+ it "cleanpath does not remove leading double backslash" do
124
+ expect(path_helper.cleanpath('\\\\a/b\\c/d/', windows: false)).to eq("//a/b/c/d")
125
+ end
126
+ end
127
+ end
128
+
129
+ context "on windows", :windows_only do
59
130
 
60
131
  before(:each) do
61
132
  allow(ChefUtils).to receive(:windows?).and_return(true)
62
133
  end
63
134
 
64
- include_examples("common_functionality")
65
-
66
135
  it "path_separator is \\" do
67
136
  expect(path_helper.path_separator).to eq('\\')
68
137
  end
69
138
 
70
- describe "platform-specific #join behavior" do
71
-
139
+ context "platform-specific #join behavior" do
72
140
  it "joins components on Windows when some end with unix separators" do
73
- expect(path_helper.join('C:\\foo/', "bar", "baz")).to eq('C:\\foo\\bar\\baz')
141
+ expected = "C:\\foo\\bar\\baz"
142
+ expect(path_helper.join('C:\\foo/', "bar", "baz")).to eq(expected)
74
143
  end
75
144
 
76
145
  it "joins components when some end with separators" do
77
- expected = path_helper.cleanpath("/foo/bar/baz")
78
- expected = "C:#{expected}"
146
+ expected = "C:\\foo\\bar\\baz"
79
147
  expect(path_helper.join('C:\\foo\\', "bar", "baz")).to eq(expected)
80
148
  end
81
149
 
82
150
  it "joins components when some end and start with separators" do
83
- expected = path_helper.cleanpath("/foo/bar/baz")
84
- expected = "C:#{expected}"
151
+ expected = "C:\\foo\\bar\\baz"
85
152
  expect(path_helper.join('C:\\foo\\', "bar/", "/baz")).to eq(expected)
86
153
  end
87
154
 
88
155
  it "joins components that don't end in separators" do
89
- expected = path_helper.cleanpath("/foo/bar/baz")
90
- expected = "C:#{expected}"
156
+ expected = "C:\\foo\\bar\\baz"
91
157
  expect(path_helper.join('C:\\foo', "bar", "baz")).to eq(expected)
92
158
  end
93
-
94
159
  end
95
160
 
96
161
  it "cleanpath changes slashes into backslashes and leaves backslashes alone" do
@@ -100,17 +165,13 @@ RSpec.describe ChefConfig::PathHelper do
100
165
  it "cleanpath does not remove leading double backslash" do
101
166
  expect(path_helper.cleanpath('\\\\a/b\\c/d/')).to eq('\\\\a\\b\\c\\d')
102
167
  end
103
-
104
168
  end
105
169
 
106
- context "on unix" do
107
-
170
+ context "on unix", :unix_only do
108
171
  before(:each) do
109
172
  allow(ChefUtils).to receive(:windows?).and_return(false)
110
173
  end
111
174
 
112
- include_examples("common_functionality")
113
-
114
175
  it "path_separator is /" do
115
176
  expect(path_helper.path_separator).to eq("/")
116
177
  end
@@ -119,8 +180,7 @@ RSpec.describe ChefConfig::PathHelper do
119
180
  expect(path_helper.cleanpath("/a///b/c/d/")).to eq("/a/b/c/d")
120
181
  end
121
182
 
122
- describe "platform-specific #join behavior" do
123
-
183
+ context "platform-specific #join behavior" do
124
184
  it "joins components when some end with separators" do
125
185
  expected = path_helper.cleanpath("/foo/bar/baz")
126
186
  expect(path_helper.join("/foo/", "bar", "baz")).to eq(expected)
@@ -135,12 +195,19 @@ RSpec.describe ChefConfig::PathHelper do
135
195
  expected = path_helper.cleanpath("/foo/bar/baz")
136
196
  expect(path_helper.join("/foo", "bar", "baz")).to eq(expected)
137
197
  end
198
+ end
138
199
 
200
+ it "cleanpath changes backslashes into slashes and leaves slashes alone" do
201
+ expect(path_helper.cleanpath('/a/b\\c/d/', windows: false)).to eq("/a/b/c/d")
139
202
  end
140
203
 
204
+ # NOTE: this seems a bit weird to me, but this is just the way Pathname#cleanpath works
205
+ it "cleanpath does not remove leading double backslash" do
206
+ expect(path_helper.cleanpath('\\\\a/b\\c/d/')).to eq("//a/b/c/d")
207
+ end
141
208
  end
142
209
 
143
- describe "validate_path" do
210
+ context "validate_path" do
144
211
  context "on windows" do
145
212
  before(:each) do
146
213
  # pass by default
@@ -171,7 +238,7 @@ RSpec.describe ChefConfig::PathHelper do
171
238
  end
172
239
  end
173
240
 
174
- describe "windows_max_length_exceeded?" do
241
+ context "windows_max_length_exceeded?" do
175
242
  it "returns true if the path is too long (259 + NUL) for the API" do
176
243
  expect(path_helper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 6)).to be_truthy
177
244
  end
@@ -185,7 +252,7 @@ RSpec.describe ChefConfig::PathHelper do
185
252
  end
186
253
  end
187
254
 
188
- describe "printable?" do
255
+ context "printable?" do
189
256
  it "returns true if the string contains no non-printable characters" do
190
257
  expect(path_helper.printable?("C:\\Program Files (x86)\\Microsoft Office\\Files.lst")).to be_truthy
191
258
  end
@@ -208,7 +275,7 @@ RSpec.describe ChefConfig::PathHelper do
208
275
  end
209
276
  end
210
277
 
211
- describe "canonical_path" do
278
+ context "canonical_path" do
212
279
  context "on windows", :windows_only do
213
280
  it "returns an absolute path with backslashes instead of slashes" do
214
281
  expect(path_helper.canonical_path("\\\\?\\C:/windows/win.ini")).to eq("\\\\?\\c:\\windows\\win.ini")
@@ -230,25 +297,25 @@ RSpec.describe ChefConfig::PathHelper do
230
297
  end
231
298
  end
232
299
 
233
- describe "paths_eql?" do
300
+ context "paths_eql?" do
234
301
  it "returns true if the paths are the same" do
235
- allow(path_helper).to receive(:canonical_path).with("bandit").and_return("c:/bandit/bandit")
236
- allow(path_helper).to receive(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
302
+ allow(path_helper).to receive(:canonical_path).with("bandit", windows: ChefUtils.windows?).and_return("c:/bandit/bandit")
303
+ allow(path_helper).to receive(:canonical_path).with("../bandit/bandit", windows: ChefUtils.windows?).and_return("c:/bandit/bandit")
237
304
  expect(path_helper.paths_eql?("bandit", "../bandit/bandit")).to be_truthy
238
305
  end
239
306
 
240
307
  it "returns false if the paths are different" do
241
- allow(path_helper).to receive(:canonical_path).with("bandit").and_return("c:/Bo/Bandit")
242
- allow(path_helper).to receive(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
308
+ allow(path_helper).to receive(:canonical_path).with("bandit", windows: ChefUtils.windows?).and_return("c:/Bo/Bandit")
309
+ allow(path_helper).to receive(:canonical_path).with("../bandit/bandit", windows: ChefUtils.windows?).and_return("c:/bandit/bandit")
243
310
  expect(path_helper.paths_eql?("bandit", "../bandit/bandit")).to be_falsey
244
311
  end
245
312
  end
246
313
 
247
- describe "escape_glob" do
314
+ context "escape_glob" do
248
315
  it "escapes characters reserved by glob" do
249
316
  path = "C:\\this\\*path\\[needs]\\escaping?"
250
317
  escaped_path = "C:\\\\this\\\\\\*path\\\\\\[needs\\]\\\\escaping\\?"
251
- expect(path_helper.escape_glob(path)).to eq(escaped_path)
318
+ expect(path_helper.escape_glob(path, windows: true)).to eq(escaped_path)
252
319
  end
253
320
 
254
321
  context "when given more than one argument" do
@@ -259,14 +326,12 @@ RSpec.describe ChefConfig::PathHelper do
259
326
  else
260
327
  "this/\\*path/\\[needs\\]/escaping\\?"
261
328
  end
262
- expect(path_helper).to receive(:join).with(*args).and_call_original
263
- expect(path_helper).to receive(:cleanpath).and_call_original
264
329
  expect(path_helper.escape_glob(*args)).to eq(escaped_path)
265
330
  end
266
331
  end
267
332
  end
268
333
 
269
- describe "escape_glob_dir" do
334
+ context "escape_glob_dir" do
270
335
  it "escapes characters reserved by glob without using backslashes for path separators" do
271
336
  path = "C:/this/*path/[needs]/escaping?"
272
337
  escaped_path = "C:/this/\\*path/\\[needs\\]/escaping\\?"
@@ -283,7 +348,7 @@ RSpec.describe ChefConfig::PathHelper do
283
348
  end
284
349
  end
285
350
 
286
- describe "all_homes" do
351
+ context "all_homes" do
287
352
  before do
288
353
  stub_const("ENV", env)
289
354
  allow(ChefUtils).to receive(:windows?).and_return(is_windows)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.2.44
4
+ version: 16.4.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-17 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-utils
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 16.2.44
19
+ version: 16.4.35
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 16.2.44
26
+ version: 16.4.35
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mixlib-shellout
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +178,7 @@ files:
178
178
  - lib/chef-config/exceptions.rb
179
179
  - lib/chef-config/fips.rb
180
180
  - lib/chef-config/logger.rb
181
+ - lib/chef-config/mixin/chef_cloud.rb
181
182
  - lib/chef-config/mixin/credentials.rb
182
183
  - lib/chef-config/mixin/dot_d.rb
183
184
  - lib/chef-config/mixin/fuzzy_hostname_matcher.rb