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} let configuration () = let conf = Otoml.Parser.from_file "/etc/lanonna.toml" in 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 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})