lib.ec.SSHClient.ssh_client(): Add type parameter

ssh_client() tries a predefined order of client class implementations
until it finds a workable candidate. For testing all, it's desirable
to be able to target the exact class. Add a "type" parameter to
achieve that.

I'm aware that type is also a function. But the semantics look so
compelling to me that I'm using the variable name anyway.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-11 10:20:28 +02:00
commit a58220a131

View file

@ -129,10 +129,12 @@ class SSHClient(ExecContext):
def username(self) -> str: def username(self) -> str:
return self.__username return self.__username
def ssh_client(*args, **kwargs) -> SSHClient: # export def ssh_client(*args, type=['AsyncSSH', 'Paramiko', 'Exec'], **kwargs) -> SSHClient: # export
from importlib import import_module from importlib import import_module
errors: list[str] = [] errors: list[str] = []
for name in ['AsyncSSH', 'Paramiko', 'Exec']: if isinstance(type, str):
type = [type]
for name in type:
try: try:
ret = getattr(import_module(f'jw.pkg.lib.ec.ssh.{name}'), name)(*args, **kwargs) ret = getattr(import_module(f'jw.pkg.lib.ec.ssh.{name}'), name)(*args, **kwargs)
log(INFO, f'Using SSH-client "{name}"') log(INFO, f'Using SSH-client "{name}"')