backend/source/conf.ts
2024-12-01 15:21:20 +01:00

353 lines
6.2 KiB
TypeScript

namespace _zeitbild.conf
{
/**
*/
const _schema : lib_plankton.conf.type_schema = {
"nullable": false,
"type": "object",
"properties": {
"version": {
"nullable": false,
"type": "integer",
"enum": [1]
},
"log": {
"nullable": false,
"type": "array",
"items": {
"anyOf": [
{
"type": "object",
"properties": {
"kind": {
"nullable": false,
"type": "string",
"enum": ["stdout"]
},
"data": {
"nullable": false,
"type": "object",
"properties": {
"threshold": {
"nullable": false,
"type": "string",
"enum": [
"debug",
"info",
"notice",
"warning",
"error"
],
"default": "info"
},
"format": {
"nullable": false,
"type": "string",
"enum": [
"human_readable",
"jsonl",
"jsonl_structured",
],
"default": "human_readable",
},
},
"required": [
]
}
}
}
]
},
"default": [
{
"kind": "stdout",
"data": {
"threshold": "info"
}
}
]
},
"server": {
"nullable": false,
"type": "object",
"properties": {
"address": {
"nullable": false,
"type": "string",
"default": "::"
},
"port": {
"nullable": false,
"type": "integer",
"default": 7845
}
},
"required": [
],
"additionalProperties": false,
"default": {
}
},
"database": {
"anyOf": [
{
"type": "object",
"properties": {
"kind": {
"nullable": false,
"type": "string",
"enum": ["sqlite"]
},
"data": {
"nullable": false,
"type": "object",
"properties": {
"path": {
"nullable": false,
"type": "string",
"default": "data.sqlite"
}
},
"required": [
],
"default": {}
}
},
"required": [
"kind"
]
},
{
"type": "object",
"properties": {
"kind": {
"nullable": false,
"type": "string",
"enum": ["postgresql"]
},
"data": {
"nullable": false,
"type": "object",
"properties": {
"host": {
"nullable": false,
"type": "string"
},
"port": {
"nullable": false,
"type": "integer",
"default": 5432
},
"username": {
"nullable": false,
"type": "string"
},
"password": {
"nullable": false,
"type": "string"
},
"schema": {
"nullable": false,
"type": "string"
}
},
"required": [
"host",
"username",
"password",
"scheme"
]
}
},
"required": [
"kind",
"data"
]
}
],
"default": {
"kind": "sqlite"
}
},
"session_management": {
"nullable": false,
"type": "object",
"properties": {
"in_memory": {
"nullable": false,
"type": "boolean",
"default": true
},
"drop_all_at_start": {
"nullable": false,
"type": "boolean",
"default": true
},
"lifetime": {
"nullable": false,
"type": "integer",
"default": 900
}
},
"required": [
],
"additionalProperties": false,
"default": {}
},
"authentication": {
"anyOf": [
{
"type": "object",
"properties": {
"kind": {
"nullable": false,
"type": "string",
"enum": ["internal"]
},
"data": {
"nullable": false,
"type": "object",
"properties": {
},
"required": [
],
"default": {}
}
},
"required": [
"kind"
]
},
{
"type": "object",
"properties": {
"kind": {
"nullable": false,
"type": "string",
"enum": ["oidc"]
},
"data": {
"nullable": false,
"type": "object",
"properties": {
"url_authorization": {
"nullable": false,
"type": "string"
},
"url_token": {
"nullable": false,
"type": "string"
},
"url_userinfo": {
"nullable": false,
"type": "string"
},
"client_id": {
"nullable": false,
"type": "string"
},
"client_secret": {
"nullable": false,
"type": "string"
},
"backend_url_base": {
"nullable": false,
"type": "string"
},
"label": {
"nullable": false,
"type": "string",
"default": "OIDC"
}
},
"required": [
"url_authorization",
"url_token",
"url_userinfo",
"client_id",
"client_secret"
]
}
},
"required": [
"kind",
"data"
]
}
],
"default": {
"kind": "internal",
"data": {
}
}
},
"misc": {
"nullable": false,
"type": "object",
"properties": {
/**
* @todo make mandatory
*/
"auth_salt": {
"nullable": false,
"type": "string",
"default": "unsafe_auth_salt"
}
},
"required": [
],
"additionalProperties": false,
"default": {}
}
},
"required": [
"version"
],
"additionalProperties": false
};
/**
*/
var _data : (null | any) = null;
/**
*/
export function schema(
) : lib_plankton.conf.type_schema
{
return _schema;
}
/**
*/
export function get(
) : any
{
if (_data === null) {
throw (new Error("conf not loaded yet"));
}
else {
return _data;
}
}
/**
*/
export async function init(
path : string
) : Promise<void>
{
_data = await lib_plankton.conf.load(
_schema,
path
);
return Promise.resolve<void>(undefined);
}
}