This commit is contained in:
swrup 2025-11-30 14:23:55 +01:00
parent cf4da6b382
commit 8db7d7bd36
4 changed files with 36 additions and 19 deletions

1
download.json Normal file
View file

@ -0,0 +1 @@
{"key":"some value"}

View file

@ -110,9 +110,34 @@ let keys_get req server _env =
let* () = add ~field:"content-type" "application/json" in
respond `OK
type foo = { key: string }
let foo_jsont =
let open Jsont in
let enc foo = foo.key in
let make key = { key } in
Object.map ~kind:"foo" make |> Object.mem "key" string ~enc |> Object.finish
let () =
let foo = { key= "uhuh" } in
let s = Api.encode foo_jsont foo |> Result.get_ok in
Fmt.epr "%s@." s; ()
let keys_post req _server _env =
let open Vif.Response in
let open Syntax in
let* () = with_string req {||} in
let* () = add ~field:"content-type" "application/json" in
respond `OK
match Vif.Request.of_json req with
| Ok (foo : foo) ->
let str = Fmt.str "key: %s@." foo.key in
let* () =
Vif.Response.add ~field:"content-type" "text/plain; charset=utf-8"
in
let* () = Vif.Response.with_string req str in
Vif.Response.respond `OK
| Error (`Msg msg) ->
Logs.err (fun m -> m "Invalid JSON: %s" msg);
let* () =
Vif.Response.add ~field:"content-type" "text/plain; charset=utf-8"
in
let* () = Vif.Response.with_string req msg in
Vif.Response.respond (`Code 422)

View file

@ -33,7 +33,10 @@ let routes =
get_ (rel / "privacy" /?? nil) --> Static.privacy;
get_ (rel / "test" /?? nil) --> Database.test_activate;
get_ (rel / "management" / "keys" /?? nil) --> Management.keys_get;
post (rel / "management" / "keys" /?? nil) any --> Management.keys_post;
post
(rel / "management" / "keys" /?? nil)
(json_encoding Management.foo_jsont)
--> Management.keys_post;
]
let () =

View file

@ -1,6 +1,5 @@
(* TODO
- clean up cmdliner
- don't depends on wget
- setup: need public key in config file
- check sigs *)
(* doc: https://docs.taler.net/manpages/taler-exchange-offline.1.html *)
@ -11,26 +10,15 @@ let download ~base_url ~output =
let uri =
Uri.with_path (Uri.of_string base_url) "/management/keys/" |> Uri.to_string
in
let wget = Cmd.(v "wget" % "-O" % output % uri) in
OS.Cmd.run wget
OS.Cmd.run Cmd.(v "hurl" % "--output" % output % uri)
let upload ~base_url ~input =
let open Bos in
let uri =
Uri.with_path (Uri.of_string base_url) "/management/keys/" |> Uri.to_string
in
let wget =
Cmd.(
v "wget"
% "--method=POST"
% "--header='Content-Type: application/json'"
% "--body-file"
% input
% "-O"
% "/dev/null"
% uri)
in
OS.Cmd.run wget
OS.Cmd.run
Cmd.(v "hurl" % "--method" % "POST" % "--json-input" % ("@=" ^ input) % uri)
let setup ~output =
let output = Fpath.v output in