-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add attributes to a SSHClient
subclass
#731
Comments
You should be able to do something like: class SSH2FAClient(asyncssh.SSHClient):
def __init__(self, secret_path: str):
super.__init__()
self._secret_path = secret_path
async def kbdint_auth_requested(self):
return ""
async def kbdint_challenge_received(
self, name: str, instructions: str, lang: str, prompts
):
...
connection = await asyncssh.connect(
...
client_factory=SSH2FAClient(secret_path),
...
) You can then use Note that there's also a |
Sorry about the confusion. That The issue is that Traceback (most recent call last):
File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/home/ubuntu/venv/lib/python3.10/site-packages/asyncssh/connection.py", line 1368, in connection_made
self._owner = self._protocol_factory()
TypeError: 'SSH2FAClient' object is not callable I resolved this by wrapping the connection = await asyncssh.connect(
...
client_factory=lambda: SSH2FAClient(secret_path),
...
) Thanks a lot for the help. |
Ah, yes - I got that wrong in my example. Using "lambda" works well in this case, but |
Hi,
I am trying to automate the login to a server that requires 2FA.
I have the secret, which is saved on a file, and I can generate the token with the TOTP algorithm.
I saw discussion #514 and implemented a custom
SSHClient
that overrides thekbdint_challenge_received
andkbdint_auth_requested
methods.It works. Now, I want to parameterize the class and remove the hard-coded secret's file path. How can I do this?
I saw that the
SSHClient
is created without parameters in the constructor.I tried to retrieve the path from the parameter of the
connection_made
method (i.e., theSSHClientConnection
instance).However, I did not find a way to do it using the
asyncssh.connect
method.The text was updated successfully, but these errors were encountered: