lib.ec.ssh.Paramiko: Support Caps.Env

Add support for modifying the execution environment via the env
parameter to Paramiko.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-18 14:12:34 +02:00 committed by janware DevOps
commit 2851ef8f42

View file

@ -12,8 +12,13 @@ from .util import join_cmd
class Paramiko(Base):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
def __init__(self, uri, *args, **kwargs) -> None:
super().__init__(
uri,
*args,
caps = self.Caps.Env,
**kwargs
)
self.__timeout: float|None = None # Untested
self.___ssh: Any|None = None
@ -44,9 +49,25 @@ class Paramiko(Base):
def __scp(self):
return SCPClient(self.__ssh.get_transport())
async def _run_ssh(self, cmd: list[str], cmd_input: bytes|None, *args, **kwargs) -> Result:
async def _run_ssh(
self,
cmd: list[str],
wd: str | None,
verbose: bool,
cmd_input: str | None,
env: dict[str, str] | None,
interactive: bool,
log_prefix: str,
) -> Result:
try:
stdin, stdout, stderr = self.__ssh.exec_command(join_cmd(cmd), timeout=self.__timeout)
kwargs: [str, Any] = {}
if env is not None:
kwargs['environment'] = env
stdin, stdout, stderr = self.__ssh.exec_command(
join_cmd(cmd),
timeout=self.__timeout,
**kwargs,
)
except Exception as e:
log(ERR, f'Command failed for {self.uri}: "{join_cmd(cmd)}"')
raise