2025-11-28 11:08:43 +01:00
|
|
|
let download ~output_file =
|
|
|
|
|
Miou_unix.run @@ fun () ->
|
|
|
|
|
let output_file = Fpath.v output_file in
|
|
|
|
|
let fn _meta _req response () data_opt =
|
|
|
|
|
let () =
|
|
|
|
|
match response.Httpcats.status with
|
|
|
|
|
| #Httpcats.Status.successful -> ()
|
|
|
|
|
| _ ->
|
|
|
|
|
Fmt.epr "Download failure: `%a`." Httpcats.Status.pp_hum
|
|
|
|
|
response.status;
|
|
|
|
|
exit 1
|
|
|
|
|
in
|
|
|
|
|
let data =
|
|
|
|
|
match data_opt with
|
|
|
|
|
| Some data -> data
|
|
|
|
|
| None ->
|
|
|
|
|
Fmt.epr "Download failure: no data received.";
|
|
|
|
|
exit 1
|
|
|
|
|
in
|
|
|
|
|
match Bos.OS.File.write output_file data with
|
|
|
|
|
| Error (`Msg err) ->
|
|
|
|
|
Fmt.epr "Write failure: `%s`." err;
|
|
|
|
|
exit 1
|
|
|
|
|
| Ok () -> ()
|
|
|
|
|
in
|
|
|
|
|
let uri = "http://localhost:3434/management/keys" in
|
|
|
|
|
let rng = Mirage_crypto_rng_miou_unix.(initialize (module Pfortuna)) in
|
|
|
|
|
let _ = Httpcats.request ~fn ~uri () in
|
|
|
|
|
Mirage_crypto_rng_miou_unix.kill rng;
|
|
|
|
|
()
|
|
|
|
|
|
|
|
|
|
(* CLI *)
|
|
|
|
|
|
|
|
|
|
open Cmdliner
|
|
|
|
|
open Cmdliner.Term.Syntax
|
|
|
|
|
|
|
|
|
|
let output =
|
|
|
|
|
let doc = "File to save data to be signed." in
|
|
|
|
|
Arg.(
|
|
|
|
|
value & opt filepath "management_keys.json" & info [ "o"; "output" ] ~doc)
|
|
|
|
|
|
|
|
|
|
let download_cmd =
|
|
|
|
|
let doc = "Downloads /management/keys/" in
|
|
|
|
|
let man =
|
|
|
|
|
[ `S Manpage.s_description; `P "$(cmd) download /management/keys." ]
|
|
|
|
|
in
|
|
|
|
|
Cmd.make (Cmd.info "offline" ~version:"%%VERSION%%" ~doc ~man)
|
|
|
|
|
@@
|
|
|
|
|
let+ output_file = output in
|
|
|
|
|
download ~output_file
|
|
|
|
|
|
|
|
|
|
let main () = Cmd.eval download_cmd
|
|
|
|
|
let () = if !Sys.interactive then () else exit (main ())
|