lib/rye/box.rb in rye-0.9.7 vs lib/rye/box.rb in rye-0.9.8
- old
+ new
@@ -104,10 +104,11 @@
# * :error => an IO object to print Rye::Box errors to. Default: STDERR
# * :getenv => pre-fetch +host+ environment variables? (default: true)
# * :password => the user's password (ignored if there's a valid private key)
# * :templates => the template engine to use for uploaded files. One of: :erb (default)
# * :sudo => Run all commands via sudo (default: false)
+ # * :password_prompt => Show a password prompt on auth failure (default: true)
#
# NOTE: +opts+ can also contain any parameter supported by
# Net::SSH.start that is not already mentioned above.
#
def initialize(host='localhost', opts={})
@@ -130,11 +131,12 @@
:info => nil,
:debug => nil,
:error => STDERR,
:getenv => true,
:templates => :erb,
- :quiet => false
+ :quiet => false,
+ :password_prompt => true
}.merge(opts)
# Close the SSH session before Ruby exits. This will do nothing
# if disconnect has already been called explicitly.
at_exit { self.disconnect }
@@ -148,12 +150,13 @@
@rye_info, @rye_error = @rye_opts.delete(:info), @rye_opts.delete(:error)
@rye_getenv = {} if @rye_opts.delete(:getenv) # Enable getenv with a hash
@rye_ostype, @rye_impltype = @rye_opts.delete(:ostype), @rye_opts.delete(:impltype)
@rye_quiet, @rye_sudo = @rye_opts.delete(:quiet), @rye_opts.delete(:sudo)
@rye_templates = @rye_opts.delete(:templates)
-
- # Store the state of the terminal
+ @rye_password_prompt = @rye_opts.delete(:password_prompt)
+
+ # Store the state of the terminal
@rye_stty_save = `stty -g`.chomp rescue nil
unless @rye_templates.nil?
require @rye_templates.to_s # should be :erb
end
@@ -682,10 +685,10 @@
# Raise Net::SSH::AuthenticationFailed if publickey is the
# only auth method
if @rye_opts[:auth_methods] == ["publickey"]
raise Net::SSH::AuthenticationFailed
- elsif STDIN.tty? && retried <= 3
+ elsif @rye_password_prompt && (STDIN.tty? && retried <= 3)
STDERR.puts "Passwordless login failed for #{@rye_user}"
@rye_opts[:password] = highline.ask("Password: ") { |q| q.echo = '' }.strip
@rye_opts[:auth_methods].push *['keyboard-interactive', 'password']
retry
else