Skip to content
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

✨ Update authentication scheme #51

Merged
merged 2 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions jupyter_forward/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass

import invoke
import paramiko
from fabric import Connection


Expand Down Expand Up @@ -45,11 +46,14 @@ def __post_init__(self):
connect_kwargs = {}
if self.identity:
connect_kwargs['key_filename'] = [self.identity]
else:
connect_kwargs['password'] = getpass.getpass()

self.session = Connection(self.host, connect_kwargs=connect_kwargs, forward_agent=True)
self.session.open()
try:
self.session.open()
except paramiko.ssh_exception.BadAuthenticationType:
loc_transport = self.session.client.get_transport()
loc_transport.auth_interactive_dumb(self.session.user, _authentication_handler)
self.session.transport = loc_transport

def dir_exists(self, directory):
"""
Expand Down Expand Up @@ -228,3 +232,13 @@ def parse_stdout(stdout: str):
token = result.query.split('token=')[-1].strip()
break
return {'hostname': hostname, 'port': port, 'token': token, 'url': url}


def _authentication_handler(title, instructions, prompt_list):
"""
Handler for paramiko auth_interactive_dumb
"""
resp = []
for pr in prompt_list:
resp.append(getpass.getpass(str(pr[0])))
return resp
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extend-ignore = E203,E501,E402,W605

[isort]
known_first_party=jupyter_forward
known_third_party=fabric,invoke,pkg_resources,pytest,setuptools,typer
known_third_party=fabric,invoke,paramiko,pkg_resources,pytest,setuptools,typer
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
Expand Down