mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Allow password to be reentered on sudo if it was entered incorrectly
git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@3371 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
77e1d1e6ae
commit
829fb7d8ed
4 changed files with 36 additions and 5 deletions
|
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Allow password to be reentered on sudo if it was entered incorrectly
|
||||
|
||||
* Use && as the command separator for the checkouts, so that errors are caught early.
|
||||
|
||||
* Ping each SSH connection every 1s during command processing so that long-running commands don't cause the connection to timeout.
|
||||
|
|
@ -18,7 +20,7 @@
|
|||
|
||||
* Added ssh_options variable to configure the SSH connection parameters #2734 [jerrett@bravenet.com]
|
||||
|
||||
* Require Net::SSH 1.0.3
|
||||
* Require Net::SSH 1.0.5
|
||||
|
||||
|
||||
*0.9.0* (October 18th, 2005)
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ module SwitchTower
|
|||
cmd = "cat > #{path}"
|
||||
cmd << " && chmod #{options[:mode].to_s(8)} #{path}" if options[:mode]
|
||||
run(cmd, options.merge(:data => data + "\n\4")) do |ch, stream, out|
|
||||
logger.important out, "#{stream} :: #{ch[:host]}" if out == :err
|
||||
logger.important out, "#{stream} :: #{ch[:host]}" if stream == :err
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -180,9 +180,23 @@ module SwitchTower
|
|||
logger.debug(out, "#{stream} :: #{ch[:host]}")
|
||||
end
|
||||
|
||||
# in order to prevent _each host_ from prompting when the password was
|
||||
# wrong, let's track which host prompted first and only allow subsequent
|
||||
# prompts from that host.
|
||||
prompt_host = nil
|
||||
|
||||
run "sudo #{command}", options do |ch, stream, out|
|
||||
if out =~ /^Password:/
|
||||
ch.send_data "#{password}\n"
|
||||
elsif out =~ /try again/
|
||||
if prompt_host.nil? || prompt_host == ch[:host]
|
||||
prompt_host = ch[:host]
|
||||
logger.important out, "#{stream} :: #{ch[:host]}"
|
||||
# reset the password to it's original value and prepare for another
|
||||
# pass (the reset allows the password prompt to be attempted again
|
||||
# if the password variable was originally a proc (the default)
|
||||
set :password, self[:original_value][:password] || self[:password]
|
||||
end
|
||||
else
|
||||
block.call(ch, stream, out)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,6 +38,9 @@ module SwitchTower
|
|||
@variables = {}
|
||||
@now = Time.now.utc
|
||||
|
||||
# for preserving the original value of Proc-valued variables
|
||||
set :original_value, Hash.new
|
||||
|
||||
set :application, nil
|
||||
set :repository, nil
|
||||
set :gateway, nil
|
||||
|
|
@ -63,10 +66,14 @@ module SwitchTower
|
|||
|
||||
alias :[]= :set
|
||||
|
||||
# Access a named variable. If the value of the variable is a Proc instance,
|
||||
# the proc will be invoked and the return value cached and returned.
|
||||
# Access a named variable. If the value of the variable responds_to? :call,
|
||||
# #call will be invoked (without parameters) and the return value cached
|
||||
# and returned.
|
||||
def [](variable)
|
||||
set variable, @variables[variable].call if Proc === @variables[variable]
|
||||
if @variables[variable].respond_to?(:call)
|
||||
self[:original_value][variable] = @variables[variable]
|
||||
set variable, @variables[variable].call
|
||||
end
|
||||
@variables[variable]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -207,4 +207,12 @@ class ConfigurationTest < Test::Unit::TestCase
|
|||
@config.set :scm, :subversion
|
||||
assert_equal "SwitchTower::SCM::Subversion", @config.source.class.name
|
||||
end
|
||||
|
||||
def test_get_proc_variable_sets_original_value_hash
|
||||
@config.set :proc, Proc.new { "foo" }
|
||||
assert_nil @config[:original_value][:proc]
|
||||
assert_equal "foo", @config[:proc]
|
||||
assert_not_nil @config[:original_value][:proc]
|
||||
assert @config[:original_value][:proc].respond_to?(:call)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue