aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-07-01 09:02:14 +0100
committerChristopher Baines <mail@cbaines.net>2018-07-01 09:02:14 +0100
commit5ba97ad556728c5a74aa86b1d18b98f4ad5e38a9 (patch)
tree2ca47f8efe96cb34a470616dd6ffe611c3b5f9cb /lib
parenta25950c4683036315632d44e3ef3d3d2d1da7a3d (diff)
downloadgovuk-mini-environment-admin-5ba97ad556728c5a74aa86b1d18b98f4ad5e38a9.tar
govuk-mini-environment-admin-5ba97ad556728c5a74aa86b1d18b98f4ad5e38a9.tar.gz
Use the remote host struct in read_json_file
Diffstat (limited to 'lib')
-rw-r--r--lib/shell_utils.rb14
1 files changed, 13 insertions, 1 deletions
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}" }