mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Switch from JSON to py
This commit is contained in:
@@ -1,143 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Littlest JupyterHub YAML config file",
|
||||
"definitions": {
|
||||
"Users": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"extra_user_groups": {
|
||||
"type": "object",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"allowed": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"banned": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"admin": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"HTTP": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"address": {
|
||||
"type": "string",
|
||||
"format": "ipv4"
|
||||
},
|
||||
"port": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"HTTPS": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"address": {
|
||||
"type": "string",
|
||||
"format": "ipv4"
|
||||
},
|
||||
"port": {
|
||||
"type": "integer"
|
||||
},
|
||||
"tls": {
|
||||
"$ref": "#/definitions/TLS"
|
||||
},
|
||||
"letsencrypt": {
|
||||
"$ref": "#/definitions/LetsEncrypt"
|
||||
}
|
||||
}
|
||||
},
|
||||
"LetsEncrypt": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string",
|
||||
"format": "email"
|
||||
},
|
||||
"domains": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "hostname"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"TLS": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"key": {
|
||||
"type": "string"
|
||||
},
|
||||
"cert": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["key", "cert"]
|
||||
},
|
||||
"Limits": {
|
||||
"description": "User CPU and memory limits.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"memory": {
|
||||
"type": "string"
|
||||
},
|
||||
"cpu": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"UserEnvironment": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"default_app": {
|
||||
"type": "string",
|
||||
"enum": ["jupyterlab", "classic"],
|
||||
"default": "jupyterlab"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"additionalProperties": false,
|
||||
"user_environment": {
|
||||
"$ref": "#/definitions/UserEnvironment"
|
||||
},
|
||||
"users": {
|
||||
"$ref": "#/definitions/Users"
|
||||
},
|
||||
"limits": {
|
||||
"$ref": "#/definitions/Limits"
|
||||
},
|
||||
"https": {
|
||||
"$ref": "#/definitions/HTTPS"
|
||||
},
|
||||
"http": {
|
||||
"$ref": "#/definitions/HTTP"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,14 +155,8 @@ def remove_item_from_config(config, property_path, value):
|
||||
|
||||
|
||||
def validate_config(config):
|
||||
import json
|
||||
|
||||
import jsonschema
|
||||
|
||||
pd = os.path.abspath(os.path.join(__file__, os.pardir))
|
||||
config_schema_file = os.path.join(pd, "config-schema.json")
|
||||
with open(config_schema_file) as f:
|
||||
config_schema = json.load(f)
|
||||
from config_schema import config_schema
|
||||
|
||||
try:
|
||||
jsonschema.validate(instance=config, schema=config_schema)
|
||||
@@ -314,7 +308,7 @@ def parse_value(value_str):
|
||||
return float(value_str)
|
||||
elif value_str.lower() == "true":
|
||||
return True
|
||||
elif value_str.lower() == "false":
|
||||
elif value_str.lower() == "False":
|
||||
return False
|
||||
else:
|
||||
# it's a string
|
||||
|
||||
77
tljh/config_schema.py
Normal file
77
tljh/config_schema.py
Normal file
@@ -0,0 +1,77 @@
|
||||
config_schema = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Littlest JupyterHub YAML config file",
|
||||
"definitions": {
|
||||
"Users": {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"properties": {
|
||||
"extra_user_groups": {"type": "object", "items": {"type": "string"}},
|
||||
"allowed": {"type": "array", "items": {"type": "string"}},
|
||||
"banned": {"type": "array", "items": {"type": "string"}},
|
||||
"admin": {"type": "array", "items": {"type": "string"}},
|
||||
},
|
||||
},
|
||||
"HTTP": {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"properties": {
|
||||
"address": {"type": "string", "format": "ipv4"},
|
||||
"port": {"type": "integer"},
|
||||
},
|
||||
},
|
||||
"HTTPS": {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"properties": {
|
||||
"enabled": {"type": "boolean"},
|
||||
"address": {"type": "string", "format": "ipv4"},
|
||||
"port": {"type": "integer"},
|
||||
"tls": {"$ref": "#/definitions/TLS"},
|
||||
"letsencrypt": {"$ref": "#/definitions/LetsEncrypt"},
|
||||
},
|
||||
},
|
||||
"LetsEncrypt": {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"properties": {
|
||||
"email": {"type": "string", "format": "email"},
|
||||
"domains": {
|
||||
"type": "array",
|
||||
"items": {"type": "string", "format": "hostname"},
|
||||
},
|
||||
},
|
||||
},
|
||||
"TLS": {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"properties": {"key": {"type": "string"}, "cert": {"type": "string"}},
|
||||
"required": ["key", "cert"],
|
||||
},
|
||||
"Limits": {
|
||||
"description": "User CPU and memory limits.",
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"properties": {"memory": {"type": "string"}, "cpu": {"type": "integer"}},
|
||||
},
|
||||
"UserEnvironment": {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"properties": {
|
||||
"default_app": {
|
||||
"type": "string",
|
||||
"enum": ["jupyterlab", "classic"],
|
||||
"default": "jupyterlab",
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
"properties": {
|
||||
"additionalProperties": False,
|
||||
"user_environment": {"$ref": "#/definitions/UserEnvironment"},
|
||||
"users": {"$ref": "#/definitions/Users"},
|
||||
"limits": {"$ref": "#/definitions/Limits"},
|
||||
"https": {"$ref": "#/definitions/HTTPS"},
|
||||
"http": {"$ref": "#/definitions/HTTP"},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user