rm auditor.ml+env.ml
This commit is contained in:
parent
439fdc6a30
commit
6e5b4fc179
6 changed files with 50 additions and 40 deletions
|
|
@ -1,19 +0,0 @@
|
||||||
type t = {
|
|
||||||
auditor_pub: Crypto.EddsaPublicKey.t;
|
|
||||||
auditor_url: string;
|
|
||||||
auditor_name: string;
|
|
||||||
last_change: Timestamp.t;
|
|
||||||
is_active: bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
let of_setup_message
|
|
||||||
Api.AuditorSetupMessage.
|
|
||||||
{ auditor_url; auditor_name; auditor_pub; master_sig= _; validity_start }
|
|
||||||
=
|
|
||||||
{
|
|
||||||
auditor_url;
|
|
||||||
auditor_name;
|
|
||||||
auditor_pub;
|
|
||||||
last_change= validity_start;
|
|
||||||
is_active= true;
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
type t = {
|
|
||||||
sw: Caqti_miou.Switch.t;
|
|
||||||
stack: Mnet.stack;
|
|
||||||
tcp: Mnet.TCP.state;
|
|
||||||
dns: Mnet_dns.t;
|
|
||||||
fs: Fat.t;
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
|
type env = {
|
||||||
|
sw: Caqti_miou.Switch.t;
|
||||||
|
stack: Mnet.stack;
|
||||||
|
tcp: Mnet.TCP.state;
|
||||||
|
dns: Mnet_dns.t;
|
||||||
|
fs: Fat.t;
|
||||||
|
}
|
||||||
|
|
||||||
(* IMPROVE: use caqti pool
|
(* IMPROVE: use caqti pool
|
||||||
[connect_pool] with parameter [?post_connect] for preflight *)
|
[connect_pool] with parameter [?post_connect] for preflight *)
|
||||||
let db_conn =
|
let db_conn =
|
||||||
let f Env.{ sw; stack; tcp; dns; fs= _ } =
|
let f { sw; stack; tcp; dns; fs= _ } =
|
||||||
Logs.info (fun m -> m "Connecting to database");
|
Logs.info (fun m -> m "Connecting to database");
|
||||||
let db_uri = Config.Exchangedb_postgres.config in
|
let db_uri = Config.Exchangedb_postgres.config in
|
||||||
match Caqti_mnet.connect ~sw stack tcp dns db_uri with
|
match Caqti_mnet.connect ~sw stack tcp dns db_uri with
|
||||||
|
|
@ -17,7 +25,7 @@ let db_conn =
|
||||||
Vifu.Device.v ~name:"db_conn" ~finally [] f
|
Vifu.Device.v ~name:"db_conn" ~finally [] f
|
||||||
|
|
||||||
let keys =
|
let keys =
|
||||||
let f (module Conn : Pg.CONN) (env : Env.t) =
|
let f (module Conn : Pg.CONN) (env : env) =
|
||||||
let (module Fs : Fat.FS) =
|
let (module Fs : Fat.FS) =
|
||||||
(module struct
|
(module struct
|
||||||
let t = env.fs
|
let t = env.fs
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ let () =
|
||||||
Caqti_miou.Switch.run @@ fun sw ->
|
Caqti_miou.Switch.run @@ fun sw ->
|
||||||
(* -- *)
|
(* -- *)
|
||||||
let fs = Fat.create storage in
|
let fs = Fat.create storage in
|
||||||
let env = Env.{ sw; stack; tcp; dns; fs } in
|
let env = Global.{ sw; stack; tcp; dns; fs } in
|
||||||
let devices = Vifu.Devices.[ Global.db_conn; Global.keys ] in
|
let devices = Vifu.Devices.[ Global.db_conn; Global.keys ] in
|
||||||
let cfg = Vifu.Config.v Config.Exchange.port in
|
let cfg = Vifu.Config.v Config.Exchange.port in
|
||||||
Logs.info (fun m -> m "Starting MTE server");
|
Logs.info (fun m -> m "Starting MTE server");
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ module Auditors = struct
|
||||||
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_caqti in
|
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_caqti in
|
||||||
match opt with
|
match opt with
|
||||||
| None ->
|
| None ->
|
||||||
let auditor = Auditor.of_setup_message v in
|
let auditor = Pg_type.Auditor.of_setup_message v in
|
||||||
let+ () = Pg.update_auditor db_conn auditor |> unwrap_caqti in
|
let+ () = Pg.update_auditor db_conn auditor |> unwrap_caqti in
|
||||||
Logs.info (fun m -> m "enabled auditor");
|
Logs.info (fun m -> m "enabled auditor");
|
||||||
()
|
()
|
||||||
|
|
|
||||||
|
|
@ -351,8 +351,33 @@ let exchange_partner_setup =
|
||||||
})
|
})
|
||||||
Caqti_type.(t7 eddsa_pub time time time_span amount master_sig string)
|
Caqti_type.(t7 eddsa_pub time time time_span amount master_sig string)
|
||||||
|
|
||||||
let auditor =
|
module Auditor = struct
|
||||||
let open Auditor in
|
type t = {
|
||||||
|
auditor_pub: Crypto.EddsaPublicKey.t;
|
||||||
|
auditor_url: string;
|
||||||
|
auditor_name: string;
|
||||||
|
last_change: Timestamp.t;
|
||||||
|
is_active: bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
let of_setup_message
|
||||||
|
Api.AuditorSetupMessage.
|
||||||
|
{
|
||||||
|
auditor_url;
|
||||||
|
auditor_name;
|
||||||
|
auditor_pub;
|
||||||
|
master_sig= _;
|
||||||
|
validity_start;
|
||||||
|
} =
|
||||||
|
{
|
||||||
|
auditor_url;
|
||||||
|
auditor_name;
|
||||||
|
auditor_pub;
|
||||||
|
last_change= validity_start;
|
||||||
|
is_active= true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let caqti =
|
||||||
Caqti_type.custom
|
Caqti_type.custom
|
||||||
~encode:(fun
|
~encode:(fun
|
||||||
{ auditor_pub; auditor_url; auditor_name; last_change; is_active } ->
|
{ auditor_pub; auditor_url; auditor_name; last_change; is_active } ->
|
||||||
|
|
@ -361,3 +386,6 @@ let auditor =
|
||||||
(auditor_pub, auditor_url, auditor_name, last_change, is_active) ->
|
(auditor_pub, auditor_url, auditor_name, last_change, is_active) ->
|
||||||
Ok { auditor_pub; auditor_url; auditor_name; last_change; is_active })
|
Ok { auditor_pub; auditor_url; auditor_name; last_change; is_active })
|
||||||
Caqti_type.(t5 eddsa_pub string string time bool)
|
Caqti_type.(t5 eddsa_pub string string time bool)
|
||||||
|
end
|
||||||
|
|
||||||
|
let auditor = Auditor.caqti
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue