From 30e7e57af7793d23211b6eb25cee839bb4004964 Mon Sep 17 00:00:00 2001 From: Dimitri Roche & Matthew Horan Date: Thu, 1 Nov 2012 12:14:57 -0700 Subject: [PATCH] CHEF-3560: Display user@hostname when prompting for pwd --- chef/lib/chef/knife/ssh.rb | 10 ++++++---- chef/spec/functional/knife/ssh_spec.rb | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/chef/lib/chef/knife/ssh.rb b/chef/lib/chef/knife/ssh.rb index a4ba569812c..7bf20f59f23 100644 --- a/chef/lib/chef/knife/ssh.rb +++ b/chef/lib/chef/knife/ssh.rb @@ -125,8 +125,10 @@ def configure_gateway session.via(gw_host, gw_user || config[:ssh_user], gw_opts) end rescue Net::SSH::AuthenticationFailed - gw_opts.merge!(:password => prompt_for_password) - session.via(gw_host, gw_user || config[:ssh_user], gw_opts) + user = gw_user || config[:ssh_user] + prompt = "Enter the password for #{user}@#{gw_host}: " + gw_opts.merge!(:password => prompt_for_password(prompt)) + session.via(gw_host, user, gw_opts) end def configure_session @@ -235,8 +237,8 @@ def get_password @password ||= prompt_for_password end - def prompt_for_password - ui.ask("Enter your password: ") { |q| q.echo = false } + def prompt_for_password(prompt = "Enter your password: ") + ui.ask(prompt) { |q| q.echo = false } end # Present the prompt and read a single line from the console. It also diff --git a/chef/spec/functional/knife/ssh_spec.rb b/chef/spec/functional/knife/ssh_spec.rb index dd8e4500c67..04a98ac58c7 100644 --- a/chef/spec/functional/knife/ssh_spec.rb +++ b/chef/spec/functional/knife/ssh_spec.rb @@ -243,7 +243,7 @@ end it "should prompt the user for a password" do - @knife.ui.should_receive(:ask).with("Enter your password: ").and_return("password") + @knife.ui.should_receive(:ask).with("Enter the password for user@ec2.public_hostname: ").and_return("password") @knife.run end end