Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to raise specific error when ssh user is not provided and root is used as default user. #466

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/train/extras/command_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ class CommandWrapper
include_options WindowsCommand

def self.load(transport, options)
if transport.os.unix?
if transport.platform.unix?
return nil unless LinuxCommand.active?(options)
res = LinuxCommand.new(transport, options)
verification_res = res.verify
if verification_res
msg, reason = verification_res
raise Train::UserError.new("Sudo failed: #{msg}", reason)
raise Train::UserError, "Sudo failed: #{msg}", reason
end
res
elsif transport.os.windows?
elsif transport.platform.windows?
res = WindowsCommand.new(transport, options)
res
end
Expand Down
6 changes: 6 additions & 0 deletions lib/train/platforms/detect/helpers/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def unix_file_exist?(path)

def command_output(cmd)
res = @backend.run_command(cmd).stdout
# When you try to execute command using ssh connction as root user and you have provided ssh user identity file
# it gives standard output to login as authorised user other than root. To show this standard ouput as an error
# to user we are matching the string of stdout and raising the error here so that user gets exact information.
if @backend.class.to_s == "Train::Transports::SSH::Connection" && res =~ /Please login as the user/
raise Train::UserError, "SSH failed: #{res}"
end
res.strip! unless res.nil?
res
end
Expand Down