diff options
author | Noah Pederson <noah.pederson@coldquanta.com> | 2022-10-07 10:13:55 -0500 |
---|---|---|
committer | Noah Pederson <noah.pederson@coldquanta.com> | 2022-10-07 10:18:07 -0500 |
commit | 4e7f7e8033b7ca4b2805beb33a1164881adaf80c (patch) | |
tree | c06e019b52b6798cb3bf528dcedc7379103db70f | |
parent | bba5b4ce1ee156e0f5aa685e80c9a172e607ff38 (diff) |
Allow Transport factory to SSHClient.connect
Adds a transport_factory argument to `SSHClient.connect` that allows you
to dynamically generate a Transport instance without, and therefore
modify inner connection parameters before a connection gets established.
This should address some of the issues in #2054 with minial changes to
the API and no changes to Transport while allowing for arbitrary control
over Transports API.
-rw-r--r-- | paramiko/client.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/paramiko/client.py b/paramiko/client.py index 92feaa1f..a866f8b6 100644 --- a/paramiko/client.py +++ b/paramiko/client.py @@ -237,6 +237,7 @@ class SSHClient(ClosingContextManager): gss_trust_dns=True, passphrase=None, disabled_algorithms=None, + transport_factory=Transport, ): """ Connect to an SSH server and authenticate to it. The server's host key @@ -314,6 +315,10 @@ class SSHClient(ClosingContextManager): :param dict disabled_algorithms: an optional dict passed directly to `.Transport` and its keyword argument of the same name. + :param transport_factory: an optional callable that takes in a new `socket` + `gss_kex`, `gss_deleg_creds`, `disabled_algorithms` and generates a + `.Transport` instance to be used by this client. Defaults to + `.Transport.__init__`. :raises: `.BadHostKeyException` -- if the server's host key could not be @@ -371,7 +376,7 @@ class SSHClient(ClosingContextManager): if len(errors) == len(to_try): raise NoValidConnectionsError(errors) - t = self._transport = Transport( + t = self._transport = transport_factory( sock, gss_kex=gss_kex, gss_deleg_creds=gss_deleg_creds, |