Skip to content
This repository

Feature/no password prompt #20

Merged
merged 4 commits into from almost 2 years ago

2 participants

Dan Richert Delano Mandelbaum
Dan Richert

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

Delano Mandelbaum
Owner
delano commented

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

Dan Richert

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

Dan Richert

Sorry, not ready yet. Need to re-rebase

Dan Richert

Fixed. Ready :)

Dan Richert

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

Delano Mandelbaum
Owner

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

Dan Richert

All set

Delano Mandelbaum delano merged commit 598d665 into from
Delano Mandelbaum delano closed this
Delano Mandelbaum
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
This page is out of date. Refresh to see the latest.
6 README.rdoc
Source Rendered
@@ -165,6 +165,12 @@ So, the hostname 'filibuster' is used from 'firewall.lan'
165 165 rset.uptime
166 166 # => [[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]]
167 167
  168 +== Example 9 -- Disable password prompt
  169 +
  170 +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:
  171 +
  172 + rbox = Rye::Box.new("foo.com", :user => "dan", :password => "inkorrect", :password_prompt => false)
  173 + rbox.uptime # => raises Net::SSH::AuthenticationFailed
168 174
169 175 == About Safe-Mode
170 176
11 lib/rye/box.rb
@@ -106,6 +106,7 @@ def exception_hook=(val); @rye_exception_hook = val; end
106 106 # * :password => the user's password (ignored if there's a valid private key)
107 107 # * :templates => the template engine to use for uploaded files. One of: :erb (default)
108 108 # * :sudo => Run all commands via sudo (default: false)
  109 + # * :password_prompt => Show a password prompt on auth failure (default: true)
109 110 #
110 111 # NOTE: +opts+ can also contain any parameter supported by
111 112 # Net::SSH.start that is not already mentioned above.
@@ -132,7 +133,8 @@ def initialize(host='localhost', opts={})
132 133 :error => STDERR,
133 134 :getenv => true,
134 135 :templates => :erb,
135   - :quiet => false
  136 + :quiet => false,
  137 + :password_prompt => true
136 138 }.merge(opts)
137 139
138 140 # Close the SSH session before Ruby exits. This will do nothing
@@ -150,8 +152,9 @@ def initialize(host='localhost', opts={})
150 152 @rye_ostype, @rye_impltype = @rye_opts.delete(:ostype), @rye_opts.delete(:impltype)
151 153 @rye_quiet, @rye_sudo = @rye_opts.delete(:quiet), @rye_opts.delete(:sudo)
152 154 @rye_templates = @rye_opts.delete(:templates)
153   -
154   - # Store the state of the terminal
  155 + @rye_password_prompt = @rye_opts.delete(:password_prompt)
  156 +
  157 + # Store the state of the terminal
155 158 @rye_stty_save = `stty -g`.chomp rescue nil
156 159
157 160 unless @rye_templates.nil?
@@ -684,7 +687,7 @@ def connect(reconnect=true)
684 687 # only auth method
685 688 if @rye_opts[:auth_methods] == ["publickey"]
686 689 raise Net::SSH::AuthenticationFailed
687   - elsif STDIN.tty? && retried <= 3
  690 + elsif @rye_password_prompt && (STDIN.tty? && retried <= 3)
688 691 STDERR.puts "Passwordless login failed for #{@rye_user}"
689 692 @rye_opts[:password] = highline.ask("Password: ") { |q| q.echo = '' }.strip
690 693 @rye_opts[:auth_methods].push *['keyboard-interactive', 'password']
18 try/14_auth_methods_tryouts.rb
... ... @@ -1,13 +1,12 @@
1 1 require "rye"
2 2
3   -## Don't prompt for password if "publickey" is the only :auth_method
4   -
5   -# May need to update this in the future with a
  3 +# May need to update this in the future with a
6 4 # different free SSH provider
7   -hostname = "shellmix.com"
  5 +@hostname = "shellmix.com"
8 6
  7 +## Don't prompt for password if "publickey" is the only :auth_method
9 8 box = Rye::Box.new(
10   - hostname,
  9 + @hostname,
11 10 :auth_methods => ["publickey"]
12 11 )
13 12
@@ -18,3 +17,12 @@
18 17 end
19 18 #=> Net::SSH::AuthenticationFailed
20 19
  20 +## Never prompt for password if :no_password_prompt option is true
  21 +box = Rye::Box.new(@hostname, :password_prompt => false)
  22 +
  23 +begin
  24 + box.connect
  25 +rescue Net::SSH::AuthenticationFailed => ex
  26 + ex.class
  27 +end
  28 +#=> Net::SSH::AuthenticationFailed

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.