Skip to content

Commit c16b1d6

Browse files
committed
Added AuthKey Authentication
1 parent 0b74f09 commit c16b1d6

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

jupyter_trame_proxy/__init__.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,54 @@
11
import os
2+
import secrets
3+
from tempfile import mkstemp
24
import logging
35

6+
47
logger = logging.getLogger(__name__)
5-
logger.setLevel('INFO')
8+
logger.setLevel("INFO")
69

710
HERE = os.path.dirname(os.path.abspath(__file__))
811

912

1013
def _trame_mappath(path):
14+
# Append authKey to URL if we are at the base-url
15+
if path in ("/", "/index.html"):
16+
path += f"?secret={_auth_key}"
17+
1118
return path
1219

1320

1421
def setup_trame():
15-
""" Setup commands and and return a dictionary compatible
16-
with jupyter-server-proxy.
17-
"""
22+
# Generate authKey
23+
global _auth_key
24+
_auth_key = secrets.token_urlsafe(32)
25+
26+
# Write authKey to tempfile
27+
tempfile, temppath = mkstemp()
28+
logger.info(f"Created tempfile with secure password for trame at {temppath}")
1829

19-
# create command
30+
with open(tempfile, "w") as file:
31+
file.write(_auth_key)
32+
33+
# Create command
2034
cmd = [
21-
os.path.join(HERE, 'share/launch_trame.sh'), "{port}"
35+
os.path.join(HERE, "share/launch_trame.sh"),
36+
"{port}",
37+
"--authKeyFile",
38+
temppath,
2239
]
23-
24-
logger.info('Command: ' + ' '.join(cmd))
40+
41+
logger.info(f"jupyter-trame-proxy command: {' '.join(cmd)}")
2542

2643
return {
27-
'command': cmd,
28-
'mappath': _trame_mappath,
29-
'absolute_url': False,
30-
'timeout': 90,
31-
'new_browser_tab': True,
32-
'launcher_entry': {
33-
'enabled': True,
34-
'icon_path': os.path.join(HERE, 'icons/logo.svg'),
35-
'title': 'ParaView trame',
44+
"command": cmd,
45+
"mappath": _trame_mappath,
46+
"absolute_url": False,
47+
"timeout": 90,
48+
"new_browser_tab": True,
49+
"launcher_entry": {
50+
"enabled": True,
51+
"icon_path": os.path.join(HERE, "icons/logo.svg"),
52+
"title": "ParaView trame",
3653
},
3754
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/bin/bash
2+
# ================================================================
3+
# Launches ParaView trame after loading the required Modules
4+
#
5+
# Usage: launch_trame.sh PORT [args]
6+
# ================================================================
27

38
# If you need to modify the envoronment before you launch pv_visualizer, do it here!
4-
59
# Example:
610
# module purge
711
# module load Stages/2022
@@ -10,4 +14,8 @@
1014
# module load trame
1115
# module load ParaView/5.10.1-EGL
1216

13-
python -c "from pv_visualizer.app.main import main; main(port=$1, open_browser=False, timeout=0)"
17+
# Pop Port from the Arguments
18+
port=$1
19+
shift
20+
21+
python -c "from pv_visualizer.app.main import main; main(port=$port, open_browser=False, timeout=0)" "$@"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
jupyter-server-proxy>=1.5
22
trame
33
pv-visualizer>=0.1.2
4+
pv-server>=2.6.0

0 commit comments

Comments
 (0)