backend/source/conf.ts

326 lines
5.6 KiB
TypeScript
Raw Permalink Normal View History

2024-09-12 00:03:29 +02:00
namespace _zeitbild.conf
{
/**
*/
2024-09-18 18:17:25 +02:00
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"
}
},
"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"
},
2024-10-26 13:37:57 +02:00
"schema": {
2024-09-18 18:17:25 +02:00
"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": {}
2024-09-19 13:34:07 +02:00
},
"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": {
}
}
2024-09-12 00:03:29 +02:00
}
2024-09-18 18:17:25 +02:00
},
"required": [
"version"
],
"additionalProperties": false
2024-09-12 00:03:29 +02:00
};
/**
*/
2024-09-18 18:17:25 +02:00
var _data : (null | any) = null;
2024-09-12 00:03:29 +02:00
/**
*/
2024-09-18 18:17:25 +02:00
export function schema(
) : lib_plankton.conf.type_schema
2024-09-12 00:03:29 +02:00
{
2024-09-18 18:17:25 +02:00
return _schema;
2024-09-12 00:03:29 +02:00
}
/**
*/
2024-09-18 18:17:25 +02:00
export function get(
) : any
2024-09-12 00:03:29 +02:00
{
2024-09-18 18:17:25 +02:00
if (_data === null) {
throw (new Error("conf not loaded yet"));
2024-09-12 00:03:29 +02:00
}
else {
2024-09-18 18:17:25 +02:00
return _data;
2024-09-12 00:03:29 +02:00
}
}
/**
*/
2024-09-18 18:17:25 +02:00
export async function init(
path : string
) : Promise<void>
2024-09-12 00:03:29 +02:00
{
2024-09-18 18:17:25 +02:00
_data = await lib_plankton.conf.load(
_schema,
path
);
return Promise.resolve<void>(undefined);
2024-09-12 00:03:29 +02:00
}
}