lib.ec.SSHClient: Support JW_DEFAULT_SSH_CLIENT

Allow to configure via the environment which class ssh_client()
picks. Can currently be exec, asyncssh, paramiko or a comma-separated
search list. The list will be tried through until a class is found
that can be instantiated.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-17 17:37:11 +02:00
commit fd336ecdcf

View file

@ -130,9 +130,15 @@ class SSHClient(ExecContext):
def username(self) -> str:
return self.__username
def ssh_client(*args, type=['AsyncSSH', 'Paramiko', 'Exec'], **kwargs) -> SSHClient: # export
def ssh_client(*args, type: str|list[str]|None=None, **kwargs) -> SSHClient: # export
from importlib import import_module
errors: list[str] = []
if type is None:
val = os.getenv('JW_DEFAULT_SSH_CLIENT')
if val is not None:
type = val.split(',')
else:
type = ['AsyncSSH', 'Paramiko', 'Exec']
if isinstance(type, str):
type = [type]
for name in type: