From cb3693971204bc4ecffede2fce7d3d935e770e77 Mon Sep 17 00:00:00 2001 From: Vasu1105 Date: Fri, 7 Jun 2019 11:21:25 +0530 Subject: [PATCH] MSYS-1047 Fix for raising error when root is used as default user for ssh connection and it don't have access previlages Signed-off-by: Vasu1105 --- lib/train/extras/command_wrapper.rb | 6 +++--- lib/train/platforms/detect/helpers/os_common.rb | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/train/extras/command_wrapper.rb b/lib/train/extras/command_wrapper.rb index abda3845..d7054228 100644 --- a/lib/train/extras/command_wrapper.rb +++ b/lib/train/extras/command_wrapper.rb @@ -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 diff --git a/lib/train/platforms/detect/helpers/os_common.rb b/lib/train/platforms/detect/helpers/os_common.rb index 88af6dad..136ce791 100644 --- a/lib/train/platforms/detect/helpers/os_common.rb +++ b/lib/train/platforms/detect/helpers/os_common.rb @@ -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