Permalink
Browse files

Add :no_password_prompt option

  • Loading branch information...
1 parent d2b2c1f commit e267b9da2187949cde9cb1ec60f2c598248cbed7 @drichert committed Jul 6, 2012
Showing with 20 additions and 9 deletions.
  1. +7 −4 lib/rye/box.rb
  2. +13 −5 try/14_auth_methods_tryouts.rb
View
@@ -106,6 +106,7 @@ def exception_hook=(val); @rye_exception_hook = val; end
# * :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)
+ # * :no_password_prompt => Never show a password prompt on auth failure (default: false)
#
# NOTE: +opts+ can also contain any parameter supported by
# Net::SSH.start that is not already mentioned above.
@@ -132,7 +133,8 @@ def initialize(host='localhost', opts={})
:error => STDERR,
:getenv => true,
:templates => :erb,
- :quiet => false
+ :quiet => false,
+ :no_password_prompt => false
}.merge(opts)
# Close the SSH session before Ruby exits. This will do nothing
@@ -150,8 +152,9 @@ def initialize(host='localhost', opts={})
@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_no_password_prompt = @rye_opts.delete(:no_password_prompt)
+
+ # Store the state of the terminal
@rye_stty_save = `stty -g`.chomp rescue nil
unless @rye_templates.nil?
@@ -684,7 +687,7 @@ def connect(reconnect=true)
# only auth method
if @rye_opts[:auth_methods] == ["publickey"]
raise Net::SSH::AuthenticationFailed
- elsif STDIN.tty? && retried <= 3
+ elsif !@rye_no_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']
@@ -1,13 +1,12 @@
require "rye"
-## Don't prompt for password if "publickey" is the only :auth_method
-
-# May need to update this in the future with a
+# May need to update this in the future with a
# different free SSH provider
-hostname = "shellmix.com"
+@hostname = "shellmix.com"
+## Don't prompt for password if "publickey" is the only :auth_method
box = Rye::Box.new(
- hostname,
+ @hostname,
:auth_methods => ["publickey"]
)
@@ -18,3 +17,12 @@
end
#=> Net::SSH::AuthenticationFailed
+## Never prompt for password if :no_password_prompt option is true
+box = Rye::Box.new(@hostname, :no_password_prompt => true)
+
+begin
+ box.connect
+rescue Net::SSH::AuthenticationFailed => ex
+ ex.class
+end
+#=> Net::SSH::AuthenticationFailed

0 comments on commit e267b9d

Please sign in to comment.