From 46a80fe43b4688f55e246ff89265f22d0955f4d1 Mon Sep 17 00:00:00 2001
From: Alexandre Iooss <erdnaxe@crans.org>
Date: Fri, 8 May 2020 10:04:08 +0200
Subject: [PATCH] Add SSH password prompt

---
 cpasswords/remote.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/cpasswords/remote.py b/cpasswords/remote.py
index f3e1f20..7cf67cf 100644
--- a/cpasswords/remote.py
+++ b/cpasswords/remote.py
@@ -9,11 +9,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
 """
 
 from functools import lru_cache
+from getpass import getpass
 import json
 import logging
 
 from paramiko.client import SSHClient
-from paramiko.ssh_exception import SSHException
+from paramiko.ssh_exception import SSHException, PasswordRequiredException, AuthenticationException
 
 from .locale import _
 
@@ -22,7 +23,7 @@ log = logging.getLogger(__name__)
 
 
 @lru_cache()
-def create_ssh_client(host):
+def create_ssh_client(host, password=None):
     """
     Create a SSH client with paramiko module
     """
@@ -30,7 +31,13 @@ def create_ssh_client(host):
     client = SSHClient()
     client.load_system_host_keys()
     try:
-        client.connect(host)
+        client.connect(host, password=password)
+    except PasswordRequiredException:
+        password = getpass("SSH password: ")
+        return create_ssh_client(host, password)
+    except AuthenticationException:
+        log.error(_("SSH authentication failed."))
+        exit(1)
     except SSHException:
         log.error(_("An error occured during SSH connection, debug with -vv"))
         raise
-- 
GitLab