Skip to content

Commit

Permalink
✨ Update authentication scheme (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlevy1981 authored Dec 3, 2020
1 parent 7cfb127 commit a11177e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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

0 comments on commit a11177e

Please sign in to comment.