235 lines
6.4 KiB
TypeScript
235 lines
6.4 KiB
TypeScript
/**
|
|
*/
|
|
async function main(
|
|
args_raw : Array<string>
|
|
) : Promise<void>
|
|
{
|
|
// args
|
|
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler({
|
|
"action": lib_plankton.args.class_argument.positional({
|
|
"index": 0,
|
|
"type": lib_plankton.args.enum_type.string,
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
"default": "serve",
|
|
"name": "action",
|
|
"info": lib_plankton.string.coin(
|
|
"auszuführende Aktion; Auswahl:\n{{selection}}\n\t\t",
|
|
{
|
|
"selection": (
|
|
[
|
|
{
|
|
"name": "serve",
|
|
"description": "Server starten",
|
|
},
|
|
{
|
|
"name": "api-doc",
|
|
"description": "API-Dokumentation gemäß OpenAPI Specification auf Standard-Ausgabe schreiben"
|
|
},
|
|
{
|
|
"name": "password-image",
|
|
"description": "Passwort-Abbild errechnen und auf Standard-Ausgabe schreiben"
|
|
},
|
|
{
|
|
"name": "export-authelia",
|
|
"description": "Export der Nutzer-Datenbank im Authelia-user-Datei-Format auf Standard-Ausgabe schreiben"
|
|
},
|
|
{
|
|
"name": "help",
|
|
"description": "Diese Hilfe auf Standard-Ausgabe schreiben"
|
|
},
|
|
]
|
|
.map(
|
|
entry => lib_plankton.string.coin(
|
|
"\t\t- {{name}}\n\t\t\t{{description}}\n",
|
|
{
|
|
"name": entry.name,
|
|
"description": entry.description,
|
|
}
|
|
)
|
|
)
|
|
.join("")
|
|
),
|
|
}
|
|
),
|
|
}),
|
|
"arg1": lib_plankton.args.class_argument.positional({
|
|
"index": 1,
|
|
"type": lib_plankton.args.enum_type.string,
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
"default": null,
|
|
// "info": null,
|
|
"name": "arg1",
|
|
"hidden": true,
|
|
}),
|
|
"arg2": lib_plankton.args.class_argument.positional({
|
|
"index": 2,
|
|
"type": lib_plankton.args.enum_type.string,
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
"default": null,
|
|
// "info": null,
|
|
"name": "arg2",
|
|
"hidden": true,
|
|
}),
|
|
"conf_path": lib_plankton.args.class_argument.volatile({
|
|
"indicators_long": ["conf_path"],
|
|
"indicators_short": ["c"],
|
|
"type": lib_plankton.args.enum_type.string,
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
"default": null,
|
|
"info": "Pfad zur Konfigurations-Datei",
|
|
"name": "conf-path",
|
|
}),
|
|
"help": lib_plankton.args.class_argument.volatile({
|
|
"indicators_long": ["help"],
|
|
"indicators_short": ["h"],
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
"default": false,
|
|
"info": "Hilfe anzeigen",
|
|
"name": "help",
|
|
}),
|
|
});
|
|
const args : Record<string, any> = arg_handler.read(lib_plankton.args.enum_environment.cli, args_raw.join(" "));
|
|
|
|
// exec
|
|
if (args["help"] || (args["action"] == "help")) {
|
|
process.stdout.write(
|
|
arg_handler.generate_help(
|
|
{
|
|
"programname": "espe",
|
|
"description": "Espe | Backend",
|
|
"executable": "espe",
|
|
}
|
|
)
|
|
+
|
|
"\n"
|
|
);
|
|
}
|
|
else {
|
|
// conf
|
|
await _espe.conf.load(args["conf_path"]);
|
|
|
|
// setup
|
|
lib_plankton.log.conf_push(
|
|
[
|
|
new lib_plankton.log.class_channel_minlevel(
|
|
new lib_plankton.log.class_channel_stdout(),
|
|
{
|
|
"none": lib_plankton.log.enum_level.error,
|
|
"error": lib_plankton.log.enum_level.error,
|
|
"warning": lib_plankton.log.enum_level.warning,
|
|
"notice": lib_plankton.log.enum_level.notice,
|
|
"info": lib_plankton.log.enum_level.info,
|
|
"debug":lib_plankton.log.enum_level.debug,
|
|
}[_espe.conf.get().general.verbosity]
|
|
),
|
|
]
|
|
);
|
|
|
|
// prepare database
|
|
await _espe.database.advance_all();
|
|
|
|
switch (args["action"]) {
|
|
default: {
|
|
process.stderr.write("invalid action: " + args["action"] + "\n");
|
|
break;
|
|
}
|
|
case "password-image": {
|
|
const input : (null | string) = args["arg1"];
|
|
if (input === null) {
|
|
throw (new Error("SYNTAX: password-image <password>"));
|
|
}
|
|
else {
|
|
const result : string = await _espe.helpers.bcrypt_compute(input);
|
|
process.stdout.write(result + "\n")
|
|
}
|
|
break;
|
|
}
|
|
case "api-doc": {
|
|
const rest_subject : lib_plankton.rest.type_rest = _espe.api.make();
|
|
process.stdout.write(
|
|
JSON.stringify(
|
|
lib_plankton.rest.to_oas(rest_subject),
|
|
undefined,
|
|
"\t"
|
|
)
|
|
);
|
|
break;
|
|
}
|
|
case "serve": {
|
|
await lib_plankton.session.setup(
|
|
{
|
|
/*
|
|
"data_chest": lib_plankton.call.convey(
|
|
lib_plankton.storage.sql_table_common.chest(
|
|
{
|
|
"database_implementation": _espe.helpers.database_implementation(),
|
|
"table_name": "session_management",
|
|
"key_names": ["key"],
|
|
}
|
|
),
|
|
[
|
|
(core) => ({
|
|
"setup": (input) => core.setup(undefined),
|
|
"clear": () => core.clear(),
|
|
"write": (key, value) => core.write([key], value),
|
|
"delete": (key) => core.delete([key]),
|
|
"read": (key) => core.read([key]),
|
|
// "search": (term) => core.search(term).then(() => []),
|
|
"search": (term) => Promise.reject(new Error("not implemented")),
|
|
}),
|
|
]
|
|
),
|
|
*/
|
|
"default_lifetime": _espe.conf.get().session_management.lifetime,
|
|
}
|
|
);
|
|
|
|
_espe.service.member.listen_change(
|
|
() => {
|
|
lib_plankton.log.info(
|
|
"member_change",
|
|
{
|
|
}
|
|
);
|
|
}
|
|
);
|
|
_espe.service.member.listen_change(
|
|
async () => {
|
|
const authelia_export : string = await _espe.service.member.export_authelia_user_file();
|
|
process.stdout.write(authelia_export + "\n");
|
|
}
|
|
);
|
|
|
|
const rest_subject : lib_plankton.rest.type_rest = _espe.api.make();
|
|
const server : lib_plankton.server.type_subject = lib_plankton.server.make(
|
|
_espe.conf.get().server.port,
|
|
async (input, metadata) => {
|
|
const http_request : lib_plankton.http.type_request = lib_plankton.http.decode_request(input);
|
|
const http_response : lib_plankton.http.type_response = await lib_plankton.rest.call(
|
|
rest_subject,
|
|
http_request,
|
|
{
|
|
"checklevel_restriction": lib_plankton.api.enum_checklevel.hard,
|
|
// "checklevel_input": lib_plankton.api.enum_checklevel.soft,
|
|
// "checklevel_output": lib_plankton.api.enum_checklevel.soft,
|
|
}
|
|
);
|
|
const output : string = lib_plankton.http.encode_response(http_response);
|
|
return output;
|
|
}
|
|
);
|
|
|
|
lib_plankton.server.start(server);
|
|
break;
|
|
}
|
|
case "export-authelia": {
|
|
process.stdout.write(await _espe.service.member.export_authelia_user_file() + "\n");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
main(process.argv.slice(2));
|