diff options
author | Tim Smith <tsmith@chef.io> | 2018-05-30 16:31:14 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-05-30 16:31:14 -0700 |
commit | 355724aacf9f8edd221e7573df4de0ae29dd6a07 (patch) | |
tree | da0a6b0fb5bd5988ccac6c804ce328bef268cdc8 /lib/chef/knife/configure.rb | |
parent | 087827cc0217273f8e33ca2050b27285ff8bc127 (diff) | |
download | chef-355724aacf9f8edd221e7573df4de0ae29dd6a07.tar.gz |
Properly print path to config file to the screen in knife configure
config[:config_file] was nil
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef/knife/configure.rb')
-rw-r--r-- | lib/chef/knife/configure.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/chef/knife/configure.rb b/lib/chef/knife/configure.rb index abde923788..df021826ae 100644 --- a/lib/chef/knife/configure.rb +++ b/lib/chef/knife/configure.rb @@ -69,15 +69,12 @@ class Chef def run FileUtils.mkdir_p(chef_config_path) - config_file = File.join(chef_config_path, "credentials") ask_user_for_config - config_file = File.expand_path(config_file) - if File.exist?(config_file) - confirm("Overwrite #{config_file}") - end - ::File.open(config_file, "w") do |f| + confirm("Overwrite #{config_file_path}") if ::File.exist?(config_file_path) + + ::File.open(config_file_path, "w") do |f| f.puts <<-EOH [default] client_name = '#{new_client_name}' @@ -110,7 +107,7 @@ EOH ui.msg("*****") end - ui.msg("Configuration file written to #{config[:config_file]}") + ui.msg("Knife configuration file written to #{config_file_path}") end def ask_user_for_config @@ -129,14 +126,21 @@ EOH @new_client_key = File.expand_path(@new_client_key) end + # @return [String] our best guess at what the servername should be using Ohai data and falling back to localhost def guess_servername o = Ohai::System.new o.all_plugins(%w{ os hostname fqdn }) o[:fqdn] || o[:machinename] || o[:hostname] || "localhost" end + # @return [String] the path to the user's .chef directory def chef_config_path - Chef::Util::PathHelper.home(".chef") + @chef_config_path ||= Chef::Util::PathHelper.home(".chef") + end + + # @return [String] the full path to the config file (credential file) + def config_file_path + @config_file_path ||= ::File.expand_path(::File.join(chef_config_path, "credentials")) end end end |