From 166eba67351bcfe1a6bc34b7c9a657ab644b6250 Mon Sep 17 00:00:00 2001 From: Jordan Bradford <36420801+jrdnbradford@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:48:31 -0500 Subject: [PATCH] Switch from JSON to py --- tljh/config-schema.json | 143 ---------------------------------------- tljh/config.py | 10 +-- tljh/config_schema.py | 77 ++++++++++++++++++++++ 3 files changed, 79 insertions(+), 151 deletions(-) delete mode 100644 tljh/config-schema.json create mode 100644 tljh/config_schema.py diff --git a/tljh/config-schema.json b/tljh/config-schema.json deleted file mode 100644 index d983dc3..0000000 --- a/tljh/config-schema.json +++ /dev/null @@ -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" - } - } -} diff --git a/tljh/config.py b/tljh/config.py index 3dbbc87..09ee92e 100644 --- a/tljh/config.py +++ b/tljh/config.py @@ -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 diff --git a/tljh/config_schema.py b/tljh/config_schema.py new file mode 100644 index 0000000..b0595b3 --- /dev/null +++ b/tljh/config_schema.py @@ -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"}, + }, +}