class ForemanRemoteExecutionCore::SudoUserMethod

Constants

LOGIN_PROMPT

Attributes

effective_user[R]
effective_user_password[R]
password_sent[R]
ssh_user[R]

Public Class Methods

new(effective_user, ssh_user, effective_user_password) click to toggle source
# File lib/foreman_remote_execution_core/script_runner.rb, line 16
def initialize(effective_user, ssh_user, effective_user_password)
  @effective_user = effective_user
  @ssh_user = ssh_user
  @effective_user_password = effective_user_password.to_s
  @password_sent = false
end

Public Instance Methods

cli_command_prefix() click to toggle source
# File lib/foreman_remote_execution_core/script_runner.rb, line 42
def cli_command_prefix
  "sudo -p '#{LOGIN_PROMPT}' -u #{effective_user} "
end
filter_password?(received_data) click to toggle source
# File lib/foreman_remote_execution_core/script_runner.rb, line 34
def filter_password?(received_data)
  !@effective_user_password.empty? && @password_sent && received_data.match(Regexp.escape(@effective_user_password))
end
login_prompt() click to toggle source
# File lib/foreman_remote_execution_core/script_runner.rb, line 30
def login_prompt
  LOGIN_PROMPT
end
on_data(received_data, ssh_channel) click to toggle source
# File lib/foreman_remote_execution_core/script_runner.rb, line 23
def on_data(received_data, ssh_channel)
  if received_data.match(login_prompt)
    ssh_channel.send_data(effective_user_password + "\n")
    @password_sent = true
  end
end
reset() click to toggle source
# File lib/foreman_remote_execution_core/script_runner.rb, line 46
def reset
  @password_sent = false
end
sent_all_data?() click to toggle source
# File lib/foreman_remote_execution_core/script_runner.rb, line 38
def sent_all_data?
  effective_user_password.empty? || password_sent
end