mirror of
https://github.com/clearml/clearml
synced 2025-02-07 21:33:25 +00:00
Add support for password protected jupyter using sdk.development.jupyter_server_password configuration option
This commit is contained in:
parent
80d3a02f4e
commit
643bc3d3ea
@ -482,9 +482,28 @@ class ScriptInfo(object):
|
|||||||
server_info = None
|
server_info = None
|
||||||
if server_info:
|
if server_info:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
cookies = None
|
||||||
|
password = None
|
||||||
|
if server_info and server_info.get('password'):
|
||||||
|
# we need to get the password
|
||||||
|
from ....config import config
|
||||||
|
password = config.get('development.jupyter_server_password', '')
|
||||||
|
if not password:
|
||||||
|
_logger.warning(
|
||||||
|
'Password protected Jupyter Notebook server was found! '
|
||||||
|
'Add `sdk.development.jupyter_server_password=<jupyter_password>` to ~/clearml.conf')
|
||||||
|
return os.path.join(os.getcwd(), 'error_notebook_not_found.py')
|
||||||
|
|
||||||
|
r = requests.get(url=server_info['url'] + 'login')
|
||||||
|
cookies = {'_xsrf': r.cookies.get('_xsrf', '')}
|
||||||
|
r = requests.post(server_info['url'] + 'login?next', cookies=cookies,
|
||||||
|
data={'_xsrf': cookies['_xsrf'], 'password': password})
|
||||||
|
cookies.update(r.cookies)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
url=server_info['url'] + 'api/sessions',
|
url=server_info['url'] + 'api/sessions', cookies=cookies,
|
||||||
headers={'Authorization': 'token {}'.format(server_info.get('token', '')), })
|
headers={'Authorization': 'token {}'.format(server_info.get('token', '')), })
|
||||||
except requests.exceptions.SSLError:
|
except requests.exceptions.SSLError:
|
||||||
# disable SSL check warning
|
# disable SSL check warning
|
||||||
@ -493,7 +512,7 @@ class ScriptInfo(object):
|
|||||||
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
||||||
# fire request
|
# fire request
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
url=server_info['url'] + 'api/sessions',
|
url=server_info['url'] + 'api/sessions', cookies=cookies,
|
||||||
headers={'Authorization': 'token {}'.format(server_info.get('token', '')), }, verify=False)
|
headers={'Authorization': 'token {}'.format(server_info.get('token', '')), }, verify=False)
|
||||||
# enable SSL check warning
|
# enable SSL check warning
|
||||||
import warnings
|
import warnings
|
||||||
@ -503,10 +522,8 @@ class ScriptInfo(object):
|
|||||||
try:
|
try:
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
_logger.warning('Failed accessing the jupyter server: {}'.format(ex))
|
_logger.warning('Failed accessing the jupyter server{}: {}'.format(
|
||||||
if server_info.get('password'):
|
' [password={}]'.format(password) if server_info.get('password') else '', ex))
|
||||||
_logger.warning('Password protected Jupyter Notebook is not supported, '
|
|
||||||
'please use token based access')
|
|
||||||
return os.path.join(os.getcwd(), 'error_notebook_not_found.py')
|
return os.path.join(os.getcwd(), 'error_notebook_not_found.py')
|
||||||
|
|
||||||
notebooks = r.json()
|
notebooks = r.json()
|
||||||
|
Loading…
Reference in New Issue
Block a user