From 64c52636c8c8727b0a735c0bd441dc4e8b4b5e13 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 8 Apr 2025 20:51:36 -0500 Subject: T7321: rename vyconf.proto message Status and enum to avoid collision The message and enum name Status conflicts with the use in vycall.proto; as the latter has consistency with other (non-conflicting) uses of the term, rename the former. --- data/vyconf.proto | 8 +++---- src/vycli.ml | 8 +++---- src/vyconf_client.ml | 4 ++-- src/vyconf_client.mli | 21 +--------------- src/vyconf_pbt.ml | 66 +++++++++++++++++++++++++-------------------------- src/vyconf_pbt.mli | 42 ++++++++++++++++---------------- src/vyconfd.ml | 2 +- 7 files changed, 66 insertions(+), 85 deletions(-) diff --git a/data/vyconf.proto b/data/vyconf.proto index 56875a3..15e10ae 100644 --- a/data/vyconf.proto +++ b/data/vyconf.proto @@ -9,7 +9,7 @@ message Request { OutJSON = 1; } - message Status { + message Prompt { } message SetupSession { @@ -125,7 +125,7 @@ message Request { oneof msg { - Status status = 1; + Prompt prompt = 1; SetupSession setup_session = 2; Set set = 3; Delete delete = 4; @@ -156,7 +156,7 @@ message RequestEnvelope { required Request request = 2; } -enum Status { +enum Errnum { SUCCESS = 0; FAIL = 1; INVALID_PATH = 2; @@ -169,7 +169,7 @@ enum Status { } message Response { - required Status status = 1; + required Errnum status = 1; optional string output = 2; optional string error = 3; optional string warning = 4; diff --git a/src/vycli.ml b/src/vycli.ml index bd14713..75e92b5 100644 --- a/src/vycli.ml +++ b/src/vycli.ml @@ -2,7 +2,7 @@ open Vyconfd_client.Vyconf_client open Vyconf_connect.Vyconf_pbt type op_t = - | OpStatus + | OpPrompt | OpSetupSession | OpTeardownSession | OpShowConfig @@ -35,7 +35,7 @@ let args = [ ("--exists", Arg.Unit (fun () -> op := Some OpExists), "Check if specified path exists"); ("--list-children", Arg.Unit (fun () -> op := Some OpListChildren), "List children of the node at the specified path"); ("--show-config", Arg.Unit (fun () -> op := Some OpShowConfig), "Show the configuration at the specified path"); - ("--status", Arg.Unit (fun () -> op := Some OpStatus), "Send a status/keepalive message"); + ("--prompt", Arg.Unit (fun () -> op := Some OpPrompt), "Send a status/keepalive message"); ("--validate", Arg.Unit (fun () -> op := Some OpValidate), "Validate path"); ("--reload-reftree", Arg.Unit (fun () -> op := Some OpReloadReftree), "Reload reference tree"); ] @@ -59,8 +59,8 @@ let main socket op path out_format config_format = | Some o -> begin match o with - | OpStatus -> - let%lwt resp = get_status client in + | OpPrompt -> + let%lwt resp = prompt client in begin match resp.status with | Success -> Ok "" |> Lwt.return diff --git a/src/vyconf_client.ml b/src/vyconf_client.ml index 7380760..c4811c5 100644 --- a/src/vyconf_client.ml +++ b/src/vyconf_client.ml @@ -48,8 +48,8 @@ let do_request client req = let%lwt resp = Vyconf_connect.Message.read client.ic in decode_pb_response (Pbrt.Decoder.of_bytes resp) |> Lwt.return -let get_status client = - let req = Status in +let prompt client = + let req = Prompt in let%lwt resp = do_request client req in Lwt.return resp diff --git a/src/vyconf_client.mli b/src/vyconf_client.mli index 5fd4df4..9c25c60 100644 --- a/src/vyconf_client.mli +++ b/src/vyconf_client.mli @@ -1,31 +1,12 @@ type t -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; -} - - 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 val shutdown : t -> t Lwt.t -val get_status : t -> response Lwt.t +val prompt : t -> Vyconf_connect.Vyconf_pbt.response Lwt.t val setup_session : ?on_behalf_of:(int option) -> t -> string -> (t, string) result Lwt.t diff --git a/src/vyconf_pbt.ml b/src/vyconf_pbt.ml index 48a8e87..8a781b5 100644 --- a/src/vyconf_pbt.ml +++ b/src/vyconf_pbt.ml @@ -8,7 +8,7 @@ type request_output_format = | Out_plain | Out_json -type request_status = unit +type request_prompt = unit type request_setup_session = { client_application : string option; @@ -118,7 +118,7 @@ type request_reload_reftree = { } type request = - | Status + | Prompt | Setup_session of request_setup_session | Set of request_set | Delete of request_delete @@ -147,7 +147,7 @@ type request_envelope = { request : request; } -type status = +type errnum = | Success | Fail | Invalid_path @@ -159,7 +159,7 @@ type status = | Path_already_exists type response = { - status : status; + status : errnum; output : string option; error : string option; warning : string option; @@ -169,7 +169,7 @@ 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_prompt = () let rec default_request_setup_session ?client_application:((client_application:string option) = None) @@ -339,7 +339,7 @@ let rec default_request_reload_reftree on_behalf_of; } -let rec default_request (): request = Status +let rec default_request (): request = Prompt let rec default_request_envelope ?token:((token:string option) = None) @@ -349,10 +349,10 @@ let rec default_request_envelope request; } -let rec default_status () = (Success:status) +let rec default_errnum () = (Success:errnum) let rec default_response - ?status:((status:status) = default_status ()) + ?status:((status:errnum) = default_errnum ()) ?output:((output:string option) = None) ?error:((error:string option) = None) ?warning:((warning:string option) = None) @@ -580,14 +580,14 @@ let default_request_envelope_mutable () : request_envelope_mutable = { } type response_mutable = { - mutable status : status; + mutable status : errnum; mutable output : string option; mutable error : string option; mutable warning : string option; } let default_response_mutable () : response_mutable = { - status = default_status (); + status = default_errnum (); output = None; error = None; warning = None; @@ -607,7 +607,7 @@ let rec pp_request_output_format fmt (v:request_output_format) = | Out_plain -> Format.fprintf fmt "Out_plain" | Out_json -> Format.fprintf fmt "Out_json" -let rec pp_request_status fmt (v:request_status) = +let rec pp_request_prompt fmt (v:request_prompt) = let pp_i fmt () = Pbrt.Pp.pp_unit fmt () in @@ -772,7 +772,7 @@ let rec pp_request_reload_reftree fmt (v:request_reload_reftree) = let rec pp_request fmt (v:request) = match v with - | Status -> Format.fprintf fmt "Status" + | Prompt -> Format.fprintf fmt "Prompt" | 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 @@ -803,7 +803,7 @@ let rec pp_request_envelope fmt (v:request_envelope) = in Pbrt.Pp.pp_brk pp_i fmt () -let rec pp_status fmt (v:status) = +let rec pp_errnum fmt (v:errnum) = match v with | Success -> Format.fprintf fmt "Success" | Fail -> Format.fprintf fmt "Fail" @@ -817,7 +817,7 @@ let rec pp_status fmt (v:status) = 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:true "status" pp_errnum 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; @@ -838,7 +838,7 @@ let rec encode_pb_request_output_format (v:request_output_format) encoder = | 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_prompt (v:request_prompt) encoder = () let rec encode_pb_request_setup_session (v:request_setup_session) encoder = @@ -1084,7 +1084,7 @@ let rec encode_pb_request_reload_reftree (v:request_reload_reftree) encoder = let rec encode_pb_request (v:request) encoder = begin match v with - | Status -> + | Prompt -> Pbrt.Encoder.key 1 Pbrt.Bytes encoder; Pbrt.Encoder.empty_nested encoder | Setup_session x -> @@ -1166,7 +1166,7 @@ let rec encode_pb_request_envelope (v:request_envelope) encoder = Pbrt.Encoder.key 2 Pbrt.Bytes encoder; () -let rec encode_pb_status (v:status) encoder = +let rec encode_pb_errnum (v:errnum) encoder = match v with | Success -> Pbrt.Encoder.int_as_varint (0) encoder | Fail -> Pbrt.Encoder.int_as_varint 1 encoder @@ -1179,7 +1179,7 @@ let rec encode_pb_status (v:status) 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; + encode_pb_errnum v.status encoder; Pbrt.Encoder.key 1 Pbrt.Varint encoder; begin match v.output with | Some x -> @@ -1217,11 +1217,11 @@ let rec decode_pb_request_output_format d = | 1 -> (Out_json:request_output_format) | _ -> Pbrt.Decoder.malformed_variant "request_output_format" -let rec decode_pb_request_status d = +let rec decode_pb_request_prompt d = match Pbrt.Decoder.key d with | None -> (); | Some (_, pk) -> - Pbrt.Decoder.unexpected_payload "Unexpected fields in empty message(request_status)" pk + Pbrt.Decoder.unexpected_payload "Unexpected fields in empty message(request_prompt)" pk let rec decode_pb_request_setup_session d = let v = default_request_setup_session_mutable () in @@ -1767,7 +1767,7 @@ let rec decode_pb_request d = | None -> Pbrt.Decoder.malformed_variant "request" | Some (1, _) -> begin Pbrt.Decoder.empty_nested d ; - (Status : request) + (Prompt : 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) @@ -1832,18 +1832,18 @@ let rec decode_pb_request_envelope d = request = v.request; } : request_envelope) -let rec decode_pb_status d = +let rec decode_pb_errnum 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" + | 0 -> (Success:errnum) + | 1 -> (Fail:errnum) + | 2 -> (Invalid_path:errnum) + | 3 -> (Invalid_value:errnum) + | 4 -> (Commit_in_progress:errnum) + | 5 -> (Configuration_locked:errnum) + | 6 -> (Internal_error:errnum) + | 7 -> (Permission_denied:errnum) + | 8 -> (Path_already_exists:errnum) + | _ -> Pbrt.Decoder.malformed_variant "errnum" let rec decode_pb_response d = let v = default_response_mutable () in @@ -1854,7 +1854,7 @@ let rec decode_pb_response d = | None -> ( ); continue__ := false | Some (1, Pbrt.Varint) -> begin - v.status <- decode_pb_status d; status_is_set := true; + v.status <- decode_pb_errnum d; status_is_set := true; end | Some (1, pk) -> Pbrt.Decoder.unexpected_payload "Message(response), field(1)" pk diff --git a/src/vyconf_pbt.mli b/src/vyconf_pbt.mli index 7189a7a..c7e0438 100644 --- a/src/vyconf_pbt.mli +++ b/src/vyconf_pbt.mli @@ -15,7 +15,7 @@ type request_output_format = | Out_plain | Out_json -type request_status = unit +type request_prompt = unit type request_setup_session = { client_application : string option; @@ -125,7 +125,7 @@ type request_reload_reftree = { } type request = - | Status + | Prompt | Setup_session of request_setup_session | Set of request_set | Delete of request_delete @@ -154,7 +154,7 @@ type request_envelope = { request : request; } -type status = +type errnum = | Success | Fail | Invalid_path @@ -166,7 +166,7 @@ type status = | Path_already_exists type response = { - status : status; + status : errnum; output : string option; error : string option; warning : string option; @@ -181,8 +181,8 @@ val default_request_config_format : unit -> 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_prompt : unit +(** [default_request_prompt ()] is the default value for type [request_prompt] *) val default_request_setup_session : ?client_application:string option -> @@ -345,11 +345,11 @@ val default_request_envelope : 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_errnum : unit -> errnum +(** [default_errnum ()] is the default value for type [errnum] *) val default_response : - ?status:status -> + ?status:errnum -> ?output:string option -> ?error:string option -> ?warning:string option -> @@ -366,8 +366,8 @@ val pp_request_config_format : Format.formatter -> request_config_format -> unit 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_prompt : Format.formatter -> request_prompt -> unit +(** [pp_request_prompt v] formats v *) val pp_request_setup_session : Format.formatter -> request_setup_session -> unit (** [pp_request_setup_session v] formats v *) @@ -444,8 +444,8 @@ val pp_request : Format.formatter -> request -> unit 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_errnum : Format.formatter -> errnum -> unit +(** [pp_errnum v] formats v *) val pp_response : Format.formatter -> response -> unit (** [pp_response v] formats v *) @@ -459,8 +459,8 @@ val encode_pb_request_config_format : request_config_format -> Pbrt.Encoder.t -> 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_prompt : request_prompt -> Pbrt.Encoder.t -> unit +(** [encode_pb_request_prompt 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] *) @@ -537,8 +537,8 @@ val encode_pb_request : request -> Pbrt.Encoder.t -> unit 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_errnum : errnum -> Pbrt.Encoder.t -> unit +(** [encode_pb_errnum 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] *) @@ -552,8 +552,8 @@ val decode_pb_request_config_format : Pbrt.Decoder.t -> request_config_format 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_prompt : Pbrt.Decoder.t -> request_prompt +(** [decode_pb_request_prompt decoder] decodes a [request_prompt] 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] *) @@ -630,8 +630,8 @@ val decode_pb_request : Pbrt.Decoder.t -> request 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_errnum : Pbrt.Decoder.t -> errnum +(** [decode_pb_errnum decoder] decodes a [errnum] 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/vyconfd.ml b/src/vyconfd.ml index fc47bf6..a5117b6 100644 --- a/src/vyconfd.ml +++ b/src/vyconfd.ml @@ -236,7 +236,7 @@ let rec handle_connection world ic oc () = | _ as req -> begin (match req with - | _, Status -> response_tmpl + | _, Prompt -> response_tmpl | _, Setup_session r -> setup_session world r | _, Reload_reftree r -> reload_reftree world r | None, _ -> {response_tmpl with status=Fail; output=(Some "Operation requires session token")} -- cgit v1.2.3