chef-config 14.2.0 → 14.3.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/chef-config.gemspec +1 -1
- data/lib/chef-config/config.rb +20 -7
- data/lib/chef-config/mixin/credentials.rb +1 -1
- data/lib/chef-config/mixin/dot_d.rb +15 -10
- data/lib/chef-config/package_task.rb +43 -43
- data/lib/chef-config/path_helper.rb +17 -1
- data/lib/chef-config/version.rb +3 -3
- data/lib/chef-config/workstation_config_loader.rb +72 -17
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/config_spec.rb +18 -0
- data/spec/unit/workstation_config_loader_spec.rb +103 -37
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8143b86ea4c5fd0ec8d4b8623aee402b2c0ade39738133a99c14f7338ff3327d
|
4
|
+
data.tar.gz: 607162e7ef57736d7ecd7154a27c4ee132bd8c61452c758084b4dcb16768ce26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81d3a5a11e0281b00c0ae18da2298e3c0227df063597734431423febe7728c0f805a815e4f6d2fd74f465724ee2a1da45bb3fbbc5022a29758e322810e1d26c1
|
7
|
+
data.tar.gz: b88d7a8a2d4fa5d5abf31839763cee4437e51bff8369ac17061f695f55b9fd3145399f98027801c9e8f0a2752e546184d764581c662f3146bdbb65caf8459624
|
data/Rakefile
CHANGED
data/chef-config.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.require_paths = ["lib"]
|
17
17
|
|
18
18
|
spec.add_dependency "mixlib-shellout", "~> 2.0"
|
19
|
-
spec.add_dependency "mixlib-config", "
|
19
|
+
spec.add_dependency "mixlib-config", ">= 2.2.12", "< 3.0"
|
20
20
|
spec.add_dependency "fuzzyurl"
|
21
21
|
spec.add_dependency "addressable"
|
22
22
|
spec.add_dependency "tomlrb", "~> 1.2"
|
data/lib/chef-config/config.rb
CHANGED
@@ -286,7 +286,7 @@ module ChefConfig
|
|
286
286
|
# the cache path.
|
287
287
|
unless path_accessible?(primary_cache_path) || path_accessible?(primary_cache_root)
|
288
288
|
secondary_cache_path = PathHelper.join(user_home, ".chef")
|
289
|
-
ChefConfig.logger.
|
289
|
+
ChefConfig.logger.trace("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}")
|
290
290
|
secondary_cache_path
|
291
291
|
else
|
292
292
|
primary_cache_path
|
@@ -656,7 +656,15 @@ module ChefConfig
|
|
656
656
|
#
|
657
657
|
# If chef-zero is enabled, this defaults to nil (no authentication).
|
658
658
|
default(:validation_key) { chef_zero.enabled ? nil : platform_specific_path("/etc/chef/validation.pem") }
|
659
|
-
default :validation_client_name
|
659
|
+
default :validation_client_name do
|
660
|
+
# If the URL is set and looks like a normal Chef Server URL, extract the
|
661
|
+
# org name and use that as part of the default.
|
662
|
+
if chef_server_url.to_s =~ %r{/organizations/(.*)$}
|
663
|
+
"#{$1}-validator"
|
664
|
+
else
|
665
|
+
"chef-validator"
|
666
|
+
end
|
667
|
+
end
|
660
668
|
|
661
669
|
default :validation_key_contents, nil
|
662
670
|
# When creating a new client via the validation_client account, Chef 11
|
@@ -698,7 +706,7 @@ module ChefConfig
|
|
698
706
|
|
699
707
|
# Deprecated:
|
700
708
|
# Move this to the default value of syntax_cache_path when this is removed.
|
701
|
-
default(:cache_options) { { :
|
709
|
+
default(:cache_options) { { path: PathHelper.join(config_dir, "syntaxcache") } }
|
702
710
|
|
703
711
|
# Whether errors should be raised for deprecation warnings. When set to
|
704
712
|
# `false` (the default setting), a warning is emitted but code using
|
@@ -715,6 +723,11 @@ module ChefConfig
|
|
715
723
|
ENV.key?("CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS")
|
716
724
|
end
|
717
725
|
|
726
|
+
# Which deprecations warnings to silence. Can be set to `true` to silence
|
727
|
+
# all warnings, or an array of strings like either `"deprecation_type"` or
|
728
|
+
# `"filename.rb:lineno"`.
|
729
|
+
default :silence_deprecation_warnings, []
|
730
|
+
|
718
731
|
# Whether the resource count should be updated for log resource
|
719
732
|
# on running chef-client
|
720
733
|
default :count_log_resource_updates, true
|
@@ -957,10 +970,10 @@ module ChefConfig
|
|
957
970
|
# TODO add some post-file-parsing logic that automatically calls this so
|
958
971
|
# users don't have to
|
959
972
|
def self.export_proxies
|
960
|
-
export_proxy("http", http_proxy, http_proxy_user, http_proxy_pass) if http_proxy
|
961
|
-
export_proxy("https", https_proxy, https_proxy_user, https_proxy_pass) if https_proxy
|
962
|
-
export_proxy("ftp", ftp_proxy, ftp_proxy_user, ftp_proxy_pass) if ftp_proxy
|
963
|
-
export_no_proxy(no_proxy) if no_proxy
|
973
|
+
export_proxy("http", http_proxy, http_proxy_user, http_proxy_pass) if key?(:http_proxy) && http_proxy
|
974
|
+
export_proxy("https", https_proxy, https_proxy_user, https_proxy_pass) if key?(:https_proxy) && https_proxy
|
975
|
+
export_proxy("ftp", ftp_proxy, ftp_proxy_user, ftp_proxy_pass) if key?(:ftp_proxy) && ftp_proxy
|
976
|
+
export_no_proxy(no_proxy) if key?(:no_proxy) && no_proxy
|
964
977
|
end
|
965
978
|
|
966
979
|
# Character classes for Addressable
|
@@ -19,17 +19,22 @@ require "chef-config/path_helper"
|
|
19
19
|
module ChefConfig
|
20
20
|
module Mixin
|
21
21
|
module DotD
|
22
|
+
# Find available configuration files in a `.d/` style include directory.
|
23
|
+
#
|
24
|
+
# @api internal
|
25
|
+
# @param path [String] Base .d/ path to load from.
|
26
|
+
# @return [Array<String>]
|
27
|
+
def find_dot_d(path)
|
28
|
+
Dir["#{PathHelper.escape_glob_dir(path)}/*.rb"].select { |entry| File.file?(entry) }.sort
|
29
|
+
end
|
30
|
+
|
31
|
+
# Load configuration from a `.d/` style include directory.
|
32
|
+
#
|
33
|
+
# @api internal
|
34
|
+
# @param path [String] Base .d/ path to load from.
|
35
|
+
# @return [void]
|
22
36
|
def load_dot_d(path)
|
23
|
-
|
24
|
-
begin
|
25
|
-
entries = Array.new
|
26
|
-
entries << Dir.glob(File.join(
|
27
|
-
ChefConfig::PathHelper.escape_glob_dir(path), "*.rb"))
|
28
|
-
entries.flatten.select do |entry|
|
29
|
-
File.file?(entry)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
dot_d_files.sort.map do |conf|
|
37
|
+
find_dot_d(path).each do |conf|
|
33
38
|
apply_config(IO.read(conf), conf)
|
34
39
|
end
|
35
40
|
end
|
@@ -131,10 +131,10 @@ module ChefConfig
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
task :
|
134
|
+
task package: :package_components
|
135
135
|
|
136
136
|
desc "Build and install component dependencies"
|
137
|
-
task :
|
137
|
+
task install_components: :package_components do
|
138
138
|
component_full_paths.each do |component_path|
|
139
139
|
Dir.chdir(component_path) do
|
140
140
|
sh "rake install"
|
@@ -142,7 +142,7 @@ module ChefConfig
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
task :
|
145
|
+
task install: :install_components
|
146
146
|
|
147
147
|
desc "Clean up builds of component dependencies"
|
148
148
|
task :clobber_component_packages do
|
@@ -153,7 +153,7 @@ module ChefConfig
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
task :
|
156
|
+
task clobber_package: :clobber_component_packages
|
157
157
|
|
158
158
|
desc "Update the version number for component dependencies"
|
159
159
|
task :update_components_versions do
|
@@ -166,12 +166,12 @@ module ChefConfig
|
|
166
166
|
|
167
167
|
namespace :version do
|
168
168
|
desc "Regenerate lib/#{module_path}/version.rb from VERSION file"
|
169
|
-
task :
|
169
|
+
task update: :update_components_versions do
|
170
170
|
update_version_rb
|
171
171
|
update_gemfile_lock
|
172
172
|
end
|
173
173
|
|
174
|
-
task :
|
174
|
+
task bump: %w{version:bump_patch version:update}
|
175
175
|
|
176
176
|
task :show do
|
177
177
|
puts version
|
@@ -201,41 +201,41 @@ module ChefConfig
|
|
201
201
|
|
202
202
|
def update_version_rb # rubocop:disable Lint/NestedMethodDefinition
|
203
203
|
puts "Updating #{version_rb_path} to include version #{version} ..."
|
204
|
-
contents =
|
205
|
-
# Copyright:: Copyright 2010-2016, Chef Software, Inc.
|
206
|
-
# License:: Apache License, Version 2.0
|
207
|
-
#
|
208
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
209
|
-
# you may not use this file except in compliance with the License.
|
210
|
-
# You may obtain a copy of the License at
|
211
|
-
#
|
212
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
213
|
-
#
|
214
|
-
# Unless required by applicable law or agreed to in writing, software
|
215
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
216
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
217
|
-
# See the License for the specific language governing permissions and
|
218
|
-
# limitations under the License.
|
219
|
-
|
220
|
-
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
221
|
-
# NOTE: This file is generated by running `rake version` in the top level of
|
222
|
-
# this repo. Do not edit this manually. Edit the VERSION file and run the rake
|
223
|
-
# task instead.
|
224
|
-
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
225
|
-
#{"\nrequire \"chef/version_string\"\n" if use_versionstring}
|
226
|
-
#{class_or_module} #{module_name}
|
227
|
-
|
228
|
-
|
229
|
-
end
|
204
|
+
contents = <<~VERSION_RB
|
205
|
+
# Copyright:: Copyright 2010-2016, Chef Software, Inc.
|
206
|
+
# License:: Apache License, Version 2.0
|
207
|
+
#
|
208
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
209
|
+
# you may not use this file except in compliance with the License.
|
210
|
+
# You may obtain a copy of the License at
|
211
|
+
#
|
212
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
213
|
+
#
|
214
|
+
# Unless required by applicable law or agreed to in writing, software
|
215
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
216
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
217
|
+
# See the License for the specific language governing permissions and
|
218
|
+
# limitations under the License.
|
219
|
+
|
220
|
+
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
221
|
+
# NOTE: This file is generated by running `rake version` in the top level of
|
222
|
+
# this repo. Do not edit this manually. Edit the VERSION file and run the rake
|
223
|
+
# task instead.
|
224
|
+
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
225
|
+
#{"\nrequire \"chef/version_string\"\n" if use_versionstring}
|
226
|
+
#{class_or_module} #{module_name}
|
227
|
+
#{module_name.upcase}_ROOT = File.expand_path("../..", __FILE__)
|
228
|
+
VERSION = #{use_versionstring ? "Chef::VersionString.new(\"#{version}\")" : "\"#{version}\""}
|
229
|
+
end
|
230
230
|
|
231
|
-
#
|
232
|
-
# NOTE: the Chef::Version class is defined in version_class.rb
|
233
|
-
#
|
234
|
-
# NOTE: DO NOT Use the Chef::Version class on #{module_name}::VERSIONs. The
|
235
|
-
# Chef::Version class is for _cookbooks_ only, and cannot handle
|
236
|
-
# pre-release versions like "10.14.0.rc.2". Please use Rubygem's
|
237
|
-
# Gem::Version class instead.
|
238
|
-
#
|
231
|
+
#
|
232
|
+
# NOTE: the Chef::Version class is defined in version_class.rb
|
233
|
+
#
|
234
|
+
# NOTE: DO NOT Use the Chef::Version class on #{module_name}::VERSIONs. The
|
235
|
+
# Chef::Version class is for _cookbooks_ only, and cannot handle
|
236
|
+
# pre-release versions like "10.14.0.rc.2". Please use Rubygem's
|
237
|
+
# Gem::Version class instead.
|
238
|
+
#
|
239
239
|
VERSION_RB
|
240
240
|
IO.write(version_rb_path, contents)
|
241
241
|
end
|
@@ -252,7 +252,7 @@ end
|
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
255
|
-
task :
|
255
|
+
task version: "version:update"
|
256
256
|
|
257
257
|
gemspec_platform_to_install = ""
|
258
258
|
Dir[File.expand_path("*.gemspec", root_path)].reverse_each do |gemspec_path|
|
@@ -264,7 +264,7 @@ end
|
|
264
264
|
end
|
265
265
|
|
266
266
|
desc "Build and install a #{module_path} gem"
|
267
|
-
task :
|
267
|
+
task install: [:package] do
|
268
268
|
with_clean_env do
|
269
269
|
full_module_path = File.join(full_package_dir, module_path)
|
270
270
|
sh %{gem install #{full_module_path}-#{version}#{gemspec_platform_to_install}.gem --no-rdoc --no-ri}
|
@@ -276,7 +276,7 @@ end
|
|
276
276
|
end
|
277
277
|
|
278
278
|
desc "Build it, tag it and ship it"
|
279
|
-
task :
|
279
|
+
task ship: [:clobber_package, :gem] do
|
280
280
|
sh("git tag #{version}")
|
281
281
|
sh("git push #{git_remote} --tags")
|
282
282
|
Dir[File.expand_path("*.gem", full_package_dir)].reverse_each do |built_gem|
|
@@ -172,6 +172,18 @@ module ChefConfig
|
|
172
172
|
Pathname.new(cleanpath(to)).relative_path_from(Pathname.new(cleanpath(from)))
|
173
173
|
end
|
174
174
|
|
175
|
+
# Set the project-specific home directory environment variable.
|
176
|
+
#
|
177
|
+
# This can be used to allow per-tool home directory aliases like $KNIFE_HOME.
|
178
|
+
#
|
179
|
+
# @param [env_var] Key for an environment variable to use.
|
180
|
+
# @return [nil]
|
181
|
+
def self.per_tool_home_environment=(env_var)
|
182
|
+
@@per_tool_home_environment = env_var
|
183
|
+
# Reset this in case .home was already called.
|
184
|
+
@@home_dir = nil
|
185
|
+
end
|
186
|
+
|
175
187
|
# Retrieves the "home directory" of the current user while trying to ascertain the existence
|
176
188
|
# of said directory. The path returned uses / for all separators (the ruby standard format).
|
177
189
|
# If the home directory doesn't exist or an error is otherwise encountered, nil is returned.
|
@@ -185,7 +197,9 @@ module ChefConfig
|
|
185
197
|
# Home-path discovery is performed once. If a path is discovered, that value is memoized so
|
186
198
|
# that subsequent calls to home_dir don't bounce around.
|
187
199
|
#
|
188
|
-
#
|
200
|
+
# @see all_homes
|
201
|
+
# @param args [Array<String>] Path components to look for under the home directory.
|
202
|
+
# @return [String]
|
189
203
|
def self.home(*args)
|
190
204
|
@@home_dir ||= all_homes { |p| break p }
|
191
205
|
if @@home_dir
|
@@ -203,6 +217,8 @@ module ChefConfig
|
|
203
217
|
# if no block is provided.
|
204
218
|
def self.all_homes(*args)
|
205
219
|
paths = []
|
220
|
+
paths << ENV[@@per_tool_home_environment] if defined?(@@per_tool_home_environment) && @@per_tool_home_environment && ENV[@@per_tool_home_environment]
|
221
|
+
paths << ENV["CHEF_HOME"] if ENV["CHEF_HOME"]
|
206
222
|
if ChefConfig.windows?
|
207
223
|
# By default, Ruby uses the the following environment variables to determine Dir.home:
|
208
224
|
# HOME
|
data/lib/chef-config/version.rb
CHANGED
@@ -13,15 +13,15 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
|
16
|
+
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
17
17
|
# NOTE: This file is generated by running `rake version` in the top level of
|
18
18
|
# this repo. Do not edit this manually. Edit the VERSION file and run the rake
|
19
19
|
# task instead.
|
20
|
-
|
20
|
+
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
21
21
|
|
22
22
|
module ChefConfig
|
23
23
|
CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__)
|
24
|
-
VERSION = "14.
|
24
|
+
VERSION = "14.3.37".freeze
|
25
25
|
end
|
26
26
|
|
27
27
|
#
|
@@ -83,6 +83,8 @@ module ChefConfig
|
|
83
83
|
end
|
84
84
|
|
85
85
|
load_dot_d(Config[:config_d_dir]) if Config[:config_d_dir]
|
86
|
+
|
87
|
+
apply_defaults
|
86
88
|
end
|
87
89
|
|
88
90
|
# (Private API, public for test purposes)
|
@@ -147,31 +149,36 @@ module ChefConfig
|
|
147
149
|
end
|
148
150
|
|
149
151
|
def apply_credentials(creds, profile)
|
152
|
+
# Store the profile used in case other things want it.
|
150
153
|
Config.profile ||= profile
|
154
|
+
# Validate the credentials data.
|
151
155
|
if creds.key?("node_name") && creds.key?("client_name")
|
152
156
|
raise ChefConfig::ConfigurationError, "Do not specify both node_name and client_name. You should prefer client_name."
|
153
157
|
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
158
|
+
# Load credentials data into the Chef configuration.
|
159
|
+
creds.each do |key, value|
|
160
|
+
case key.to_s
|
161
|
+
when "client_name"
|
162
|
+
# Special case because it's weird to set your username via `node_name`.
|
163
|
+
Config.node_name = value
|
164
|
+
when "validation_key", "validator_key"
|
165
|
+
extract_key(value, :validation_key, :validation_key_contents)
|
166
|
+
when "client_key"
|
167
|
+
extract_key(value, :client_key, :client_key_contents)
|
168
|
+
when "knife"
|
169
|
+
Config.knife.merge!(Hash[value.map { |k, v| [k.to_sym, v] }])
|
170
|
+
else
|
171
|
+
Config[key.to_sym] = value
|
172
|
+
end
|
173
|
+
end
|
164
174
|
@credentials_found = true
|
165
175
|
end
|
166
176
|
|
167
|
-
def extract_key(
|
168
|
-
|
169
|
-
|
170
|
-
val = creds.fetch(name)
|
171
|
-
if val.start_with?("-----BEGIN RSA PRIVATE KEY-----")
|
172
|
-
Config.send(config_contents, val)
|
177
|
+
def extract_key(key_value, config_path, config_contents)
|
178
|
+
if key_value.start_with?("-----BEGIN RSA PRIVATE KEY-----")
|
179
|
+
Config.send(config_contents, key_value)
|
173
180
|
else
|
174
|
-
abs_path = Pathname.new(
|
181
|
+
abs_path = Pathname.new(key_value).expand_path(home_chef_dir)
|
175
182
|
Config.send(config_path, abs_path)
|
176
183
|
end
|
177
184
|
end
|
@@ -205,6 +212,54 @@ module ChefConfig
|
|
205
212
|
raise ChefConfig::ConfigurationError, message
|
206
213
|
end
|
207
214
|
|
215
|
+
# Apply default configuration values for workstation-style tools.
|
216
|
+
#
|
217
|
+
# Global defaults should go in {ChefConfig::Config} instead, this is only
|
218
|
+
# for things like `knife` and `chef`.
|
219
|
+
#
|
220
|
+
# @api private
|
221
|
+
# @since 14.3
|
222
|
+
# @return [void]
|
223
|
+
def apply_defaults
|
224
|
+
# If we don't have a better guess use the username.
|
225
|
+
Config[:node_name] ||= Etc.getlogin
|
226
|
+
# If we don't have a key (path or inline) check user.pem and $node_name.pem.
|
227
|
+
unless Config.key?(:client_key) || Config.key?(:client_key_contents)
|
228
|
+
Config[:client_key] = find_default_key(["#{Config[:node_name]}.pem", "user.pem"])
|
229
|
+
end
|
230
|
+
# Similarly look for a validation key file, though this should be less
|
231
|
+
# common these days.
|
232
|
+
unless Config.key?(:validation_key) || Config.key?(:validation_key_contents)
|
233
|
+
Config[:validation_key] = find_default_key(["#{Config[:validation_client_name]}.pem", "validator.pem", "validation.pem"])
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# Look for a default key file.
|
238
|
+
#
|
239
|
+
# This searches for any of a list of possible default keys, checking both
|
240
|
+
# the local `.chef/` folder and the home directory `~/.chef/`. Returns `nil`
|
241
|
+
# if no matching file is found.
|
242
|
+
#
|
243
|
+
# @api private
|
244
|
+
# @since 14.3
|
245
|
+
# @param key_names [Array<String>] A list of possible filenames to check for.
|
246
|
+
# The first one found will be returned.
|
247
|
+
# @return [String, nil]
|
248
|
+
def find_default_key(key_names)
|
249
|
+
key_names.each do |filename|
|
250
|
+
path = Pathname.new(filename)
|
251
|
+
# If we have a config location (like ./.chef/), look there first.
|
252
|
+
if config_location
|
253
|
+
local_path = path.expand_path(File.dirname(config_location))
|
254
|
+
return local_path.to_s if local_path.exist?
|
255
|
+
end
|
256
|
+
# Then check ~/.chef.
|
257
|
+
home_path = path.expand_path(home_chef_dir)
|
258
|
+
return home_path.to_s if home_path.exist?
|
259
|
+
end
|
260
|
+
nil
|
261
|
+
end
|
262
|
+
|
208
263
|
def highlight_config_error(file, line)
|
209
264
|
config_file_lines = []
|
210
265
|
IO.readlines(file).each_with_index { |l, i| config_file_lines << "#{(i + 1).to_s.rjust(3)}: #{l.chomp}" }
|
data/spec/spec_helper.rb
CHANGED
@@ -32,8 +32,8 @@ RSpec.configure do |config|
|
|
32
32
|
config.filter_run :focus
|
33
33
|
config.run_all_when_everything_filtered = true
|
34
34
|
|
35
|
-
config.filter_run_excluding :
|
36
|
-
config.filter_run_excluding :
|
35
|
+
config.filter_run_excluding windows_only: true unless ChefConfig.windows?
|
36
|
+
config.filter_run_excluding unix_only: true if ChefConfig.windows?
|
37
37
|
|
38
38
|
# Limits the available syntax to the non-monkey patched syntax that is
|
39
39
|
# recommended. For more details, see:
|
data/spec/unit/config_spec.rb
CHANGED
@@ -1191,4 +1191,22 @@ RSpec.describe ChefConfig::Config do
|
|
1191
1191
|
|
1192
1192
|
end
|
1193
1193
|
|
1194
|
+
describe "validation_client_name" do
|
1195
|
+
context "with a normal server URL" do
|
1196
|
+
before { ChefConfig::Config[:chef_server_url] = "https://chef.example/organizations/myorg" }
|
1197
|
+
|
1198
|
+
it "sets the validation client to myorg-validator" do
|
1199
|
+
expect(ChefConfig::Config[:validation_client_name]).to eq "myorg-validator"
|
1200
|
+
end
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
context "with an unusual server URL" do
|
1204
|
+
before { ChefConfig::Config[:chef_server_url] = "https://chef.example/myorg" }
|
1205
|
+
|
1206
|
+
it "sets the validation client to chef-validator" do
|
1207
|
+
expect(ChefConfig::Config[:validation_client_name]).to eq "chef-validator"
|
1208
|
+
end
|
1209
|
+
end
|
1210
|
+
end
|
1211
|
+
|
1194
1212
|
end
|
@@ -271,6 +271,70 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do
|
|
271
271
|
config_loader.load
|
272
272
|
expect(ChefConfig::Config.config_file).to eq(explicit_config_location)
|
273
273
|
end
|
274
|
+
|
275
|
+
it "loads a default value for node_name" do
|
276
|
+
allow(Etc).to receive(:getlogin).and_return("notauser")
|
277
|
+
config_loader.load
|
278
|
+
expect(ChefConfig::Config.node_name).to eq("notauser")
|
279
|
+
end
|
280
|
+
|
281
|
+
context "with a user.pem" do
|
282
|
+
before do
|
283
|
+
allow(Etc).to receive(:getlogin).and_return("notauser")
|
284
|
+
allow(FileTest).to receive(:exist?).and_call_original
|
285
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../notauser.pem", explicit_config_location)).and_return(false)
|
286
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../user.pem", explicit_config_location)).and_return(true)
|
287
|
+
end
|
288
|
+
|
289
|
+
it "loads a default value for client_key" do
|
290
|
+
config_loader.load
|
291
|
+
expect(ChefConfig::Config.client_key).to eq(File.expand_path("../user.pem", explicit_config_location))
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context "with a notauser.pem" do
|
296
|
+
before do
|
297
|
+
allow(Etc).to receive(:getlogin).and_return("notauser")
|
298
|
+
allow(FileTest).to receive(:exist?).and_call_original
|
299
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../notauser.pem", explicit_config_location)).and_return(true)
|
300
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../user.pem", explicit_config_location)).and_return(false)
|
301
|
+
end
|
302
|
+
|
303
|
+
it "loads a default value for client_key" do
|
304
|
+
config_loader.load
|
305
|
+
expect(ChefConfig::Config.client_key).to eq(File.expand_path("../notauser.pem", explicit_config_location))
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context "with a valclient.pem" do
|
310
|
+
before do
|
311
|
+
ChefConfig::Config.validation_client_name = "valclient"
|
312
|
+
allow(FileTest).to receive(:exist?).and_call_original
|
313
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../valclient.pem", explicit_config_location)).and_return(true)
|
314
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../validator.pem", explicit_config_location)).and_return(false)
|
315
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../validation.pem", explicit_config_location)).and_return(false)
|
316
|
+
end
|
317
|
+
|
318
|
+
it "loads a default value for validation_key" do
|
319
|
+
config_loader.load
|
320
|
+
expect(ChefConfig::Config.validation_key).to eq(File.expand_path("../valclient.pem", explicit_config_location))
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
context "with a validator.pem" do
|
325
|
+
before do
|
326
|
+
ChefConfig::Config.validation_client_name = "valclient"
|
327
|
+
allow(FileTest).to receive(:exist?).and_call_original
|
328
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../valclient.pem", explicit_config_location)).and_return(false)
|
329
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../validator.pem", explicit_config_location)).and_return(true)
|
330
|
+
allow(FileTest).to receive(:exist?).with(File.expand_path("../validation.pem", explicit_config_location)).and_return(false)
|
331
|
+
end
|
332
|
+
|
333
|
+
it "loads a default value for validation_key" do
|
334
|
+
config_loader.load
|
335
|
+
expect(ChefConfig::Config.validation_key).to eq(File.expand_path("../validator.pem", explicit_config_location))
|
336
|
+
end
|
337
|
+
end
|
274
338
|
end
|
275
339
|
|
276
340
|
context "and has a syntax error" do
|
@@ -389,11 +453,12 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do
|
|
389
453
|
|
390
454
|
context "and has a default profile" do
|
391
455
|
let(:content) do
|
392
|
-
content =
|
393
|
-
[default]
|
394
|
-
node_name = 'barney'
|
395
|
-
client_key = "barney_rubble.pem"
|
396
|
-
chef_server_url = "https://api.chef.io/organizations/bedrock"
|
456
|
+
content = <<~EOH
|
457
|
+
[default]
|
458
|
+
node_name = 'barney'
|
459
|
+
client_key = "barney_rubble.pem"
|
460
|
+
chef_server_url = "https://api.chef.io/organizations/bedrock"
|
461
|
+
invalid_config_option1234 = "foobar"
|
397
462
|
EOH
|
398
463
|
content
|
399
464
|
end
|
@@ -403,21 +468,22 @@ EOH
|
|
403
468
|
expect(ChefConfig::Config.chef_server_url).to eq("https://api.chef.io/organizations/bedrock")
|
404
469
|
expect(ChefConfig::Config.client_key.to_s).to eq("#{home}/.chef/barney_rubble.pem")
|
405
470
|
expect(ChefConfig::Config.profile.to_s).to eq("default")
|
471
|
+
expect(ChefConfig::Config[:invalid_config_option1234]).to eq("foobar")
|
406
472
|
end
|
407
473
|
end
|
408
474
|
|
409
475
|
context "and has a default profile with knife settings" do
|
410
476
|
let(:content) do
|
411
|
-
content =
|
412
|
-
[default]
|
413
|
-
node_name = 'barney'
|
414
|
-
client_key = "barney_rubble.pem"
|
415
|
-
chef_server_url = "https://api.chef.io/organizations/bedrock"
|
416
|
-
knife = {
|
417
|
-
|
418
|
-
}
|
419
|
-
[default.knife]
|
420
|
-
ssh_user = "knife_ssh_user"
|
477
|
+
content = <<~EOH
|
478
|
+
[default]
|
479
|
+
node_name = 'barney'
|
480
|
+
client_key = "barney_rubble.pem"
|
481
|
+
chef_server_url = "https://api.chef.io/organizations/bedrock"
|
482
|
+
knife = {
|
483
|
+
secret_file = "/home/barney/.chef/encrypted_data_bag_secret.pem"
|
484
|
+
}
|
485
|
+
[default.knife]
|
486
|
+
ssh_user = "knife_ssh_user"
|
421
487
|
EOH
|
422
488
|
content
|
423
489
|
end
|
@@ -434,21 +500,21 @@ EOH
|
|
434
500
|
|
435
501
|
context "and has a profile containing a full key" do
|
436
502
|
let(:content) do
|
437
|
-
content =
|
438
|
-
[default]
|
439
|
-
client_key = """
|
440
|
-
-----BEGIN RSA PRIVATE KEY-----
|
441
|
-
foo
|
442
|
-
"""
|
503
|
+
content = <<~EOH
|
504
|
+
[default]
|
505
|
+
client_key = """
|
506
|
+
-----BEGIN RSA PRIVATE KEY-----
|
507
|
+
foo
|
508
|
+
"""
|
443
509
|
EOH
|
444
510
|
content
|
445
511
|
end
|
446
512
|
|
447
513
|
it "applies the expected config" do
|
448
514
|
expect { config_loader.load_credentials }.not_to raise_error
|
449
|
-
expect(ChefConfig::Config.client_key_contents).to eq(
|
450
|
-
-----BEGIN RSA PRIVATE KEY-----
|
451
|
-
foo
|
515
|
+
expect(ChefConfig::Config.client_key_contents).to eq(<<~EOH
|
516
|
+
-----BEGIN RSA PRIVATE KEY-----
|
517
|
+
foo
|
452
518
|
EOH
|
453
519
|
)
|
454
520
|
end
|
@@ -456,15 +522,15 @@ EOH
|
|
456
522
|
|
457
523
|
context "and has several profiles" do
|
458
524
|
let(:content) do
|
459
|
-
content =
|
460
|
-
[default]
|
461
|
-
client_name = "default"
|
462
|
-
[environment]
|
463
|
-
client_name = "environment"
|
464
|
-
[explicit]
|
465
|
-
client_name = "explicit"
|
466
|
-
[context]
|
467
|
-
client_name = "context"
|
525
|
+
content = <<~EOH
|
526
|
+
[default]
|
527
|
+
client_name = "default"
|
528
|
+
[environment]
|
529
|
+
client_name = "environment"
|
530
|
+
[explicit]
|
531
|
+
client_name = "explicit"
|
532
|
+
[context]
|
533
|
+
client_name = "context"
|
468
534
|
EOH
|
469
535
|
content
|
470
536
|
end
|
@@ -503,10 +569,10 @@ EOH
|
|
503
569
|
|
504
570
|
context "and contains both node_name and client_name" do
|
505
571
|
let(:content) do
|
506
|
-
content =
|
507
|
-
[default]
|
508
|
-
node_name = 'barney'
|
509
|
-
client_name = 'barney'
|
572
|
+
content = <<~EOH
|
573
|
+
[default]
|
574
|
+
node_name = 'barney'
|
575
|
+
client_name = 'barney'
|
510
576
|
EOH
|
511
577
|
content
|
512
578
|
end
|
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: 14.
|
4
|
+
version: 14.3.37
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|
@@ -28,16 +28,22 @@ dependencies:
|
|
28
28
|
name: mixlib-config
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.2.12
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3.0'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
43
|
+
version: 2.2.12
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: fuzzyurl
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|