2021-11-07 00:31:32 +01:00
|
|
|
module App_id = struct
|
|
|
|
|
let qualifier = "org"
|
|
|
|
|
|
|
|
|
|
let organization = "Permap"
|
|
|
|
|
|
|
|
|
|
let application = "permap"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
module Project_dirs = Directories.Project_dirs (App_id)
|
|
|
|
|
|
|
|
|
|
let data_dir =
|
|
|
|
|
match Project_dirs.data_dir with
|
|
|
|
|
| None -> failwith "can't compute data directory"
|
|
|
|
|
| Some data_dir -> data_dir
|
2022-02-19 22:13:45 +01:00
|
|
|
|
|
|
|
|
let config_dir =
|
|
|
|
|
match Project_dirs.config_dir with
|
|
|
|
|
| None -> failwith "can't compute configuration directory"
|
|
|
|
|
| Some config_dir -> config_dir
|
|
|
|
|
|
|
|
|
|
let config =
|
|
|
|
|
let filename = Filename.concat config_dir "config.scfg" in
|
|
|
|
|
if not @@ Sys.file_exists filename then
|
|
|
|
|
failwith
|
|
|
|
|
@@ Format.sprintf "configuration file `%s` does not exist, please create it"
|
|
|
|
|
filename;
|
|
|
|
|
Dream.log "config file: %s" filename;
|
|
|
|
|
match Scfg.Parse.from_file filename with
|
|
|
|
|
| Error e -> failwith e
|
|
|
|
|
| Ok config -> config
|
|
|
|
|
|
|
|
|
|
let open_registration =
|
|
|
|
|
match Scfg.Query.get_dir "open_registration" config with
|
|
|
|
|
| None -> true
|
|
|
|
|
| Some open_registration -> (
|
|
|
|
|
match Scfg.Query.get_param 0 open_registration with
|
|
|
|
|
| Error e -> failwith e
|
|
|
|
|
| Ok "true" -> true
|
|
|
|
|
| Ok "false" -> false
|
2022-02-19 22:25:07 +01:00
|
|
|
| Ok _unknown ->
|
|
|
|
|
failwith "invalid `open_registration` value in configuration file" )
|
|
|
|
|
|
|
|
|
|
let () = Dream.log "open_registration: %b" open_registration
|
|
|
|
|
|
2022-02-27 19:44:19 +01:00
|
|
|
let hostname =
|
|
|
|
|
match Scfg.Query.get_dir "hostname" config with
|
|
|
|
|
| None -> failwith "no `hostname` in configuration file"
|
|
|
|
|
| Some hostname ->
|
|
|
|
|
Result.fold ~error:failwith ~ok:Fun.id (Scfg.Query.get_param 0 hostname)
|
|
|
|
|
|
|
|
|
|
let () = Dream.log "hostname: %s" hostname
|
|
|
|
|
|
2022-02-19 22:25:07 +01:00
|
|
|
let port =
|
|
|
|
|
match Scfg.Query.get_dir "port" config with
|
|
|
|
|
| None -> 8080
|
2022-02-23 22:39:48 +01:00
|
|
|
| Some port -> (
|
|
|
|
|
match Scfg.Query.get_param 0 port with
|
2022-02-19 22:25:07 +01:00
|
|
|
| Error e -> failwith e
|
|
|
|
|
| Ok n -> (
|
|
|
|
|
try
|
|
|
|
|
let n = int_of_string n in
|
|
|
|
|
if n < 0 then raise (Invalid_argument "negative port number");
|
|
|
|
|
n
|
|
|
|
|
with Invalid_argument _msg ->
|
|
|
|
|
failwith "invalid `port` value in configuration file" ) )
|
|
|
|
|
|
|
|
|
|
let () = Dream.log "port: %d" port
|
2022-02-19 22:29:17 +01:00
|
|
|
|
|
|
|
|
let log =
|
|
|
|
|
match Scfg.Query.get_dir "log" config with
|
|
|
|
|
| None -> true
|
2022-02-23 22:39:48 +01:00
|
|
|
| Some log -> (
|
|
|
|
|
match Scfg.Query.get_param 0 log with
|
2022-02-19 22:29:17 +01:00
|
|
|
| Error e -> failwith e
|
|
|
|
|
| Ok "true" -> true
|
|
|
|
|
| Ok "false" -> false
|
|
|
|
|
| Ok _unknown -> failwith "invalid `log` value in configuration file" )
|
|
|
|
|
|
|
|
|
|
let () = Dream.log "log: %b" log
|
2022-02-23 22:39:48 +01:00
|
|
|
|
|
|
|
|
let admins =
|
|
|
|
|
let dirs = Scfg.Query.get_dirs "admin" config in
|
|
|
|
|
List.map
|
|
|
|
|
(fun dir ->
|
|
|
|
|
Result.fold ~error:failwith ~ok:Fun.id (Scfg.Query.get_param 0 dir) )
|
|
|
|
|
dirs
|