Class: Dkdeploy::InteractionHandler::MySql
- Inherits:
-
Object
- Object
- Dkdeploy::InteractionHandler::MySql
- Defined in:
- lib/dkdeploy/interaction_handler/mysql.rb
Overview
Interaction handler for mysql
Instance Method Summary collapse
-
#initialize(password) ⇒ MySql
constructor
Interaction handler for sending password to MySQL client This InteractionHandler provides output of the error code if MySQL answers with an error to the command.
-
#on_data(_command, _stream_name, data, channel) ⇒ Object
Method to send password to terminal.
Constructor Details
#initialize(password) ⇒ MySql
Interaction handler for sending password to MySQL client This InteractionHandler provides output of the error code if MySQL answers with an error to the command.
10 11 12 13 14 15 |
# File 'lib/dkdeploy/interaction_handler/mysql.rb', line 10 def initialize(password) @password = password # these two are declared as instance variables because the on_data method is called multiple times = '' @mysql_error_seen = false end |
Instance Method Details
#on_data(_command, _stream_name, data, channel) ⇒ Object
Method to send password to terminal
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dkdeploy/interaction_handler/mysql.rb', line 23 def on_data(_command, _stream_name, data, channel) if data =~ /.*password.*/i channel.send_data("#{@password}\n") else @mysql_error_seen = true if data =~ /.*ERROR.*/i return raise 'Unexpected data from stream. Can not send password to undefined stream' unless @mysql_error_seen # combine the multiple lines from error message. The fact that the error message will be shown multiple times is simply ignored << data = 'Error on executing MySQL command! Response (error code) is: ' SSHKit.config.output.send(:error, "#{message}\n #{@return_message}") raise 'InteractionHandler caught a MySQL error' end end |