From 3512397c14fccfa029df96c4c2f270de0d5d3130 Mon Sep 17 00:00:00 2001 From: Adam Cooper Date: Thu, 19 Jan 2023 15:14:23 -0600 Subject: [PATCH] Allow passthrough arguments for SSH connections (#37) This allows users to make more use of complex SSH configuration. The existing interface only allowed for direct connection to a single host. This made basic things like jump hosts inaccessible. Users can now pass through any keyword arguments accepted by [`fabric.Connection`](https://docs.fabfile.org/en/stable/api/connection.html) --- chi/ssh.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/chi/ssh.py b/chi/ssh.py index f15aa5a..498a055 100644 --- a/chi/ssh.py +++ b/chi/ssh.py @@ -5,15 +5,17 @@ class Remote(Connection): - def __init__(self, ip=None, server=None, user="cc"): + def __init__(self, ip=None, server=None, user="cc", **kwargs): if ip is None: if server is None: raise ValueError("ip or server must be provided.") ip = server.ip + if not kwargs.get("connect_kwargs"): + kwargs["connect_kwargs"] = {} key_filename = context.get("keypair_private_key") - connect_kwargs = {"key_filename": key_filename} - super(Remote, self).__init__(ip, user=user, connect_kwargs=connect_kwargs) + kwargs["connect_kwargs"].setdefault("key_filename", key_filename) + super(Remote, self).__init__(ip, user=user, **kwargs) # Default policy is to reject unknown hosts - for our use-case, # printing a warning is probably enough, given the host is almost # always guaranteed to be unknown.