Merge branch 'dev-outputs_revise' into 'master'
Outputs neu machen See merge request espe/backend!1
This commit is contained in:
commit
0219d9ffe2
5 changed files with 991 additions and 190 deletions
33
lib/plankton/plankton.d.ts
vendored
33
lib/plankton/plankton.d.ts
vendored
|
@ -3005,13 +3005,13 @@ declare namespace lib_plankton.http {
|
|||
* @author fenris <frass@greenscale.de>
|
||||
*/
|
||||
enum enum_method {
|
||||
get = "get",
|
||||
post = "post",
|
||||
patch = "patch",
|
||||
put = "put",
|
||||
delete = "delete",
|
||||
options = "options",
|
||||
head = "head"
|
||||
head = "head",
|
||||
get = "get",
|
||||
delete = "delete",
|
||||
post = "post",
|
||||
put = "put",
|
||||
patch = "patch"
|
||||
}
|
||||
/**
|
||||
* @author fenris <frass@greenscale.de>
|
||||
|
@ -3305,16 +3305,28 @@ declare namespace lib_plankton.server {
|
|||
* @author fenris
|
||||
*/
|
||||
type type_subject = {
|
||||
host: string;
|
||||
port: int;
|
||||
handle: ((input: string, metadata?: type_metadata) => Promise<string>);
|
||||
threshold: (null | float);
|
||||
handle: ((input: Buffer, metadata?: type_metadata) => Promise<string>);
|
||||
serverobj: any;
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function make(port: int, handle: ((input: string, metadata?: type_metadata) => Promise<string>)): type_subject;
|
||||
function make(handle: ((input: string, metadata?: type_metadata) => Promise<string>), options?: {
|
||||
host?: string;
|
||||
port?: int;
|
||||
threshold?: (null | float);
|
||||
}): type_subject;
|
||||
/**
|
||||
* @author fenris
|
||||
* @deprecated
|
||||
*/
|
||||
function make_old(port: int, handle: ((input: string, metadata?: type_metadata) => Promise<string>)): type_subject;
|
||||
/**
|
||||
* @author fenris
|
||||
* @see https://nodejs.org/api/net.html#serverlistenport-host-backlog-callback
|
||||
*/
|
||||
function start(subject: type_subject): Promise<void>;
|
||||
/**
|
||||
|
@ -3334,7 +3346,10 @@ declare namespace lib_plankton.server {
|
|||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
constructor(port: int, handle: ((input: string) => Promise<string>));
|
||||
constructor(handle: ((input: Buffer, metadata?: type_metadata) => Promise<string>), options?: {
|
||||
host?: string;
|
||||
port?: int;
|
||||
});
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
|
|
File diff suppressed because it is too large
Load diff
484
source/conf.ts
484
source/conf.ts
|
@ -79,6 +79,7 @@ namespace _espe.conf
|
|||
}
|
||||
>;
|
||||
server : {
|
||||
host : string;
|
||||
port : int;
|
||||
path_base : string;
|
||||
};
|
||||
|
@ -176,9 +177,36 @@ namespace _espe.conf
|
|||
email_address : (null | string);
|
||||
}
|
||||
>;
|
||||
output : {
|
||||
authelia : (null | string);
|
||||
};
|
||||
outputs : Array<
|
||||
{
|
||||
kind : "authelia_file";
|
||||
data : {
|
||||
path : string;
|
||||
}
|
||||
}
|
||||
|
|
||||
{
|
||||
kind : "http";
|
||||
data : {
|
||||
scheme : ("http" | "https");
|
||||
host : string;
|
||||
path : string;
|
||||
method : ("get" | "post" | "put" | "patch" | "delete" | "head" | "options");
|
||||
query : (null | string);
|
||||
headers : Record<string,string>;
|
||||
};
|
||||
}
|
||||
|
|
||||
{
|
||||
kind : "arc";
|
||||
data : {
|
||||
http_scheme : ("http" | "https");
|
||||
http_host : string;
|
||||
http_port : int;
|
||||
hash_salt : string;
|
||||
}
|
||||
}
|
||||
>;
|
||||
};
|
||||
|
||||
|
||||
|
@ -212,6 +240,7 @@ namespace _espe.conf
|
|||
],
|
||||
"server": (
|
||||
((node_server) => ({
|
||||
"host": "::",
|
||||
"port": (node_server["port"] ?? 4916),
|
||||
"path_base": (node_server["path_base"] ?? ""),
|
||||
})) (conf_raw["server"] ?? {})
|
||||
|
@ -355,10 +384,20 @@ namespace _espe.conf
|
|||
})) (conf_raw["settings"] ?? {})
|
||||
),
|
||||
"admins": (conf_raw["admins"] ?? []),
|
||||
"output": (
|
||||
((node_session_output) => ({
|
||||
"authelia": (node_session_output["authelia"] ?? null),
|
||||
})) (conf_raw["output"] ?? {})
|
||||
"outputs": (
|
||||
((node_output) => (
|
||||
("authelia" in node_output)
|
||||
? [
|
||||
{
|
||||
"kind": "authelia_file",
|
||||
"data": {
|
||||
"path": node_output["authelia"],
|
||||
}
|
||||
}
|
||||
]
|
||||
: [
|
||||
]
|
||||
)) (conf_raw["output"] ?? {})
|
||||
),
|
||||
};
|
||||
break;
|
||||
|
@ -397,6 +436,7 @@ namespace _espe.conf
|
|||
),
|
||||
"server": (
|
||||
((node_server) => ({
|
||||
"host": "::",
|
||||
"port": (node_server["port"] ?? 4916),
|
||||
"path_base": (node_server["path_base"] ?? ""),
|
||||
})) (conf_raw["server"] ?? {})
|
||||
|
@ -540,10 +580,432 @@ namespace _espe.conf
|
|||
})) (conf_raw["settings"] ?? {})
|
||||
),
|
||||
"admins": (conf_raw["admins"] ?? []),
|
||||
"output": (
|
||||
((node_session_output) => ({
|
||||
"authelia": (node_session_output["authelia"] ?? null),
|
||||
})) (conf_raw["output"] ?? {})
|
||||
"outputs": (
|
||||
((node_output) => (
|
||||
("authelia" in node_output)
|
||||
? [
|
||||
{
|
||||
"kind": "authelia_file",
|
||||
"data": {
|
||||
"path": node_output["authelia"],
|
||||
}
|
||||
}
|
||||
]
|
||||
: [
|
||||
]
|
||||
)) (conf_raw["output"] ?? {})
|
||||
),
|
||||
};
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
_data = {
|
||||
"general": (
|
||||
((node_general) => ({
|
||||
"language": (node_general["language"] ?? null),
|
||||
"verification_secret": (node_general["verification_secret"] ?? null),
|
||||
})) (conf_raw["general"] ?? {})
|
||||
),
|
||||
"log": (
|
||||
((node_log) => node_log.map(
|
||||
(node_log_entry : any) => ({
|
||||
"kind": node_log_entry["kind"],
|
||||
"data": Object.assign(
|
||||
{
|
||||
"format": "human_readable",
|
||||
"threshold": "notice",
|
||||
},
|
||||
(node_log_entry["data"] ?? {})
|
||||
)
|
||||
})
|
||||
)) (
|
||||
conf_raw["log"]
|
||||
??
|
||||
[
|
||||
{
|
||||
"kind": "console",
|
||||
"data": {
|
||||
}
|
||||
},
|
||||
]
|
||||
)
|
||||
),
|
||||
"server": (
|
||||
((node_server) => ({
|
||||
"host": "::",
|
||||
"port": (node_server["port"] ?? 4916),
|
||||
"path_base": (node_server["path_base"] ?? ""),
|
||||
})) (conf_raw["server"] ?? {})
|
||||
),
|
||||
"database": (
|
||||
((node_database) => {
|
||||
const kind : string = (node_database["kind"] ?? "sqlite");
|
||||
const node_database_data_raw = (node_database["data"] ?? {});
|
||||
switch (kind) {
|
||||
case "sqlite": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
"path": (node_database_data_raw["path"] ?? "data.sqlite"),
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "postgresql": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": node_database_data_raw,
|
||||
};
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw (new Error("unhandled"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}) (conf_raw["database"] ?? {})
|
||||
),
|
||||
"email_sending": (
|
||||
((node_email_sending) => {
|
||||
const kind : string = (node_email_sending["kind"] ?? "console");
|
||||
const data_raw = (node_email_sending["data"] ?? {});
|
||||
switch (kind) {
|
||||
case "regular": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
|
||||
"sender": data_raw["sender"],
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "redirect": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
|
||||
"sender": data_raw["sender"],
|
||||
"target": data_raw["target"],
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "console": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "drop": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw (new Error("unhandled"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}) (conf_raw["email_sending"] ?? {})
|
||||
),
|
||||
"session_management": (
|
||||
((node_session_management) => ({
|
||||
"in_memory": (node_session_management["in_memory"] ?? true),
|
||||
"drop_all_at_start": (node_session_management["drop_all_at_start"] ?? true),
|
||||
"lifetime": (node_session_management["lifetime"] ?? 900),
|
||||
})) (conf_raw["session_management"] ?? {})
|
||||
),
|
||||
"settings": (
|
||||
((node_settings) => ({
|
||||
"organisation": {
|
||||
"name": ((node_settings["organisation"] ?? {})["name"] ?? "Example Orginsation"), // TODO: mandatory?
|
||||
"domain": ((node_settings["organisation"] ?? {})["domain"] ?? "example.org"), // TODO: mandatory?
|
||||
},
|
||||
"misc": (
|
||||
((node_settings_misc) => ({
|
||||
"prefix_for_veiled_email_addresses": (node_settings_misc["prefix_for_veiled_email_addresses"] ?? "member-"),
|
||||
"facultative_membership_number": (node_settings_misc["facultative_membership_number"] ?? false),
|
||||
"auto_register": (node_settings_misc["auto_register"] ?? false),
|
||||
})) (node_settings["misc"] ?? {})
|
||||
),
|
||||
"summon_email": (
|
||||
((node_settings_summon_email) => ({
|
||||
"remark": (node_settings_summon_email["remark"] ?? null),
|
||||
})) (node_settings["summon_email"] ?? {})
|
||||
),
|
||||
"password_policy": (
|
||||
((node_settings_password_policy) => ({
|
||||
"minimum_length": (
|
||||
("minimum_length" in node_settings_password_policy)
|
||||
? node_settings_password_policy["minimum_length"]
|
||||
: 8
|
||||
),
|
||||
"maximum_length": (
|
||||
("maximum_length" in node_settings_password_policy)
|
||||
? node_settings_password_policy["maximum_length"]
|
||||
: 240
|
||||
),
|
||||
"must_contain_letter": (node_settings_password_policy["must_contain_letter"] ?? true),
|
||||
"must_contain_number": (node_settings_password_policy["must_contain_number"] ?? true),
|
||||
"must_contain_special_character": (node_settings_password_policy["must_contain_special_character"] ?? true),
|
||||
})) (node_settings["password_policy"] ?? {})
|
||||
),
|
||||
"password_change": (
|
||||
((node_settings_password_change) => ({
|
||||
"cooldown_time": (node_settings_password_change["cooldown_time"] ?? 86400),
|
||||
})) (node_settings["password_change"] ?? {})
|
||||
),
|
||||
"name_index": (
|
||||
((node_settings_password_policy) => ({
|
||||
"veil": (node_settings_password_policy["veil"] ?? true),
|
||||
"salt": (node_settings_password_policy["salt"] ?? ""),
|
||||
})) (node_settings["name_index"] ?? {})
|
||||
),
|
||||
"connections": (
|
||||
((node_settings_connections) => ({
|
||||
"frontend_url_base": (node_settings_connections["frontend_url_base"] ?? null),
|
||||
"login_url": (node_settings_connections["login_url"] ?? null),
|
||||
})) (node_settings["connections"] ?? {})
|
||||
),
|
||||
})) (conf_raw["settings"] ?? {})
|
||||
),
|
||||
"admins": (conf_raw["admins"] ?? []),
|
||||
"outputs": (conf_raw["outputs"] ?? []),
|
||||
};
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
_data = {
|
||||
"general": (
|
||||
((node_general) => ({
|
||||
"language": (node_general["language"] ?? null),
|
||||
"verification_secret": (node_general["verification_secret"] ?? null),
|
||||
})) (conf_raw["general"] ?? {})
|
||||
),
|
||||
"log": (
|
||||
((node_log) => node_log.map(
|
||||
(node_log_entry : any) => ({
|
||||
"kind": node_log_entry["kind"],
|
||||
"data": Object.assign(
|
||||
{
|
||||
"format": "human_readable",
|
||||
"threshold": "notice",
|
||||
},
|
||||
(node_log_entry["data"] ?? {})
|
||||
)
|
||||
})
|
||||
)) (
|
||||
conf_raw["log"]
|
||||
??
|
||||
[
|
||||
{
|
||||
"kind": "console",
|
||||
"data": {
|
||||
}
|
||||
},
|
||||
]
|
||||
)
|
||||
),
|
||||
"server": (
|
||||
((node_server) => ({
|
||||
"host": (node_server["host"] ?? "::"),
|
||||
"port": (node_server["port"] ?? 4916),
|
||||
"path_base": (node_server["path_base"] ?? ""),
|
||||
})) (conf_raw["server"] ?? {})
|
||||
),
|
||||
"database": (
|
||||
((node_database) => {
|
||||
const kind : string = (node_database["kind"] ?? "sqlite");
|
||||
const node_database_data_raw = (node_database["data"] ?? {});
|
||||
switch (kind) {
|
||||
case "sqlite": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
"path": (node_database_data_raw["path"] ?? "data.sqlite"),
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "postgresql": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": node_database_data_raw,
|
||||
};
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw (new Error("unhandled"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}) (conf_raw["database"] ?? {})
|
||||
),
|
||||
"email_sending": (
|
||||
((node_email_sending) => {
|
||||
const kind : string = (node_email_sending["kind"] ?? "console");
|
||||
const data_raw = (node_email_sending["data"] ?? {});
|
||||
switch (kind) {
|
||||
case "regular": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
|
||||
"sender": data_raw["sender"],
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "redirect": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
"smtp_credentials": (data_raw["smtp_credentials"] ?? null),
|
||||
"sender": data_raw["sender"],
|
||||
"target": data_raw["target"],
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "console": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "drop": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw (new Error("unhandled"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}) (conf_raw["email_sending"] ?? {})
|
||||
),
|
||||
"session_management": (
|
||||
((node_session_management) => ({
|
||||
"in_memory": (node_session_management["in_memory"] ?? true),
|
||||
"drop_all_at_start": (node_session_management["drop_all_at_start"] ?? true),
|
||||
"lifetime": (node_session_management["lifetime"] ?? 900),
|
||||
})) (conf_raw["session_management"] ?? {})
|
||||
),
|
||||
"settings": (
|
||||
((node_settings) => ({
|
||||
"organisation": {
|
||||
"name": ((node_settings["organisation"] ?? {})["name"] ?? "Example Orginsation"), // TODO: mandatory?
|
||||
"domain": ((node_settings["organisation"] ?? {})["domain"] ?? "example.org"), // TODO: mandatory?
|
||||
},
|
||||
"misc": (
|
||||
((node_settings_misc) => ({
|
||||
"prefix_for_veiled_email_addresses": (node_settings_misc["prefix_for_veiled_email_addresses"] ?? "member-"),
|
||||
"facultative_membership_number": (node_settings_misc["facultative_membership_number"] ?? false),
|
||||
"auto_register": (node_settings_misc["auto_register"] ?? false),
|
||||
})) (node_settings["misc"] ?? {})
|
||||
),
|
||||
"summon_email": (
|
||||
((node_settings_summon_email) => ({
|
||||
"remark": (node_settings_summon_email["remark"] ?? null),
|
||||
})) (node_settings["summon_email"] ?? {})
|
||||
),
|
||||
"password_policy": (
|
||||
((node_settings_password_policy) => ({
|
||||
"minimum_length": (
|
||||
("minimum_length" in node_settings_password_policy)
|
||||
? node_settings_password_policy["minimum_length"]
|
||||
: 8
|
||||
),
|
||||
"maximum_length": (
|
||||
("maximum_length" in node_settings_password_policy)
|
||||
? node_settings_password_policy["maximum_length"]
|
||||
: 240
|
||||
),
|
||||
"must_contain_letter": (node_settings_password_policy["must_contain_letter"] ?? true),
|
||||
"must_contain_number": (node_settings_password_policy["must_contain_number"] ?? true),
|
||||
"must_contain_special_character": (node_settings_password_policy["must_contain_special_character"] ?? true),
|
||||
})) (node_settings["password_policy"] ?? {})
|
||||
),
|
||||
"password_change": (
|
||||
((node_settings_password_change) => ({
|
||||
"cooldown_time": (node_settings_password_change["cooldown_time"] ?? 86400),
|
||||
})) (node_settings["password_change"] ?? {})
|
||||
),
|
||||
"name_index": (
|
||||
((node_settings_password_policy) => ({
|
||||
"veil": (node_settings_password_policy["veil"] ?? true),
|
||||
"salt": (node_settings_password_policy["salt"] ?? ""),
|
||||
})) (node_settings["name_index"] ?? {})
|
||||
),
|
||||
"connections": (
|
||||
((node_settings_connections) => ({
|
||||
"frontend_url_base": (node_settings_connections["frontend_url_base"] ?? null),
|
||||
"login_url": (node_settings_connections["login_url"] ?? null),
|
||||
})) (node_settings["connections"] ?? {})
|
||||
),
|
||||
})) (conf_raw["settings"] ?? {})
|
||||
),
|
||||
"admins": (conf_raw["admins"] ?? []),
|
||||
"outputs": (
|
||||
((node_outputs) => node_outputs.map(
|
||||
(output_description : {kind : string; data : any;}) => {
|
||||
const kind : string = output_description["kind"];
|
||||
const node_options_data_raw = (output_description["data"] ?? {});
|
||||
switch (kind) {
|
||||
case "authelia_file": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
"path": (node_options_data_raw["path"] ?? "/var/authelia/users.yaml"),
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "http": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
"scheme": (node_options_data_raw["scheme"] ?? "http"),
|
||||
"host": (node_options_data_raw["host"] ?? "localhost"),
|
||||
"path": (node_options_data_raw["path"] ?? ""),
|
||||
"method": (node_options_data_raw["method"] ?? "post"),
|
||||
"query": (node_options_data_raw["query"] ?? null),
|
||||
"headers": (node_options_data_raw["headers"] ?? {"Content-Type": "application/json"}),
|
||||
},
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "arc": {
|
||||
return {
|
||||
"kind": kind,
|
||||
"data": {
|
||||
"http_scheme": (node_options_data_raw["scheme"] ?? "http"),
|
||||
"http_host": (node_options_data_raw["http_host"] ?? "localhost"),
|
||||
"http_port": (node_options_data_raw["http_port"] ?? 7463),
|
||||
"hash_salt": node_options_data_raw["hash_salt"],
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw (new Error("unhandled"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
)) (conf_raw["outputs"] ?? [])
|
||||
),
|
||||
};
|
||||
break;
|
||||
|
|
|
@ -309,6 +309,7 @@ async function main(
|
|||
}
|
||||
);
|
||||
|
||||
// outputs
|
||||
_espe.service.member.listen_change(
|
||||
() => {
|
||||
lib_plankton.log.info(
|
||||
|
@ -316,31 +317,62 @@ async function main(
|
|||
{
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
// outputs
|
||||
{
|
||||
if (_espe.conf.get().output.authelia === null) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
_espe.service.member.listen_change(
|
||||
async () => {
|
||||
const authelia_export : string = await _espe.service.member.export_authelia_user_file();
|
||||
lib_plankton.file.write(
|
||||
_espe.conf.get().output.authelia,
|
||||
authelia_export
|
||||
_espe.conf.get().outputs.forEach(
|
||||
output_description => {
|
||||
const procedure : (() => Promise<void>) = (
|
||||
(() => {
|
||||
switch (output_description.kind) {
|
||||
default: {
|
||||
lib_plankton.log.warning(
|
||||
"output_kind_unhandled",
|
||||
{
|
||||
"description": output_description,
|
||||
}
|
||||
);
|
||||
return (() => Promise.resolve<void>(undefined));
|
||||
break;
|
||||
}
|
||||
case "authelia_file": {
|
||||
return (() => _espe.service.member.output_authelia_file(output_description.data));
|
||||
break;
|
||||
}
|
||||
case "http": {
|
||||
return (() => _espe.service.member.output_http(output_description.data));
|
||||
break;
|
||||
}
|
||||
case "arc": {
|
||||
return (() => _espe.service.member.output_arc(output_description.data));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}) ()
|
||||
);
|
||||
(
|
||||
procedure()
|
||||
.then(
|
||||
() => {
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(error) => {
|
||||
lib_plankton.log.warning(
|
||||
"output_procedure_failed",
|
||||
{
|
||||
"error": String(error),
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
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_request : lib_plankton.http.type_request = lib_plankton.http.decode_request(input.toString());
|
||||
const http_response : lib_plankton.http.type_response = await lib_plankton.rest.call(
|
||||
rest_subject,
|
||||
http_request,
|
||||
|
@ -352,6 +384,12 @@ async function main(
|
|||
);
|
||||
const output : string = lib_plankton.http.encode_response(http_response);
|
||||
return output;
|
||||
},
|
||||
{
|
||||
"host": _espe.conf.get().server.host,
|
||||
"port": _espe.conf.get().server.port,
|
||||
// DANGER! DANGER!
|
||||
"threshold": 0.125,
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -253,7 +253,7 @@ namespace _espe.service.member
|
|||
/**
|
||||
* gibt die vollständigen Daten aller Mitglieder aus
|
||||
*/
|
||||
async function dump(
|
||||
export async function dump(
|
||||
) : Promise<
|
||||
Array<
|
||||
{
|
||||
|
@ -776,11 +776,11 @@ namespace _espe.service.member
|
|||
/**
|
||||
* @todo check validity (e.g. username characters)
|
||||
*/
|
||||
export async function export_authelia_user_file(
|
||||
export async function export_authelia_user_data(
|
||||
options : {
|
||||
custom_data ?: (null | Array<_espe.type.member_object>);
|
||||
} = {}
|
||||
) : Promise<string>
|
||||
) : Promise<any>
|
||||
{
|
||||
options = Object.assign(
|
||||
{
|
||||
|
@ -789,8 +789,6 @@ namespace _espe.service.member
|
|||
options
|
||||
);
|
||||
|
||||
const nm_yaml = require("yaml");
|
||||
|
||||
type type_entry = {
|
||||
disabled : boolean;
|
||||
displayname : string;
|
||||
|
@ -842,10 +840,163 @@ namespace _espe.service.member
|
|||
),
|
||||
Object.fromEntries,
|
||||
(x : Record<string, type_entry>) => ({"users": x}),
|
||||
(x : {users : Record<string, type_entry>}) => nm_yaml.stringify(x),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function export_authelia_user_file(
|
||||
options : {
|
||||
custom_data ?: (null | Array<_espe.type.member_object>);
|
||||
} = {}
|
||||
) : Promise<string>
|
||||
{
|
||||
options = Object.assign(
|
||||
{
|
||||
"custom_data": null,
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
const nm_yaml = require("yaml");
|
||||
return nm_yaml.stringify(await export_authelia_user_data(options));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function output_authelia_file(
|
||||
output_parameters : {
|
||||
path : string;
|
||||
}
|
||||
) : Promise<void>
|
||||
{
|
||||
await lib_plankton.file.write(
|
||||
output_parameters.path,
|
||||
await _espe.service.member.export_authelia_user_file()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function output_http(
|
||||
output_parameters : {
|
||||
scheme : ("http" | "https");
|
||||
host : string;
|
||||
path : string;
|
||||
method : ("get" | "post" | "put" | "patch" | "delete" | "head" | "options");
|
||||
query : (null | string);
|
||||
headers : Record<string,string>;
|
||||
}
|
||||
) : Promise<void>
|
||||
{
|
||||
const http_request : lib_plankton.http.type_request = {
|
||||
"scheme": output_parameters.scheme,
|
||||
"host": output_parameters.host,
|
||||
"path": output_parameters.path,
|
||||
"version": "HTTP/1.1",
|
||||
"method": (
|
||||
(
|
||||
{
|
||||
"get": lib_plankton.http.enum_method.get,
|
||||
"post": lib_plankton.http.enum_method.post,
|
||||
"put": lib_plankton.http.enum_method.put,
|
||||
"patch": lib_plankton.http.enum_method.patch,
|
||||
"delete": lib_plankton.http.enum_method.delete,
|
||||
"head": lib_plankton.http.enum_method.head,
|
||||
"options": lib_plankton.http.enum_method.options,
|
||||
}[output_parameters.method]
|
||||
)
|
||||
??
|
||||
lib_plankton.http.enum_method.post
|
||||
),
|
||||
"query": output_parameters.query,
|
||||
"headers": output_parameters.headers,
|
||||
"body": lib_plankton.json.encode(await _espe.service.member.dump()),
|
||||
};
|
||||
const http_response : lib_plankton.http.type_response = await lib_plankton.http.call(
|
||||
http_request
|
||||
);
|
||||
if (! ((http_response.status_code >= 200) && (http_response.status_code < 400))) {
|
||||
lib_plankton.log.warning(
|
||||
"output_http_failed",
|
||||
{
|
||||
"http_request": http_request,
|
||||
"http_response_status_code": http_response.status_code,
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function output_arc(
|
||||
output_parameters : {
|
||||
http_scheme : ("http" | "https");
|
||||
http_host : string;
|
||||
http_port : int;
|
||||
hash_salt : string;
|
||||
}
|
||||
) : Promise<void>
|
||||
{
|
||||
const timestamp : float = lib_plankton.base.get_current_timestamp();
|
||||
const auth : string = lib_plankton.sha256.get(
|
||||
timestamp.toFixed(0)
|
||||
+
|
||||
output_parameters.hash_salt
|
||||
);
|
||||
const http_request : lib_plankton.http.type_request = {
|
||||
"scheme": output_parameters.http_scheme,
|
||||
"host": lib_plankton.string.coin(
|
||||
"{{host}}:{{port}}",
|
||||
{
|
||||
"host": output_parameters.http_host,
|
||||
"port": output_parameters.http_port.toFixed(0),
|
||||
}
|
||||
),
|
||||
"path": "/users/set",
|
||||
"version": "HTTP/1.1",
|
||||
"method": lib_plankton.http.enum_method.put,
|
||||
"query": lib_plankton.string.coin(
|
||||
"?timestamp={{timestamp}}&auth={{auth}}",
|
||||
{
|
||||
"timestamp": timestamp.toFixed(0),
|
||||
"auth": auth,
|
||||
}
|
||||
),
|
||||
"headers": {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
// @ts-ignore
|
||||
"body": Buffer.from(
|
||||
lib_plankton.json.encode(
|
||||
(await _espe.service.member.export_authelia_user_data())
|
||||
),
|
||||
"utf8"
|
||||
),
|
||||
};
|
||||
const http_response : lib_plankton.http.type_response = await lib_plankton.http.call(
|
||||
http_request
|
||||
);
|
||||
if (http_response.status_code !== 200) {
|
||||
lib_plankton.log.warning(
|
||||
"output_arcback_failed",
|
||||
{
|
||||
"http_response_status_code": http_response.status_code,
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue