Class: SSHKit::Sudo::PasswordSendingInteractionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkit/sudo/password_sending_interaction_handler.rb

Overview

Slightly simplified version of the original:

  • assumed that there is a password

  • assumes the same pwd for the hosts

  • replaced the class/dead methods with constants

  • removed the InteractionHandler subclass

Constant Summary collapse

WRONG_PASSWORD_MESSAGE_REGEX =
/Sorry.*\stry\sagain/
PASSWORD_PROMPT_REGEX =
/[Pp]assword.*:/

Instance Method Summary collapse

Constructor Details

#initialize(servers_password) ⇒ PasswordSendingInteractionHandler

Returns a new instance of PasswordSendingInteractionHandler.



14
15
16
# File 'lib/sshkit/sudo/password_sending_interaction_handler.rb', line 14

def initialize(servers_password)
  @servers_password = servers_password
end

Instance Method Details

#on_data(command, stream_name, data, channel) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/sshkit/sudo/password_sending_interaction_handler.rb', line 18

def on_data(command, stream_name, data, channel)
  raise "Wrong password!" if data =~ WRONG_PASSWORD_MESSAGE_REGEX

  if data =~ PASSWORD_PROMPT_REGEX
    pass = @servers_password
    channel.send_data(pass)
  end
end