mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
Merge pull request #2070 from samoht/sdk-api-fix-build
sdk: add missing files
This commit is contained in:
commit
75c7bcb027
1
projects/miragesdk/src/sdk/api.ml
Normal file
1
projects/miragesdk/src/sdk/api.ml
Normal file
@ -0,0 +1 @@
|
||||
include Proto.MakeRPC(Capnp.BytesMessage)(Capnp_rpc_lwt)
|
@ -43,7 +43,7 @@ let errorf fmt =
|
||||
|
||||
module Client = struct
|
||||
|
||||
module C = Ctl_api.Reader.Ctl
|
||||
module C = Api.Reader.Ctl
|
||||
|
||||
type error = [`Msg of string]
|
||||
let pp_error ppf (`Msg s) = Fmt.string ppf s
|
||||
@ -51,8 +51,8 @@ module Client = struct
|
||||
type t = C.t Capability.t
|
||||
|
||||
let read t path =
|
||||
let module P = Ctl_api.Builder.Ctl.Read_params in
|
||||
let module R = Ctl_api.Reader.Response in
|
||||
let module P = Api.Builder.Ctl.Read_params in
|
||||
let module R = Api.Reader.Response in
|
||||
let req, p = Capability.Request.create P.init_pointer in
|
||||
P.path_set_list p path |> ignore;
|
||||
Capability.call_for_value t C.read_method req >|= function
|
||||
@ -65,7 +65,7 @@ module Client = struct
|
||||
| R.Undefined _ -> Error (`Msg "invalid return")
|
||||
|
||||
let write t path data =
|
||||
let module P = Ctl_api.Builder.Ctl.Write_params in
|
||||
let module P = Api.Builder.Ctl.Write_params in
|
||||
let req, p = Capability.Request.create P.init_pointer in
|
||||
P.path_set_list p path |> ignore;
|
||||
P.data_set p data;
|
||||
@ -74,7 +74,7 @@ module Client = struct
|
||||
| Error e -> errorf "error: write(%a) -> %a" pp_path path Capnp_rpc.Error.pp e
|
||||
|
||||
let delete t path =
|
||||
let module P = Ctl_api.Builder.Ctl.Delete_params in
|
||||
let module P = Api.Builder.Ctl.Delete_params in
|
||||
let req, p = Capability.Request.create P.init_pointer in
|
||||
P.path_set_list p path |> ignore;
|
||||
Capability.call_for_value t C.delete_method req >|= function
|
||||
@ -87,6 +87,8 @@ module Server = struct
|
||||
|
||||
type op = [ `Read | `Write | `Delete ]
|
||||
|
||||
type t = Api.Reader.Ctl.t Capability.t
|
||||
|
||||
let infof fmt =
|
||||
Fmt.kstrf (fun msg () ->
|
||||
let date = Int64.of_float (Unix.gettimeofday ()) in
|
||||
@ -113,11 +115,11 @@ module Server = struct
|
||||
| exception Not_found -> Service.fail "%s" (not_allowed key)
|
||||
|
||||
let service ~routes db =
|
||||
Ctl_api.Builder.Ctl.local @@
|
||||
object (_ : Ctl_api.Builder.Ctl.service)
|
||||
Api.Builder.Ctl.local @@
|
||||
object (_ : Api.Builder.Ctl.service)
|
||||
method read req =
|
||||
let module P = Ctl_api.Reader.Ctl.Read_params in
|
||||
let module R = Ctl_api.Builder.Response in
|
||||
let module P = Api.Reader.Ctl.Read_params in
|
||||
let module R = Api.Builder.Response in
|
||||
let params = P.of_payload req in
|
||||
let key = P.path_get_list params in
|
||||
with_permission_check ~routes `Read key @@ fun () ->
|
||||
@ -131,7 +133,7 @@ module Server = struct
|
||||
)
|
||||
|
||||
method write req =
|
||||
let module P = Ctl_api.Reader.Ctl.Write_params in
|
||||
let module P = Api.Reader.Ctl.Write_params in
|
||||
let params = P.of_payload req in
|
||||
let key = P.path_get_list params in
|
||||
let value = P.data_get params in
|
||||
@ -142,7 +144,7 @@ module Server = struct
|
||||
)
|
||||
|
||||
method delete req =
|
||||
let module P = Ctl_api.Reader.Ctl.Delete_params in
|
||||
let module P = Api.Reader.Ctl.Delete_params in
|
||||
let params = P.of_payload req in
|
||||
let key = P.path_get_list params in
|
||||
with_permission_check ~routes `Delete key @@ fun () ->
|
||||
|
@ -13,7 +13,7 @@ module Client: sig
|
||||
TODO: decide if we want to support test_and_set (instead of
|
||||
write) and some kind of watches. *)
|
||||
|
||||
type t = Ctl_api.Reader.Ctl.t Capnp_rpc_lwt.Capability.t
|
||||
type t = Api.Reader.Ctl.t Capnp_rpc_lwt.Capability.t
|
||||
(** The type for client state. *)
|
||||
|
||||
type error
|
||||
@ -45,10 +45,13 @@ val v: string -> KV.t Lwt.t
|
||||
|
||||
module Server: sig
|
||||
|
||||
type t = Api.Reader.Ctl.t Capnp_rpc_lwt.Capability.t
|
||||
(** The type for server state. *)
|
||||
|
||||
type op = [ `Read | `Write | `Delete ]
|
||||
(** The type for operations to perform on routes. *)
|
||||
|
||||
val service: routes:(string list * op list) list -> KV.t -> Ctl_api.Reader.Ctl.t Capnp_rpc_lwt.Capability.t
|
||||
val service: routes:(string list * op list) list -> KV.t -> t
|
||||
(** [service ~routes kv] is the thread exposing the KV store [kv],
|
||||
holding control plane state, running inside the privileged
|
||||
container. [routes] are the routes exposed by the server to the
|
||||
|
Loading…
Reference in New Issue
Block a user