aboutsummaryrefslogtreecommitdiff
path: root/lib/user.ml
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2023-12-20 20:43:25 -0600
committerMarc Coquand <marc@mccd.space>2023-12-20 20:43:25 -0600
commitcc783c157f31e7e713c8b83be67449b1859dac27 (patch)
tree52559c115159671839f4b497b9191222faa35520 /lib/user.ml
downloadfixgen-cc783c157f31e7e713c8b83be67449b1859dac27.tar.gz
fixgen-cc783c157f31e7e713c8b83be67449b1859dac27.tar.bz2
fixgen-cc783c157f31e7e713c8b83be67449b1859dac27.zip
Initial commit
Diffstat (limited to 'lib/user.ml')
-rw-r--r--lib/user.ml31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/user.ml b/lib/user.ml
new file mode 100644
index 0000000..ba802c0
--- /dev/null
+++ b/lib/user.ml
@@ -0,0 +1,31 @@
+open Ppx_yojson_conv_lib.Yojson_conv.Primitives
+open Cohttp
+open Cohttp_lwt_unix
+open Lwt
+
+type public_key = {
+ id : string;
+ owner : string;
+ public_key_pem : string; [@key "publicKeyPem"]
+}
+[@@deriving yojson] [@@yojson.allow_extra_fields]
+
+type t = { name : string; public_key : public_key [@key "publicKey"] }
+[@@deriving yojson] [@@yojson.allow_extra_fields]
+
+let activity_header =
+ Some (Header.of_list [ ("Accept", "application/activity+json") ])
+
+let get_user actor_url =
+ let%lwt _, body =
+ Client.get ?headers:activity_header (Uri.of_string actor_url)
+ in
+ body |> Cohttp_lwt.Body.to_string >|= fun body ->
+ let body = Yojson.Safe.from_string body |> t_of_yojson in
+ body
+
+let get_public_pem user =
+ user.public_key.public_key_pem |> Cstruct.of_string
+ |> X509.Public_key.decode_pem
+
+let name user = user.name