Adding update_base_url from tljh config

This commit is contained in:
Jean-Marc Alkazzi
2020-10-19 19:48:23 +02:00
committed by GeorgianaElena
parent e0d6d32a14
commit 66cd578d75
2 changed files with 16 additions and 3 deletions

View File

@@ -240,9 +240,12 @@ def remove_config_value(config_path, key_path, value):
def check_hub_ready(): def check_hub_ready():
from .configurer import load_config from .configurer import load_config
base_url = load_config()['base_url']
base_url = base_url[:-1] if base_url[-1] == '/' else base_url
http_port = load_config()['http']['port'] http_port = load_config()['http']['port']
try: try:
r = requests.get('http://127.0.0.1:%d/hub/api' % http_port, verify=False) r = requests.get('http://127.0.0.1:%d%s/hub/api' % (http_port, base_url), verify=False)
return r.status_code == 200 return r.status_code == 200
except: except:
return False return False

View File

@@ -17,6 +17,7 @@ from .yaml import yaml
# Default configuration for tljh # Default configuration for tljh
# User provided config is merged into this # User provided config is merged into this
default = { default = {
'base_url': '/',
'auth': { 'auth': {
'type': 'firstuseauthenticator.FirstUseAuthenticator', 'type': 'firstuseauthenticator.FirstUseAuthenticator',
'FirstUseAuthenticator': { 'FirstUseAuthenticator': {
@@ -69,6 +70,7 @@ default = {
} }
} }
def load_config(config_file=CONFIG_FILE): def load_config(config_file=CONFIG_FILE):
"""Load the current config as a dictionary """Load the current config as a dictionary
@@ -92,6 +94,7 @@ def apply_config(config_overrides, c):
""" """
tljh_config = _merge_dictionaries(dict(default), config_overrides) tljh_config = _merge_dictionaries(dict(default), config_overrides)
update_base_url(c, tljh_config)
update_auth(c, tljh_config) update_auth(c, tljh_config)
update_userlists(c, tljh_config) update_userlists(c, tljh_config)
update_usergroups(c, tljh_config) update_usergroups(c, tljh_config)
@@ -115,7 +118,7 @@ def load_traefik_api_credentials():
proxy_secret_path = os.path.join(STATE_DIR, 'traefik-api.secret') proxy_secret_path = os.path.join(STATE_DIR, 'traefik-api.secret')
if not os.path.exists(proxy_secret_path): if not os.path.exists(proxy_secret_path):
return {} return {}
with open(proxy_secret_path,'r') as f: with open(proxy_secret_path, 'r') as f:
password = f.read() password = f.read()
return { return {
'traefik_api': { 'traefik_api': {
@@ -134,6 +137,13 @@ def load_secrets():
return config return config
def update_base_url(c, config):
"""
Update base_url of JupyterHub through tljh config
"""
c.JupyterHub.base_url = config['base_url']
def update_auth(c, config): def update_auth(c, config):
""" """
Set auth related configuration from YAML config file Set auth related configuration from YAML config file
@@ -218,7 +228,7 @@ def set_cull_idle_service(config):
Set Idle Culler service Set Idle Culler service
""" """
cull_cmd = [ cull_cmd = [
sys.executable, '-m', 'jupyterhub_idle_culler' sys.executable, '-m', 'jupyterhub_idle_culler'
] ]
cull_config = config['services']['cull'] cull_config = config['services']['cull']
print() print()