Skip to content
Snippets Groups Projects
Commit fbd252532ab7 authored by Noah Pederson's avatar Noah Pederson
Browse files

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.
parent 93049b53913d
No related branches found
No related tags found
No related merge requests found
...@@ -237,6 +237,7 @@ ...@@ -237,6 +237,7 @@
gss_trust_dns=True, gss_trust_dns=True,
passphrase=None, passphrase=None,
disabled_algorithms=None, disabled_algorithms=None,
transport_factory=Transport,
): ):
""" """
Connect to an SSH server and authenticate to it. The server's host key Connect to an SSH server and authenticate to it. The server's host key
...@@ -314,6 +315,10 @@ ...@@ -314,6 +315,10 @@
:param dict disabled_algorithms: :param dict disabled_algorithms:
an optional dict passed directly to `.Transport` and its keyword an optional dict passed directly to `.Transport` and its keyword
argument of the same name. 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: :raises:
`.BadHostKeyException` -- if the server's host key could not be `.BadHostKeyException` -- if the server's host key could not be
...@@ -371,7 +376,7 @@ ...@@ -371,7 +376,7 @@
if len(errors) == len(to_try): if len(errors) == len(to_try):
raise NoValidConnectionsError(errors) raise NoValidConnectionsError(errors)
t = self._transport = Transport( t = self._transport = transport_factory(
sock, sock,
gss_kex=gss_kex, gss_kex=gss_kex,
gss_deleg_creds=gss_deleg_creds, gss_deleg_creds=gss_deleg_creds,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment