package guardian

  1. Overview
  2. Docs
Role-based access control for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

0.0.4.tar.gz
md5=45ecb4358a2405a3b4cc263f25ad995c
sha512=d070bd79c14123f720bd0c14291ee520bda3bfac5d6ceb58ceb85185c9be4cebbc5c99894ce29b62bf9e2ed4291ae094506d4d176c12945e99ed9d0283f55db8

doc/src/guardian/role_set.ml.html

Source file role_set.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module type S = sig
  include Set.S

  val to_yojson : t -> Yojson.Safe.t
  val of_yojson : Yojson.Safe.t -> (t, string) CCResult.t
  val pp : Format.formatter -> t -> unit
end

module Make (R : Role.Sig) : S with type elt = R.t = struct
  include Set.Make (R)

  let to_yojson t = `List (CCList.map R.to_yojson (elements t))

  let of_yojson =
    let open CCResult in
    function
    | `List items ->
      CCList.fold_left
        (fun acc x ->
          acc >>= fun acc' -> x |> R.of_yojson >|= CCFun.flip add acc')
        (Ok empty)
        items
    | _ -> Error "Invalid role set"
  ;;

  let pp fmt t =
    let show = [%show: R.t list] in
    Format.fprintf fmt "[%s]" (show (elements t))
  ;;
end
OCaml

Innovation. Community. Security.