This commit is contained in:
parent
2e5539eeb9
commit
388ecbdfb2
5 changed files with 95 additions and 79 deletions
|
|
@ -5,12 +5,12 @@
|
||||||
(libraries cmdliner bos fmt mirage-crypto ptime mte vif))
|
(libraries cmdliner bos fmt mirage-crypto ptime mte vif))
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
(public_name gen_taler_signatures)
|
(public_name gen_registry_files)
|
||||||
(name gen_taler_signatures)
|
(name gen_registry_files)
|
||||||
(modules gen_taler_signatures)
|
(modules gen_registry_files)
|
||||||
(libraries recfile_parser bos fmt))
|
(libraries recfile_parser bos fmt))
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name recfile_parser)
|
(name recfile_parser)
|
||||||
(modules recfile_parser)
|
(modules recfile_parser)
|
||||||
(libraries angstrom bos fmt))
|
(libraries angstrom bos cmdliner fmt))
|
||||||
|
|
|
||||||
89
tools/gen_registry_files.ml
Normal file
89
tools/gen_registry_files.ml
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
module Signature_code = struct
|
||||||
|
type t = {
|
||||||
|
number: int32;
|
||||||
|
name: string;
|
||||||
|
comment: string;
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
let parse_signature_codes records =
|
||||||
|
records
|
||||||
|
|> List.filter_map (fun l ->
|
||||||
|
match l with
|
||||||
|
| a :: b :: c :: _ -> (
|
||||||
|
let open Recfile_parser in
|
||||||
|
match a.k = "Number" && b.k = "Name" && c.k = "Comment" with
|
||||||
|
| false -> None
|
||||||
|
| true ->
|
||||||
|
Some
|
||||||
|
Signature_code.
|
||||||
|
{
|
||||||
|
number= Int32.of_int (int_of_string a.v);
|
||||||
|
name= String.lowercase_ascii b.v;
|
||||||
|
comment= c.v;
|
||||||
|
})
|
||||||
|
| _ -> None)
|
||||||
|
|> List.filter (fun v -> v.Signature_code.number >= 1000_l)
|
||||||
|
|
||||||
|
let pp_taler_signatures_ml ppf purposes =
|
||||||
|
let header =
|
||||||
|
{|(* This file was generated from the GANA database:
|
||||||
|
https://git-www.gnunet.org/gana.git/tree/gnunet-signatures/registry.rec *)|}
|
||||||
|
in
|
||||||
|
let pp ppf Signature_code.{ number; name; comment } =
|
||||||
|
Fmt.pf ppf "(** %s *)\nlet %s : int32 = %ld_l\n\n" comment name number
|
||||||
|
in
|
||||||
|
Fmt.pf ppf "%s\n\n%a@." header (Fmt.list ~sep:Fmt.nop pp) purposes;
|
||||||
|
()
|
||||||
|
|
||||||
|
let download ~tmp ~url =
|
||||||
|
let open Bos in
|
||||||
|
let res =
|
||||||
|
OS.Cmd.run
|
||||||
|
Cmd.(
|
||||||
|
v "curl" % "--silent" % "--show-error" % "-o" % tmp % "-X" % "GET" % url)
|
||||||
|
in
|
||||||
|
match res with
|
||||||
|
| Error (`Msg s) -> Fmt.failwith "download failure: %s" s
|
||||||
|
| Ok () -> ()
|
||||||
|
|
||||||
|
let signatures ~output =
|
||||||
|
let url =
|
||||||
|
"https://git-www.gnunet.org/gana.git/plain/gnunet-signatures/registry.rec"
|
||||||
|
in
|
||||||
|
let tmp_file = Bos.OS.File.tmp "registry.rec.%s" |> Result.get_ok in
|
||||||
|
download ~tmp:(Fpath.to_string tmp_file) ~url;
|
||||||
|
let content = Bos.OS.File.read tmp_file |> Result.get_ok in
|
||||||
|
match Recfile_parser.parse content with
|
||||||
|
| Error msg -> Fmt.failwith "Recfile_parser parse error: %s" msg
|
||||||
|
| Ok records ->
|
||||||
|
let purposes = parse_signature_codes records in
|
||||||
|
let module_content = Fmt.str "%a" pp_taler_signatures_ml purposes in
|
||||||
|
Bos.OS.File.write (Fpath.v output) module_content |> Result.get_ok
|
||||||
|
|
||||||
|
(* --- *)
|
||||||
|
open Cmdliner
|
||||||
|
open Cmdliner.Term.Syntax
|
||||||
|
|
||||||
|
let output =
|
||||||
|
let doc = "output file" in
|
||||||
|
Arg.(required & opt (some filepath) None & info [ "o"; "output" ] ~doc)
|
||||||
|
|
||||||
|
let signatures_cmd =
|
||||||
|
let doc =
|
||||||
|
"Generate taler_signatures.ml from GANA gnunet-signatures registry"
|
||||||
|
in
|
||||||
|
Cmd.make (Cmd.info "signatures" ~doc)
|
||||||
|
@@
|
||||||
|
let+ output = output in
|
||||||
|
signatures ~output
|
||||||
|
|
||||||
|
let cli =
|
||||||
|
let info =
|
||||||
|
let doc = "Tool to generate OCaml module from GANA registries" in
|
||||||
|
Cmd.info "gen_registry_files" ~doc
|
||||||
|
in
|
||||||
|
Cmd.group info [ signatures_cmd ]
|
||||||
|
|
||||||
|
let main () = Cmd.eval cli
|
||||||
|
let () = if !Sys.interactive then () else exit (main ())
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
type purpose = {
|
|
||||||
number: int32;
|
|
||||||
name: string;
|
|
||||||
comment: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
let download ~output ~url =
|
|
||||||
let open Bos in
|
|
||||||
let res =
|
|
||||||
OS.Cmd.run
|
|
||||||
Cmd.(
|
|
||||||
v "curl"
|
|
||||||
% "--silent"
|
|
||||||
% "--show-error"
|
|
||||||
% "-o"
|
|
||||||
% output
|
|
||||||
% "-X"
|
|
||||||
% "GET"
|
|
||||||
% url)
|
|
||||||
in
|
|
||||||
match res with
|
|
||||||
| Error (`Msg s) -> Fmt.failwith "download failure: %s" s
|
|
||||||
| Ok () -> ()
|
|
||||||
|
|
||||||
let parse_purposes records =
|
|
||||||
records
|
|
||||||
|> List.filter_map (fun l ->
|
|
||||||
match l with
|
|
||||||
| a :: b :: c :: _ -> (
|
|
||||||
let open Recfile_parser in
|
|
||||||
match a.k = "Number" && b.k = "Name" && c.k = "Comment" with
|
|
||||||
| false -> None
|
|
||||||
| true ->
|
|
||||||
Some
|
|
||||||
{
|
|
||||||
number= Int32.of_int (int_of_string a.v);
|
|
||||||
name= String.lowercase_ascii b.v;
|
|
||||||
comment= c.v;
|
|
||||||
})
|
|
||||||
| _ -> None)
|
|
||||||
|> List.filter (fun v -> v.number >= 1000_l)
|
|
||||||
|
|
||||||
let print_module purposes =
|
|
||||||
let header =
|
|
||||||
{|(* This file was generated from the GANA database:
|
|
||||||
https://git-www.gnunet.org/gana.git/tree/gnunet-signatures/registry.rec *)|}
|
|
||||||
in
|
|
||||||
let pp ppf { number; name; comment } =
|
|
||||||
Fmt.pf ppf "(** %s *)\nlet %s : int32 = %ld_l\n\n" comment name number
|
|
||||||
in
|
|
||||||
Fmt.pr "%s\n\n%a@." header (Fmt.list ~sep:Fmt.nop pp) purposes;
|
|
||||||
()
|
|
||||||
|
|
||||||
(* --- *)
|
|
||||||
|
|
||||||
let url =
|
|
||||||
"https://git-www.gnunet.org/gana.git/plain/gnunet-signatures/registry.rec"
|
|
||||||
|
|
||||||
let main () =
|
|
||||||
let tmp_file = Bos.OS.File.tmp "registry.rec.%s" |> Result.get_ok in
|
|
||||||
download ~output:(Fpath.to_string tmp_file) ~url;
|
|
||||||
let content = Bos.OS.File.read tmp_file |> Result.get_ok in
|
|
||||||
match Recfile_parser.parse content with
|
|
||||||
| Error msg -> Fmt.failwith "Recfile_parser parse error: %s" msg
|
|
||||||
| Ok records -> print_module (parse_purposes records)
|
|
||||||
|
|
||||||
let () = main ()
|
|
||||||
|
|
@ -1,13 +1,7 @@
|
||||||
(* TODO
|
(* TODO
|
||||||
better cmd doc
|
|
||||||
change arguments: '_' -> '-'
|
|
||||||
|
|
||||||
all management operations:
|
all management operations:
|
||||||
/management/wire
|
/management/wire
|
||||||
/management/wire/disable
|
/management/wire/disable
|
||||||
-> how to build WireSetupMessage?
|
|
||||||
we need additional data to craft master_sig
|
|
||||||
maybe supposed to be found in the full payto-uri?
|
|
||||||
|
|
||||||
/management/aml-officers
|
/management/aml-officers
|
||||||
-> /aml
|
-> /aml
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(* rudimentary recfile parser
|
(* very rudimentary recfile parser
|
||||||
https://www.gnu.org/software/recutils/manual/recutils.html#The-Rec-Format *)
|
https://www.gnu.org/software/recutils/manual/recutils.html#The-Rec-Format *)
|
||||||
|
|
||||||
open Angstrom
|
open Angstrom
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue