add --postgres-password cmdline arg + make keys

This commit is contained in:
swrup 2026-05-12 04:10:43 +02:00 committed by Swrup
parent 42b7e13eae
commit 6cb6a96784
11 changed files with 84 additions and 53 deletions

View file

@ -62,10 +62,6 @@ module Exchangedb = struct
let default_purse_limit = get "default_purse_limit" |> int
end
module Exchangedb_postgres = struct
let config = get config ~section:"exchangedb-postgres" ~field:"config" |> uri
end
module Currency = struct
type t = {
enabled: [ `YES | `NO ];

View file

@ -4,4 +4,5 @@ type t = {
tcp: Mnet.TCP.state;
dns: Mnet_dns.t;
fs: Fat.t;
db_uri: Uri.t;
}

View file

@ -50,10 +50,9 @@ let routes =
module RNG = Mirage_crypto_rng.Fortuna
let t0 = Mkernel.clock_monotonic ()
let () =
let run postgres_password =
let ( let@ ) finally fn = Fun.protect ~finally fn in
let t0 = Mkernel.clock_monotonic () in
Log_reporter.setup ~t0;
let rng =
let rng () = Mirage_crypto_rng_mkernel.initialize (module RNG) in
@ -81,6 +80,30 @@ let () =
Vifu.Devices.[ Mte_device.sm_eddsa; Mte_device.sm_rsa; Mte_device.pool ]
in
let handlers = [ Mte_handler.not_implemented_route ] in
let env = { Env.sw; stack; tcp; dns; fs } in
let env =
let db_uri =
Uri.of_string
@@ Fmt.str "pgx://mte:%s@10.0.0.1:5432/taler-exchange" postgres_password
in
{ Env.sw; stack; tcp; dns; fs; db_uri }
in
Logs.info (fun m -> m "Starting MTE server");
Vifu.run ~cfg ~devices ~handlers tcp routes env
open Cmdliner
(* todo: tls *)
let postgres_password =
let doc = "PostgreSQL password." in
let open Arg in
required & opt (some string) None & info [ "postgres-password" ] ~doc
let term =
let open Term in
const run $ postgres_password
let cmd =
let info = Cmd.info "blame" in
Cmd.v info term
let () = Cmd.(exit @@ eval cmd)

View file

@ -9,9 +9,8 @@ let sm_rsa =
Vifu.Device.v ~name:"secmod-rsa" ~finally [] f
let pool : (Env.t, Pg.pool) Vifu.Device.device =
let f { Env.sw; stack; tcp; dns; fs= _ } =
let f { Env.sw; stack; tcp; dns; db_uri; fs= _ } =
Logs.info (fun m -> m "Connecting to database");
let db_uri = Config.Exchangedb_postgres.config in
let post_connect conn = Pg.preflight conn in
match Caqti_mnet.connect_pool ~post_connect ~sw stack tcp dns db_uri with
| Error e ->