196 lines
5.2 KiB
TypeScript
196 lines
5.2 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",
|
|
"info": "Aktion (serve | doc | password-image | export-authelia | help)",
|
|
"name": "action",
|
|
}),
|
|
"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": "conf.json",
|
|
"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(" "));
|
|
|
|
// conf
|
|
await _aum.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,
|
|
}[_aum.conf.get().verbosity]
|
|
),
|
|
]
|
|
);
|
|
await lib_plankton.session.setup(
|
|
{
|
|
/*
|
|
"data_chest": lib_plankton.call.convey(
|
|
lib_plankton.storage.sql_table_common.chest(
|
|
{
|
|
"database_implementation": _aum.helpers.database_implementation(),
|
|
"table_name": "sessions",
|
|
"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": _aum.conf.get().session_lifetime,
|
|
}
|
|
);
|
|
_aum.service.member.listen_change(
|
|
() => {
|
|
lib_plankton.log.info(
|
|
"member_change",
|
|
{
|
|
}
|
|
);
|
|
}
|
|
);
|
|
_aum.service.member.listen_change(
|
|
async () => {
|
|
const authelia_export : string = await _aum.service.member.export_authelia_member_file();
|
|
process.stdout.write(authelia_export + "\n");
|
|
}
|
|
);
|
|
|
|
// exec
|
|
if (args["help"] || (args["action"] == "help")) {
|
|
process.stdout.write(
|
|
arg_handler.generate_help(
|
|
{
|
|
"programname": "aum",
|
|
"description": "member management for authelia",
|
|
"executable": "aum",
|
|
}
|
|
)
|
|
+
|
|
"\n"
|
|
);
|
|
}
|
|
else {
|
|
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 _aum.helpers.bcrypt_compute(input);
|
|
process.stdout.write(result + "\n")
|
|
}
|
|
break;
|
|
}
|
|
case "doc": {
|
|
const rest_subject : lib_plankton.rest.type_rest = _aum.api.make();
|
|
process.stdout.write(
|
|
JSON.stringify(
|
|
lib_plankton.rest.to_oas(rest_subject),
|
|
undefined,
|
|
"\t"
|
|
)
|
|
);
|
|
break;
|
|
}
|
|
case "serve": {
|
|
const rest_subject : lib_plankton.rest.type_rest = _aum.api.make();
|
|
const server : lib_plankton.server.type_subject = lib_plankton.server.make(
|
|
_aum.conf.get().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 _aum.service.member.export_authelia_member_file() + "\n");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
main(process.argv.slice(2));
|