From a37b74ad38e73de3dbfdd7bb10a308f34b9d600d Mon Sep 17 00:00:00 2001
From: Jake Smith <jws52@cam.ac.uk>
Date: Wed, 29 Jun 2022 15:00:25 +0100
Subject: [PATCH] feat: ssh will not prompt user

The ssh commands now do not check new server identities. This prevents a
user prompt on first-time use, which otherwise inhibits Amazon Web
Server instances.
---
 Processor.py           |  2 --
 ProcessorComponents.py | 14 +++++++-------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/Processor.py b/Processor.py
index 7978678..12e7461 100755
--- a/Processor.py
+++ b/Processor.py
@@ -41,8 +41,6 @@ import NAMEPreProcessor as npp
 import ProcessorComponents
 from ProcessorUtils import endScript, endJob, open_and_check_config, PasswordODKFilter
 
-# TODO: Replace subprocess scp and ssh commands with paramiko.SSHClient() instance
-
 # initialise default values for configuration
 
 script_name = 'Processor'
diff --git a/ProcessorComponents.py b/ProcessorComponents.py
index 89c3426..28c19f0 100644
--- a/ProcessorComponents.py
+++ b/ProcessorComponents.py
@@ -45,6 +45,8 @@ from python.common.plotting_coordinator.ews_depo_disease_plotting_coordinator im
 from python.common.plotting_coordinator.ews_epi_disease_plotting_coordinator import EWSPlottingEPIBase
 from ProcessorUtils import open_and_check_config, get_only_existing_globs, subprocess_and_log, endScript, endJob, add_filters_to_sublogger
 
+# TODO: Replace subprocess scp and ssh commands with paramiko.SSHClient() instance
+
 logger = logging.getLogger('Processor.Components')
 add_filters_to_sublogger(logger)
 
@@ -94,7 +96,7 @@ def process_pre_job_server_download(input_args):
 
         timenow = datetime.datetime.now(tz=datetime.timezone.utc).time()
 
-        cmd_ssh = ["ssh","-i",config['ServerKey'],config['ServerName'],f"test -f {file_path}/{file_name}.tar.gz"]
+        cmd_ssh = ["ssh","-i",config['ServerKey'],"-o","StrictHostKeyChecking=no",config['ServerName'],f"test -f {file_path}/{file_name}.tar.gz"]
         description_short = 'subprocess_ssh'
         description_long = f"Checking for existence of {file_path}/{file_name}.tar.gz"
 
@@ -1276,7 +1278,7 @@ def process_in_job_env2_0(jobPath,status,config,component):
     #TODO: check if file exists already (may be the case for multiple configs in one)
 
     # TODO: perform ssh file transfer in python instead of subprocess
-    cmd_scp = ["scp","-i",config['ServerKey'],f"{config['ServerName']}:{file_path}/{file_name}.tar.gz", jobPath]
+    cmd_scp = ["scp","-i",config['ServerKey'],"-o","StrictHostKeyChecking=no",f"{config['ServerName']}:{file_path}/{file_name}.tar.gz", jobPath]
     description_short = 'env2 scp'
     description_long = 'Copying file from remote server to job directory'
 
@@ -1367,7 +1369,7 @@ def process_in_job_dep(jobPath,status,config,component):
     logger.info('Copying file from remote server to job directory')
 
     # TODO: perform ssh file transfer in python instead of subprocess
-    cmd_scp = ["scp","-i",config['ServerKey'],f"{config['ServerName']}:{file_path}/{file_name}.tar.gz", jobPath]
+    cmd_scp = ["scp","-i",config['ServerKey'],"-o","StrictHostKeyChecking=no",f"{config['ServerName']}:{file_path}/{file_name}.tar.gz", jobPath]
     description_short = 'dep scp'
     description_long = 'scp from server to job directory'
     subprocess_and_log(cmd_scp, description_short, description_long)
@@ -2065,8 +2067,6 @@ def process_EWS_plotting_epi(jobPath,config):
 
 def upload(config,FilesToSend,component):
 
-    # TODO: replace subprocess ssh and scp commands with python-based paramiko
-
     usual_path = f"{config['StartString']}_0000/"
 
     component_path = {
@@ -2091,7 +2091,7 @@ def upload(config,FilesToSend,component):
 
     logger.debug("Making path directory on remote server if it doesn't already exist")
 
-    ssh_cmd = ["ssh","-vvv","-i",config['ServerKey'],config['ServerName'], f"mkdir -p {OutputServerPath}"]
+    ssh_cmd = ["ssh","-i",config['ServerKey'],"-o","StrictHostKeyChecking=no",config['ServerName'], f"mkdir -p {OutputServerPath}"]
 
     description_short = 'upload ssh'
     description_long = 'make remote directory'
@@ -2099,7 +2099,7 @@ def upload(config,FilesToSend,component):
 
     logger.debug('Sending file(s) to remote server')
 
-    scp_cmd = ["scp","-v","-ri",config['ServerKey'],*FilesToSend, f"{config['ServerName']}:{OutputServerPath}"]
+    scp_cmd = ["scp","-ri",config['ServerKey'],"-o","StrictHostKeyChecking=no",*FilesToSend, f"{config['ServerName']}:{OutputServerPath}"]
 
     description_short = 'upload scp'
     description_long = 'scp files to remote directory'
-- 
GitLab