mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
pre-commit: run black with string normalization
This commit is contained in:
@@ -17,50 +17,50 @@ from .yaml import yaml
|
||||
# Default configuration for tljh
|
||||
# User provided config is merged into this
|
||||
default = {
|
||||
'base_url': '/',
|
||||
'auth': {
|
||||
'type': 'firstuseauthenticator.FirstUseAuthenticator',
|
||||
'FirstUseAuthenticator': {'create_users': False},
|
||||
"base_url": "/",
|
||||
"auth": {
|
||||
"type": "firstuseauthenticator.FirstUseAuthenticator",
|
||||
"FirstUseAuthenticator": {"create_users": False},
|
||||
},
|
||||
'users': {'allowed': [], 'banned': [], 'admin': [], 'extra_user_groups': {}},
|
||||
'limits': {
|
||||
'memory': None,
|
||||
'cpu': None,
|
||||
"users": {"allowed": [], "banned": [], "admin": [], "extra_user_groups": {}},
|
||||
"limits": {
|
||||
"memory": None,
|
||||
"cpu": None,
|
||||
},
|
||||
'http': {
|
||||
'port': 80,
|
||||
"http": {
|
||||
"port": 80,
|
||||
},
|
||||
'https': {
|
||||
'enabled': False,
|
||||
'port': 443,
|
||||
'tls': {
|
||||
'cert': '',
|
||||
'key': '',
|
||||
"https": {
|
||||
"enabled": False,
|
||||
"port": 443,
|
||||
"tls": {
|
||||
"cert": "",
|
||||
"key": "",
|
||||
},
|
||||
'letsencrypt': {
|
||||
'email': '',
|
||||
'domains': [],
|
||||
"letsencrypt": {
|
||||
"email": "",
|
||||
"domains": [],
|
||||
},
|
||||
},
|
||||
'traefik_api': {
|
||||
'ip': "127.0.0.1",
|
||||
'port': 8099,
|
||||
'username': 'api_admin',
|
||||
'password': '',
|
||||
"traefik_api": {
|
||||
"ip": "127.0.0.1",
|
||||
"port": 8099,
|
||||
"username": "api_admin",
|
||||
"password": "",
|
||||
},
|
||||
'user_environment': {
|
||||
'default_app': 'classic',
|
||||
"user_environment": {
|
||||
"default_app": "classic",
|
||||
},
|
||||
'services': {
|
||||
'cull': {
|
||||
'enabled': True,
|
||||
'timeout': 600,
|
||||
'every': 60,
|
||||
'concurrency': 5,
|
||||
'users': False,
|
||||
'max_age': 0,
|
||||
"services": {
|
||||
"cull": {
|
||||
"enabled": True,
|
||||
"timeout": 600,
|
||||
"every": 60,
|
||||
"concurrency": 5,
|
||||
"users": False,
|
||||
"max_age": 0,
|
||||
},
|
||||
'configurator': {'enabled': False},
|
||||
"configurator": {"enabled": False},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -109,14 +109,14 @@ def set_if_not_none(parent, key, value):
|
||||
|
||||
def load_traefik_api_credentials():
|
||||
"""Load traefik api secret from a file"""
|
||||
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):
|
||||
return {}
|
||||
with open(proxy_secret_path) as f:
|
||||
password = f.read()
|
||||
return {
|
||||
'traefik_api': {
|
||||
'password': password,
|
||||
"traefik_api": {
|
||||
"password": password,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ def update_base_url(c, config):
|
||||
"""
|
||||
Update base_url of JupyterHub through tljh config
|
||||
"""
|
||||
c.JupyterHub.base_url = config['base_url']
|
||||
c.JupyterHub.base_url = config["base_url"]
|
||||
|
||||
|
||||
def update_auth(c, config):
|
||||
@@ -172,13 +172,13 @@ def update_auth(c, config):
|
||||
c.JupyterHub.authenticator_class and any configured value being None won't
|
||||
be set.
|
||||
"""
|
||||
tljh_auth_config = config['auth']
|
||||
tljh_auth_config = config["auth"]
|
||||
|
||||
c.JupyterHub.authenticator_class = tljh_auth_config['type']
|
||||
c.JupyterHub.authenticator_class = tljh_auth_config["type"]
|
||||
|
||||
for auth_key, auth_value in tljh_auth_config.items():
|
||||
if not (auth_key[0] == auth_key[0].upper() and isinstance(auth_value, dict)):
|
||||
if auth_key == 'type':
|
||||
if auth_key == "type":
|
||||
continue
|
||||
raise ValueError(
|
||||
f"Error: auth.{auth_key} was ignored, it didn't look like a valid configuration"
|
||||
@@ -194,75 +194,75 @@ def update_userlists(c, config):
|
||||
"""
|
||||
Set user whitelists & admin lists
|
||||
"""
|
||||
users = config['users']
|
||||
users = config["users"]
|
||||
|
||||
c.Authenticator.allowed_users = set(users['allowed'])
|
||||
c.Authenticator.blocked_users = set(users['banned'])
|
||||
c.Authenticator.admin_users = set(users['admin'])
|
||||
c.Authenticator.allowed_users = set(users["allowed"])
|
||||
c.Authenticator.blocked_users = set(users["banned"])
|
||||
c.Authenticator.admin_users = set(users["admin"])
|
||||
|
||||
|
||||
def update_usergroups(c, config):
|
||||
"""
|
||||
Set user groups
|
||||
"""
|
||||
users = config['users']
|
||||
c.UserCreatingSpawner.user_groups = users['extra_user_groups']
|
||||
users = config["users"]
|
||||
c.UserCreatingSpawner.user_groups = users["extra_user_groups"]
|
||||
|
||||
|
||||
def update_limits(c, config):
|
||||
"""
|
||||
Set user server limits
|
||||
"""
|
||||
limits = config['limits']
|
||||
limits = config["limits"]
|
||||
|
||||
c.Spawner.mem_limit = limits['memory']
|
||||
c.Spawner.cpu_limit = limits['cpu']
|
||||
c.Spawner.mem_limit = limits["memory"]
|
||||
c.Spawner.cpu_limit = limits["cpu"]
|
||||
|
||||
|
||||
def update_user_environment(c, config):
|
||||
"""
|
||||
Set user environment configuration
|
||||
"""
|
||||
user_env = config['user_environment']
|
||||
user_env = config["user_environment"]
|
||||
|
||||
# Set default application users are launched into
|
||||
if user_env['default_app'] == 'jupyterlab':
|
||||
c.Spawner.default_url = '/lab'
|
||||
elif user_env['default_app'] == 'nteract':
|
||||
c.Spawner.default_url = '/nteract'
|
||||
if user_env["default_app"] == "jupyterlab":
|
||||
c.Spawner.default_url = "/lab"
|
||||
elif user_env["default_app"] == "nteract":
|
||||
c.Spawner.default_url = "/nteract"
|
||||
|
||||
|
||||
def update_user_account_config(c, config):
|
||||
c.SystemdSpawner.username_template = 'jupyter-{USERNAME}'
|
||||
c.SystemdSpawner.username_template = "jupyter-{USERNAME}"
|
||||
|
||||
|
||||
def update_traefik_api(c, config):
|
||||
"""
|
||||
Set traefik api endpoint credentials
|
||||
"""
|
||||
c.TraefikTomlProxy.traefik_api_username = config['traefik_api']['username']
|
||||
c.TraefikTomlProxy.traefik_api_password = config['traefik_api']['password']
|
||||
c.TraefikTomlProxy.traefik_api_username = config["traefik_api"]["username"]
|
||||
c.TraefikTomlProxy.traefik_api_password = config["traefik_api"]["password"]
|
||||
|
||||
|
||||
def set_cull_idle_service(config):
|
||||
"""
|
||||
Set Idle Culler service
|
||||
"""
|
||||
cull_cmd = [sys.executable, '-m', 'jupyterhub_idle_culler']
|
||||
cull_config = config['services']['cull']
|
||||
cull_cmd = [sys.executable, "-m", "jupyterhub_idle_culler"]
|
||||
cull_config = config["services"]["cull"]
|
||||
print()
|
||||
|
||||
cull_cmd += ['--timeout=%d' % cull_config['timeout']]
|
||||
cull_cmd += ['--cull-every=%d' % cull_config['every']]
|
||||
cull_cmd += ['--concurrency=%d' % cull_config['concurrency']]
|
||||
cull_cmd += ['--max-age=%d' % cull_config['max_age']]
|
||||
if cull_config['users']:
|
||||
cull_cmd += ['--cull-users']
|
||||
cull_cmd += ["--timeout=%d" % cull_config["timeout"]]
|
||||
cull_cmd += ["--cull-every=%d" % cull_config["every"]]
|
||||
cull_cmd += ["--concurrency=%d" % cull_config["concurrency"]]
|
||||
cull_cmd += ["--max-age=%d" % cull_config["max_age"]]
|
||||
if cull_config["users"]:
|
||||
cull_cmd += ["--cull-users"]
|
||||
|
||||
cull_service = {
|
||||
'name': 'cull-idle',
|
||||
'admin': True,
|
||||
'command': cull_cmd,
|
||||
"name": "cull-idle",
|
||||
"admin": True,
|
||||
"command": cull_cmd,
|
||||
}
|
||||
|
||||
return cull_service
|
||||
@@ -280,9 +280,9 @@ def set_configurator(config):
|
||||
f"--Configurator.config_file={HERE}/jupyterhub_configurator_config.py",
|
||||
]
|
||||
configurator_service = {
|
||||
'name': 'configurator',
|
||||
'url': 'http://127.0.0.1:10101',
|
||||
'command': configurator_cmd,
|
||||
"name": "configurator",
|
||||
"url": "http://127.0.0.1:10101",
|
||||
"command": configurator_cmd,
|
||||
}
|
||||
|
||||
return configurator_service
|
||||
@@ -291,9 +291,9 @@ def set_configurator(config):
|
||||
def update_services(c, config):
|
||||
c.JupyterHub.services = []
|
||||
|
||||
if config['services']['cull']['enabled']:
|
||||
if config["services"]["cull"]["enabled"]:
|
||||
c.JupyterHub.services.append(set_cull_idle_service(config))
|
||||
if config['services']['configurator']['enabled']:
|
||||
if config["services"]["configurator"]["enabled"]:
|
||||
c.JupyterHub.services.append(set_configurator(config))
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ def _merge_dictionaries(a, b, path=None, update=True):
|
||||
elif update:
|
||||
a[key] = b[key]
|
||||
else:
|
||||
raise Exception('Conflict at %s' % '.'.join(path + [str(key)]))
|
||||
raise Exception("Conflict at %s" % ".".join(path + [str(key)]))
|
||||
else:
|
||||
a[key] = b[key]
|
||||
return a
|
||||
|
||||
Reference in New Issue
Block a user