2024-04-02 14:38:00 +02:00
|
|
|
type repo_data = {forgejo_id: string; base64_password: string; matrix_room: string}
|
|
|
|
type config = {mq_url: string; mq_user: string; mq_password: string; repos: repo_data list}
|
2024-03-16 09:34:29 +01:00
|
|
|
let configuration () =
|
|
|
|
let conf = Otoml.Parser.from_file "/etc/lanonna.toml" in
|
2024-03-25 14:17:34 +01:00
|
|
|
let mq_url = Otoml.find conf Otoml.get_string ["pam"; "mq_url"] in
|
|
|
|
let mq_user = Otoml.find conf Otoml.get_string ["pam"; "mq_user"] in
|
|
|
|
let mq_password = Otoml.find conf Otoml.get_string ["pam"; "mq_password"] in
|
2024-04-02 14:38:00 +02:00
|
|
|
|
|
|
|
let repos = Otoml.find conf (Otoml.get_array (Otoml.get_array Otoml.get_string)) ["pam"; "repos"]
|
|
|
|
in
|
|
|
|
repos
|
|
|
|
|> List.fold_left (fun accum elem ->
|
|
|
|
match (accum, elem) with
|
|
|
|
| (Error e, _) -> Error e
|
|
|
|
| (Ok accum, id::psw::room::[]) -> {forgejo_id=id; base64_password=psw; matrix_room=room}::accum |> Result.ok
|
|
|
|
| (_, _) -> "Can't parse the list of repos. The format must be: [[owner/repo, base64_password, matrix_room], [...]]" |> Result.error
|
|
|
|
) (Ok [])
|
|
|
|
|> Result.map (fun repo_data -> {mq_url=mq_url; mq_user=mq_user; mq_password=mq_password; repos=repo_data})
|