Skip to content
Snippets Groups Projects
Verified Commit 46a80fe4 authored by me5na7qbjqbrp's avatar me5na7qbjqbrp
Browse files

Add SSH password prompt

parent 5865912d
No related branches found
No related tags found
No related merge requests found
Pipeline #3115 passed with warnings with stages
in 3 minutes and 20 seconds
...@@ -9,11 +9,12 @@ SPDX-License-Identifier: GPL-3.0-or-later ...@@ -9,11 +9,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
""" """
from functools import lru_cache from functools import lru_cache
from getpass import getpass
import json import json
import logging import logging
from paramiko.client import SSHClient from paramiko.client import SSHClient
from paramiko.ssh_exception import SSHException from paramiko.ssh_exception import SSHException, PasswordRequiredException, AuthenticationException
from .locale import _ from .locale import _
...@@ -22,7 +23,7 @@ log = logging.getLogger(__name__) ...@@ -22,7 +23,7 @@ log = logging.getLogger(__name__)
@lru_cache() @lru_cache()
def create_ssh_client(host): def create_ssh_client(host, password=None):
""" """
Create a SSH client with paramiko module Create a SSH client with paramiko module
""" """
...@@ -30,7 +31,13 @@ def create_ssh_client(host): ...@@ -30,7 +31,13 @@ def create_ssh_client(host):
client = SSHClient() client = SSHClient()
client.load_system_host_keys() client.load_system_host_keys()
try: 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: except SSHException:
log.error(_("An error occured during SSH connection, debug with -vv")) log.error(_("An error occured during SSH connection, debug with -vv"))
raise raise
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment