Skip to content

Commit

Permalink
CHEF-3560: Display user@hostname when prompting for pwd
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri Roche & Matthew Horan authored and Matthew Horan & Ryan Ong committed Nov 30, 2012
1 parent 1b93f1c commit 30e7e57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions chef/lib/chef/knife/ssh.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chef/spec/functional/knife/ssh_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 30e7e57

Please sign in to comment.