mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
lib.ec.ssh.Exec: Support Caps.Env
Add support for modifying the execution environment via the env parameter to Exec. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
6cdcd23010
commit
3574c0f1bf
1 changed files with 21 additions and 4 deletions
|
|
@ -12,10 +12,14 @@ if TYPE_CHECKING:
|
|||
|
||||
class Exec(Base):
|
||||
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
def __init__(self, uri, *args, **kwargs) -> None:
|
||||
self.__askpass: str|None = None
|
||||
self.__askpass_orig: dict[str, str|None] = dict()
|
||||
super().__init__(*args, **kwargs)
|
||||
super().__init__(
|
||||
uri = uri,
|
||||
caps = self.Caps.Env,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def __del__(self):
|
||||
for key, val in self.__askpass_orig.items():
|
||||
|
|
@ -39,8 +43,21 @@ class Exec(Base):
|
|||
self.__askpass_orig[key] = os.getenv(key)
|
||||
os.environ[key] = val
|
||||
|
||||
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: bytes|None,
|
||||
env: dict[str, str]|None,
|
||||
interactive: bool,
|
||||
log_prefix: str
|
||||
) -> Result:
|
||||
self.__init_askpass()
|
||||
if cmd_input is None:
|
||||
cmd_input = InputMode.Interactive if self.interactive else InputMode.NonInteractive
|
||||
return await run_cmd(['ssh', self.hostname, join_cmd(cmd)], cmd_input=cmd_input, throw=False)
|
||||
opts: dict[str, str] = []
|
||||
if env:
|
||||
for key, val in env.items():
|
||||
opts.extend(['-o', f'SetEnv {key}="{val}"'])
|
||||
return await run_cmd(['ssh', *opts, self.hostname, join_cmd(cmd)], cmd_input=cmd_input, throw=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue