From 5ba97ad556728c5a74aa86b1d18b98f4ad5e38a9 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 1 Jul 2018 09:02:14 +0100 Subject: Use the remote host struct in read_json_file --- lib/shell_utils.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/shell_utils.rb b/lib/shell_utils.rb index 75ee3ca..b426e44 100644 --- a/lib/shell_utils.rb +++ b/lib/shell_utils.rb @@ -73,15 +73,27 @@ module ShellUtils def read_json_file(filename, from_remote_host: nil) if from_remote_host + identity_file = Tempfile.new( + 'private-identity-file', + Rails.root.join('tmp') + ) + identity_file.write(from_remote_host.private_key) + identity_file.close + command = [ 'ssh', - from_remote_host, + from_remote_host.user_at_address, + # Use a automatically trust on first use model + '-o', 'StrictHostKeyChecking=no', + '-i', identity_file.path, 'cat', filename ] stdout_str, status = Open3.capture2(*command) + identity_file.unlink if identity_file + unless status.exitstatus == 0 logger.error(self.class) { "failed, exit status #{exit_status}" } -- cgit v1.2.3