Skip to content

Commit 40a8732

Browse files
committed
add extra parameter
1 parent 9f6f5f0 commit 40a8732

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

jupyter_nestdesktop_proxy/__init__.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,20 @@ def get_nestdesktop_executable(prog):
3131

3232
raise FileNotFoundError(f'Could not find {prog} in PATH')
3333

34+
def _nestdesktop_urlparams():
35+
36+
url_params = '?' + '&'.join([
37+
'token=' + _nestsrv_token,
38+
])
39+
40+
return url_params
3441

3542
def _nestdesktop_mappath(path):
3643

3744
# always pass the url parameter
3845
if path in ('/', '/index.html', ):
39-
path = '/index.html'
46+
url_params = _nestdesktop_urlparams()
47+
path = '/index.html' + url_params
4048

4149
return path
4250

@@ -45,16 +53,50 @@ def setup_nestdesktop():
4553
""" Setup commands and and return a dictionary compatible
4654
with jupyter-server-proxy.
4755
"""
56+
from tempfile import mkstemp
57+
from random import choice
58+
from string import ascii_letters, digits
59+
60+
global _nestsrv_url, _nestsrv_token
61+
62+
# password generator
63+
def _get_random_alphanumeric_string(length):
64+
letters_and_digits = ascii_letters + digits
65+
return (''.join((choice(letters_and_digits) for i in range(length))))
66+
67+
_nestsrv_token = _get_random_alphanumeric_string(16)
68+
try:
69+
fd_nestsrv_token, fpath_nestsrv_token = mkstemp()
70+
logger.info('Created secure token file for NEST Server: ' + fpath_nestsrv_token)
71+
72+
with open(fd_nestsrv_token, 'w') as f:
73+
f.write(_nestsrv_token)
74+
75+
except Exception:
76+
logger.error("Passwd generation in temp file FAILED")
77+
raise FileNotFoundError("Passwd generation in temp file FAILED")
4878

4979
# launchers url file including url parameters
50-
path_info = 'nestdesktop/index.html'
80+
path_info = 'nestdesktop/index.html' + _nestdesktop_urlparams()
81+
82+
# check for a free port
83+
#import socket
84+
#s=socket.socket()
85+
#s.bind(("", 0))
86+
#nestsrv_port = s.getsockname()[1]
87+
#s.close()
88+
nestsrv_port = 52425
5189

5290
# create command
5391
cmd = [
5492
get_nestdesktop_executable('nest-desktop'),
5593
'start',
5694
'-h', 'localhost',
5795
'-p', '{port}',
96+
'--srv-start',
97+
'--srv-auth', 'file:filename=' + fpath_nestsrv_token,
98+
'--srv-port', str(nestsrv_port),
99+
# '--srv-log' nestsrv_logfile # default: /tmp/nest-server-$USER-$$.log
58100
]
59101
logger.info('NEST Desktop command: ' + ' '.join(cmd))
60102

0 commit comments

Comments
 (0)