@@ -31,12 +31,20 @@ def get_nestdesktop_executable(prog):
31
31
32
32
raise FileNotFoundError (f'Could not find { prog } in PATH' )
33
33
34
+ def _nestdesktop_urlparams ():
35
+
36
+ url_params = '?' + '&' .join ([
37
+ 'token=' + _nestsrv_token ,
38
+ ])
39
+
40
+ return url_params
34
41
35
42
def _nestdesktop_mappath (path ):
36
43
37
44
# always pass the url parameter
38
45
if path in ('/' , '/index.html' , ):
39
- path = '/index.html'
46
+ url_params = _nestdesktop_urlparams ()
47
+ path = '/index.html' + url_params
40
48
41
49
return path
42
50
@@ -45,16 +53,50 @@ def setup_nestdesktop():
45
53
""" Setup commands and and return a dictionary compatible
46
54
with jupyter-server-proxy.
47
55
"""
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" )
48
78
49
79
# 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
51
89
52
90
# create command
53
91
cmd = [
54
92
get_nestdesktop_executable ('nest-desktop' ),
55
93
'start' ,
56
94
'-h' , 'localhost' ,
57
95
'-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
58
100
]
59
101
logger .info ('NEST Desktop command: ' + ' ' .join (cmd ))
60
102
0 commit comments