Module: Capistrano::Switchuser

Defined in:
lib/capistrano/switchuser.rb,
lib/capistrano/switchuser/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#close_sessions ⇒ Object

close any open ssh sessions to force login as a new user



18
19
20
21
# File 'lib/capistrano/switchuser.rb', line 18

def close_sessions
  sessions.values.each { |session| session.close }
  sessions.clear
end

#switchuser(new_user) ⇒ Object

switch to using a different ssh user



6
7
8
9
10
11
12
13
14
15
# File 'lib/capistrano/switchuser.rb', line 6

def switchuser(new_user)
  old_user = fetch(:user)
  set(:user, new_user)
  close_sessions
  if block_given?
    yield 
    set(:user, old_user)
    close_sessions
  end
end