From 5d7927e392e70436aaca1f8261e5d4ab8e4ec8f8 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 23 Oct 2024 18:50:46 -0500 Subject: T6718: update build system, drop batteries, and adjust for lib changes Update as needed for use with contemporary vyos1x-config: . update build system to use dune . drop use of batteries . update for protoc breaking changes in versions >= 3.0 . remove files now in vyos1x-config (config_tree et. al.; parsing) --- src/dune | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/dune (limited to 'src/dune') diff --git a/src/dune b/src/dune new file mode 100644 index 0000000..ff86052 --- /dev/null +++ b/src/dune @@ -0,0 +1,5 @@ +(library + (name vyconf) + (public_name vyconf) + (libraries vyos1x-config lwt lwt.unix lwt_log lwt_ppx ocaml-protoc toml sha yojson ppx_deriving.show ppx_deriving_yojson) + (preprocess (pps lwt_ppx ppx_deriving.show ppx_deriving_yojson))) -- cgit v1.2.3 From 037c3ce961e1fec94b1d50b069b69c6636ac0393 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 23 Oct 2024 18:50:46 -0500 Subject: T6718: reorganize layout for dune build of libs/executables --- src/dune | 28 +++++++++++++++++++++++++--- src/message.ml | 9 +++++++-- src/session.ml | 6 +++--- src/session.mli | 2 +- src/startup.ml | 6 +++--- src/startup.mli | 4 ++-- src/util.ml | 38 -------------------------------------- src/util.mli | 9 --------- src/vyconf_client.ml | 8 ++++---- src/vyconf_client.mli | 2 +- src/vyconfd.ml | 27 +++++++++++++++------------ vyconf.opam | 6 +++--- 12 files changed, 64 insertions(+), 81 deletions(-) delete mode 100644 src/util.ml delete mode 100644 src/util.mli (limited to 'src/dune') diff --git a/src/dune b/src/dune index ff86052..a259da4 100644 --- a/src/dune +++ b/src/dune @@ -1,5 +1,27 @@ (library - (name vyconf) - (public_name vyconf) - (libraries vyos1x-config lwt lwt.unix lwt_log lwt_ppx ocaml-protoc toml sha yojson ppx_deriving.show ppx_deriving_yojson) + (name vyconf_connect) + (public_name vyconf.vyconf-connect) + (modules vyconf_types vyconf_pb message) + (libraries lwt lwt.unix lwt_log lwt_ppx ocaml-protoc fileutils ppx_deriving_yojson) + (preprocess (pps lwt_ppx ppx_deriving_yojson))) + +(library + (name vyconfd_config) + (modules vyconf_config session directories defaults) + (libraries vyos1x-config vyconf_connect toml sha ppx_deriving.show) + (preprocess (pps ppx_deriving.show ppx_deriving_yojson))) + +(library + (name client) + (public_name vyconf.vyconf-client) + (modules vyconf_client) + (libraries vyos1x-config vyconf_connect lwt lwt.unix lwt_log lwt_ppx ocaml-protoc toml sha + yojson ppx_deriving.show ppx_deriving_yojson) (preprocess (pps lwt_ppx ppx_deriving.show ppx_deriving_yojson))) + +(executable + (name vyconfd) + (public_name vyconfd) + (modules vyconfd startup version util) + (libraries vyos1x-config vyconfd_config vyconf_connect) + (preprocess (pps lwt_ppx))) diff --git a/src/message.ml b/src/message.ml index 3629f0d..d4cc374 100644 --- a/src/message.ml +++ b/src/message.ml @@ -3,6 +3,11 @@ Messages are preceded by a length header, four bytes in network order. *) +(** Makes a hex dump of a byte string *) +let hexdump b = + let dump = ref "" in + Bytes.iter (fun c -> dump := Char.code c |> Printf.sprintf "%s %02x" !dump) b; + !dump let read ic = let header = Bytes.create 4 in @@ -12,14 +17,14 @@ let read ic = if length < 0 then failwith (Printf.sprintf "Bad message length: %d" length) else let buffer = Bytes.create length in let%lwt () = Lwt_io.read_into_exactly ic buffer 0 length in - Lwt_log.debug (Util.hexdump buffer |> Printf.sprintf "Read mesage: %s") |> Lwt.ignore_result; + Lwt_log.debug (hexdump buffer |> Printf.sprintf "Read mesage: %s") |> Lwt.ignore_result; Lwt.return buffer let write oc msg = let length = Bytes.length msg in let length' = Int32.of_int length in Lwt_log.debug (Printf.sprintf "Write length: %d\n" length) |> Lwt.ignore_result; - Lwt_log.debug (Util.hexdump msg |> Printf.sprintf "Write message: %s") |> Lwt.ignore_result; + Lwt_log.debug (hexdump msg |> Printf.sprintf "Write message: %s") |> Lwt.ignore_result; if length' < 0l then failwith (Printf.sprintf "Bad message length: %d" length) else let header = Bytes.create 4 in let () = EndianBytes.BigEndian.set_int32 header 0 length' in diff --git a/src/session.ml b/src/session.ml index 7624bb0..1a422f7 100644 --- a/src/session.ml +++ b/src/session.ml @@ -37,12 +37,12 @@ let make world client_app user = { let string_of_op op = match op with | CfgSet (path, value, _) -> - let path_str = Util.string_of_list path in + let path_str = Vyos1x.Util.string_of_list path in (match value with | None -> Printf.sprintf "set %s" path_str | Some v -> Printf.sprintf "set %s \"%s\"" path_str v) | CfgDelete (path, value) -> - let path_str = Util.string_of_list path in + let path_str = Vyos1x.Util.string_of_list path in (match value with | None -> Printf.sprintf "delete %s" path_str | Some v -> Printf.sprintf "delete %s \"%s\"" path_str v) @@ -110,7 +110,7 @@ let exists _w s path = VT.exists s.proposed_config path let show_config _w s path fmt = - let open Vyconf_types in + let open Vyconf_connect.Vyconf_types in if (path <> []) && not (VT.exists s.proposed_config path) then raise (Session_error ("Path does not exist")) else diff --git a/src/session.mli b/src/session.mli index f59ea7b..9670edd 100644 --- a/src/session.mli +++ b/src/session.mli @@ -40,4 +40,4 @@ val list_children : world -> session_data -> string list -> string list val string_of_op : cfg_op -> string -val show_config : world -> session_data -> string list -> Vyconf_types.request_config_format -> string +val show_config : world -> session_data -> string list -> Vyconf_connect.Vyconf_types.request_config_format -> string diff --git a/src/startup.ml b/src/startup.ml index 4cf109c..b3a967e 100644 --- a/src/startup.ml +++ b/src/startup.ml @@ -33,7 +33,7 @@ let setup_logger daemonize log_file template = (** Load the config file or panic if it fails *) let load_daemon_config path = - let result = Vyconf_config.load path in + let result = Vyconfd_config.Vyconf_config.load path in match result with | Ok cfg -> cfg | Error err -> @@ -41,7 +41,7 @@ let load_daemon_config path = (** Check if appliance directories exist and panic if they don't *) let check_dirs dirs = - let res = Directories.test dirs in + let res = Vyconfd_config.Directories.test dirs in match res with | Ok _ -> () | Error err -> panic err @@ -112,7 +112,7 @@ let load_interface_definitions dir = let open Vyos1x.Reference_tree in let relative_paths = FileUtil.ls dir in let absolute_paths = - try Ok (List.map Util.absolute_path relative_paths) + try Ok (List.map Vyos1x.Util.absolute_path relative_paths) with Sys_error no_dir_msg -> Error no_dir_msg in let load_aux tree file = diff --git a/src/startup.mli b/src/startup.mli index abe731f..77c35ac 100644 --- a/src/startup.mli +++ b/src/startup.mli @@ -2,9 +2,9 @@ val panic : string -> 'a val setup_logger : bool -> string option -> Lwt_log.template -> unit Lwt.t -val load_daemon_config : string -> Vyconf_config.t +val load_daemon_config : string -> Vyconfd_config.Vyconf_config.t -val check_dirs : Directories.t -> unit +val check_dirs : Vyconfd_config.Directories.t -> unit val create_socket : string -> Lwt_unix.file_descr Lwt.t diff --git a/src/util.ml b/src/util.ml deleted file mode 100644 index ec988e9..0000000 --- a/src/util.ml +++ /dev/null @@ -1,38 +0,0 @@ -(** The unavoidable module for functions that don't fit anywhere else *) - -(** Find a child node in xml-lite *) -let find_xml_child name xml = - let find_aux e = - match e with - | Xml.Element (name', _, _) when name' = name -> true - | _ -> false - in - match xml with - | Xml.Element (_, _, children) -> Vyos1x.Vylist.find find_aux children - | Xml.PCData _ -> None - -(** Convert a list of strings to a string of unquoted, space separated words *) -let string_of_list ss = - let rec aux xs acc = - match xs with - | [] -> acc - | x :: xs' -> aux xs' (Printf.sprintf "%s %s" acc x) - in - match ss with - | [] -> "" - | x :: xs -> Printf.sprintf "%s%s" x (aux xs "") - -(** Convert a list of strings to JSON *) -let json_of_list ss = - let ss = List.map (fun x -> `String x) ss in - Yojson.Safe.to_string (`List ss) - -(** Convert a relative path to an absolute path based on the current working directory *) -let absolute_path relative_path = - FilePath.make_absolute (Sys.getcwd ()) relative_path - -(** Makes a hex dump of a byte string *) -let hexdump b = - let dump = ref "" in - Bytes.iter (fun c -> dump := Char.code c |> Printf.sprintf "%s %02x" !dump) b; - !dump diff --git a/src/util.mli b/src/util.mli deleted file mode 100644 index 4c11d9e..0000000 --- a/src/util.mli +++ /dev/null @@ -1,9 +0,0 @@ -val find_xml_child : string -> Xml.xml -> Xml.xml option - -val string_of_list : string list -> string - -val json_of_list : string list -> string - -val absolute_path : FilePath.filename -> FilePath.filename - -val hexdump : bytes -> string diff --git a/src/vyconf_client.ml b/src/vyconf_client.ml index 63ff121..bc4002c 100644 --- a/src/vyconf_client.ml +++ b/src/vyconf_client.ml @@ -1,5 +1,5 @@ -include Vyconf_pb -include Vyconf_types +include Vyconf_connect.Vyconf_pb +include Vyconf_connect.Vyconf_types type t = { sock: Lwt_unix.file_descr; @@ -45,8 +45,8 @@ let do_request client req = let enc = Pbrt.Encoder.create () in let () = encode_request_envelope {token=client.session; request=req} enc in let msg = Pbrt.Encoder.to_bytes enc in - let%lwt () = Message.write client.oc msg in - let%lwt resp = Message.read client.ic in + let%lwt () = Vyconf_connect.Message.write client.oc msg in + let%lwt resp = Vyconf_connect.Message.read client.ic in decode_response (Pbrt.Decoder.of_bytes resp) |> Lwt.return let get_status client = diff --git a/src/vyconf_client.mli b/src/vyconf_client.mli index 8eaada8..8621130 100644 --- a/src/vyconf_client.mli +++ b/src/vyconf_client.mli @@ -19,7 +19,7 @@ type response = { } -val create : ?token:(string option) -> string -> Vyconf_types.request_output_format -> Vyconf_types.request_config_format -> t Lwt.t +val create : ?token:(string option) -> string -> Vyconf_connect.Vyconf_types.request_output_format -> Vyconf_connect.Vyconf_types.request_config_format -> t Lwt.t val get_token : t -> (string, string) result Lwt.t diff --git a/src/vyconfd.ml b/src/vyconfd.ml index f3816d4..59425ee 100644 --- a/src/vyconfd.ml +++ b/src/vyconfd.ml @@ -1,11 +1,14 @@ open Lwt -open Defaults -open Vyconf_config -open Vyconf_pb -open Vyconf_types + +open Vyconf_connect.Vyconf_types +open Vyconf_connect.Vyconf_pb +open Vyconfd_config.Defaults module FP = FilePath module CT = Vyos1x.Config_tree +module Gen = Vyos1x.Generate +module Session = Vyconfd_config.Session +module Directories = Vyconfd_config.Directories (* On UNIX, self_init uses /dev/random for seed *) let () = Random.self_init () @@ -94,7 +97,7 @@ let exists world token (req: request_exists) = let get_value world token (req: request_get_value) = try - let () = (Lwt_log.debug @@ Printf.sprintf "[%s]\n" (Util.string_of_list req.path)) |> Lwt.ignore_result in + let () = (Lwt_log.debug @@ Printf.sprintf "[%s]\n" (Vyos1x.Util.string_of_list req.path)) |> Lwt.ignore_result in let value = Session.get_value world (find_session token) req.path in let fmt = Option.value req.output_format ~default:Out_plain in let value_str = @@ -110,8 +113,8 @@ let get_values world token (req: request_get_values) = let fmt = Option.value req.output_format ~default:Out_plain in let values_str = (match fmt with - | Out_plain -> Util.string_of_list @@ List.map (Printf.sprintf "\'%s\'") values - | Out_json -> Util.json_of_list values) + | Out_plain -> Vyos1x.Util.string_of_list @@ List.map (Printf.sprintf "\'%s\'") values + | Out_json -> Vyos1x.Util.json_of_list values) in {response_tmpl with output=(Some values_str)} with Session.Session_error msg -> {response_tmpl with status=Fail; error=(Some msg)} @@ -121,8 +124,8 @@ let list_children world token (req: request_list_children) = let fmt = Option.value req.output_format ~default:Out_plain in let children_str = (match fmt with - | Out_plain -> Util.string_of_list @@ List.map (Printf.sprintf "\'%s\'") children - | Out_json -> Util.json_of_list children) + | Out_plain -> Vyos1x.Util.string_of_list @@ List.map (Printf.sprintf "\'%s\'") children + | Out_json -> Vyos1x.Util.json_of_list children) in {response_tmpl with output=(Some children_str)} with Session.Session_error msg -> {response_tmpl with status=Fail; error=(Some msg)} @@ -137,12 +140,12 @@ let send_response oc resp = let enc = Pbrt.Encoder.create () in let%lwt () = encode_response resp enc |> return in let%lwt resp_msg = Pbrt.Encoder.to_bytes enc |> return in - let%lwt () = Message.write oc resp_msg in + let%lwt () = Vyconf_connect.Message.write oc resp_msg in Lwt.return () let rec handle_connection world ic oc fd () = try%lwt - let%lwt req_msg = Message.read ic in + let%lwt req_msg = Vyconf_connect.Message.read ic in let%lwt req = try let envelope = decode_request_envelope (Pbrt.Decoder.of_bytes req_msg) in @@ -196,7 +199,7 @@ let main_loop basepath world () = let load_interface_definitions dir = (* let open Session in *) - let reftree = Startup.load_interface_definitions dir in + let reftree = Gen.load_interface_definitions dir in match reftree with | Ok r -> r | Error s -> Startup.panic s diff --git a/vyconf.opam b/vyconf.opam index 68e8d45..b947e39 100644 --- a/vyconf.opam +++ b/vyconf.opam @@ -1,12 +1,13 @@ opam-version: "2.0" name: "vyconf" version: "0.1" +synopsis: "VyOS 2.x config file control library" +description: "An appliance configuration framework" maintainer: "Daniil Baturin " authors: "VyOS maintainers and contributors " homepage: "https://github.com/vyos/vyconf" bug-reports: "https://phabricator.vyos.net" -license: "LGPL with OCaml linking exception" -description: "An appliance configuration framework" +license: "LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception" dev-repo: "git+https://github.com/vyos/vyconf/" build: [ ["dune" "subst"] {pinned} @@ -29,4 +30,3 @@ depends: [ "sha" {build} "pcre" {build} ] -available: ocaml-version >= "4.14.2" -- cgit v1.2.3 From 92b9c5e1a47be12b1e5dd7c6f069e69d28465eac Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 23 Oct 2024 18:50:46 -0500 Subject: T6718: add rule to generate protobuf with name change Regenerate protobuf files: ocaml-protoc --ml_out src/ data/vyconf.proto The generated files vyconf.* are renamed vyconf_pbt.* instead of the split into vyconf_pb/vyconf_types as in the original implementation. --- src/dune | 14 +- src/session.ml | 2 +- src/session.mli | 2 +- src/vyconf_client.ml | 7 +- src/vyconf_client.mli | 2 +- src/vyconf_pb.ml | 1121 -------------------------------- src/vyconf_pb.mli | 151 ----- src/vyconf_pbt.ml | 1702 +++++++++++++++++++++++++++++++++++++++++++++++++ src/vyconf_pbt.mli | 576 +++++++++++++++++ src/vyconf_types.ml | 318 --------- src/vyconf_types.mli | 306 --------- src/vyconfd.ml | 7 +- 12 files changed, 2300 insertions(+), 1908 deletions(-) delete mode 100644 src/vyconf_pb.ml delete mode 100644 src/vyconf_pb.mli create mode 100644 src/vyconf_pbt.ml create mode 100644 src/vyconf_pbt.mli delete mode 100644 src/vyconf_types.ml delete mode 100644 src/vyconf_types.mli (limited to 'src/dune') diff --git a/src/dune b/src/dune index a259da4..954a055 100644 --- a/src/dune +++ b/src/dune @@ -1,7 +1,7 @@ (library (name vyconf_connect) (public_name vyconf.vyconf-connect) - (modules vyconf_types vyconf_pb message) + (modules vyconf_pbt message) (libraries lwt lwt.unix lwt_log lwt_ppx ocaml-protoc fileutils ppx_deriving_yojson) (preprocess (pps lwt_ppx ppx_deriving_yojson))) @@ -25,3 +25,15 @@ (modules vyconfd startup version util) (libraries vyos1x-config vyconfd_config vyconf_connect) (preprocess (pps lwt_ppx))) + +(rule + (alias protoc) + (mode promote) + (targets vyconf_pbt.ml vyconf_pbt.mli) + (action + (chdir + %{project_root} + (progn + (run ocaml-protoc --ml_out src data/vyconf.proto) + (run mv src/vyconf.ml src/vyconf_pbt.ml) + (run mv src/vyconf.mli src/vyconf_pbt.mli))))) diff --git a/src/session.ml b/src/session.ml index 1a422f7..3898abe 100644 --- a/src/session.ml +++ b/src/session.ml @@ -110,7 +110,7 @@ let exists _w s path = VT.exists s.proposed_config path let show_config _w s path fmt = - let open Vyconf_connect.Vyconf_types in + let open Vyconf_connect.Vyconf_pbt in if (path <> []) && not (VT.exists s.proposed_config path) then raise (Session_error ("Path does not exist")) else diff --git a/src/session.mli b/src/session.mli index 9670edd..8d10707 100644 --- a/src/session.mli +++ b/src/session.mli @@ -40,4 +40,4 @@ val list_children : world -> session_data -> string list -> string list val string_of_op : cfg_op -> string -val show_config : world -> session_data -> string list -> Vyconf_connect.Vyconf_types.request_config_format -> string +val show_config : world -> session_data -> string list -> Vyconf_connect.Vyconf_pbt.request_config_format -> string diff --git a/src/vyconf_client.ml b/src/vyconf_client.ml index bc4002c..f6ce448 100644 --- a/src/vyconf_client.ml +++ b/src/vyconf_client.ml @@ -1,5 +1,4 @@ -include Vyconf_connect.Vyconf_pb -include Vyconf_connect.Vyconf_types +include Vyconf_connect.Vyconf_pbt type t = { sock: Lwt_unix.file_descr; @@ -43,11 +42,11 @@ let shutdown client = let do_request client req = let enc = Pbrt.Encoder.create () in - let () = encode_request_envelope {token=client.session; request=req} enc in + let () = encode_pb_request_envelope {token=client.session; request=req} enc in let msg = Pbrt.Encoder.to_bytes enc in let%lwt () = Vyconf_connect.Message.write client.oc msg in let%lwt resp = Vyconf_connect.Message.read client.ic in - decode_response (Pbrt.Decoder.of_bytes resp) |> Lwt.return + decode_pb_response (Pbrt.Decoder.of_bytes resp) |> Lwt.return let get_status client = let req = Status in diff --git a/src/vyconf_client.mli b/src/vyconf_client.mli index 8621130..dbf9e25 100644 --- a/src/vyconf_client.mli +++ b/src/vyconf_client.mli @@ -19,7 +19,7 @@ type response = { } -val create : ?token:(string option) -> string -> Vyconf_connect.Vyconf_types.request_output_format -> Vyconf_connect.Vyconf_types.request_config_format -> t Lwt.t +val create : ?token:(string option) -> string -> Vyconf_connect.Vyconf_pbt.request_output_format -> Vyconf_connect.Vyconf_pbt.request_config_format -> t Lwt.t val get_token : t -> (string, string) result Lwt.t diff --git a/src/vyconf_pb.ml b/src/vyconf_pb.ml deleted file mode 100644 index c6155da..0000000 --- a/src/vyconf_pb.ml +++ /dev/null @@ -1,1121 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - -type request_setup_session_mutable = { - mutable client_application : string option; - mutable on_behalf_of : int32 option; -} - -let default_request_setup_session_mutable () : request_setup_session_mutable = { - client_application = None; - on_behalf_of = None; -} - -type request_set_mutable = { - mutable path : string list; - mutable ephemeral : bool option; -} - -let default_request_set_mutable () : request_set_mutable = { - path = []; - ephemeral = None; -} - -type request_delete_mutable = { - mutable path : string list; -} - -let default_request_delete_mutable () : request_delete_mutable = { - path = []; -} - -type request_rename_mutable = { - mutable edit_level : string list; - mutable from : string; - mutable to_ : string; -} - -let default_request_rename_mutable () : request_rename_mutable = { - edit_level = []; - from = ""; - to_ = ""; -} - -type request_copy_mutable = { - mutable edit_level : string list; - mutable from : string; - mutable to_ : string; -} - -let default_request_copy_mutable () : request_copy_mutable = { - edit_level = []; - from = ""; - to_ = ""; -} - -type request_comment_mutable = { - mutable path : string list; - mutable comment : string; -} - -let default_request_comment_mutable () : request_comment_mutable = { - path = []; - comment = ""; -} - -type request_commit_mutable = { - mutable confirm : bool option; - mutable confirm_timeout : int32 option; - mutable comment : string option; -} - -let default_request_commit_mutable () : request_commit_mutable = { - confirm = None; - confirm_timeout = None; - comment = None; -} - -type request_rollback_mutable = { - mutable revision : int32; -} - -let default_request_rollback_mutable () : request_rollback_mutable = { - revision = 0l; -} - -type request_load_mutable = { - mutable location : string; - mutable format : Vyconf_types.request_config_format option; -} - -let default_request_load_mutable () : request_load_mutable = { - location = ""; - format = None; -} - -type request_merge_mutable = { - mutable location : string; - mutable format : Vyconf_types.request_config_format option; -} - -let default_request_merge_mutable () : request_merge_mutable = { - location = ""; - format = None; -} - -type request_save_mutable = { - mutable location : string; - mutable format : Vyconf_types.request_config_format option; -} - -let default_request_save_mutable () : request_save_mutable = { - location = ""; - format = None; -} - -type request_show_config_mutable = { - mutable path : string list; - mutable format : Vyconf_types.request_config_format option; -} - -let default_request_show_config_mutable () : request_show_config_mutable = { - path = []; - format = None; -} - -type request_exists_mutable = { - mutable path : string list; -} - -let default_request_exists_mutable () : request_exists_mutable = { - path = []; -} - -type request_get_value_mutable = { - mutable path : string list; - mutable output_format : Vyconf_types.request_output_format option; -} - -let default_request_get_value_mutable () : request_get_value_mutable = { - path = []; - output_format = None; -} - -type request_get_values_mutable = { - mutable path : string list; - mutable output_format : Vyconf_types.request_output_format option; -} - -let default_request_get_values_mutable () : request_get_values_mutable = { - path = []; - output_format = None; -} - -type request_list_children_mutable = { - mutable path : string list; - mutable output_format : Vyconf_types.request_output_format option; -} - -let default_request_list_children_mutable () : request_list_children_mutable = { - path = []; - output_format = None; -} - -type request_run_op_mode_mutable = { - mutable path : string list; - mutable output_format : Vyconf_types.request_output_format option; -} - -let default_request_run_op_mode_mutable () : request_run_op_mode_mutable = { - path = []; - output_format = None; -} - -type request_enter_configuration_mode_mutable = { - mutable exclusive : bool; - mutable override_exclusive : bool; -} - -let default_request_enter_configuration_mode_mutable () : request_enter_configuration_mode_mutable = { - exclusive = false; - override_exclusive = false; -} - -type request_envelope_mutable = { - mutable token : string option; - mutable request : Vyconf_types.request; -} - -let default_request_envelope_mutable () : request_envelope_mutable = { - token = None; - request = Vyconf_types.default_request (); -} - -type response_mutable = { - mutable status : Vyconf_types.status; - mutable output : string option; - mutable error : string option; - mutable warning : string option; -} - -let default_response_mutable () : response_mutable = { - status = Vyconf_types.default_status (); - output = None; - error = None; - warning = None; -} - - -let rec decode_request_config_format d = - match Pbrt.Decoder.int_as_varint d with - | 0 -> (Vyconf_types.Curly:Vyconf_types.request_config_format) - | 1 -> (Vyconf_types.Json:Vyconf_types.request_config_format) - | _ -> Pbrt.Decoder.malformed_variant "request_config_format" - -let rec decode_request_output_format d = - match Pbrt.Decoder.int_as_varint d with - | 0 -> (Vyconf_types.Out_plain:Vyconf_types.request_output_format) - | 1 -> (Vyconf_types.Out_json:Vyconf_types.request_output_format) - | _ -> Pbrt.Decoder.malformed_variant "request_output_format" - -let rec decode_request_setup_session d = - let v = default_request_setup_session_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.client_application <- Some (Pbrt.Decoder.string d); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_setup_session), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.on_behalf_of <- Some (Pbrt.Decoder.int32_as_varint d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_setup_session), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.client_application = v.client_application; - Vyconf_types.on_behalf_of = v.on_behalf_of; - } : Vyconf_types.request_setup_session) - -let rec decode_request_set d = - let v = default_request_set_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.path <- List.rev v.path; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.path <- (Pbrt.Decoder.string d) :: v.path; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_set), field(1)" pk - | Some (3, Pbrt.Varint) -> begin - v.ephemeral <- Some (Pbrt.Decoder.bool d); - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_set), field(3)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.path = v.path; - Vyconf_types.ephemeral = v.ephemeral; - } : Vyconf_types.request_set) - -let rec decode_request_delete d = - let v = default_request_delete_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.path <- List.rev v.path; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.path <- (Pbrt.Decoder.string d) :: v.path; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_delete), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.path = v.path; - } : Vyconf_types.request_delete) - -let rec decode_request_rename d = - let v = default_request_rename_mutable () in - let continue__= ref true in - let to__is_set = ref false in - let from_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.edit_level <- List.rev v.edit_level; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.edit_level <- (Pbrt.Decoder.string d) :: v.edit_level; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_rename), field(1)" pk - | Some (2, Pbrt.Bytes) -> begin - v.from <- Pbrt.Decoder.string d; from_is_set := true; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_rename), field(2)" pk - | Some (3, Pbrt.Bytes) -> begin - v.to_ <- Pbrt.Decoder.string d; to__is_set := true; - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_rename), field(3)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !to__is_set then Pbrt.Decoder.missing_field "to_" end; - begin if not !from_is_set then Pbrt.Decoder.missing_field "from" end; - ({ - Vyconf_types.edit_level = v.edit_level; - Vyconf_types.from = v.from; - Vyconf_types.to_ = v.to_; - } : Vyconf_types.request_rename) - -let rec decode_request_copy d = - let v = default_request_copy_mutable () in - let continue__= ref true in - let to__is_set = ref false in - let from_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.edit_level <- List.rev v.edit_level; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.edit_level <- (Pbrt.Decoder.string d) :: v.edit_level; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_copy), field(1)" pk - | Some (2, Pbrt.Bytes) -> begin - v.from <- Pbrt.Decoder.string d; from_is_set := true; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_copy), field(2)" pk - | Some (3, Pbrt.Bytes) -> begin - v.to_ <- Pbrt.Decoder.string d; to__is_set := true; - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_copy), field(3)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !to__is_set then Pbrt.Decoder.missing_field "to_" end; - begin if not !from_is_set then Pbrt.Decoder.missing_field "from" end; - ({ - Vyconf_types.edit_level = v.edit_level; - Vyconf_types.from = v.from; - Vyconf_types.to_ = v.to_; - } : Vyconf_types.request_copy) - -let rec decode_request_comment d = - let v = default_request_comment_mutable () in - let continue__= ref true in - let comment_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.path <- List.rev v.path; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.path <- (Pbrt.Decoder.string d) :: v.path; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_comment), field(1)" pk - | Some (2, Pbrt.Bytes) -> begin - v.comment <- Pbrt.Decoder.string d; comment_is_set := true; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_comment), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !comment_is_set then Pbrt.Decoder.missing_field "comment" end; - ({ - Vyconf_types.path = v.path; - Vyconf_types.comment = v.comment; - } : Vyconf_types.request_comment) - -let rec decode_request_commit d = - let v = default_request_commit_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.confirm <- Some (Pbrt.Decoder.bool d); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_commit), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.confirm_timeout <- Some (Pbrt.Decoder.int32_as_varint d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_commit), field(2)" pk - | Some (3, Pbrt.Bytes) -> begin - v.comment <- Some (Pbrt.Decoder.string d); - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_commit), field(3)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.confirm = v.confirm; - Vyconf_types.confirm_timeout = v.confirm_timeout; - Vyconf_types.comment = v.comment; - } : Vyconf_types.request_commit) - -let rec decode_request_rollback d = - let v = default_request_rollback_mutable () in - let continue__= ref true in - let revision_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.revision <- Pbrt.Decoder.int32_as_varint d; revision_is_set := true; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_rollback), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !revision_is_set then Pbrt.Decoder.missing_field "revision" end; - ({ - Vyconf_types.revision = v.revision; - } : Vyconf_types.request_rollback) - -let rec decode_request_load d = - let v = default_request_load_mutable () in - let continue__= ref true in - let location_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.location <- Pbrt.Decoder.string d; location_is_set := true; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_load), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.format <- Some (decode_request_config_format d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_load), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !location_is_set then Pbrt.Decoder.missing_field "location" end; - ({ - Vyconf_types.location = v.location; - Vyconf_types.format = v.format; - } : Vyconf_types.request_load) - -let rec decode_request_merge d = - let v = default_request_merge_mutable () in - let continue__= ref true in - let location_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.location <- Pbrt.Decoder.string d; location_is_set := true; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_merge), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.format <- Some (decode_request_config_format d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_merge), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !location_is_set then Pbrt.Decoder.missing_field "location" end; - ({ - Vyconf_types.location = v.location; - Vyconf_types.format = v.format; - } : Vyconf_types.request_merge) - -let rec decode_request_save d = - let v = default_request_save_mutable () in - let continue__= ref true in - let location_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.location <- Pbrt.Decoder.string d; location_is_set := true; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_save), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.format <- Some (decode_request_config_format d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_save), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !location_is_set then Pbrt.Decoder.missing_field "location" end; - ({ - Vyconf_types.location = v.location; - Vyconf_types.format = v.format; - } : Vyconf_types.request_save) - -let rec decode_request_show_config d = - let v = default_request_show_config_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.path <- List.rev v.path; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.path <- (Pbrt.Decoder.string d) :: v.path; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_show_config), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.format <- Some (decode_request_config_format d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_show_config), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.path = v.path; - Vyconf_types.format = v.format; - } : Vyconf_types.request_show_config) - -let rec decode_request_exists d = - let v = default_request_exists_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.path <- List.rev v.path; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.path <- (Pbrt.Decoder.string d) :: v.path; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_exists), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.path = v.path; - } : Vyconf_types.request_exists) - -let rec decode_request_get_value d = - let v = default_request_get_value_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.path <- List.rev v.path; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.path <- (Pbrt.Decoder.string d) :: v.path; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_get_value), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.output_format <- Some (decode_request_output_format d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_get_value), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.path = v.path; - Vyconf_types.output_format = v.output_format; - } : Vyconf_types.request_get_value) - -let rec decode_request_get_values d = - let v = default_request_get_values_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.path <- List.rev v.path; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.path <- (Pbrt.Decoder.string d) :: v.path; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_get_values), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.output_format <- Some (decode_request_output_format d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_get_values), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.path = v.path; - Vyconf_types.output_format = v.output_format; - } : Vyconf_types.request_get_values) - -let rec decode_request_list_children d = - let v = default_request_list_children_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.path <- List.rev v.path; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.path <- (Pbrt.Decoder.string d) :: v.path; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_list_children), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.output_format <- Some (decode_request_output_format d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_list_children), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.path = v.path; - Vyconf_types.output_format = v.output_format; - } : Vyconf_types.request_list_children) - -let rec decode_request_run_op_mode d = - let v = default_request_run_op_mode_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.path <- List.rev v.path; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.path <- (Pbrt.Decoder.string d) :: v.path; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_run_op_mode), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.output_format <- Some (decode_request_output_format d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_run_op_mode), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Vyconf_types.path = v.path; - Vyconf_types.output_format = v.output_format; - } : Vyconf_types.request_run_op_mode) - -let rec decode_request_enter_configuration_mode d = - let v = default_request_enter_configuration_mode_mutable () in - let continue__= ref true in - let override_exclusive_is_set = ref false in - let exclusive_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.exclusive <- Pbrt.Decoder.bool d; exclusive_is_set := true; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_enter_configuration_mode), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.override_exclusive <- Pbrt.Decoder.bool d; override_exclusive_is_set := true; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_enter_configuration_mode), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !override_exclusive_is_set then Pbrt.Decoder.missing_field "override_exclusive" end; - begin if not !exclusive_is_set then Pbrt.Decoder.missing_field "exclusive" end; - ({ - Vyconf_types.exclusive = v.exclusive; - Vyconf_types.override_exclusive = v.override_exclusive; - } : Vyconf_types.request_enter_configuration_mode) - -let rec decode_request d = - let rec loop () = - let ret:Vyconf_types.request = match Pbrt.Decoder.key d with - | None -> Pbrt.Decoder.malformed_variant "request" - | Some (1, _) -> (Pbrt.Decoder.empty_nested d ; Vyconf_types.Status) - | Some (2, _) -> Vyconf_types.Setup_session (decode_request_setup_session (Pbrt.Decoder.nested d)) - | Some (3, _) -> Vyconf_types.Set (decode_request_set (Pbrt.Decoder.nested d)) - | Some (4, _) -> Vyconf_types.Delete (decode_request_delete (Pbrt.Decoder.nested d)) - | Some (5, _) -> Vyconf_types.Rename (decode_request_rename (Pbrt.Decoder.nested d)) - | Some (6, _) -> Vyconf_types.Copy (decode_request_copy (Pbrt.Decoder.nested d)) - | Some (7, _) -> Vyconf_types.Comment (decode_request_comment (Pbrt.Decoder.nested d)) - | Some (8, _) -> Vyconf_types.Commit (decode_request_commit (Pbrt.Decoder.nested d)) - | Some (9, _) -> Vyconf_types.Rollback (decode_request_rollback (Pbrt.Decoder.nested d)) - | Some (10, _) -> Vyconf_types.Merge (decode_request_merge (Pbrt.Decoder.nested d)) - | Some (11, _) -> Vyconf_types.Save (decode_request_save (Pbrt.Decoder.nested d)) - | Some (12, _) -> Vyconf_types.Show_config (decode_request_show_config (Pbrt.Decoder.nested d)) - | Some (13, _) -> Vyconf_types.Exists (decode_request_exists (Pbrt.Decoder.nested d)) - | Some (14, _) -> Vyconf_types.Get_value (decode_request_get_value (Pbrt.Decoder.nested d)) - | Some (15, _) -> Vyconf_types.Get_values (decode_request_get_values (Pbrt.Decoder.nested d)) - | Some (16, _) -> Vyconf_types.List_children (decode_request_list_children (Pbrt.Decoder.nested d)) - | Some (17, _) -> Vyconf_types.Run_op_mode (decode_request_run_op_mode (Pbrt.Decoder.nested d)) - | Some (18, _) -> (Pbrt.Decoder.empty_nested d ; Vyconf_types.Confirm) - | Some (19, _) -> Vyconf_types.Configure (decode_request_enter_configuration_mode (Pbrt.Decoder.nested d)) - | Some (20, _) -> (Pbrt.Decoder.empty_nested d ; Vyconf_types.Exit_configure) - | Some (21, _) -> Vyconf_types.Teardown (Pbrt.Decoder.string d) - | Some (n, payload_kind) -> ( - Pbrt.Decoder.skip d payload_kind; - loop () - ) - in - ret - in - loop () - -let rec decode_request_envelope d = - let v = default_request_envelope_mutable () in - let continue__= ref true in - let request_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.token <- Some (Pbrt.Decoder.string d); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_envelope), field(1)" pk - | Some (2, Pbrt.Bytes) -> begin - v.request <- decode_request (Pbrt.Decoder.nested d); request_is_set := true; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(request_envelope), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !request_is_set then Pbrt.Decoder.missing_field "request" end; - ({ - Vyconf_types.token = v.token; - Vyconf_types.request = v.request; - } : Vyconf_types.request_envelope) - -let rec decode_status d = - match Pbrt.Decoder.int_as_varint d with - | 0 -> (Vyconf_types.Success:Vyconf_types.status) - | 1 -> (Vyconf_types.Fail:Vyconf_types.status) - | 2 -> (Vyconf_types.Invalid_path:Vyconf_types.status) - | 3 -> (Vyconf_types.Invalid_value:Vyconf_types.status) - | 4 -> (Vyconf_types.Commit_in_progress:Vyconf_types.status) - | 5 -> (Vyconf_types.Configuration_locked:Vyconf_types.status) - | 6 -> (Vyconf_types.Internal_error:Vyconf_types.status) - | 7 -> (Vyconf_types.Permission_denied:Vyconf_types.status) - | 8 -> (Vyconf_types.Path_already_exists:Vyconf_types.status) - | _ -> Pbrt.Decoder.malformed_variant "status" - -let rec decode_response d = - let v = default_response_mutable () in - let continue__= ref true in - let status_is_set = ref false in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.status <- decode_status d; status_is_set := true; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(response), field(1)" pk - | Some (2, Pbrt.Bytes) -> begin - v.output <- Some (Pbrt.Decoder.string d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(response), field(2)" pk - | Some (3, Pbrt.Bytes) -> begin - v.error <- Some (Pbrt.Decoder.string d); - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(response), field(3)" pk - | Some (4, Pbrt.Bytes) -> begin - v.warning <- Some (Pbrt.Decoder.string d); - end - | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(response), field(4)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - begin if not !status_is_set then Pbrt.Decoder.missing_field "status" end; - ({ - Vyconf_types.status = v.status; - Vyconf_types.output = v.output; - Vyconf_types.error = v.error; - Vyconf_types.warning = v.warning; - } : Vyconf_types.response) - -let rec encode_request_config_format (v:Vyconf_types.request_config_format) encoder = - match v with - | Vyconf_types.Curly -> Pbrt.Encoder.int_as_varint (0) encoder - | Vyconf_types.Json -> Pbrt.Encoder.int_as_varint 1 encoder - -let rec encode_request_output_format (v:Vyconf_types.request_output_format) encoder = - match v with - | Vyconf_types.Out_plain -> Pbrt.Encoder.int_as_varint (0) encoder - | Vyconf_types.Out_json -> Pbrt.Encoder.int_as_varint 1 encoder - -let rec encode_request_setup_session (v:Vyconf_types.request_setup_session) encoder = - begin match v.Vyconf_types.client_application with - | Some x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - | None -> (); - end; - begin match v.Vyconf_types.on_behalf_of with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - Pbrt.Encoder.int32_as_varint x encoder; - | None -> (); - end; - () - -let rec encode_request_set (v:Vyconf_types.request_set) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.path; - begin match v.Vyconf_types.ephemeral with - | Some x -> - Pbrt.Encoder.key 3 Pbrt.Varint encoder; - Pbrt.Encoder.bool x encoder; - | None -> (); - end; - () - -let rec encode_request_delete (v:Vyconf_types.request_delete) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.path; - () - -let rec encode_request_rename (v:Vyconf_types.request_rename) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.edit_level; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.Vyconf_types.from encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.Vyconf_types.to_ encoder; - () - -let rec encode_request_copy (v:Vyconf_types.request_copy) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.edit_level; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.Vyconf_types.from encoder; - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.Vyconf_types.to_ encoder; - () - -let rec encode_request_comment (v:Vyconf_types.request_comment) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.path; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.Vyconf_types.comment encoder; - () - -let rec encode_request_commit (v:Vyconf_types.request_commit) encoder = - begin match v.Vyconf_types.confirm with - | Some x -> - Pbrt.Encoder.key 1 Pbrt.Varint encoder; - Pbrt.Encoder.bool x encoder; - | None -> (); - end; - begin match v.Vyconf_types.confirm_timeout with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - Pbrt.Encoder.int32_as_varint x encoder; - | None -> (); - end; - begin match v.Vyconf_types.comment with - | Some x -> - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - | None -> (); - end; - () - -let rec encode_request_rollback (v:Vyconf_types.request_rollback) encoder = - Pbrt.Encoder.key 1 Pbrt.Varint encoder; - Pbrt.Encoder.int32_as_varint v.Vyconf_types.revision encoder; - () - -let rec encode_request_load (v:Vyconf_types.request_load) encoder = - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.Vyconf_types.location encoder; - begin match v.Vyconf_types.format with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - encode_request_config_format x encoder; - | None -> (); - end; - () - -let rec encode_request_merge (v:Vyconf_types.request_merge) encoder = - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.Vyconf_types.location encoder; - begin match v.Vyconf_types.format with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - encode_request_config_format x encoder; - | None -> (); - end; - () - -let rec encode_request_save (v:Vyconf_types.request_save) encoder = - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string v.Vyconf_types.location encoder; - begin match v.Vyconf_types.format with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - encode_request_config_format x encoder; - | None -> (); - end; - () - -let rec encode_request_show_config (v:Vyconf_types.request_show_config) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.path; - begin match v.Vyconf_types.format with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - encode_request_config_format x encoder; - | None -> (); - end; - () - -let rec encode_request_exists (v:Vyconf_types.request_exists) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.path; - () - -let rec encode_request_get_value (v:Vyconf_types.request_get_value) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.path; - begin match v.Vyconf_types.output_format with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - encode_request_output_format x encoder; - | None -> (); - end; - () - -let rec encode_request_get_values (v:Vyconf_types.request_get_values) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.path; - begin match v.Vyconf_types.output_format with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - encode_request_output_format x encoder; - | None -> (); - end; - () - -let rec encode_request_list_children (v:Vyconf_types.request_list_children) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.path; - begin match v.Vyconf_types.output_format with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - encode_request_output_format x encoder; - | None -> (); - end; - () - -let rec encode_request_run_op_mode (v:Vyconf_types.request_run_op_mode) encoder = - List.iter (fun x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - ) v.Vyconf_types.path; - begin match v.Vyconf_types.output_format with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - encode_request_output_format x encoder; - | None -> (); - end; - () - -let rec encode_request_enter_configuration_mode (v:Vyconf_types.request_enter_configuration_mode) encoder = - Pbrt.Encoder.key 1 Pbrt.Varint encoder; - Pbrt.Encoder.bool v.Vyconf_types.exclusive encoder; - Pbrt.Encoder.key 2 Pbrt.Varint encoder; - Pbrt.Encoder.bool v.Vyconf_types.override_exclusive encoder; - () - -let rec encode_request (v:Vyconf_types.request) encoder = - begin match v with - | Vyconf_types.Status -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.empty_nested encoder - | Vyconf_types.Setup_session x -> - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_setup_session x encoder; - | Vyconf_types.Set x -> - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_set x encoder; - | Vyconf_types.Delete x -> - Pbrt.Encoder.key 4 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_delete x encoder; - | Vyconf_types.Rename x -> - Pbrt.Encoder.key 5 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_rename x encoder; - | Vyconf_types.Copy x -> - Pbrt.Encoder.key 6 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_copy x encoder; - | Vyconf_types.Comment x -> - Pbrt.Encoder.key 7 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_comment x encoder; - | Vyconf_types.Commit x -> - Pbrt.Encoder.key 8 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_commit x encoder; - | Vyconf_types.Rollback x -> - Pbrt.Encoder.key 9 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_rollback x encoder; - | Vyconf_types.Merge x -> - Pbrt.Encoder.key 10 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_merge x encoder; - | Vyconf_types.Save x -> - Pbrt.Encoder.key 11 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_save x encoder; - | Vyconf_types.Show_config x -> - Pbrt.Encoder.key 12 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_show_config x encoder; - | Vyconf_types.Exists x -> - Pbrt.Encoder.key 13 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_exists x encoder; - | Vyconf_types.Get_value x -> - Pbrt.Encoder.key 14 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_get_value x encoder; - | Vyconf_types.Get_values x -> - Pbrt.Encoder.key 15 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_get_values x encoder; - | Vyconf_types.List_children x -> - Pbrt.Encoder.key 16 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_list_children x encoder; - | Vyconf_types.Run_op_mode x -> - Pbrt.Encoder.key 17 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_run_op_mode x encoder; - | Vyconf_types.Confirm -> - Pbrt.Encoder.key 18 Pbrt.Bytes encoder; - Pbrt.Encoder.empty_nested encoder - | Vyconf_types.Configure x -> - Pbrt.Encoder.key 19 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request_enter_configuration_mode x encoder; - | Vyconf_types.Exit_configure -> - Pbrt.Encoder.key 20 Pbrt.Bytes encoder; - Pbrt.Encoder.empty_nested encoder - | Vyconf_types.Teardown x -> - Pbrt.Encoder.key 21 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - end - -let rec encode_request_envelope (v:Vyconf_types.request_envelope) encoder = - begin match v.Vyconf_types.token with - | Some x -> - Pbrt.Encoder.key 1 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - | None -> (); - end; - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.Encoder.nested encode_request v.Vyconf_types.request encoder; - () - -let rec encode_status (v:Vyconf_types.status) encoder = - match v with - | Vyconf_types.Success -> Pbrt.Encoder.int_as_varint (0) encoder - | Vyconf_types.Fail -> Pbrt.Encoder.int_as_varint 1 encoder - | Vyconf_types.Invalid_path -> Pbrt.Encoder.int_as_varint 2 encoder - | Vyconf_types.Invalid_value -> Pbrt.Encoder.int_as_varint 3 encoder - | Vyconf_types.Commit_in_progress -> Pbrt.Encoder.int_as_varint 4 encoder - | Vyconf_types.Configuration_locked -> Pbrt.Encoder.int_as_varint 5 encoder - | Vyconf_types.Internal_error -> Pbrt.Encoder.int_as_varint 6 encoder - | Vyconf_types.Permission_denied -> Pbrt.Encoder.int_as_varint 7 encoder - | Vyconf_types.Path_already_exists -> Pbrt.Encoder.int_as_varint 8 encoder - -let rec encode_response (v:Vyconf_types.response) encoder = - Pbrt.Encoder.key 1 Pbrt.Varint encoder; - encode_status v.Vyconf_types.status encoder; - begin match v.Vyconf_types.output with - | Some x -> - Pbrt.Encoder.key 2 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - | None -> (); - end; - begin match v.Vyconf_types.error with - | Some x -> - Pbrt.Encoder.key 3 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - | None -> (); - end; - begin match v.Vyconf_types.warning with - | Some x -> - Pbrt.Encoder.key 4 Pbrt.Bytes encoder; - Pbrt.Encoder.string x encoder; - | None -> (); - end; - () diff --git a/src/vyconf_pb.mli b/src/vyconf_pb.mli deleted file mode 100644 index 8a1249c..0000000 --- a/src/vyconf_pb.mli +++ /dev/null @@ -1,151 +0,0 @@ -(** vyconf.proto Binary Encoding *) - - -(** {2 Protobuf Encoding} *) - -val encode_request_config_format : Vyconf_types.request_config_format -> Pbrt.Encoder.t -> unit -(** [encode_request_config_format v encoder] encodes [v] with the given [encoder] *) - -val encode_request_output_format : Vyconf_types.request_output_format -> Pbrt.Encoder.t -> unit -(** [encode_request_output_format v encoder] encodes [v] with the given [encoder] *) - -val encode_request_setup_session : Vyconf_types.request_setup_session -> Pbrt.Encoder.t -> unit -(** [encode_request_setup_session v encoder] encodes [v] with the given [encoder] *) - -val encode_request_set : Vyconf_types.request_set -> Pbrt.Encoder.t -> unit -(** [encode_request_set v encoder] encodes [v] with the given [encoder] *) - -val encode_request_delete : Vyconf_types.request_delete -> Pbrt.Encoder.t -> unit -(** [encode_request_delete v encoder] encodes [v] with the given [encoder] *) - -val encode_request_rename : Vyconf_types.request_rename -> Pbrt.Encoder.t -> unit -(** [encode_request_rename v encoder] encodes [v] with the given [encoder] *) - -val encode_request_copy : Vyconf_types.request_copy -> Pbrt.Encoder.t -> unit -(** [encode_request_copy v encoder] encodes [v] with the given [encoder] *) - -val encode_request_comment : Vyconf_types.request_comment -> Pbrt.Encoder.t -> unit -(** [encode_request_comment v encoder] encodes [v] with the given [encoder] *) - -val encode_request_commit : Vyconf_types.request_commit -> Pbrt.Encoder.t -> unit -(** [encode_request_commit v encoder] encodes [v] with the given [encoder] *) - -val encode_request_rollback : Vyconf_types.request_rollback -> Pbrt.Encoder.t -> unit -(** [encode_request_rollback v encoder] encodes [v] with the given [encoder] *) - -val encode_request_load : Vyconf_types.request_load -> Pbrt.Encoder.t -> unit -(** [encode_request_load v encoder] encodes [v] with the given [encoder] *) - -val encode_request_merge : Vyconf_types.request_merge -> Pbrt.Encoder.t -> unit -(** [encode_request_merge v encoder] encodes [v] with the given [encoder] *) - -val encode_request_save : Vyconf_types.request_save -> Pbrt.Encoder.t -> unit -(** [encode_request_save v encoder] encodes [v] with the given [encoder] *) - -val encode_request_show_config : Vyconf_types.request_show_config -> Pbrt.Encoder.t -> unit -(** [encode_request_show_config v encoder] encodes [v] with the given [encoder] *) - -val encode_request_exists : Vyconf_types.request_exists -> Pbrt.Encoder.t -> unit -(** [encode_request_exists v encoder] encodes [v] with the given [encoder] *) - -val encode_request_get_value : Vyconf_types.request_get_value -> Pbrt.Encoder.t -> unit -(** [encode_request_get_value v encoder] encodes [v] with the given [encoder] *) - -val encode_request_get_values : Vyconf_types.request_get_values -> Pbrt.Encoder.t -> unit -(** [encode_request_get_values v encoder] encodes [v] with the given [encoder] *) - -val encode_request_list_children : Vyconf_types.request_list_children -> Pbrt.Encoder.t -> unit -(** [encode_request_list_children v encoder] encodes [v] with the given [encoder] *) - -val encode_request_run_op_mode : Vyconf_types.request_run_op_mode -> Pbrt.Encoder.t -> unit -(** [encode_request_run_op_mode v encoder] encodes [v] with the given [encoder] *) - -val encode_request_enter_configuration_mode : Vyconf_types.request_enter_configuration_mode -> Pbrt.Encoder.t -> unit -(** [encode_request_enter_configuration_mode v encoder] encodes [v] with the given [encoder] *) - -val encode_request : Vyconf_types.request -> Pbrt.Encoder.t -> unit -(** [encode_request v encoder] encodes [v] with the given [encoder] *) - -val encode_request_envelope : Vyconf_types.request_envelope -> Pbrt.Encoder.t -> unit -(** [encode_request_envelope v encoder] encodes [v] with the given [encoder] *) - -val encode_status : Vyconf_types.status -> Pbrt.Encoder.t -> unit -(** [encode_status v encoder] encodes [v] with the given [encoder] *) - -val encode_response : Vyconf_types.response -> Pbrt.Encoder.t -> unit -(** [encode_response v encoder] encodes [v] with the given [encoder] *) - - -(** {2 Protobuf Decoding} *) - -val decode_request_config_format : Pbrt.Decoder.t -> Vyconf_types.request_config_format -(** [decode_request_config_format decoder] decodes a [request_config_format] value from [decoder] *) - -val decode_request_output_format : Pbrt.Decoder.t -> Vyconf_types.request_output_format -(** [decode_request_output_format decoder] decodes a [request_output_format] value from [decoder] *) - -val decode_request_setup_session : Pbrt.Decoder.t -> Vyconf_types.request_setup_session -(** [decode_request_setup_session decoder] decodes a [request_setup_session] value from [decoder] *) - -val decode_request_set : Pbrt.Decoder.t -> Vyconf_types.request_set -(** [decode_request_set decoder] decodes a [request_set] value from [decoder] *) - -val decode_request_delete : Pbrt.Decoder.t -> Vyconf_types.request_delete -(** [decode_request_delete decoder] decodes a [request_delete] value from [decoder] *) - -val decode_request_rename : Pbrt.Decoder.t -> Vyconf_types.request_rename -(** [decode_request_rename decoder] decodes a [request_rename] value from [decoder] *) - -val decode_request_copy : Pbrt.Decoder.t -> Vyconf_types.request_copy -(** [decode_request_copy decoder] decodes a [request_copy] value from [decoder] *) - -val decode_request_comment : Pbrt.Decoder.t -> Vyconf_types.request_comment -(** [decode_request_comment decoder] decodes a [request_comment] value from [decoder] *) - -val decode_request_commit : Pbrt.Decoder.t -> Vyconf_types.request_commit -(** [decode_request_commit decoder] decodes a [request_commit] value from [decoder] *) - -val decode_request_rollback : Pbrt.Decoder.t -> Vyconf_types.request_rollback -(** [decode_request_rollback decoder] decodes a [request_rollback] value from [decoder] *) - -val decode_request_load : Pbrt.Decoder.t -> Vyconf_types.request_load -(** [decode_request_load decoder] decodes a [request_load] value from [decoder] *) - -val decode_request_merge : Pbrt.Decoder.t -> Vyconf_types.request_merge -(** [decode_request_merge decoder] decodes a [request_merge] value from [decoder] *) - -val decode_request_save : Pbrt.Decoder.t -> Vyconf_types.request_save -(** [decode_request_save decoder] decodes a [request_save] value from [decoder] *) - -val decode_request_show_config : Pbrt.Decoder.t -> Vyconf_types.request_show_config -(** [decode_request_show_config decoder] decodes a [request_show_config] value from [decoder] *) - -val decode_request_exists : Pbrt.Decoder.t -> Vyconf_types.request_exists -(** [decode_request_exists decoder] decodes a [request_exists] value from [decoder] *) - -val decode_request_get_value : Pbrt.Decoder.t -> Vyconf_types.request_get_value -(** [decode_request_get_value decoder] decodes a [request_get_value] value from [decoder] *) - -val decode_request_get_values : Pbrt.Decoder.t -> Vyconf_types.request_get_values -(** [decode_request_get_values decoder] decodes a [request_get_values] value from [decoder] *) - -val decode_request_list_children : Pbrt.Decoder.t -> Vyconf_types.request_list_children -(** [decode_request_list_children decoder] decodes a [request_list_children] value from [decoder] *) - -val decode_request_run_op_mode : Pbrt.Decoder.t -> Vyconf_types.request_run_op_mode -(** [decode_request_run_op_mode decoder] decodes a [request_run_op_mode] value from [decoder] *) - -val decode_request_enter_configuration_mode : Pbrt.Decoder.t -> Vyconf_types.request_enter_configuration_mode -(** [decode_request_enter_configuration_mode decoder] decodes a [request_enter_configuration_mode] value from [decoder] *) - -val decode_request : Pbrt.Decoder.t -> Vyconf_types.request -(** [decode_request decoder] decodes a [request] value from [decoder] *) - -val decode_request_envelope : Pbrt.Decoder.t -> Vyconf_types.request_envelope -(** [decode_request_envelope decoder] decodes a [request_envelope] value from [decoder] *) - -val decode_status : Pbrt.Decoder.t -> Vyconf_types.status -(** [decode_status decoder] decodes a [status] value from [decoder] *) - -val decode_response : Pbrt.Decoder.t -> Vyconf_types.response -(** [decode_response decoder] decodes a [response] value from [decoder] *) diff --git a/src/vyconf_pbt.ml b/src/vyconf_pbt.ml new file mode 100644 index 0000000..7e0aaad --- /dev/null +++ b/src/vyconf_pbt.ml @@ -0,0 +1,1702 @@ +[@@@ocaml.warning "-27-30-39-44"] + +type request_config_format = + | Curly + | Json + +type request_output_format = + | Out_plain + | Out_json + +type request_status = unit + +type request_setup_session = { + client_application : string option; + on_behalf_of : int32 option; +} + +type request_set = { + path : string list; + ephemeral : bool option; +} + +type request_delete = { + path : string list; +} + +type request_rename = { + edit_level : string list; + from : string; + to_ : string; +} + +type request_copy = { + edit_level : string list; + from : string; + to_ : string; +} + +type request_comment = { + path : string list; + comment : string; +} + +type request_commit = { + confirm : bool option; + confirm_timeout : int32 option; + comment : string option; +} + +type request_rollback = { + revision : int32; +} + +type request_load = { + location : string; + format : request_config_format option; +} + +type request_merge = { + location : string; + format : request_config_format option; +} + +type request_save = { + location : string; + format : request_config_format option; +} + +type request_show_config = { + path : string list; + format : request_config_format option; +} + +type request_exists = { + path : string list; +} + +type request_get_value = { + path : string list; + output_format : request_output_format option; +} + +type request_get_values = { + path : string list; + output_format : request_output_format option; +} + +type request_list_children = { + path : string list; + output_format : request_output_format option; +} + +type request_run_op_mode = { + path : string list; + output_format : request_output_format option; +} + +type request_confirm = unit + +type request_enter_configuration_mode = { + exclusive : bool; + override_exclusive : bool; +} + +type request_exit_configuration_mode = unit + +type request = + | Status + | Setup_session of request_setup_session + | Set of request_set + | Delete of request_delete + | Rename of request_rename + | Copy of request_copy + | Comment of request_comment + | Commit of request_commit + | Rollback of request_rollback + | Merge of request_merge + | Save of request_save + | Show_config of request_show_config + | Exists of request_exists + | Get_value of request_get_value + | Get_values of request_get_values + | List_children of request_list_children + | Run_op_mode of request_run_op_mode + | Confirm + | Configure of request_enter_configuration_mode + | Exit_configure + | Teardown of string + +type request_envelope = { + token : string option; + request : request; +} + +type status = + | Success + | Fail + | Invalid_path + | Invalid_value + | Commit_in_progress + | Configuration_locked + | Internal_error + | Permission_denied + | Path_already_exists + +type response = { + status : status; + output : string option; + error : string option; + warning : string option; +} + +let rec default_request_config_format () = (Curly:request_config_format) + +let rec default_request_output_format () = (Out_plain:request_output_format) + +let rec default_request_status = () + +let rec default_request_setup_session + ?client_application:((client_application:string option) = None) + ?on_behalf_of:((on_behalf_of:int32 option) = None) + () : request_setup_session = { + client_application; + on_behalf_of; +} + +let rec default_request_set + ?path:((path:string list) = []) + ?ephemeral:((ephemeral:bool option) = None) + () : request_set = { + path; + ephemeral; +} + +let rec default_request_delete + ?path:((path:string list) = []) + () : request_delete = { + path; +} + +let rec default_request_rename + ?edit_level:((edit_level:string list) = []) + ?from:((from:string) = "") + ?to_:((to_:string) = "") + () : request_rename = { + edit_level; + from; + to_; +} + +let rec default_request_copy + ?edit_level:((edit_level:string list) = []) + ?from:((from:string) = "") + ?to_:((to_:string) = "") + () : request_copy = { + edit_level; + from; + to_; +} + +let rec default_request_comment + ?path:((path:string list) = []) + ?comment:((comment:string) = "") + () : request_comment = { + path; + comment; +} + +let rec default_request_commit + ?confirm:((confirm:bool option) = None) + ?confirm_timeout:((confirm_timeout:int32 option) = None) + ?comment:((comment:string option) = None) + () : request_commit = { + confirm; + confirm_timeout; + comment; +} + +let rec default_request_rollback + ?revision:((revision:int32) = 0l) + () : request_rollback = { + revision; +} + +let rec default_request_load + ?location:((location:string) = "") + ?format:((format:request_config_format option) = None) + () : request_load = { + location; + format; +} + +let rec default_request_merge + ?location:((location:string) = "") + ?format:((format:request_config_format option) = None) + () : request_merge = { + location; + format; +} + +let rec default_request_save + ?location:((location:string) = "") + ?format:((format:request_config_format option) = None) + () : request_save = { + location; + format; +} + +let rec default_request_show_config + ?path:((path:string list) = []) + ?format:((format:request_config_format option) = None) + () : request_show_config = { + path; + format; +} + +let rec default_request_exists + ?path:((path:string list) = []) + () : request_exists = { + path; +} + +let rec default_request_get_value + ?path:((path:string list) = []) + ?output_format:((output_format:request_output_format option) = None) + () : request_get_value = { + path; + output_format; +} + +let rec default_request_get_values + ?path:((path:string list) = []) + ?output_format:((output_format:request_output_format option) = None) + () : request_get_values = { + path; + output_format; +} + +let rec default_request_list_children + ?path:((path:string list) = []) + ?output_format:((output_format:request_output_format option) = None) + () : request_list_children = { + path; + output_format; +} + +let rec default_request_run_op_mode + ?path:((path:string list) = []) + ?output_format:((output_format:request_output_format option) = None) + () : request_run_op_mode = { + path; + output_format; +} + +let rec default_request_confirm = () + +let rec default_request_enter_configuration_mode + ?exclusive:((exclusive:bool) = false) + ?override_exclusive:((override_exclusive:bool) = false) + () : request_enter_configuration_mode = { + exclusive; + override_exclusive; +} + +let rec default_request_exit_configuration_mode = () + +let rec default_request (): request = Status + +let rec default_request_envelope + ?token:((token:string option) = None) + ?request:((request:request) = default_request ()) + () : request_envelope = { + token; + request; +} + +let rec default_status () = (Success:status) + +let rec default_response + ?status:((status:status) = default_status ()) + ?output:((output:string option) = None) + ?error:((error:string option) = None) + ?warning:((warning:string option) = None) + () : response = { + status; + output; + error; + warning; +} + +type request_setup_session_mutable = { + mutable client_application : string option; + mutable on_behalf_of : int32 option; +} + +let default_request_setup_session_mutable () : request_setup_session_mutable = { + client_application = None; + on_behalf_of = None; +} + +type request_set_mutable = { + mutable path : string list; + mutable ephemeral : bool option; +} + +let default_request_set_mutable () : request_set_mutable = { + path = []; + ephemeral = None; +} + +type request_delete_mutable = { + mutable path : string list; +} + +let default_request_delete_mutable () : request_delete_mutable = { + path = []; +} + +type request_rename_mutable = { + mutable edit_level : string list; + mutable from : string; + mutable to_ : string; +} + +let default_request_rename_mutable () : request_rename_mutable = { + edit_level = []; + from = ""; + to_ = ""; +} + +type request_copy_mutable = { + mutable edit_level : string list; + mutable from : string; + mutable to_ : string; +} + +let default_request_copy_mutable () : request_copy_mutable = { + edit_level = []; + from = ""; + to_ = ""; +} + +type request_comment_mutable = { + mutable path : string list; + mutable comment : string; +} + +let default_request_comment_mutable () : request_comment_mutable = { + path = []; + comment = ""; +} + +type request_commit_mutable = { + mutable confirm : bool option; + mutable confirm_timeout : int32 option; + mutable comment : string option; +} + +let default_request_commit_mutable () : request_commit_mutable = { + confirm = None; + confirm_timeout = None; + comment = None; +} + +type request_rollback_mutable = { + mutable revision : int32; +} + +let default_request_rollback_mutable () : request_rollback_mutable = { + revision = 0l; +} + +type request_load_mutable = { + mutable location : string; + mutable format : request_config_format option; +} + +let default_request_load_mutable () : request_load_mutable = { + location = ""; + format = None; +} + +type request_merge_mutable = { + mutable location : string; + mutable format : request_config_format option; +} + +let default_request_merge_mutable () : request_merge_mutable = { + location = ""; + format = None; +} + +type request_save_mutable = { + mutable location : string; + mutable format : request_config_format option; +} + +let default_request_save_mutable () : request_save_mutable = { + location = ""; + format = None; +} + +type request_show_config_mutable = { + mutable path : string list; + mutable format : request_config_format option; +} + +let default_request_show_config_mutable () : request_show_config_mutable = { + path = []; + format = None; +} + +type request_exists_mutable = { + mutable path : string list; +} + +let default_request_exists_mutable () : request_exists_mutable = { + path = []; +} + +type request_get_value_mutable = { + mutable path : string list; + mutable output_format : request_output_format option; +} + +let default_request_get_value_mutable () : request_get_value_mutable = { + path = []; + output_format = None; +} + +type request_get_values_mutable = { + mutable path : string list; + mutable output_format : request_output_format option; +} + +let default_request_get_values_mutable () : request_get_values_mutable = { + path = []; + output_format = None; +} + +type request_list_children_mutable = { + mutable path : string list; + mutable output_format : request_output_format option; +} + +let default_request_list_children_mutable () : request_list_children_mutable = { + path = []; + output_format = None; +} + +type request_run_op_mode_mutable = { + mutable path : string list; + mutable output_format : request_output_format option; +} + +let default_request_run_op_mode_mutable () : request_run_op_mode_mutable = { + path = []; + output_format = None; +} + +type request_enter_configuration_mode_mutable = { + mutable exclusive : bool; + mutable override_exclusive : bool; +} + +let default_request_enter_configuration_mode_mutable () : request_enter_configuration_mode_mutable = { + exclusive = false; + override_exclusive = false; +} + +type request_envelope_mutable = { + mutable token : string option; + mutable request : request; +} + +let default_request_envelope_mutable () : request_envelope_mutable = { + token = None; + request = default_request (); +} + +type response_mutable = { + mutable status : status; + mutable output : string option; + mutable error : string option; + mutable warning : string option; +} + +let default_response_mutable () : response_mutable = { + status = default_status (); + output = None; + error = None; + warning = None; +} + +[@@@ocaml.warning "-27-30-39"] + +(** {2 Formatters} *) + +let rec pp_request_config_format fmt (v:request_config_format) = + match v with + | Curly -> Format.fprintf fmt "Curly" + | Json -> Format.fprintf fmt "Json" + +let rec pp_request_output_format fmt (v:request_output_format) = + match v with + | Out_plain -> Format.fprintf fmt "Out_plain" + | Out_json -> Format.fprintf fmt "Out_json" + +let rec pp_request_status fmt (v:request_status) = + let pp_i fmt () = + Pbrt.Pp.pp_unit fmt () + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_setup_session fmt (v:request_setup_session) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "client_application" (Pbrt.Pp.pp_option Pbrt.Pp.pp_string) fmt v.client_application; + Pbrt.Pp.pp_record_field ~first:false "on_behalf_of" (Pbrt.Pp.pp_option Pbrt.Pp.pp_int32) fmt v.on_behalf_of; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_set fmt (v:request_set) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path; + Pbrt.Pp.pp_record_field ~first:false "ephemeral" (Pbrt.Pp.pp_option Pbrt.Pp.pp_bool) fmt v.ephemeral; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_delete fmt (v:request_delete) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_rename fmt (v:request_rename) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "edit_level" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.edit_level; + Pbrt.Pp.pp_record_field ~first:false "from" Pbrt.Pp.pp_string fmt v.from; + Pbrt.Pp.pp_record_field ~first:false "to_" Pbrt.Pp.pp_string fmt v.to_; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_copy fmt (v:request_copy) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "edit_level" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.edit_level; + Pbrt.Pp.pp_record_field ~first:false "from" Pbrt.Pp.pp_string fmt v.from; + Pbrt.Pp.pp_record_field ~first:false "to_" Pbrt.Pp.pp_string fmt v.to_; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_comment fmt (v:request_comment) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path; + Pbrt.Pp.pp_record_field ~first:false "comment" Pbrt.Pp.pp_string fmt v.comment; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_commit fmt (v:request_commit) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "confirm" (Pbrt.Pp.pp_option Pbrt.Pp.pp_bool) fmt v.confirm; + Pbrt.Pp.pp_record_field ~first:false "confirm_timeout" (Pbrt.Pp.pp_option Pbrt.Pp.pp_int32) fmt v.confirm_timeout; + Pbrt.Pp.pp_record_field ~first:false "comment" (Pbrt.Pp.pp_option Pbrt.Pp.pp_string) fmt v.comment; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_rollback fmt (v:request_rollback) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "revision" Pbrt.Pp.pp_int32 fmt v.revision; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_load fmt (v:request_load) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "location" Pbrt.Pp.pp_string fmt v.location; + Pbrt.Pp.pp_record_field ~first:false "format" (Pbrt.Pp.pp_option pp_request_config_format) fmt v.format; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_merge fmt (v:request_merge) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "location" Pbrt.Pp.pp_string fmt v.location; + Pbrt.Pp.pp_record_field ~first:false "format" (Pbrt.Pp.pp_option pp_request_config_format) fmt v.format; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_save fmt (v:request_save) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "location" Pbrt.Pp.pp_string fmt v.location; + Pbrt.Pp.pp_record_field ~first:false "format" (Pbrt.Pp.pp_option pp_request_config_format) fmt v.format; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_show_config fmt (v:request_show_config) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path; + Pbrt.Pp.pp_record_field ~first:false "format" (Pbrt.Pp.pp_option pp_request_config_format) fmt v.format; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_exists fmt (v:request_exists) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_get_value fmt (v:request_get_value) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path; + Pbrt.Pp.pp_record_field ~first:false "output_format" (Pbrt.Pp.pp_option pp_request_output_format) fmt v.output_format; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_get_values fmt (v:request_get_values) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path; + Pbrt.Pp.pp_record_field ~first:false "output_format" (Pbrt.Pp.pp_option pp_request_output_format) fmt v.output_format; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_list_children fmt (v:request_list_children) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path; + Pbrt.Pp.pp_record_field ~first:false "output_format" (Pbrt.Pp.pp_option pp_request_output_format) fmt v.output_format; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_run_op_mode fmt (v:request_run_op_mode) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path; + Pbrt.Pp.pp_record_field ~first:false "output_format" (Pbrt.Pp.pp_option pp_request_output_format) fmt v.output_format; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_confirm fmt (v:request_confirm) = + let pp_i fmt () = + Pbrt.Pp.pp_unit fmt () + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_enter_configuration_mode fmt (v:request_enter_configuration_mode) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "exclusive" Pbrt.Pp.pp_bool fmt v.exclusive; + Pbrt.Pp.pp_record_field ~first:false "override_exclusive" Pbrt.Pp.pp_bool fmt v.override_exclusive; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request_exit_configuration_mode fmt (v:request_exit_configuration_mode) = + let pp_i fmt () = + Pbrt.Pp.pp_unit fmt () + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_request fmt (v:request) = + match v with + | Status -> Format.fprintf fmt "Status" + | Setup_session x -> Format.fprintf fmt "@[Setup_session(@,%a)@]" pp_request_setup_session x + | Set x -> Format.fprintf fmt "@[Set(@,%a)@]" pp_request_set x + | Delete x -> Format.fprintf fmt "@[Delete(@,%a)@]" pp_request_delete x + | Rename x -> Format.fprintf fmt "@[Rename(@,%a)@]" pp_request_rename x + | Copy x -> Format.fprintf fmt "@[Copy(@,%a)@]" pp_request_copy x + | Comment x -> Format.fprintf fmt "@[Comment(@,%a)@]" pp_request_comment x + | Commit x -> Format.fprintf fmt "@[Commit(@,%a)@]" pp_request_commit x + | Rollback x -> Format.fprintf fmt "@[Rollback(@,%a)@]" pp_request_rollback x + | Merge x -> Format.fprintf fmt "@[Merge(@,%a)@]" pp_request_merge x + | Save x -> Format.fprintf fmt "@[Save(@,%a)@]" pp_request_save x + | Show_config x -> Format.fprintf fmt "@[Show_config(@,%a)@]" pp_request_show_config x + | Exists x -> Format.fprintf fmt "@[Exists(@,%a)@]" pp_request_exists x + | Get_value x -> Format.fprintf fmt "@[Get_value(@,%a)@]" pp_request_get_value x + | Get_values x -> Format.fprintf fmt "@[Get_values(@,%a)@]" pp_request_get_values x + | List_children x -> Format.fprintf fmt "@[List_children(@,%a)@]" pp_request_list_children x + | Run_op_mode x -> Format.fprintf fmt "@[Run_op_mode(@,%a)@]" pp_request_run_op_mode x + | Confirm -> Format.fprintf fmt "Confirm" + | Configure x -> Format.fprintf fmt "@[Configure(@,%a)@]" pp_request_enter_configuration_mode x + | Exit_configure -> Format.fprintf fmt "Exit_configure" + | Teardown x -> Format.fprintf fmt "@[Teardown(@,%a)@]" Pbrt.Pp.pp_string x + +let rec pp_request_envelope fmt (v:request_envelope) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "token" (Pbrt.Pp.pp_option Pbrt.Pp.pp_string) fmt v.token; + Pbrt.Pp.pp_record_field ~first:false "request" pp_request fmt v.request; + in + Pbrt.Pp.pp_brk pp_i fmt () + +let rec pp_status fmt (v:status) = + match v with + | Success -> Format.fprintf fmt "Success" + | Fail -> Format.fprintf fmt "Fail" + | Invalid_path -> Format.fprintf fmt "Invalid_path" + | Invalid_value -> Format.fprintf fmt "Invalid_value" + | Commit_in_progress -> Format.fprintf fmt "Commit_in_progress" + | Configuration_locked -> Format.fprintf fmt "Configuration_locked" + | Internal_error -> Format.fprintf fmt "Internal_error" + | Permission_denied -> Format.fprintf fmt "Permission_denied" + | Path_already_exists -> Format.fprintf fmt "Path_already_exists" + +let rec pp_response fmt (v:response) = + let pp_i fmt () = + Pbrt.Pp.pp_record_field ~first:true "status" pp_status fmt v.status; + Pbrt.Pp.pp_record_field ~first:false "output" (Pbrt.Pp.pp_option Pbrt.Pp.pp_string) fmt v.output; + Pbrt.Pp.pp_record_field ~first:false "error" (Pbrt.Pp.pp_option Pbrt.Pp.pp_string) fmt v.error; + Pbrt.Pp.pp_record_field ~first:false "warning" (Pbrt.Pp.pp_option Pbrt.Pp.pp_string) fmt v.warning; + in + Pbrt.Pp.pp_brk pp_i fmt () + +[@@@ocaml.warning "-27-30-39"] + +(** {2 Protobuf Encoding} *) + +let rec encode_pb_request_config_format (v:request_config_format) encoder = + match v with + | Curly -> Pbrt.Encoder.int_as_varint (0) encoder + | Json -> Pbrt.Encoder.int_as_varint 1 encoder + +let rec encode_pb_request_output_format (v:request_output_format) encoder = + match v with + | Out_plain -> Pbrt.Encoder.int_as_varint (0) encoder + | Out_json -> Pbrt.Encoder.int_as_varint 1 encoder + +let rec encode_pb_request_status (v:request_status) encoder = +() + +let rec encode_pb_request_setup_session (v:request_setup_session) encoder = + begin match v.client_application with + | Some x -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + | None -> (); + end; + begin match v.on_behalf_of with + | Some x -> + Pbrt.Encoder.int32_as_varint x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_set (v:request_set) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.path encoder; + begin match v.ephemeral with + | Some x -> + Pbrt.Encoder.bool x encoder; + Pbrt.Encoder.key 3 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_delete (v:request_delete) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.path encoder; + () + +let rec encode_pb_request_rename (v:request_rename) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.edit_level encoder; + Pbrt.Encoder.string v.from encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + Pbrt.Encoder.string v.to_ encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + () + +let rec encode_pb_request_copy (v:request_copy) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.edit_level encoder; + Pbrt.Encoder.string v.from encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + Pbrt.Encoder.string v.to_ encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + () + +let rec encode_pb_request_comment (v:request_comment) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.path encoder; + Pbrt.Encoder.string v.comment encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + () + +let rec encode_pb_request_commit (v:request_commit) encoder = + begin match v.confirm with + | Some x -> + Pbrt.Encoder.bool x encoder; + Pbrt.Encoder.key 1 Pbrt.Varint encoder; + | None -> (); + end; + begin match v.confirm_timeout with + | Some x -> + Pbrt.Encoder.int32_as_varint x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + begin match v.comment with + | Some x -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + | None -> (); + end; + () + +let rec encode_pb_request_rollback (v:request_rollback) encoder = + Pbrt.Encoder.int32_as_varint v.revision encoder; + Pbrt.Encoder.key 1 Pbrt.Varint encoder; + () + +let rec encode_pb_request_load (v:request_load) encoder = + Pbrt.Encoder.string v.location encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + begin match v.format with + | Some x -> + encode_pb_request_config_format x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_merge (v:request_merge) encoder = + Pbrt.Encoder.string v.location encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + begin match v.format with + | Some x -> + encode_pb_request_config_format x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_save (v:request_save) encoder = + Pbrt.Encoder.string v.location encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + begin match v.format with + | Some x -> + encode_pb_request_config_format x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_show_config (v:request_show_config) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.path encoder; + begin match v.format with + | Some x -> + encode_pb_request_config_format x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_exists (v:request_exists) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.path encoder; + () + +let rec encode_pb_request_get_value (v:request_get_value) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.path encoder; + begin match v.output_format with + | Some x -> + encode_pb_request_output_format x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_get_values (v:request_get_values) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.path encoder; + begin match v.output_format with + | Some x -> + encode_pb_request_output_format x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_list_children (v:request_list_children) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.path encoder; + begin match v.output_format with + | Some x -> + encode_pb_request_output_format x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_run_op_mode (v:request_run_op_mode) encoder = + Pbrt.List_util.rev_iter_with (fun x encoder -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + ) v.path encoder; + begin match v.output_format with + | Some x -> + encode_pb_request_output_format x encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + | None -> (); + end; + () + +let rec encode_pb_request_confirm (v:request_confirm) encoder = +() + +let rec encode_pb_request_enter_configuration_mode (v:request_enter_configuration_mode) encoder = + Pbrt.Encoder.bool v.exclusive encoder; + Pbrt.Encoder.key 1 Pbrt.Varint encoder; + Pbrt.Encoder.bool v.override_exclusive encoder; + Pbrt.Encoder.key 2 Pbrt.Varint encoder; + () + +let rec encode_pb_request_exit_configuration_mode (v:request_exit_configuration_mode) encoder = +() + +let rec encode_pb_request (v:request) encoder = + begin match v with + | Status -> + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + Pbrt.Encoder.empty_nested encoder + | Setup_session x -> + Pbrt.Encoder.nested encode_pb_request_setup_session x encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + | Set x -> + Pbrt.Encoder.nested encode_pb_request_set x encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + | Delete x -> + Pbrt.Encoder.nested encode_pb_request_delete x encoder; + Pbrt.Encoder.key 4 Pbrt.Bytes encoder; + | Rename x -> + Pbrt.Encoder.nested encode_pb_request_rename x encoder; + Pbrt.Encoder.key 5 Pbrt.Bytes encoder; + | Copy x -> + Pbrt.Encoder.nested encode_pb_request_copy x encoder; + Pbrt.Encoder.key 6 Pbrt.Bytes encoder; + | Comment x -> + Pbrt.Encoder.nested encode_pb_request_comment x encoder; + Pbrt.Encoder.key 7 Pbrt.Bytes encoder; + | Commit x -> + Pbrt.Encoder.nested encode_pb_request_commit x encoder; + Pbrt.Encoder.key 8 Pbrt.Bytes encoder; + | Rollback x -> + Pbrt.Encoder.nested encode_pb_request_rollback x encoder; + Pbrt.Encoder.key 9 Pbrt.Bytes encoder; + | Merge x -> + Pbrt.Encoder.nested encode_pb_request_merge x encoder; + Pbrt.Encoder.key 10 Pbrt.Bytes encoder; + | Save x -> + Pbrt.Encoder.nested encode_pb_request_save x encoder; + Pbrt.Encoder.key 11 Pbrt.Bytes encoder; + | Show_config x -> + Pbrt.Encoder.nested encode_pb_request_show_config x encoder; + Pbrt.Encoder.key 12 Pbrt.Bytes encoder; + | Exists x -> + Pbrt.Encoder.nested encode_pb_request_exists x encoder; + Pbrt.Encoder.key 13 Pbrt.Bytes encoder; + | Get_value x -> + Pbrt.Encoder.nested encode_pb_request_get_value x encoder; + Pbrt.Encoder.key 14 Pbrt.Bytes encoder; + | Get_values x -> + Pbrt.Encoder.nested encode_pb_request_get_values x encoder; + Pbrt.Encoder.key 15 Pbrt.Bytes encoder; + | List_children x -> + Pbrt.Encoder.nested encode_pb_request_list_children x encoder; + Pbrt.Encoder.key 16 Pbrt.Bytes encoder; + | Run_op_mode x -> + Pbrt.Encoder.nested encode_pb_request_run_op_mode x encoder; + Pbrt.Encoder.key 17 Pbrt.Bytes encoder; + | Confirm -> + Pbrt.Encoder.key 18 Pbrt.Bytes encoder; + Pbrt.Encoder.empty_nested encoder + | Configure x -> + Pbrt.Encoder.nested encode_pb_request_enter_configuration_mode x encoder; + Pbrt.Encoder.key 19 Pbrt.Bytes encoder; + | Exit_configure -> + Pbrt.Encoder.key 20 Pbrt.Bytes encoder; + Pbrt.Encoder.empty_nested encoder + | Teardown x -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 21 Pbrt.Bytes encoder; + end + +let rec encode_pb_request_envelope (v:request_envelope) encoder = + begin match v.token with + | Some x -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 1 Pbrt.Bytes encoder; + | None -> (); + end; + Pbrt.Encoder.nested encode_pb_request v.request encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + () + +let rec encode_pb_status (v:status) encoder = + match v with + | Success -> Pbrt.Encoder.int_as_varint (0) encoder + | Fail -> Pbrt.Encoder.int_as_varint 1 encoder + | Invalid_path -> Pbrt.Encoder.int_as_varint 2 encoder + | Invalid_value -> Pbrt.Encoder.int_as_varint 3 encoder + | Commit_in_progress -> Pbrt.Encoder.int_as_varint 4 encoder + | Configuration_locked -> Pbrt.Encoder.int_as_varint 5 encoder + | Internal_error -> Pbrt.Encoder.int_as_varint 6 encoder + | Permission_denied -> Pbrt.Encoder.int_as_varint 7 encoder + | Path_already_exists -> Pbrt.Encoder.int_as_varint 8 encoder + +let rec encode_pb_response (v:response) encoder = + encode_pb_status v.status encoder; + Pbrt.Encoder.key 1 Pbrt.Varint encoder; + begin match v.output with + | Some x -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 2 Pbrt.Bytes encoder; + | None -> (); + end; + begin match v.error with + | Some x -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 3 Pbrt.Bytes encoder; + | None -> (); + end; + begin match v.warning with + | Some x -> + Pbrt.Encoder.string x encoder; + Pbrt.Encoder.key 4 Pbrt.Bytes encoder; + | None -> (); + end; + () + +[@@@ocaml.warning "-27-30-39"] + +(** {2 Protobuf Decoding} *) + +let rec decode_pb_request_config_format d = + match Pbrt.Decoder.int_as_varint d with + | 0 -> (Curly:request_config_format) + | 1 -> (Json:request_config_format) + | _ -> Pbrt.Decoder.malformed_variant "request_config_format" + +let rec decode_pb_request_output_format d = + match Pbrt.Decoder.int_as_varint d with + | 0 -> (Out_plain:request_output_format) + | 1 -> (Out_json:request_output_format) + | _ -> Pbrt.Decoder.malformed_variant "request_output_format" + +let rec decode_pb_request_status d = + match Pbrt.Decoder.key d with + | None -> (); + | Some (_, pk) -> + Pbrt.Decoder.unexpected_payload "Unexpected fields in empty message(request_status)" pk + +let rec decode_pb_request_setup_session d = + let v = default_request_setup_session_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.client_application <- Some (Pbrt.Decoder.string d); + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_setup_session), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.on_behalf_of <- Some (Pbrt.Decoder.int32_as_varint d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_setup_session), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + client_application = v.client_application; + on_behalf_of = v.on_behalf_of; + } : request_setup_session) + +let rec decode_pb_request_set d = + let v = default_request_set_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.path <- List.rev v.path; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.path <- (Pbrt.Decoder.string d) :: v.path; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_set), field(1)" pk + | Some (3, Pbrt.Varint) -> begin + v.ephemeral <- Some (Pbrt.Decoder.bool d); + end + | Some (3, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_set), field(3)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + path = v.path; + ephemeral = v.ephemeral; + } : request_set) + +let rec decode_pb_request_delete d = + let v = default_request_delete_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.path <- List.rev v.path; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.path <- (Pbrt.Decoder.string d) :: v.path; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_delete), field(1)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + path = v.path; + } : request_delete) + +let rec decode_pb_request_rename d = + let v = default_request_rename_mutable () in + let continue__= ref true in + let to__is_set = ref false in + let from_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.edit_level <- List.rev v.edit_level; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.edit_level <- (Pbrt.Decoder.string d) :: v.edit_level; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_rename), field(1)" pk + | Some (2, Pbrt.Bytes) -> begin + v.from <- Pbrt.Decoder.string d; from_is_set := true; + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_rename), field(2)" pk + | Some (3, Pbrt.Bytes) -> begin + v.to_ <- Pbrt.Decoder.string d; to__is_set := true; + end + | Some (3, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_rename), field(3)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !to__is_set then Pbrt.Decoder.missing_field "to_" end; + begin if not !from_is_set then Pbrt.Decoder.missing_field "from" end; + ({ + edit_level = v.edit_level; + from = v.from; + to_ = v.to_; + } : request_rename) + +let rec decode_pb_request_copy d = + let v = default_request_copy_mutable () in + let continue__= ref true in + let to__is_set = ref false in + let from_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.edit_level <- List.rev v.edit_level; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.edit_level <- (Pbrt.Decoder.string d) :: v.edit_level; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_copy), field(1)" pk + | Some (2, Pbrt.Bytes) -> begin + v.from <- Pbrt.Decoder.string d; from_is_set := true; + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_copy), field(2)" pk + | Some (3, Pbrt.Bytes) -> begin + v.to_ <- Pbrt.Decoder.string d; to__is_set := true; + end + | Some (3, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_copy), field(3)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !to__is_set then Pbrt.Decoder.missing_field "to_" end; + begin if not !from_is_set then Pbrt.Decoder.missing_field "from" end; + ({ + edit_level = v.edit_level; + from = v.from; + to_ = v.to_; + } : request_copy) + +let rec decode_pb_request_comment d = + let v = default_request_comment_mutable () in + let continue__= ref true in + let comment_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.path <- List.rev v.path; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.path <- (Pbrt.Decoder.string d) :: v.path; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_comment), field(1)" pk + | Some (2, Pbrt.Bytes) -> begin + v.comment <- Pbrt.Decoder.string d; comment_is_set := true; + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_comment), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !comment_is_set then Pbrt.Decoder.missing_field "comment" end; + ({ + path = v.path; + comment = v.comment; + } : request_comment) + +let rec decode_pb_request_commit d = + let v = default_request_commit_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + ); continue__ := false + | Some (1, Pbrt.Varint) -> begin + v.confirm <- Some (Pbrt.Decoder.bool d); + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_commit), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.confirm_timeout <- Some (Pbrt.Decoder.int32_as_varint d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_commit), field(2)" pk + | Some (3, Pbrt.Bytes) -> begin + v.comment <- Some (Pbrt.Decoder.string d); + end + | Some (3, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_commit), field(3)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + confirm = v.confirm; + confirm_timeout = v.confirm_timeout; + comment = v.comment; + } : request_commit) + +let rec decode_pb_request_rollback d = + let v = default_request_rollback_mutable () in + let continue__= ref true in + let revision_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + ); continue__ := false + | Some (1, Pbrt.Varint) -> begin + v.revision <- Pbrt.Decoder.int32_as_varint d; revision_is_set := true; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_rollback), field(1)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !revision_is_set then Pbrt.Decoder.missing_field "revision" end; + ({ + revision = v.revision; + } : request_rollback) + +let rec decode_pb_request_load d = + let v = default_request_load_mutable () in + let continue__= ref true in + let location_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.location <- Pbrt.Decoder.string d; location_is_set := true; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_load), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.format <- Some (decode_pb_request_config_format d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_load), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !location_is_set then Pbrt.Decoder.missing_field "location" end; + ({ + location = v.location; + format = v.format; + } : request_load) + +let rec decode_pb_request_merge d = + let v = default_request_merge_mutable () in + let continue__= ref true in + let location_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.location <- Pbrt.Decoder.string d; location_is_set := true; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_merge), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.format <- Some (decode_pb_request_config_format d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_merge), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !location_is_set then Pbrt.Decoder.missing_field "location" end; + ({ + location = v.location; + format = v.format; + } : request_merge) + +let rec decode_pb_request_save d = + let v = default_request_save_mutable () in + let continue__= ref true in + let location_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.location <- Pbrt.Decoder.string d; location_is_set := true; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_save), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.format <- Some (decode_pb_request_config_format d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_save), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !location_is_set then Pbrt.Decoder.missing_field "location" end; + ({ + location = v.location; + format = v.format; + } : request_save) + +let rec decode_pb_request_show_config d = + let v = default_request_show_config_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.path <- List.rev v.path; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.path <- (Pbrt.Decoder.string d) :: v.path; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_show_config), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.format <- Some (decode_pb_request_config_format d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_show_config), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + path = v.path; + format = v.format; + } : request_show_config) + +let rec decode_pb_request_exists d = + let v = default_request_exists_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.path <- List.rev v.path; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.path <- (Pbrt.Decoder.string d) :: v.path; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_exists), field(1)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + path = v.path; + } : request_exists) + +let rec decode_pb_request_get_value d = + let v = default_request_get_value_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.path <- List.rev v.path; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.path <- (Pbrt.Decoder.string d) :: v.path; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_get_value), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.output_format <- Some (decode_pb_request_output_format d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_get_value), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + path = v.path; + output_format = v.output_format; + } : request_get_value) + +let rec decode_pb_request_get_values d = + let v = default_request_get_values_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.path <- List.rev v.path; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.path <- (Pbrt.Decoder.string d) :: v.path; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_get_values), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.output_format <- Some (decode_pb_request_output_format d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_get_values), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + path = v.path; + output_format = v.output_format; + } : request_get_values) + +let rec decode_pb_request_list_children d = + let v = default_request_list_children_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.path <- List.rev v.path; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.path <- (Pbrt.Decoder.string d) :: v.path; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_list_children), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.output_format <- Some (decode_pb_request_output_format d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_list_children), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + path = v.path; + output_format = v.output_format; + } : request_list_children) + +let rec decode_pb_request_run_op_mode d = + let v = default_request_run_op_mode_mutable () in + let continue__= ref true in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + v.path <- List.rev v.path; + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.path <- (Pbrt.Decoder.string d) :: v.path; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_run_op_mode), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.output_format <- Some (decode_pb_request_output_format d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_run_op_mode), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + ({ + path = v.path; + output_format = v.output_format; + } : request_run_op_mode) + +let rec decode_pb_request_confirm d = + match Pbrt.Decoder.key d with + | None -> (); + | Some (_, pk) -> + Pbrt.Decoder.unexpected_payload "Unexpected fields in empty message(request_confirm)" pk + +let rec decode_pb_request_enter_configuration_mode d = + let v = default_request_enter_configuration_mode_mutable () in + let continue__= ref true in + let override_exclusive_is_set = ref false in + let exclusive_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + ); continue__ := false + | Some (1, Pbrt.Varint) -> begin + v.exclusive <- Pbrt.Decoder.bool d; exclusive_is_set := true; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_enter_configuration_mode), field(1)" pk + | Some (2, Pbrt.Varint) -> begin + v.override_exclusive <- Pbrt.Decoder.bool d; override_exclusive_is_set := true; + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_enter_configuration_mode), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !override_exclusive_is_set then Pbrt.Decoder.missing_field "override_exclusive" end; + begin if not !exclusive_is_set then Pbrt.Decoder.missing_field "exclusive" end; + ({ + exclusive = v.exclusive; + override_exclusive = v.override_exclusive; + } : request_enter_configuration_mode) + +let rec decode_pb_request_exit_configuration_mode d = + match Pbrt.Decoder.key d with + | None -> (); + | Some (_, pk) -> + Pbrt.Decoder.unexpected_payload "Unexpected fields in empty message(request_exit_configuration_mode)" pk + +let rec decode_pb_request d = + let rec loop () = + let ret:request = match Pbrt.Decoder.key d with + | None -> Pbrt.Decoder.malformed_variant "request" + | Some (1, _) -> begin + Pbrt.Decoder.empty_nested d ; + (Status : request) + end + | Some (2, _) -> (Setup_session (decode_pb_request_setup_session (Pbrt.Decoder.nested d)) : request) + | Some (3, _) -> (Set (decode_pb_request_set (Pbrt.Decoder.nested d)) : request) + | Some (4, _) -> (Delete (decode_pb_request_delete (Pbrt.Decoder.nested d)) : request) + | Some (5, _) -> (Rename (decode_pb_request_rename (Pbrt.Decoder.nested d)) : request) + | Some (6, _) -> (Copy (decode_pb_request_copy (Pbrt.Decoder.nested d)) : request) + | Some (7, _) -> (Comment (decode_pb_request_comment (Pbrt.Decoder.nested d)) : request) + | Some (8, _) -> (Commit (decode_pb_request_commit (Pbrt.Decoder.nested d)) : request) + | Some (9, _) -> (Rollback (decode_pb_request_rollback (Pbrt.Decoder.nested d)) : request) + | Some (10, _) -> (Merge (decode_pb_request_merge (Pbrt.Decoder.nested d)) : request) + | Some (11, _) -> (Save (decode_pb_request_save (Pbrt.Decoder.nested d)) : request) + | Some (12, _) -> (Show_config (decode_pb_request_show_config (Pbrt.Decoder.nested d)) : request) + | Some (13, _) -> (Exists (decode_pb_request_exists (Pbrt.Decoder.nested d)) : request) + | Some (14, _) -> (Get_value (decode_pb_request_get_value (Pbrt.Decoder.nested d)) : request) + | Some (15, _) -> (Get_values (decode_pb_request_get_values (Pbrt.Decoder.nested d)) : request) + | Some (16, _) -> (List_children (decode_pb_request_list_children (Pbrt.Decoder.nested d)) : request) + | Some (17, _) -> (Run_op_mode (decode_pb_request_run_op_mode (Pbrt.Decoder.nested d)) : request) + | Some (18, _) -> begin + Pbrt.Decoder.empty_nested d ; + (Confirm : request) + end + | Some (19, _) -> (Configure (decode_pb_request_enter_configuration_mode (Pbrt.Decoder.nested d)) : request) + | Some (20, _) -> begin + Pbrt.Decoder.empty_nested d ; + (Exit_configure : request) + end + | Some (21, _) -> (Teardown (Pbrt.Decoder.string d) : request) + | Some (n, payload_kind) -> ( + Pbrt.Decoder.skip d payload_kind; + loop () + ) + in + ret + in + loop () + +let rec decode_pb_request_envelope d = + let v = default_request_envelope_mutable () in + let continue__= ref true in + let request_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + ); continue__ := false + | Some (1, Pbrt.Bytes) -> begin + v.token <- Some (Pbrt.Decoder.string d); + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_envelope), field(1)" pk + | Some (2, Pbrt.Bytes) -> begin + v.request <- decode_pb_request (Pbrt.Decoder.nested d); request_is_set := true; + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(request_envelope), field(2)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !request_is_set then Pbrt.Decoder.missing_field "request" end; + ({ + token = v.token; + request = v.request; + } : request_envelope) + +let rec decode_pb_status d = + match Pbrt.Decoder.int_as_varint d with + | 0 -> (Success:status) + | 1 -> (Fail:status) + | 2 -> (Invalid_path:status) + | 3 -> (Invalid_value:status) + | 4 -> (Commit_in_progress:status) + | 5 -> (Configuration_locked:status) + | 6 -> (Internal_error:status) + | 7 -> (Permission_denied:status) + | 8 -> (Path_already_exists:status) + | _ -> Pbrt.Decoder.malformed_variant "status" + +let rec decode_pb_response d = + let v = default_response_mutable () in + let continue__= ref true in + let status_is_set = ref false in + while !continue__ do + match Pbrt.Decoder.key d with + | None -> ( + ); continue__ := false + | Some (1, Pbrt.Varint) -> begin + v.status <- decode_pb_status d; status_is_set := true; + end + | Some (1, pk) -> + Pbrt.Decoder.unexpected_payload "Message(response), field(1)" pk + | Some (2, Pbrt.Bytes) -> begin + v.output <- Some (Pbrt.Decoder.string d); + end + | Some (2, pk) -> + Pbrt.Decoder.unexpected_payload "Message(response), field(2)" pk + | Some (3, Pbrt.Bytes) -> begin + v.error <- Some (Pbrt.Decoder.string d); + end + | Some (3, pk) -> + Pbrt.Decoder.unexpected_payload "Message(response), field(3)" pk + | Some (4, Pbrt.Bytes) -> begin + v.warning <- Some (Pbrt.Decoder.string d); + end + | Some (4, pk) -> + Pbrt.Decoder.unexpected_payload "Message(response), field(4)" pk + | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind + done; + begin if not !status_is_set then Pbrt.Decoder.missing_field "status" end; + ({ + status = v.status; + output = v.output; + error = v.error; + warning = v.warning; + } : response) diff --git a/src/vyconf_pbt.mli b/src/vyconf_pbt.mli new file mode 100644 index 0000000..fc0df2f --- /dev/null +++ b/src/vyconf_pbt.mli @@ -0,0 +1,576 @@ + +(** Code for vyconf.proto *) + +(* generated from "data/vyconf.proto", do not edit *) + + + +(** {2 Types} *) + +type request_config_format = + | Curly + | Json + +type request_output_format = + | Out_plain + | Out_json + +type request_status = unit + +type request_setup_session = { + client_application : string option; + on_behalf_of : int32 option; +} + +type request_set = { + path : string list; + ephemeral : bool option; +} + +type request_delete = { + path : string list; +} + +type request_rename = { + edit_level : string list; + from : string; + to_ : string; +} + +type request_copy = { + edit_level : string list; + from : string; + to_ : string; +} + +type request_comment = { + path : string list; + comment : string; +} + +type request_commit = { + confirm : bool option; + confirm_timeout : int32 option; + comment : string option; +} + +type request_rollback = { + revision : int32; +} + +type request_load = { + location : string; + format : request_config_format option; +} + +type request_merge = { + location : string; + format : request_config_format option; +} + +type request_save = { + location : string; + format : request_config_format option; +} + +type request_show_config = { + path : string list; + format : request_config_format option; +} + +type request_exists = { + path : string list; +} + +type request_get_value = { + path : string list; + output_format : request_output_format option; +} + +type request_get_values = { + path : string list; + output_format : request_output_format option; +} + +type request_list_children = { + path : string list; + output_format : request_output_format option; +} + +type request_run_op_mode = { + path : string list; + output_format : request_output_format option; +} + +type request_confirm = unit + +type request_enter_configuration_mode = { + exclusive : bool; + override_exclusive : bool; +} + +type request_exit_configuration_mode = unit + +type request = + | Status + | Setup_session of request_setup_session + | Set of request_set + | Delete of request_delete + | Rename of request_rename + | Copy of request_copy + | Comment of request_comment + | Commit of request_commit + | Rollback of request_rollback + | Merge of request_merge + | Save of request_save + | Show_config of request_show_config + | Exists of request_exists + | Get_value of request_get_value + | Get_values of request_get_values + | List_children of request_list_children + | Run_op_mode of request_run_op_mode + | Confirm + | Configure of request_enter_configuration_mode + | Exit_configure + | Teardown of string + +type request_envelope = { + token : string option; + request : request; +} + +type status = + | Success + | Fail + | Invalid_path + | Invalid_value + | Commit_in_progress + | Configuration_locked + | Internal_error + | Permission_denied + | Path_already_exists + +type response = { + status : status; + output : string option; + error : string option; + warning : string option; +} + + +(** {2 Basic values} *) + +val default_request_config_format : unit -> request_config_format +(** [default_request_config_format ()] is the default value for type [request_config_format] *) + +val default_request_output_format : unit -> request_output_format +(** [default_request_output_format ()] is the default value for type [request_output_format] *) + +val default_request_status : unit +(** [default_request_status ()] is the default value for type [request_status] *) + +val default_request_setup_session : + ?client_application:string option -> + ?on_behalf_of:int32 option -> + unit -> + request_setup_session +(** [default_request_setup_session ()] is the default value for type [request_setup_session] *) + +val default_request_set : + ?path:string list -> + ?ephemeral:bool option -> + unit -> + request_set +(** [default_request_set ()] is the default value for type [request_set] *) + +val default_request_delete : + ?path:string list -> + unit -> + request_delete +(** [default_request_delete ()] is the default value for type [request_delete] *) + +val default_request_rename : + ?edit_level:string list -> + ?from:string -> + ?to_:string -> + unit -> + request_rename +(** [default_request_rename ()] is the default value for type [request_rename] *) + +val default_request_copy : + ?edit_level:string list -> + ?from:string -> + ?to_:string -> + unit -> + request_copy +(** [default_request_copy ()] is the default value for type [request_copy] *) + +val default_request_comment : + ?path:string list -> + ?comment:string -> + unit -> + request_comment +(** [default_request_comment ()] is the default value for type [request_comment] *) + +val default_request_commit : + ?confirm:bool option -> + ?confirm_timeout:int32 option -> + ?comment:string option -> + unit -> + request_commit +(** [default_request_commit ()] is the default value for type [request_commit] *) + +val default_request_rollback : + ?revision:int32 -> + unit -> + request_rollback +(** [default_request_rollback ()] is the default value for type [request_rollback] *) + +val default_request_load : + ?location:string -> + ?format:request_config_format option -> + unit -> + request_load +(** [default_request_load ()] is the default value for type [request_load] *) + +val default_request_merge : + ?location:string -> + ?format:request_config_format option -> + unit -> + request_merge +(** [default_request_merge ()] is the default value for type [request_merge] *) + +val default_request_save : + ?location:string -> + ?format:request_config_format option -> + unit -> + request_save +(** [default_request_save ()] is the default value for type [request_save] *) + +val default_request_show_config : + ?path:string list -> + ?format:request_config_format option -> + unit -> + request_show_config +(** [default_request_show_config ()] is the default value for type [request_show_config] *) + +val default_request_exists : + ?path:string list -> + unit -> + request_exists +(** [default_request_exists ()] is the default value for type [request_exists] *) + +val default_request_get_value : + ?path:string list -> + ?output_format:request_output_format option -> + unit -> + request_get_value +(** [default_request_get_value ()] is the default value for type [request_get_value] *) + +val default_request_get_values : + ?path:string list -> + ?output_format:request_output_format option -> + unit -> + request_get_values +(** [default_request_get_values ()] is the default value for type [request_get_values] *) + +val default_request_list_children : + ?path:string list -> + ?output_format:request_output_format option -> + unit -> + request_list_children +(** [default_request_list_children ()] is the default value for type [request_list_children] *) + +val default_request_run_op_mode : + ?path:string list -> + ?output_format:request_output_format option -> + unit -> + request_run_op_mode +(** [default_request_run_op_mode ()] is the default value for type [request_run_op_mode] *) + +val default_request_confirm : unit +(** [default_request_confirm ()] is the default value for type [request_confirm] *) + +val default_request_enter_configuration_mode : + ?exclusive:bool -> + ?override_exclusive:bool -> + unit -> + request_enter_configuration_mode +(** [default_request_enter_configuration_mode ()] is the default value for type [request_enter_configuration_mode] *) + +val default_request_exit_configuration_mode : unit +(** [default_request_exit_configuration_mode ()] is the default value for type [request_exit_configuration_mode] *) + +val default_request : unit -> request +(** [default_request ()] is the default value for type [request] *) + +val default_request_envelope : + ?token:string option -> + ?request:request -> + unit -> + request_envelope +(** [default_request_envelope ()] is the default value for type [request_envelope] *) + +val default_status : unit -> status +(** [default_status ()] is the default value for type [status] *) + +val default_response : + ?status:status -> + ?output:string option -> + ?error:string option -> + ?warning:string option -> + unit -> + response +(** [default_response ()] is the default value for type [response] *) + + +(** {2 Formatters} *) + +val pp_request_config_format : Format.formatter -> request_config_format -> unit +(** [pp_request_config_format v] formats v *) + +val pp_request_output_format : Format.formatter -> request_output_format -> unit +(** [pp_request_output_format v] formats v *) + +val pp_request_status : Format.formatter -> request_status -> unit +(** [pp_request_status v] formats v *) + +val pp_request_setup_session : Format.formatter -> request_setup_session -> unit +(** [pp_request_setup_session v] formats v *) + +val pp_request_set : Format.formatter -> request_set -> unit +(** [pp_request_set v] formats v *) + +val pp_request_delete : Format.formatter -> request_delete -> unit +(** [pp_request_delete v] formats v *) + +val pp_request_rename : Format.formatter -> request_rename -> unit +(** [pp_request_rename v] formats v *) + +val pp_request_copy : Format.formatter -> request_copy -> unit +(** [pp_request_copy v] formats v *) + +val pp_request_comment : Format.formatter -> request_comment -> unit +(** [pp_request_comment v] formats v *) + +val pp_request_commit : Format.formatter -> request_commit -> unit +(** [pp_request_commit v] formats v *) + +val pp_request_rollback : Format.formatter -> request_rollback -> unit +(** [pp_request_rollback v] formats v *) + +val pp_request_load : Format.formatter -> request_load -> unit +(** [pp_request_load v] formats v *) + +val pp_request_merge : Format.formatter -> request_merge -> unit +(** [pp_request_merge v] formats v *) + +val pp_request_save : Format.formatter -> request_save -> unit +(** [pp_request_save v] formats v *) + +val pp_request_show_config : Format.formatter -> request_show_config -> unit +(** [pp_request_show_config v] formats v *) + +val pp_request_exists : Format.formatter -> request_exists -> unit +(** [pp_request_exists v] formats v *) + +val pp_request_get_value : Format.formatter -> request_get_value -> unit +(** [pp_request_get_value v] formats v *) + +val pp_request_get_values : Format.formatter -> request_get_values -> unit +(** [pp_request_get_values v] formats v *) + +val pp_request_list_children : Format.formatter -> request_list_children -> unit +(** [pp_request_list_children v] formats v *) + +val pp_request_run_op_mode : Format.formatter -> request_run_op_mode -> unit +(** [pp_request_run_op_mode v] formats v *) + +val pp_request_confirm : Format.formatter -> request_confirm -> unit +(** [pp_request_confirm v] formats v *) + +val pp_request_enter_configuration_mode : Format.formatter -> request_enter_configuration_mode -> unit +(** [pp_request_enter_configuration_mode v] formats v *) + +val pp_request_exit_configuration_mode : Format.formatter -> request_exit_configuration_mode -> unit +(** [pp_request_exit_configuration_mode v] formats v *) + +val pp_request : Format.formatter -> request -> unit +(** [pp_request v] formats v *) + +val pp_request_envelope : Format.formatter -> request_envelope -> unit +(** [pp_request_envelope v] formats v *) + +val pp_status : Format.formatter -> status -> unit +(** [pp_status v] formats v *) + +val pp_response : Format.formatter -> response -> unit +(** [pp_response v] formats v *) + + +(** {2 Protobuf Encoding} *) + +val encode_pb_request_config_format : request_config_format -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_config_format v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_output_format : request_output_format -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_output_format v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_status : request_status -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_status v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_setup_session : request_setup_session -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_setup_session v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_set : request_set -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_set v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_delete : request_delete -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_delete v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_rename : request_rename -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_rename v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_copy : request_copy -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_copy v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_comment : request_comment -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_comment v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_commit : request_commit -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_commit v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_rollback : request_rollback -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_rollback v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_load : request_load -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_load v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_merge : request_merge -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_merge v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_save : request_save -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_save v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_show_config : request_show_config -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_show_config v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_exists : request_exists -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_exists v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_get_value : request_get_value -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_get_value v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_get_values : request_get_values -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_get_values v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_list_children : request_list_children -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_list_children v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_run_op_mode : request_run_op_mode -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_run_op_mode v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_confirm : request_confirm -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_confirm v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_enter_configuration_mode : request_enter_configuration_mode -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_enter_configuration_mode v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_exit_configuration_mode : request_exit_configuration_mode -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_exit_configuration_mode v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request : request -> Pbrt.Encoder.t -> unit +(** [encode_pb_request v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_request_envelope : request_envelope -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_envelope v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_status : status -> Pbrt.Encoder.t -> unit +(** [encode_pb_status v encoder] encodes [v] with the given [encoder] *) + +val encode_pb_response : response -> Pbrt.Encoder.t -> unit +(** [encode_pb_response v encoder] encodes [v] with the given [encoder] *) + + +(** {2 Protobuf Decoding} *) + +val decode_pb_request_config_format : Pbrt.Decoder.t -> request_config_format +(** [decode_pb_request_config_format decoder] decodes a [request_config_format] binary value from [decoder] *) + +val decode_pb_request_output_format : Pbrt.Decoder.t -> request_output_format +(** [decode_pb_request_output_format decoder] decodes a [request_output_format] binary value from [decoder] *) + +val decode_pb_request_status : Pbrt.Decoder.t -> request_status +(** [decode_pb_request_status decoder] decodes a [request_status] binary value from [decoder] *) + +val decode_pb_request_setup_session : Pbrt.Decoder.t -> request_setup_session +(** [decode_pb_request_setup_session decoder] decodes a [request_setup_session] binary value from [decoder] *) + +val decode_pb_request_set : Pbrt.Decoder.t -> request_set +(** [decode_pb_request_set decoder] decodes a [request_set] binary value from [decoder] *) + +val decode_pb_request_delete : Pbrt.Decoder.t -> request_delete +(** [decode_pb_request_delete decoder] decodes a [request_delete] binary value from [decoder] *) + +val decode_pb_request_rename : Pbrt.Decoder.t -> request_rename +(** [decode_pb_request_rename decoder] decodes a [request_rename] binary value from [decoder] *) + +val decode_pb_request_copy : Pbrt.Decoder.t -> request_copy +(** [decode_pb_request_copy decoder] decodes a [request_copy] binary value from [decoder] *) + +val decode_pb_request_comment : Pbrt.Decoder.t -> request_comment +(** [decode_pb_request_comment decoder] decodes a [request_comment] binary value from [decoder] *) + +val decode_pb_request_commit : Pbrt.Decoder.t -> request_commit +(** [decode_pb_request_commit decoder] decodes a [request_commit] binary value from [decoder] *) + +val decode_pb_request_rollback : Pbrt.Decoder.t -> request_rollback +(** [decode_pb_request_rollback decoder] decodes a [request_rollback] binary value from [decoder] *) + +val decode_pb_request_load : Pbrt.Decoder.t -> request_load +(** [decode_pb_request_load decoder] decodes a [request_load] binary value from [decoder] *) + +val decode_pb_request_merge : Pbrt.Decoder.t -> request_merge +(** [decode_pb_request_merge decoder] decodes a [request_merge] binary value from [decoder] *) + +val decode_pb_request_save : Pbrt.Decoder.t -> request_save +(** [decode_pb_request_save decoder] decodes a [request_save] binary value from [decoder] *) + +val decode_pb_request_show_config : Pbrt.Decoder.t -> request_show_config +(** [decode_pb_request_show_config decoder] decodes a [request_show_config] binary value from [decoder] *) + +val decode_pb_request_exists : Pbrt.Decoder.t -> request_exists +(** [decode_pb_request_exists decoder] decodes a [request_exists] binary value from [decoder] *) + +val decode_pb_request_get_value : Pbrt.Decoder.t -> request_get_value +(** [decode_pb_request_get_value decoder] decodes a [request_get_value] binary value from [decoder] *) + +val decode_pb_request_get_values : Pbrt.Decoder.t -> request_get_values +(** [decode_pb_request_get_values decoder] decodes a [request_get_values] binary value from [decoder] *) + +val decode_pb_request_list_children : Pbrt.Decoder.t -> request_list_children +(** [decode_pb_request_list_children decoder] decodes a [request_list_children] binary value from [decoder] *) + +val decode_pb_request_run_op_mode : Pbrt.Decoder.t -> request_run_op_mode +(** [decode_pb_request_run_op_mode decoder] decodes a [request_run_op_mode] binary value from [decoder] *) + +val decode_pb_request_confirm : Pbrt.Decoder.t -> request_confirm +(** [decode_pb_request_confirm decoder] decodes a [request_confirm] binary value from [decoder] *) + +val decode_pb_request_enter_configuration_mode : Pbrt.Decoder.t -> request_enter_configuration_mode +(** [decode_pb_request_enter_configuration_mode decoder] decodes a [request_enter_configuration_mode] binary value from [decoder] *) + +val decode_pb_request_exit_configuration_mode : Pbrt.Decoder.t -> request_exit_configuration_mode +(** [decode_pb_request_exit_configuration_mode decoder] decodes a [request_exit_configuration_mode] binary value from [decoder] *) + +val decode_pb_request : Pbrt.Decoder.t -> request +(** [decode_pb_request decoder] decodes a [request] binary value from [decoder] *) + +val decode_pb_request_envelope : Pbrt.Decoder.t -> request_envelope +(** [decode_pb_request_envelope decoder] decodes a [request_envelope] binary value from [decoder] *) + +val decode_pb_status : Pbrt.Decoder.t -> status +(** [decode_pb_status decoder] decodes a [status] binary value from [decoder] *) + +val decode_pb_response : Pbrt.Decoder.t -> response +(** [decode_pb_response decoder] decodes a [response] binary value from [decoder] *) diff --git a/src/vyconf_types.ml b/src/vyconf_types.ml deleted file mode 100644 index f7e5d50..0000000 --- a/src/vyconf_types.ml +++ /dev/null @@ -1,318 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - - -type request_config_format = - | Curly - | Json - -type request_output_format = - | Out_plain - | Out_json - -type request_setup_session = { - client_application : string option; - on_behalf_of : int32 option; -} - -type request_set = { - path : string list; - ephemeral : bool option; -} - -type request_delete = { - path : string list; -} - -type request_rename = { - edit_level : string list; - from : string; - to_ : string; -} - -type request_copy = { - edit_level : string list; - from : string; - to_ : string; -} - -type request_comment = { - path : string list; - comment : string; -} - -type request_commit = { - confirm : bool option; - confirm_timeout : int32 option; - comment : string option; -} - -type request_rollback = { - revision : int32; -} - -type request_load = { - location : string; - format : request_config_format option; -} - -type request_merge = { - location : string; - format : request_config_format option; -} - -type request_save = { - location : string; - format : request_config_format option; -} - -type request_show_config = { - path : string list; - format : request_config_format option; -} - -type request_exists = { - path : string list; -} - -type request_get_value = { - path : string list; - output_format : request_output_format option; -} - -type request_get_values = { - path : string list; - output_format : request_output_format option; -} - -type request_list_children = { - path : string list; - output_format : request_output_format option; -} - -type request_run_op_mode = { - path : string list; - output_format : request_output_format option; -} - -type request_enter_configuration_mode = { - exclusive : bool; - override_exclusive : bool; -} - -type request = - | Status - | Setup_session of request_setup_session - | Set of request_set - | Delete of request_delete - | Rename of request_rename - | Copy of request_copy - | Comment of request_comment - | Commit of request_commit - | Rollback of request_rollback - | Merge of request_merge - | Save of request_save - | Show_config of request_show_config - | Exists of request_exists - | Get_value of request_get_value - | Get_values of request_get_values - | List_children of request_list_children - | Run_op_mode of request_run_op_mode - | Confirm - | Configure of request_enter_configuration_mode - | Exit_configure - | Teardown of string - -type request_envelope = { - token : string option; - request : request; -} - -type status = - | Success - | Fail - | Invalid_path - | Invalid_value - | Commit_in_progress - | Configuration_locked - | Internal_error - | Permission_denied - | Path_already_exists - -type response = { - status : status; - output : string option; - error : string option; - warning : string option; -} - -let rec default_request_config_format () = (Curly:request_config_format) - -let rec default_request_output_format () = (Out_plain:request_output_format) - -let rec default_request_setup_session - ?client_application:((client_application:string option) = None) - ?on_behalf_of:((on_behalf_of:int32 option) = None) - () : request_setup_session = { - client_application; - on_behalf_of; -} - -let rec default_request_set - ?path:((path:string list) = []) - ?ephemeral:((ephemeral:bool option) = None) - () : request_set = { - path; - ephemeral; -} - -let rec default_request_delete - ?path:((path:string list) = []) - () : request_delete = { - path; -} - -let rec default_request_rename - ?edit_level:((edit_level:string list) = []) - ?from:((from:string) = "") - ?to_:((to_:string) = "") - () : request_rename = { - edit_level; - from; - to_; -} - -let rec default_request_copy - ?edit_level:((edit_level:string list) = []) - ?from:((from:string) = "") - ?to_:((to_:string) = "") - () : request_copy = { - edit_level; - from; - to_; -} - -let rec default_request_comment - ?path:((path:string list) = []) - ?comment:((comment:string) = "") - () : request_comment = { - path; - comment; -} - -let rec default_request_commit - ?confirm:((confirm:bool option) = None) - ?confirm_timeout:((confirm_timeout:int32 option) = None) - ?comment:((comment:string option) = None) - () : request_commit = { - confirm; - confirm_timeout; - comment; -} - -let rec default_request_rollback - ?revision:((revision:int32) = 0l) - () : request_rollback = { - revision; -} - -let rec default_request_load - ?location:((location:string) = "") - ?format:((format:request_config_format option) = None) - () : request_load = { - location; - format; -} - -let rec default_request_merge - ?location:((location:string) = "") - ?format:((format:request_config_format option) = None) - () : request_merge = { - location; - format; -} - -let rec default_request_save - ?location:((location:string) = "") - ?format:((format:request_config_format option) = None) - () : request_save = { - location; - format; -} - -let rec default_request_show_config - ?path:((path:string list) = []) - ?format:((format:request_config_format option) = None) - () : request_show_config = { - path; - format; -} - -let rec default_request_exists - ?path:((path:string list) = []) - () : request_exists = { - path; -} - -let rec default_request_get_value - ?path:((path:string list) = []) - ?output_format:((output_format:request_output_format option) = None) - () : request_get_value = { - path; - output_format; -} - -let rec default_request_get_values - ?path:((path:string list) = []) - ?output_format:((output_format:request_output_format option) = None) - () : request_get_values = { - path; - output_format; -} - -let rec default_request_list_children - ?path:((path:string list) = []) - ?output_format:((output_format:request_output_format option) = None) - () : request_list_children = { - path; - output_format; -} - -let rec default_request_run_op_mode - ?path:((path:string list) = []) - ?output_format:((output_format:request_output_format option) = None) - () : request_run_op_mode = { - path; - output_format; -} - -let rec default_request_enter_configuration_mode - ?exclusive:((exclusive:bool) = false) - ?override_exclusive:((override_exclusive:bool) = false) - () : request_enter_configuration_mode = { - exclusive; - override_exclusive; -} - -let rec default_request (): request = Status - -let rec default_request_envelope - ?token:((token:string option) = None) - ?request:((request:request) = default_request ()) - () : request_envelope = { - token; - request; -} - -let rec default_status () = (Success:status) - -let rec default_response - ?status:((status:status) = default_status ()) - ?output:((output:string option) = None) - ?error:((error:string option) = None) - ?warning:((warning:string option) = None) - () : response = { - status; - output; - error; - warning; -} diff --git a/src/vyconf_types.mli b/src/vyconf_types.mli deleted file mode 100644 index 194d66c..0000000 --- a/src/vyconf_types.mli +++ /dev/null @@ -1,306 +0,0 @@ -(** vyconf.proto Types *) - - - -(** {2 Types} *) - -type request_config_format = - | Curly - | Json - -type request_output_format = - | Out_plain - | Out_json - -type request_setup_session = { - client_application : string option; - on_behalf_of : int32 option; -} - -type request_set = { - path : string list; - ephemeral : bool option; -} - -type request_delete = { - path : string list; -} - -type request_rename = { - edit_level : string list; - from : string; - to_ : string; -} - -type request_copy = { - edit_level : string list; - from : string; - to_ : string; -} - -type request_comment = { - path : string list; - comment : string; -} - -type request_commit = { - confirm : bool option; - confirm_timeout : int32 option; - comment : string option; -} - -type request_rollback = { - revision : int32; -} - -type request_load = { - location : string; - format : request_config_format option; -} - -type request_merge = { - location : string; - format : request_config_format option; -} - -type request_save = { - location : string; - format : request_config_format option; -} - -type request_show_config = { - path : string list; - format : request_config_format option; -} - -type request_exists = { - path : string list; -} - -type request_get_value = { - path : string list; - output_format : request_output_format option; -} - -type request_get_values = { - path : string list; - output_format : request_output_format option; -} - -type request_list_children = { - path : string list; - output_format : request_output_format option; -} - -type request_run_op_mode = { - path : string list; - output_format : request_output_format option; -} - -type request_enter_configuration_mode = { - exclusive : bool; - override_exclusive : bool; -} - -type request = - | Status - | Setup_session of request_setup_session - | Set of request_set - | Delete of request_delete - | Rename of request_rename - | Copy of request_copy - | Comment of request_comment - | Commit of request_commit - | Rollback of request_rollback - | Merge of request_merge - | Save of request_save - | Show_config of request_show_config - | Exists of request_exists - | Get_value of request_get_value - | Get_values of request_get_values - | List_children of request_list_children - | Run_op_mode of request_run_op_mode - | Confirm - | Configure of request_enter_configuration_mode - | Exit_configure - | Teardown of string - -type request_envelope = { - token : string option; - request : request; -} - -type status = - | Success - | Fail - | Invalid_path - | Invalid_value - | Commit_in_progress - | Configuration_locked - | Internal_error - | Permission_denied - | Path_already_exists - -type response = { - status : status; - output : string option; - error : string option; - warning : string option; -} - - -(** {2 Default values} *) - -val default_request_config_format : unit -> request_config_format -(** [default_request_config_format ()] is the default value for type [request_config_format] *) - -val default_request_output_format : unit -> request_output_format -(** [default_request_output_format ()] is the default value for type [request_output_format] *) - -val default_request_setup_session : - ?client_application:string option -> - ?on_behalf_of:int32 option -> - unit -> - request_setup_session -(** [default_request_setup_session ()] is the default value for type [request_setup_session] *) - -val default_request_set : - ?path:string list -> - ?ephemeral:bool option -> - unit -> - request_set -(** [default_request_set ()] is the default value for type [request_set] *) - -val default_request_delete : - ?path:string list -> - unit -> - request_delete -(** [default_request_delete ()] is the default value for type [request_delete] *) - -val default_request_rename : - ?edit_level:string list -> - ?from:string -> - ?to_:string -> - unit -> - request_rename -(** [default_request_rename ()] is the default value for type [request_rename] *) - -val default_request_copy : - ?edit_level:string list -> - ?from:string -> - ?to_:string -> - unit -> - request_copy -(** [default_request_copy ()] is the default value for type [request_copy] *) - -val default_request_comment : - ?path:string list -> - ?comment:string -> - unit -> - request_comment -(** [default_request_comment ()] is the default value for type [request_comment] *) - -val default_request_commit : - ?confirm:bool option -> - ?confirm_timeout:int32 option -> - ?comment:string option -> - unit -> - request_commit -(** [default_request_commit ()] is the default value for type [request_commit] *) - -val default_request_rollback : - ?revision:int32 -> - unit -> - request_rollback -(** [default_request_rollback ()] is the default value for type [request_rollback] *) - -val default_request_load : - ?location:string -> - ?format:request_config_format option -> - unit -> - request_load -(** [default_request_load ()] is the default value for type [request_load] *) - -val default_request_merge : - ?location:string -> - ?format:request_config_format option -> - unit -> - request_merge -(** [default_request_merge ()] is the default value for type [request_merge] *) - -val default_request_save : - ?location:string -> - ?format:request_config_format option -> - unit -> - request_save -(** [default_request_save ()] is the default value for type [request_save] *) - -val default_request_show_config : - ?path:string list -> - ?format:request_config_format option -> - unit -> - request_show_config -(** [default_request_show_config ()] is the default value for type [request_show_config] *) - -val default_request_exists : - ?path:string list -> - unit -> - request_exists -(** [default_request_exists ()] is the default value for type [request_exists] *) - -val default_request_get_value : - ?path:string list -> - ?output_format:request_output_format option -> - unit -> - request_get_value -(** [default_request_get_value ()] is the default value for type [request_get_value] *) - -val default_request_get_values : - ?path:string list -> - ?output_format:request_output_format option -> - unit -> - request_get_values -(** [default_request_get_values ()] is the default value for type [request_get_values] *) - -val default_request_list_children : - ?path:string list -> - ?output_format:request_output_format option -> - unit -> - request_list_children -(** [default_request_list_children ()] is the default value for type [request_list_children] *) - -val default_request_run_op_mode : - ?path:string list -> - ?output_format:request_output_format option -> - unit -> - request_run_op_mode -(** [default_request_run_op_mode ()] is the default value for type [request_run_op_mode] *) - -val default_request_enter_configuration_mode : - ?exclusive:bool -> - ?override_exclusive:bool -> - unit -> - request_enter_configuration_mode -(** [default_request_enter_configuration_mode ()] is the default value for type [request_enter_configuration_mode] *) - -val default_request : unit -> request -(** [default_request ()] is the default value for type [request] *) - -val default_request_envelope : - ?token:string option -> - ?request:request -> - unit -> - request_envelope -(** [default_request_envelope ()] is the default value for type [request_envelope] *) - -val default_status : unit -> status -(** [default_status ()] is the default value for type [status] *) - -val default_response : - ?status:status -> - ?output:string option -> - ?error:string option -> - ?warning:string option -> - unit -> - response -(** [default_response ()] is the default value for type [response] *) diff --git a/src/vyconfd.ml b/src/vyconfd.ml index 59425ee..729be73 100644 --- a/src/vyconfd.ml +++ b/src/vyconfd.ml @@ -1,7 +1,6 @@ open Lwt -open Vyconf_connect.Vyconf_types -open Vyconf_connect.Vyconf_pb +open Vyconf_connect.Vyconf_pbt open Vyconfd_config.Defaults module FP = FilePath @@ -138,7 +137,7 @@ let show_config world token (req: request_show_config) = let send_response oc resp = let enc = Pbrt.Encoder.create () in - let%lwt () = encode_response resp enc |> return in + let%lwt () = encode_pb_response resp enc |> return in let%lwt resp_msg = Pbrt.Encoder.to_bytes enc |> return in let%lwt () = Vyconf_connect.Message.write oc resp_msg in Lwt.return () @@ -148,7 +147,7 @@ let rec handle_connection world ic oc fd () = let%lwt req_msg = Vyconf_connect.Message.read ic in let%lwt req = try - let envelope = decode_request_envelope (Pbrt.Decoder.of_bytes req_msg) in + let envelope = decode_pb_request_envelope (Pbrt.Decoder.of_bytes req_msg) in Lwt.return (Ok (envelope.token, envelope.request)) with Pbrt.Decoder.Failure e -> Lwt.return (Error (Pbrt.Decoder.error_to_string e)) in -- cgit v1.2.3 From 561630399499ba2ae08cc4e674fe413c4504394f Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 23 Oct 2024 18:50:46 -0500 Subject: T6718: use vycli as test case --- src/dune | 7 +++++++ src/vycli.ml | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src/dune') diff --git a/src/dune b/src/dune index 954a055..54d2de9 100644 --- a/src/dune +++ b/src/dune @@ -26,6 +26,13 @@ (libraries vyos1x-config vyconfd_config vyconf_connect) (preprocess (pps lwt_ppx))) +(executable + (name vycli) + (public_name vycli) + (modules vycli) + (libraries client) + (preprocess (pps lwt_ppx))) + (rule (alias protoc) (mode promote) diff --git a/src/vycli.ml b/src/vycli.ml index 6c1ed0c..4310cbd 100644 --- a/src/vycli.ml +++ b/src/vycli.ml @@ -1,5 +1,5 @@ -open Vyconf_client -open Vyconf_types +open Client.Vyconf_client +open Vyconf_connect.Vyconf_pbt type op_t = | OpStatus @@ -49,7 +49,7 @@ let output_format_of_string s = | _ -> failwith (Printf.sprintf "Unknown output format %s, should be plain or json" s) let main socket op path out_format config_format = - let%lwt client = Vyconf_client.create ~token:!token socket out_format config_format in + let%lwt client = Client.Vyconf_client.create ~token:!token socket out_format config_format in let%lwt result = match op with | None -> Error "Operation required" |> Lwt.return | Some o -> -- cgit v1.2.3 From 43df38febc4798d991d5d1425e997a2cd3fc29fd Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 23 Oct 2024 18:50:46 -0500 Subject: T6718: drop ref to util For convenience and to avoid dune build conflict, all util functions now reside in vyos1x-config.util. --- src/dune | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dune') diff --git a/src/dune b/src/dune index 54d2de9..05d1f7a 100644 --- a/src/dune +++ b/src/dune @@ -22,7 +22,7 @@ (executable (name vyconfd) (public_name vyconfd) - (modules vyconfd startup version util) + (modules vyconfd startup version) (libraries vyos1x-config vyconfd_config vyconf_connect) (preprocess (pps lwt_ppx))) -- cgit v1.2.3 From b8dbd4d03ebb058aaf1e8ddd9261b0628e520e8b Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 23 Oct 2024 18:50:46 -0500 Subject: T6718: add client_session module and test executable validate.ml --- src/dune | 8 +++++- src/validate.ml | 32 ++++++++++++++++++++++ src/vyconf_client_session.ml | 64 +++++++++++++++++++++++++++++++++++++++++++ src/vyconf_client_session.mli | 16 +++++++++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/validate.ml create mode 100644 src/vyconf_client_session.ml create mode 100644 src/vyconf_client_session.mli (limited to 'src/dune') diff --git a/src/dune b/src/dune index 05d1f7a..8b14764 100644 --- a/src/dune +++ b/src/dune @@ -14,7 +14,7 @@ (library (name client) (public_name vyconf.vyconf-client) - (modules vyconf_client) + (modules vyconf_client vyconf_client_session) (libraries vyos1x-config vyconf_connect lwt lwt.unix lwt_log lwt_ppx ocaml-protoc toml sha yojson ppx_deriving.show ppx_deriving_yojson) (preprocess (pps lwt_ppx ppx_deriving.show ppx_deriving_yojson))) @@ -33,6 +33,12 @@ (libraries client) (preprocess (pps lwt_ppx))) +(executable + (name validate) + (public_name validate) + (modules validate) + (libraries client)) + (rule (alias protoc) (mode promote) diff --git a/src/validate.ml b/src/validate.ml new file mode 100644 index 0000000..7b3b596 --- /dev/null +++ b/src/validate.ml @@ -0,0 +1,32 @@ +open Client.Vyconf_client_session + +let path_opt = ref "" + +let usage = "Usage: " ^ Sys.argv.(0) ^ " [options]" + +let args = [ + ("--path", Arg.String (fun s -> path_opt := s), " Configuration path"); + ] + +let get_sockname = + "/var/run/vyconfd.sock" + +let main socket path_list = + let token = session_init socket in + match token with + | Error e -> "Failed to initialize session: " ^ e + | Ok token -> + let out = session_validate_path socket token path_list + in + let _ = session_free socket token in + match out with + | Error e -> "Failed to validate path: " ^ e + | Ok _ -> "No error" + +let _ = + let () = Arg.parse args (fun _ -> ()) usage in + let path_list = Vyos1x.Util.list_of_path !path_opt in + let socket = get_sockname in + let result = main socket path_list in + let () = print_endline result in + exit 0 diff --git a/src/vyconf_client_session.ml b/src/vyconf_client_session.ml new file mode 100644 index 0000000..70a2a13 --- /dev/null +++ b/src/vyconf_client_session.ml @@ -0,0 +1,64 @@ +open Vyconf_connect.Vyconf_pbt + +type op_t = + | OpSetupSession + | OpExists + | OpTeardownSession + | OpShowConfig + | OpValidate + +let config_format_of_string s = + match s with + | "curly" -> Curly + | "json" -> Json + | _ -> failwith (Printf.sprintf "Unknown config format %s, should be curly or json" s) + +let output_format_of_string s = + match s with + | "plain" -> Out_plain + | "json" -> Out_json + | _ -> failwith (Printf.sprintf "Unknown output format %s, should be plain or json" s) + +let call_op ?(out_format="plain") ?(config_format="curly") socket token op path = + let config_format = config_format_of_string config_format in + let out_format = output_format_of_string out_format in + let run = + let%lwt client = + Vyconf_client.create ~token:token socket out_format config_format + in + let%lwt result = match op with + | None -> Error "Operation required" |> Lwt.return + | Some o -> + begin + match o with + | OpSetupSession -> + let%lwt resp = Vyconf_client.setup_session client "vyconf_client_session" in + begin + match resp with + | Ok c -> Vyconf_client.get_token c + | Error e -> Error e |> Lwt.return + end + | OpExists -> Vyconf_client.exists client path + | OpTeardownSession -> Vyconf_client.teardown_session client + | OpShowConfig -> Vyconf_client.show_config client path + | OpValidate -> Vyconf_client.validate client path + end + in + Lwt.return result + in + Lwt_main.run run + +let session_init ?(out_format="plain") ?(config_format="curly") socket = + call_op ~out_format:out_format ~config_format:config_format socket None (Some OpSetupSession) [] + +let session_free socket token = + call_op socket (Some token) (Some OpTeardownSession) [] + +let session_validate_path socket token path = + call_op socket (Some token) (Some OpValidate) path + +let session_show_config socket token path = + call_op socket (Some token) (Some OpShowConfig) path + +let session_path_exists socket token path = + call_op socket (Some token) (Some OpExists) path diff --git a/src/vyconf_client_session.mli b/src/vyconf_client_session.mli new file mode 100644 index 0000000..98fa3c2 --- /dev/null +++ b/src/vyconf_client_session.mli @@ -0,0 +1,16 @@ +type op_t = + | OpSetupSession + | OpExists + | OpTeardownSession + | OpShowConfig + | OpValidate + +val session_init : ?out_format:string -> ?config_format:string -> string -> (string, string) result + +val session_free : string -> string -> (string, string) result + +val session_validate_path : string -> string -> string list -> (string, string) result + +val session_show_config : string -> string -> string list -> (string, string) result + +val session_path_exists : string -> string -> string list -> (string, string) result -- cgit v1.2.3 From 4aee642874a29f4f77704c97286f201d3c4bd2c3 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 23 Oct 2024 18:50:46 -0500 Subject: T6718: move vyos1x-adapter into subdirectory The vyos1x-adapter provides access to the legacy CStore set/delete functions using ctypes. Developed as a separate package, include as a subdir, to be retired when full replacements are available. --- src/adapter/vy_delete.ml | 40 ++++++++++++ src/adapter/vy_load_config.ml | 47 ++++++++++++++ src/adapter/vy_set.ml | 79 +++++++++++++++++++++++ src/adapter/vyos1x_adapter.ml | 140 +++++++++++++++++++++++++++++++++++++++++ src/adapter/vyos1x_adapter.mli | 16 +++++ src/dune | 27 ++++++++ 6 files changed, 349 insertions(+) create mode 100644 src/adapter/vy_delete.ml create mode 100644 src/adapter/vy_load_config.ml create mode 100644 src/adapter/vy_set.ml create mode 100644 src/adapter/vyos1x_adapter.ml create mode 100644 src/adapter/vyos1x_adapter.mli (limited to 'src/dune') diff --git a/src/adapter/vy_delete.ml b/src/adapter/vy_delete.ml new file mode 100644 index 0000000..652fdad --- /dev/null +++ b/src/adapter/vy_delete.ml @@ -0,0 +1,40 @@ +let path_opt = ref [] + +let usage = "Usage: " ^ Sys.argv.(0) ^ " [options]" + +let read_path p = + path_opt := p::!path_opt + +let speclist = [ + ] + +let () = + let () = Arg.parse speclist read_path usage in + let path_list = List.rev !path_opt in + let () = + if List.length path_list = 0 then + (Printf.printf "no path specified\n"; exit 1) + in + let handle = + let h = Vyos1x_adapter.cstore_handle_init () in + if not (Vyos1x_adapter.cstore_in_config_session_handle h) then + (Vyos1x_adapter.cstore_handle_free h; + Printf.printf "not in config session\n"; exit 1) + else Some h + in + let output = + match handle with + | Some h -> Vyos1x_adapter.cstore_delete_path h path_list + | None -> "missing session handle" + in + let ret = + if output = "" then 0 + else 1 + in + let () = + match handle with + | Some h -> Vyos1x_adapter.cstore_handle_free h + | None -> () + in + let () = print_endline output in + exit ret diff --git a/src/adapter/vy_load_config.ml b/src/adapter/vy_load_config.ml new file mode 100644 index 0000000..66bbfb8 --- /dev/null +++ b/src/adapter/vy_load_config.ml @@ -0,0 +1,47 @@ +(* Adapter load_config + *) + +open Vyos1x + +let read_config filename = + let ch = open_in filename in + let s = really_input_string ch (in_channel_length ch) in + let ct = + try + Ok (Parser.from_string s) + with Vyos1x.Util.Syntax_error (opt, msg) -> + begin + match opt with + | None -> Error msg + | Some (line, pos) -> + let out = Printf.sprintf "%s line %d pos %d\n" msg line pos + in Error out + end + in + close_in ch; + ct + +let read_configs f g = + let l = read_config f in + let r = read_config g in + match l, r with + | Ok left, Ok right -> Ok (left, right) + | Error msg_l, Error msg_r -> Error (msg_l ^ msg_r) + | Error msg_l, _ -> Error msg_l + | _, Error msg_r -> Error msg_r + + +let args = [] +let usage = Printf.sprintf "Usage: %s " Sys.argv.(0) + +let () = if Array.length Sys.argv <> 3 then (Arg.usage args usage; exit 1) + +let () = +let left_name = Sys.argv.(1) in +let right_name = Sys.argv.(2) in +let read = read_configs left_name right_name in +let res = + match read with + | Ok (left, right) -> Vyos1x_adapter.load_config left right + | Error msg -> msg +in Printf.printf "%s\n" res diff --git a/src/adapter/vy_set.ml b/src/adapter/vy_set.ml new file mode 100644 index 0000000..1fb29aa --- /dev/null +++ b/src/adapter/vy_set.ml @@ -0,0 +1,79 @@ +let legacy = ref false +let no_set = ref false +let valid = ref false +let output = ref "" +let path_opt = ref [] + +let usage = "Usage: " ^ Sys.argv.(0) ^ " [options]" + +let read_path p = + path_opt := p::!path_opt + +let speclist = [ + ("--legacy", Arg.Unit (fun _ -> legacy := true), "Use legacy validation"); + ("--no-set", Arg.Unit (fun _ -> no_set := true), "Do not set path"); + ] + +let format_out l = + let fl = List.filter (fun s -> (String.length s) > 0) l in + String.concat "\n\n" fl + +let is_valid v = + match v with + | None -> true + | Some _ -> false + +let valid_err v = + Option.value v ~default:"" + +let () = + let () = Arg.parse speclist read_path usage in + let path_list = List.rev !path_opt in + let () = + if List.length path_list = 0 then + (Printf.printf "no path specified\n"; exit 1) + in + let handle = + if !legacy || not !no_set then + let h = Vyos1x_adapter.cstore_handle_init () in + if not (Vyos1x_adapter.cstore_in_config_session_handle h) then + (Vyos1x_adapter.cstore_handle_free h; + Printf.printf "not in config session\n"; exit 1) + else Some h + else None + in + let valid = + if not !legacy then + Vyos1x_adapter.vyconf_validate_path path_list + else + begin + let out = + match handle with + | Some h -> Vyos1x_adapter.legacy_validate_path h path_list + | None -> "missing session handle" + in + match out with + | "" -> None + | _ -> Some out + end + in + let res = + if not !no_set && (is_valid valid) then + match handle with + | Some h -> + Vyos1x_adapter.cstore_set_path h path_list + | None -> "missing session handle" + else "" + in + let ret = + if (is_valid valid) && (res = "") then 0 + else 1 + in + let output = format_out [(valid_err valid); res] in + let () = + match handle with + | Some h -> Vyos1x_adapter.cstore_handle_free h + | None -> () + in + let () = print_endline output in + exit ret diff --git a/src/adapter/vyos1x_adapter.ml b/src/adapter/vyos1x_adapter.ml new file mode 100644 index 0000000..5835f5a --- /dev/null +++ b/src/adapter/vyos1x_adapter.ml @@ -0,0 +1,140 @@ +open Ctypes +open Foreign + +let libvyatta = Dl.dlopen ~flags:[Dl.RTLD_LAZY] ~filename:"libvyatta-cfg.so" + +let cstore_init = foreign ~from:libvyatta "vy_cstore_init" (void @-> returning uint64_t) +let cstore_free = foreign ~from:libvyatta "vy_cstore_free" (uint64_t @-> returning void) +let in_session = foreign ~from:libvyatta "vy_in_session" (uint64_t @-> returning int) +let cstore_set_path = foreign ~from:libvyatta "vy_set_path" (uint64_t @-> (ptr void) @-> size_t @-> returning string) +let cstore_del_path = foreign ~from:libvyatta "vy_delete_path" (uint64_t @-> (ptr void) @-> size_t @-> returning string) +let cstore_validate_path = foreign ~from:libvyatta "vy_validate_path" (uint64_t @-> (ptr void) @-> size_t @-> returning string) +let cstore_legacy_set_path = foreign ~from:libvyatta "vy_legacy_set_path" (uint64_t @-> (ptr void) @-> size_t @-> returning string) + +let cstore_handle_init () = Unsigned.UInt64.to_int (cstore_init ()) +let cstore_handle_free h = cstore_free (Unsigned.UInt64.of_int h) +let cstore_in_config_session_handle h = in_session (Unsigned.UInt64.of_int h) = 1 +let cstore_in_config_session () = cstore_in_config_session_handle (cstore_handle_init ()) + +let cstore_set_path handle path = + let len = List.length path in + let arr = CArray.of_list string path in + cstore_set_path (Unsigned.UInt64.of_int handle) (to_voidp (CArray.start arr)) (Unsigned.Size_t.of_int len) + +let legacy_validate_path handle path = + let len = List.length path in + let arr = CArray.of_list string path in + cstore_validate_path (Unsigned.UInt64.of_int handle) (to_voidp (CArray.start arr)) (Unsigned.Size_t.of_int len) + +let legacy_set_path handle path = + let len = List.length path in + let arr = CArray.of_list string path in + cstore_legacy_set_path (Unsigned.UInt64.of_int handle) (to_voidp (CArray.start arr)) (Unsigned.Size_t.of_int len) + +let cstore_delete_path handle path = + let len = List.length path in + let arr = CArray.of_list string path in + cstore_del_path (Unsigned.UInt64.of_int handle) (to_voidp (CArray.start arr)) (Unsigned.Size_t.of_int len) + +let set_path_reversed handle path _len = + let path = List.rev path in + cstore_set_path handle path + +let delete_path_reversed handle path _len = + let path = List.rev path in + cstore_delete_path handle path + +module VC = Client.Vyconf_client_session + +let get_sockname = + "/var/run/vyconfd.sock" + +let vyconf_validate_path path = + let socket = get_sockname in + let token = VC.session_init socket in + match token with + | Error e -> Some e + | Ok token -> + let out = VC.session_validate_path socket token path in + let _ = VC.session_free socket token in + match out with + | Ok _ -> None + | Error e -> Some e + +open Vyos1x + +module CT = Config_tree +module CD = Config_diff + +module ValueSet = Set.Make(String) + +let add_value handle acc out v = + let acc = v :: acc in + out ^ (set_path_reversed handle acc (List.length acc)) + +let add_values handle acc out vs = + match vs with + | [] -> out ^ (set_path_reversed handle acc (List.length acc)) + | _ -> List.fold_left (add_value handle acc) out vs + +let rec add_path handle acc out (node : CT.t) = + let acc = (Vytree.name_of_node node) :: acc in + let children = Vytree.children_of_node node in + match children with + | [] -> let data = Vytree.data_of_node node in + let values = data.values in + add_values handle acc out values + | _ -> List.fold_left (add_path handle acc) out children + +let del_value handle acc out v = + let acc = v :: acc in + out ^ (delete_path_reversed handle acc (List.length acc)) + +let del_values handle acc out vs = + match vs with + | [] -> out ^ (delete_path_reversed handle acc (List.length acc)) + | _ -> List.fold_left (del_value handle acc) out vs + +let del_path handle path out = + out ^ (cstore_delete_path handle path) + +(* +let update_data (CD.Diff_cstore data) m = + CD.Diff_cstore { data with out = m; } +*) + +let cstore_diff ?recurse:_ (path : string list) (CD.Diff_cstore res) (m : CD.change) = + let handle = res.handle in + match m with + | Added -> let node = Vytree.get res.right path in + let acc = List.tl (List.rev path) in + CD.Diff_cstore { res with out = add_path handle acc res.out node } + | Subtracted -> CD.Diff_cstore { res with out = del_path handle path res.out } + | Unchanged -> CD.Diff_cstore (res) + | Updated v -> + let ov = CT.get_values res.left path in + let acc = List.rev path in + match ov, v with + | [x], [y] -> let out = del_value handle acc res.out x in + let out = add_value handle acc out y in + CD.Diff_cstore { res with out = out } + | _, _ -> let ov_set = ValueSet.of_list ov in + let v_set = ValueSet.of_list v in + let sub_vals = ValueSet.elements (ValueSet.diff ov_set v_set) in + let add_vals = ValueSet.elements (ValueSet.diff v_set ov_set) in + let out = del_values handle acc res.out sub_vals in + let out = add_values handle acc out add_vals in + CD.Diff_cstore { res with out = out } + +let load_config left right = + let h = cstore_handle_init () in + if not (cstore_in_config_session_handle h) then + (cstore_handle_free h; + let out = "not in config session\n" in + out) + else + let dcstore = CD.make_diff_cstore left right h in + let dcstore = CD.diff [] cstore_diff dcstore (Option.some left, Option.some right) in + let ret = CD.eval_result dcstore in + cstore_handle_free h; + ret.out diff --git a/src/adapter/vyos1x_adapter.mli b/src/adapter/vyos1x_adapter.mli new file mode 100644 index 0000000..cb40e2b --- /dev/null +++ b/src/adapter/vyos1x_adapter.mli @@ -0,0 +1,16 @@ +open Vyos1x + +val cstore_handle_init : unit -> int +val cstore_handle_free : int -> unit +val cstore_in_config_session_handle : int -> bool +val cstore_in_config_session : unit -> bool +val cstore_set_path : int -> string list -> string +val legacy_validate_path : int -> string list -> string +val legacy_set_path : int -> string list -> string +val cstore_delete_path : int -> string list -> string +val set_path_reversed : int -> string list -> int -> string +val delete_path_reversed : int -> string list -> int -> string + +val vyconf_validate_path : string list -> string option + +val load_config : Config_tree.t -> Config_tree.t -> string diff --git a/src/dune b/src/dune index 8b14764..2fef6cc 100644 --- a/src/dune +++ b/src/dune @@ -1,3 +1,5 @@ +(include_subdirs unqualified) + (library (name vyconf_connect) (public_name vyconf.vyconf-connect) @@ -50,3 +52,28 @@ (run ocaml-protoc --ml_out src data/vyconf.proto) (run mv src/vyconf.ml src/vyconf_pbt.ml) (run mv src/vyconf.mli src/vyconf_pbt.mli))))) + +(library + (name vyos1x_adapter) + (public_name vyconf.vyos1x-adapter) + (libraries vyos1x-config vyconf.vyconf-client ctypes ctypes-foreign lwt lwt.unix lwt_log lwt_ppx) + (modules vyos1x_adapter) + (preprocess (pps lwt_ppx ppx_deriving_yojson))) + +(executable + (name vy_set) + (public_name vy_set) + (libraries vyos1x_adapter vyconf.vyconf-client) + (modules vy_set)) + +(executable + (name vy_delete) + (public_name vy_delete) + (libraries vyos1x_adapter vyconf.vyconf-client) + (modules vy_delete)) + +(executable + (name vy_load_config) + (public_name vy_load_config) + (libraries vyos1x_adapter vyos1x-config) + (modules vy_load_config)) -- cgit v1.2.3