Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature/no password prompt #20

Merged
merged 4 commits into from

2 participants

@drichert

Disable password prompt. Useful when STDIN.tty? is true

@delano
Owner

Seems reasonable. Do you know why there's so much whitespace noise in the diff?

@drichert

Force of habit; editor auto-strips trailing whitespace. Rebased.

@drichert

Sorry, not ready yet. Need to re-rebase

@drichert

Fixed. Ready :)

@drichert

Are there any other changes you'd like to see?

@delano
Owner

Just one. Rename the option no_password_prompt to password_prompt. I'll pull it in and release it.

@drichert

All set

@delano delano merged commit 598d665 into delano:master
@delano
Owner

Great, thanks for making Rye better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 30, 2012
  1. @drichert
  2. @drichert

    Update README

    drichert authored
Commits on Aug 15, 2012
  1. @drichert
  2. @drichert

    Correct doc comment

    drichert authored
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 9 deletions.
  1. +6 −0 README.rdoc
  2. +7 −4 lib/rye/box.rb
  3. +13 −5 try/14_auth_methods_tryouts.rb
View
6 README.rdoc
@@ -165,6 +165,12 @@ So, the hostname 'filibuster' is used from 'firewall.lan'
rset.uptime
# => [[17:17:44 up 548 days, 13:37, 20 users, load average: 0.12, 0.07, 0.06], [01:17:49 up 6 days, 1:39, 9 users, load average: 0.13, 0.09, 0.09]]
+== Example 9 -- Disable password prompt
+
+If you're running in a terminal but you want <tt>Net::SSH::AuthenticationFailed</tt> to be raised instead of getting a password prompt when authentication fails, set <tt>:password_prompt</tt> option to false:
+
+ rbox = Rye::Box.new("foo.com", :user => "dan", :password => "inkorrect", :password_prompt => false)
+ rbox.uptime # => raises Net::SSH::AuthenticationFailed
== About Safe-Mode
View
11 lib/rye/box.rb
@@ -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)
+ # * :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.
@@ -132,7 +133,8 @@ def initialize(host='localhost', opts={})
: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
@@ -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_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?
@@ -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_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']
View
18 try/14_auth_methods_tryouts.rb
@@ -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, :password_prompt => false)
+
+begin
+ box.connect
+rescue Net::SSH::AuthenticationFailed => ex
+ ex.class
+end
+#=> Net::SSH::AuthenticationFailed
Something went wrong with that request. Please try again.