Class: ForemanRemoteExecutionCore::SudoUserMethod
- Inherits:
-
Object
- Object
- ForemanRemoteExecutionCore::SudoUserMethod
- Defined in:
- lib/foreman_remote_execution_core/script_runner.rb
Direct Known Subclasses
Constant Summary collapse
- LOGIN_PROMPT =
'rex login: '.freeze
Instance Attribute Summary collapse
-
#effective_user ⇒ Object
readonly
Returns the value of attribute effective_user.
-
#effective_user_password ⇒ Object
readonly
Returns the value of attribute effective_user_password.
-
#password_sent ⇒ Object
readonly
Returns the value of attribute password_sent.
-
#ssh_user ⇒ Object
readonly
Returns the value of attribute ssh_user.
Instance Method Summary collapse
- #cli_command_prefix ⇒ Object
- #filter_password?(received_data) ⇒ Boolean
-
#initialize(effective_user, ssh_user, effective_user_password) ⇒ SudoUserMethod
constructor
A new instance of SudoUserMethod.
- #login_prompt ⇒ Object
- #on_data(received_data, ssh_channel) ⇒ Object
- #reset ⇒ Object
- #sent_all_data? ⇒ Boolean
Constructor Details
#initialize(effective_user, ssh_user, effective_user_password) ⇒ SudoUserMethod
Returns a new instance of SudoUserMethod.
16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#effective_user ⇒ Object (readonly)
Returns the value of attribute effective_user.
14 15 16 |
# File 'lib/foreman_remote_execution_core/script_runner.rb', line 14 def effective_user @effective_user end |
#effective_user_password ⇒ Object (readonly)
Returns the value of attribute effective_user_password.
14 15 16 |
# File 'lib/foreman_remote_execution_core/script_runner.rb', line 14 def effective_user_password @effective_user_password end |
#password_sent ⇒ Object (readonly)
Returns the value of attribute password_sent.
14 15 16 |
# File 'lib/foreman_remote_execution_core/script_runner.rb', line 14 def password_sent @password_sent end |
#ssh_user ⇒ Object (readonly)
Returns the value of attribute ssh_user.
14 15 16 |
# File 'lib/foreman_remote_execution_core/script_runner.rb', line 14 def ssh_user @ssh_user end |
Instance Method Details
#cli_command_prefix ⇒ Object
42 43 44 |
# 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) ⇒ Boolean
34 35 36 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/foreman_remote_execution_core/script_runner.rb', line 30 def login_prompt LOGIN_PROMPT end |
#on_data(received_data, ssh_channel) ⇒ Object
23 24 25 26 27 28 |
# 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 ⇒ Object
46 47 48 |
# File 'lib/foreman_remote_execution_core/script_runner.rb', line 46 def reset @password_sent = false end |
#sent_all_data? ⇒ Boolean
38 39 40 |
# File 'lib/foreman_remote_execution_core/script_runner.rb', line 38 def sent_all_data? effective_user_password.empty? || password_sent end |