···197197 write_type_and_argument t 5 (Int64.of_int len) ;
198198 ordered_map_keys m
199199 |> List.iter (fun k ->
200200- write_string t k ;
201201- write_value t (String_map.find k m) )
200200+ write_string t k ;
201201+ write_value t (String_map.find k m) )
202202 | `Link cid ->
203203 write_cid t cid
204204
···239239 | None, [] ->
240240 Lwt.return 0
241241 | Some left, [] -> (
242242- match%lwt retrieve_node_raw t left with
243243- | Some node ->
244244- let%lwt height = get_node_height t node in
245245- Lwt.return (height + 1)
246246- | None ->
247247- failwith ("couldn't find node " ^ Cid.to_string left) )
242242+ match%lwt retrieve_node_raw t left with
243243+ | Some node ->
244244+ let%lwt height = get_node_height t node in
245245+ Lwt.return (height + 1)
246246+ | None ->
247247+ failwith ("couldn't find node " ^ Cid.to_string left) )
248248 | _, leaf :: _ -> (
249249 match leaf.p with
250250 | 0 ->
···497497 let%lwt blocks =
498498 match Util.at_index index seq with
499499 | Some (Leaf (k, v, _)) when k = key -> (
500500- (* include the found leaf block to prove existence *)
501501- match%lwt Store.get_bytes t.blockstore v with
502502- | Some leaf_bytes ->
503503- Lwt.return (Block_map.set v leaf_bytes Block_map.empty)
504504- | None ->
505505- Lwt.return Block_map.empty )
500500+ (* include the found leaf block to prove existence *)
501501+ match%lwt
502502+ Store.get_bytes t.blockstore v
503503+ with
504504+ | Some leaf_bytes ->
505505+ Lwt.return (Block_map.set v leaf_bytes Block_map.empty)
506506+ | None ->
507507+ Lwt.return Block_map.empty )
506508 | _ -> (
507509 let prev =
508510 if index - 1 >= 0 then Util.at_index (index - 1) seq else None
···529531 let%lwt bm =
530532 match left_leaf with
531533 | Some cid_left -> (
532532- match%lwt Store.get_bytes t.blockstore cid_left with
533533- | Some b ->
534534- Lwt.return
535535- (Block_map.set cid_left b Block_map.empty)
536536- | None ->
537537- Lwt.return Block_map.empty )
534534+ match%lwt Store.get_bytes t.blockstore cid_left with
535535+ | Some b ->
536536+ Lwt.return (Block_map.set cid_left b Block_map.empty)
537537+ | None ->
538538+ Lwt.return Block_map.empty )
538539 | None ->
539540 Lwt.return Block_map.empty
540541 in
541542 let%lwt bm =
542543 match right_leaf with
543544 | Some cid_right -> (
544544- match%lwt Store.get_bytes t.blockstore cid_right with
545545- | Some b ->
546546- Lwt.return (Block_map.set cid_right b bm)
547547- | None ->
548548- Lwt.return bm )
545545+ match%lwt Store.get_bytes t.blockstore cid_right with
546546+ | Some b ->
547547+ Lwt.return (Block_map.set cid_right b bm)
548548+ | None ->
549549+ Lwt.return bm )
549550 | None ->
550551 Lwt.return bm
551552 in
···571572 | Some (Tree c) ->
572573 proof_for_left_sibling t c key
573574 | Some (Leaf (_, v_left, _)) -> (
574574- match%lwt Store.get_bytes t.blockstore v_left with
575575- | Some b ->
576576- Lwt.return (Block_map.set v_left b Block_map.empty)
577577- | None ->
578578- Lwt.return Block_map.empty )
575575+ match%lwt Store.get_bytes t.blockstore v_left with
576576+ | Some b ->
577577+ Lwt.return (Block_map.set v_left b Block_map.empty)
578578+ | None ->
579579+ Lwt.return Block_map.empty )
579580 | _ ->
580581 Lwt.return Block_map.empty
581582 in
···612613 | Some (Tree c) ->
613614 proof_for_right_sibling t c key
614615 | Some (Leaf (_, v_right, _)) -> (
615615- match%lwt Store.get_bytes t.blockstore v_right with
616616- | Some b ->
617617- Lwt.return (Block_map.set v_right b Block_map.empty)
618618- | None ->
619619- Lwt.return Block_map.empty )
616616+ match%lwt Store.get_bytes t.blockstore v_right with
617617+ | Some b ->
618618+ Lwt.return (Block_map.set v_right b Block_map.empty)
619619+ | None ->
620620+ Lwt.return Block_map.empty )
620621 | _ ->
621622 Lwt.return Block_map.empty )
622623 | None ->
+7-7
mist/test/test_util.ml
···88 Hashtbl.add cases "app.bsky.feed.post/9adeb165882c" 8 ;
99 cases
1010 |> Hashtbl.iter (fun key value ->
1111- Alcotest.(check int)
1212- ("leading zeros on hash " ^ key)
1313- value
1414- (leading_zeros_on_hash key) )
1111+ Alcotest.(check int)
1212+ ("leading zeros on hash " ^ key)
1313+ value
1414+ (leading_zeros_on_hash key) )
15151616let test_shared_prefix_length () =
1717 let cases = Hashtbl.create 5 in
···2222 Hashtbl.add cases ("2653ae71", "0653ae71") 0 ;
2323 cases
2424 |> Hashtbl.iter (fun (a, b) value ->
2525- Alcotest.(check int)
2626- ("prefix length between " ^ a ^ " and " ^ b)
2727- value (shared_prefix_length a b) )
2525+ Alcotest.(check int)
2626+ ("prefix length between " ^ a ^ " and " ^ b)
2727+ value (shared_prefix_length a b) )
28282929let () =
3030 Alcotest.run "util"
+6-6
pegasus/lib/api/identity/resolveHandle.ml
···1414 Dream.json @@ Yojson.Safe.to_string
1515 @@ response_to_yojson {did= actor.did}
1616 | None -> (
1717- match%lwt Id_resolver.Handle.resolve handle with
1818- | Ok did ->
1919- Dream.json @@ Yojson.Safe.to_string @@ response_to_yojson {did}
2020- | Error e ->
2121- Errors.log_exn (Failure e) ;
2222- Errors.internal_error ~msg:"could not resolve handle" () ) )
1717+ match%lwt Id_resolver.Handle.resolve handle with
1818+ | Ok did ->
1919+ Dream.json @@ Yojson.Safe.to_string @@ response_to_yojson {did}
2020+ | Error e ->
2121+ Errors.log_exn (Failure e) ;
2222+ Errors.internal_error ~msg:"could not resolve handle" () ) )
+54-57
pegasus/lib/api/identity/updateHandle.ml
···1515 | Error e ->
1616 raise e
1717 | Ok () -> (
1818- match%lwt Data_store.get_actor_by_identifier handle db with
1919- | Some _ ->
2020- Errors.invalid_request ~name:"InvalidHandle"
2121- "handle already in use"
2222- | None ->
2323- let%lwt () = Data_store.update_actor_handle ~did ~handle db in
2424- let%lwt _ =
2525- if String.starts_with ~prefix:"did:plc:" did then
2626- match%lwt Plc.get_audit_log did with
2727- | Error e ->
2828- Dream.error (fun log -> log ~request:req "%s" e) ;
2929- Errors.internal_error ~msg:"failed to fetch did doc" ()
3030- | Ok log -> (
3131- let latest = List.rev log |> List.hd in
3232- let aka =
3333- match
3434- List.mem ("at://" ^ handle)
3535- latest.operation.also_known_as
3636- with
3737- | true ->
3838- latest.operation.also_known_as
3939- | false ->
4040- ("at://" ^ handle) :: latest.operation.also_known_as
4141- in
4242- let%lwt signing_key =
4343- match%lwt Data_store.get_actor_by_identifier did db with
4444- | Some {signing_key; _} ->
4545- Lwt.return @@ Kleidos.parse_multikey_str signing_key
4646- | _ ->
4747- Errors.internal_error ()
4848- in
4949- let signed =
5050- Plc.sign_operation signing_key
5151- (Operation
5252- { type'= "plc_operation"
5353- ; prev= Some latest.cid
5454- ; also_known_as= aka
5555- ; rotation_keys= latest.operation.rotation_keys
5656- ; verification_methods=
5757- latest.operation.verification_methods
5858- ; services= latest.operation.services } )
5959- in
6060- match%lwt Plc.submit_operation did signed with
6161- | Ok _ ->
6262- Lwt.return_unit
6363- | Error (status, msg) ->
6464- Dream.error (fun log ->
6565- log ~request:req "%d %s" status msg ) ;
6666- Errors.internal_error
6767- ~msg:"failed to submit plc operation" () )
6868- else Lwt.return_unit
6969- in
7070- let () =
7171- Ttl_cache.String_cache.remove Id_resolver.Did.cache did
7272- in
7373- let%lwt _ = Sequencer.sequence_identity db ~did ~handle () in
7474- Dream.empty `OK ) )
1818+ match%lwt Data_store.get_actor_by_identifier handle db with
1919+ | Some _ ->
2020+ Errors.invalid_request ~name:"InvalidHandle" "handle already in use"
2121+ | None ->
2222+ let%lwt () = Data_store.update_actor_handle ~did ~handle db in
2323+ let%lwt _ =
2424+ if String.starts_with ~prefix:"did:plc:" did then
2525+ match%lwt Plc.get_audit_log did with
2626+ | Error e ->
2727+ Dream.error (fun log -> log ~request:req "%s" e) ;
2828+ Errors.internal_error ~msg:"failed to fetch did doc" ()
2929+ | Ok log -> (
3030+ let latest = List.rev log |> List.hd in
3131+ let aka =
3232+ match
3333+ List.mem ("at://" ^ handle)
3434+ latest.operation.also_known_as
3535+ with
3636+ | true ->
3737+ latest.operation.also_known_as
3838+ | false ->
3939+ ("at://" ^ handle) :: latest.operation.also_known_as
4040+ in
4141+ let%lwt signing_key =
4242+ match%lwt Data_store.get_actor_by_identifier did db with
4343+ | Some {signing_key; _} ->
4444+ Lwt.return @@ Kleidos.parse_multikey_str signing_key
4545+ | _ ->
4646+ Errors.internal_error ()
4747+ in
4848+ let signed =
4949+ Plc.sign_operation signing_key
5050+ (Operation
5151+ { type'= "plc_operation"
5252+ ; prev= Some latest.cid
5353+ ; also_known_as= aka
5454+ ; rotation_keys= latest.operation.rotation_keys
5555+ ; verification_methods=
5656+ latest.operation.verification_methods
5757+ ; services= latest.operation.services } )
5858+ in
5959+ match%lwt Plc.submit_operation did signed with
6060+ | Ok _ ->
6161+ Lwt.return_unit
6262+ | Error (status, msg) ->
6363+ Dream.error (fun log ->
6464+ log ~request:req "%d %s" status msg ) ;
6565+ Errors.internal_error
6666+ ~msg:"failed to submit plc operation" () )
6767+ else Lwt.return_unit
6868+ in
6969+ let () = Ttl_cache.String_cache.remove Id_resolver.Did.cache did in
7070+ let%lwt _ = Sequencer.sequence_identity db ~did ~handle () in
7171+ Dream.empty `OK ) )
+87-87
pegasus/lib/api/oauth_/authorize.ml
···3737 Yojson.Safe.from_string req_record.request_data
3838 |> par_request_of_yojson
3939 |> Result.map_error (fun _ ->
4040- Errors.internal_error
4141- ~msg:"failed to parse par request" () )
4040+ Errors.internal_error ~msg:"failed to parse par request"
4141+ () )
4242 |> Result.get_ok
4343 in
4444 let%lwt _client =
···103103 | None ->
104104 Errors.auth_required "missing authentication"
105105 | Some user_did -> (
106106- match%lwt Dream.form ctx.req with
107107- | `Ok fields -> (
108108- let action = List.assoc_opt "action" fields in
109109- let code = List.assoc_opt "code" fields in
110110- let request_uri = List.assoc_opt "request_uri" fields in
111111- match (action, code, request_uri) with
112112- | Some "deny", _, Some request_uri -> (
113113- let prefix = Constants.request_uri_prefix in
114114- let request_id =
115115- String.sub request_uri (String.length prefix)
116116- (String.length request_uri - String.length prefix)
117117- in
118118- let%lwt req_record =
119119- Queries.get_par_request ctx.db request_id
120120- in
121121- match req_record with
122122- | Some rec_ ->
123123- let req =
124124- Yojson.Safe.from_string rec_.request_data
125125- |> par_request_of_yojson |> Result.get_ok
106106+ match%lwt Dream.form ctx.req with
107107+ | `Ok fields -> (
108108+ let action = List.assoc_opt "action" fields in
109109+ let code = List.assoc_opt "code" fields in
110110+ let request_uri = List.assoc_opt "request_uri" fields in
111111+ match (action, code, request_uri) with
112112+ | Some "deny", _, Some request_uri -> (
113113+ let prefix = Constants.request_uri_prefix in
114114+ let request_id =
115115+ String.sub request_uri (String.length prefix)
116116+ (String.length request_uri - String.length prefix)
117117+ in
118118+ let%lwt req_record =
119119+ Queries.get_par_request ctx.db request_id
120120+ in
121121+ match req_record with
122122+ | Some rec_ ->
123123+ let req =
124124+ Yojson.Safe.from_string rec_.request_data
125125+ |> par_request_of_yojson |> Result.get_ok
126126+ in
127127+ let params =
128128+ [ ("error", "access_denied")
129129+ ; ("error_description", "Unable to authorize user.")
130130+ ; ("state", req.state)
131131+ ; ("iss", "https://" ^ Env.hostname) ]
132132+ in
133133+ let query =
134134+ String.concat "&"
135135+ (List.map
136136+ (fun (k, v) -> k ^ "=" ^ Uri.pct_encode v)
137137+ params )
138138+ in
139139+ Dream.redirect ctx.req (req.redirect_uri ^ "?" ^ query)
140140+ | None ->
141141+ Errors.invalid_request "request expired" )
142142+ | Some "allow", Some code, Some _request_uri -> (
143143+ let%lwt code_record = Queries.get_auth_code ctx.db code in
144144+ match code_record with
145145+ | None ->
146146+ Errors.invalid_request "invalid code"
147147+ | Some code_rec -> (
148148+ if code_rec.authorized_by <> None then
149149+ Errors.invalid_request "code already authorized"
150150+ else if code_rec.used then
151151+ Errors.invalid_request "code already used"
152152+ else if Util.now_ms () > code_rec.expires_at then
153153+ Errors.invalid_request "code expired"
154154+ else
155155+ let%lwt () =
156156+ Queries.activate_auth_code ctx.db code user_did
126157 in
127127- let params =
128128- [ ("error", "access_denied")
129129- ; ("error_description", "Unable to authorize user.")
130130- ; ("state", req.state)
131131- ; ("iss", "https://" ^ Env.hostname) ]
132132- in
133133- let query =
134134- String.concat "&"
135135- (List.map
136136- (fun (k, v) -> k ^ "=" ^ Uri.pct_encode v)
137137- params )
158158+ let%lwt req_record =
159159+ Queries.get_par_request ctx.db code_rec.request_id
138160 in
139139- Dream.redirect ctx.req (req.redirect_uri ^ "?" ^ query)
140140- | None ->
141141- Errors.invalid_request "request expired" )
142142- | Some "allow", Some code, Some _request_uri -> (
143143- let%lwt code_record = Queries.get_auth_code ctx.db code in
144144- match code_record with
145145- | None ->
146146- Errors.invalid_request "invalid code"
147147- | Some code_rec -> (
148148- if code_rec.authorized_by <> None then
149149- Errors.invalid_request "code already authorized"
150150- else if code_rec.used then
151151- Errors.invalid_request "code already used"
152152- else if Util.now_ms () > code_rec.expires_at then
153153- Errors.invalid_request "code expired"
154154- else
155155- let%lwt () =
156156- Queries.activate_auth_code ctx.db code user_did
157157- in
158158- let%lwt req_record =
159159- Queries.get_par_request ctx.db code_rec.request_id
160160- in
161161- match req_record with
162162- | None ->
163163- Errors.internal_error ~msg:"request not found" ()
164164- | Some rec_ ->
165165- let req =
166166- Yojson.Safe.from_string rec_.request_data
167167- |> par_request_of_yojson |> Result.get_ok
168168- in
169169- let params =
170170- [ ("code", code)
171171- ; ("state", req.state)
172172- ; ("iss", "https://" ^ Env.hostname) ]
173173- in
174174- let query =
175175- String.concat "&"
176176- (List.map
177177- (fun (k, v) -> k ^ "=" ^ Uri.pct_encode v)
178178- params )
179179- in
180180- let separator =
181181- match req.response_mode with
182182- | Some "fragment" ->
183183- "#"
184184- | _ ->
185185- "?"
186186- in
187187- Dream.redirect ctx.req
188188- (req.redirect_uri ^ separator ^ query) ) )
189189- | _ ->
190190- Errors.invalid_request "invalid request" )
191191- | _ ->
192192- Errors.invalid_request "invalid request" ) )
161161+ match req_record with
162162+ | None ->
163163+ Errors.internal_error ~msg:"request not found" ()
164164+ | Some rec_ ->
165165+ let req =
166166+ Yojson.Safe.from_string rec_.request_data
167167+ |> par_request_of_yojson |> Result.get_ok
168168+ in
169169+ let params =
170170+ [ ("code", code)
171171+ ; ("state", req.state)
172172+ ; ("iss", "https://" ^ Env.hostname) ]
173173+ in
174174+ let query =
175175+ String.concat "&"
176176+ (List.map
177177+ (fun (k, v) -> k ^ "=" ^ Uri.pct_encode v)
178178+ params )
179179+ in
180180+ let separator =
181181+ match req.response_mode with
182182+ | Some "fragment" ->
183183+ "#"
184184+ | _ ->
185185+ "?"
186186+ in
187187+ Dream.redirect ctx.req
188188+ (req.redirect_uri ^ separator ^ query) ) )
189189+ | _ ->
190190+ Errors.invalid_request "invalid request" )
191191+ | _ ->
192192+ Errors.invalid_request "invalid request" ) )
+10-10
pegasus/lib/api/repo/createAccount.ml
···5757 let%lwt did =
5858 match input.did with
5959 | Some did -> (
6060- match%lwt Data_store.get_actor_by_identifier did ctx.db with
6161- | Some _ ->
6262- Errors.invalid_request "an account with that did already exists"
6363- | None ->
6464- Lwt.return did )
6060+ match%lwt Data_store.get_actor_by_identifier did ctx.db with
6161+ | Some _ ->
6262+ Errors.invalid_request "an account with that did already exists"
6363+ | None ->
6464+ Lwt.return did )
6565 | None -> (
6666 let sk_did = Kleidos.K256.pubkey_to_did_key signing_pubkey in
6767 let rotation_did_keys =
···7979 let%lwt _ =
8080 match input.invite_code with
8181 | Some code -> (
8282- match%lwt Data_store.use_invite ~code ctx.db with
8383- | Some _ ->
8484- Lwt.return ()
8585- | None ->
8686- failwith "failed to use invite code" )
8282+ match%lwt Data_store.use_invite ~code ctx.db with
8383+ | Some _ ->
8484+ Lwt.return ()
8585+ | None ->
8686+ failwith "failed to use invite code" )
8787 | None ->
8888 Lwt.return ()
8989 in
+24-24
pegasus/lib/auth.ml
···151151 fun {req; db} ->
152152 match parse_bearer req with
153153 | Ok jwt -> (
154154- match%lwt verify_bearer_jwt db jwt "com.atproto.access" with
155155- | Ok {sub= did; _} -> (
156156- match%lwt Data_store.get_actor_by_identifier did db with
157157- | Some {deactivated_at= None; _} ->
158158- Lwt.return_ok (Access {did})
159159- | Some {deactivated_at= Some _; _} ->
160160- Lwt.return_error
161161- @@ Errors.auth_required ~name:"AccountDeactivated"
162162- "account is deactivated"
163163- | None ->
164164- Lwt.return_error @@ Errors.auth_required "invalid credentials" )
165165- | Error _ ->
154154+ match%lwt verify_bearer_jwt db jwt "com.atproto.access" with
155155+ | Ok {sub= did; _} -> (
156156+ match%lwt Data_store.get_actor_by_identifier did db with
157157+ | Some {deactivated_at= None; _} ->
158158+ Lwt.return_ok (Access {did})
159159+ | Some {deactivated_at= Some _; _} ->
160160+ Lwt.return_error
161161+ @@ Errors.auth_required ~name:"AccountDeactivated"
162162+ "account is deactivated"
163163+ | None ->
166164 Lwt.return_error @@ Errors.auth_required "invalid credentials" )
165165+ | Error _ ->
166166+ Lwt.return_error @@ Errors.auth_required "invalid credentials" )
167167 | Error _ ->
168168 Lwt.return_error @@ Errors.auth_required "invalid authorization header"
169169···220220 fun {req; db} ->
221221 match parse_bearer req with
222222 | Ok jwt -> (
223223- match%lwt verify_bearer_jwt db jwt "com.atproto.refresh" with
224224- | Ok {sub= did; jti; _} -> (
225225- match%lwt Data_store.get_actor_by_identifier did db with
226226- | Some {deactivated_at= None; _} ->
227227- Lwt.return_ok (Refresh {did; jti})
228228- | Some {deactivated_at= Some _; _} ->
229229- Lwt.return_error
230230- @@ Errors.auth_required ~name:"AccountDeactivated"
231231- "account is deactivated"
232232- | None ->
233233- Lwt.return_error @@ Errors.auth_required "invalid credentials" )
234234- | Error "" | Error _ ->
223223+ match%lwt verify_bearer_jwt db jwt "com.atproto.refresh" with
224224+ | Ok {sub= did; jti; _} -> (
225225+ match%lwt Data_store.get_actor_by_identifier did db with
226226+ | Some {deactivated_at= None; _} ->
227227+ Lwt.return_ok (Refresh {did; jti})
228228+ | Some {deactivated_at= Some _; _} ->
229229+ Lwt.return_error
230230+ @@ Errors.auth_required ~name:"AccountDeactivated"
231231+ "account is deactivated"
232232+ | None ->
235233 Lwt.return_error @@ Errors.auth_required "invalid credentials" )
234234+ | Error "" | Error _ ->
235235+ Lwt.return_error @@ Errors.auth_required "invalid credentials" )
236236 | Error _ ->
237237 Lwt.return_error @@ Errors.auth_required "invalid authorization header"
238238
+11-11
pegasus/lib/repository.ml
···180180 let%lwt map = get_map t in
181181 String_map.bindings map
182182 |> List.filter (fun (path, _) ->
183183- String.starts_with ~prefix:(path ^ "/") collection )
183183+ String.starts_with ~prefix:(path ^ "/") collection )
184184 |> Lwt_list.fold_left_s
185185 (fun acc (path, cid) ->
186186 match%lwt User_store.get_record t.db path with
···320320 let%lwt () =
321321 match old_cid with
322322 | Some _ -> (
323323- match%lwt User_store.get_record t.db path with
324324- | Some record ->
325325- let refs =
326326- Util.find_blob_refs record.value
327327- |> List.map (fun (r : Mist.Blob_ref.t) -> r.ref)
328328- in
329329- let%lwt () = User_store.clear_blob_refs t.db path refs in
330330- Lwt.return_unit
331331- | None ->
332332- Lwt.return_unit )
323323+ match%lwt User_store.get_record t.db path with
324324+ | Some record ->
325325+ let refs =
326326+ Util.find_blob_refs record.value
327327+ |> List.map (fun (r : Mist.Blob_ref.t) -> r.ref)
328328+ in
329329+ let%lwt () = User_store.clear_blob_refs t.db path refs in
330330+ Lwt.return_unit
331331+ | None ->
332332+ Lwt.return_unit )
333333 | None ->
334334 Lwt.return_unit
335335 in
+28-28
pegasus/lib/sequencer.ml
···330330 let blobs =
331331 j |> member "blobs" |> to_list
332332 |> List.filter_map (fun x ->
333333- match Cid.of_yojson x with Ok c -> Some c | _ -> None )
333333+ match Cid.of_yojson x with Ok c -> Some c | _ -> None )
334334 in
335335 let prev_data =
336336 match j |> member "prevData" with
···342342 let ops =
343343 j |> member "ops" |> to_list
344344 |> List.map (fun opj ->
345345- let action =
346346- match opj |> member "action" |> to_string with
347347- | "create" ->
348348- `Create
349349- | "update" ->
350350- `Update
351351- | "delete" ->
352352- `Delete
353353- | _ ->
354354- `Create
355355- in
356356- let path = opj |> member "path" |> to_string in
357357- let cid =
358358- match opj |> member "cid" with
359359- | `Null ->
360360- None
361361- | v -> (
362362- match Cid.of_yojson v with Ok c -> Some c | _ -> None )
363363- in
364364- let prev =
365365- match opj |> member "prev" with
366366- | `Null ->
367367- None
368368- | v -> (
369369- match Cid.of_yojson v with Ok c -> Some c | _ -> None )
370370- in
371371- {action; path; cid; prev} )
345345+ let action =
346346+ match opj |> member "action" |> to_string with
347347+ | "create" ->
348348+ `Create
349349+ | "update" ->
350350+ `Update
351351+ | "delete" ->
352352+ `Delete
353353+ | _ ->
354354+ `Create
355355+ in
356356+ let path = opj |> member "path" |> to_string in
357357+ let cid =
358358+ match opj |> member "cid" with
359359+ | `Null ->
360360+ None
361361+ | v -> (
362362+ match Cid.of_yojson v with Ok c -> Some c | _ -> None )
363363+ in
364364+ let prev =
365365+ match opj |> member "prev" with
366366+ | `Null ->
367367+ None
368368+ | v -> (
369369+ match Cid.of_yojson v with Ok c -> Some c | _ -> None )
370370+ in
371371+ {action; path; cid; prev} )
372372 in
373373 Ok
374374 { rebase
+2-2
pegasus/lib/user_store.ml
···386386let get_record t path : record option Lwt.t =
387387 Util.use_pool t.db @@ Queries.get_record ~path
388388 >|= Option.map (fun (cid, data, since) ->
389389- {path; cid; value= Lex.of_cbor data; since} )
389389+ {path; cid; value= Lex.of_cbor data; since} )
390390391391let list_records t ?(limit = 100) ?(cursor = "") ?(reverse = false) collection :
392392 record list Lwt.t =
···395395 in
396396 Util.use_pool t.db @@ fn ~collection ~limit ~cursor
397397 >|= List.map (fun (path, cid, data, since) ->
398398- {path; cid; value= Lex.of_cbor data; since} )
398398+ {path; cid; value= Lex.of_cbor data; since} )
399399400400let put_record t record path : (Cid.t * bytes) Lwt.t =
401401 let cid, data = Lex.to_cbor_block record in
+15-17
pegasus/lib/util.ml
···287287let is_none = function None -> true | _ -> false
288288289289let validate_handle handle =
290290- let front =
291291- String.sub handle 0
292292- (String.length handle - (String.length Env.hostname + 1))
293293- in
294294- if String.contains front '.' then
295295- Error
296296- (Errors.InvalidRequestError
297297- ("InvalidHandle", "invalid characters in handle") )
298298- else
299299- match String.length front with
300300- | l when l < 3 ->
301301- Error
302302- (Errors.InvalidRequestError ("InvalidHandle", "handle too short"))
303303- | l when l > 18 ->
304304- Error (Errors.InvalidRequestError ("InvalidHandle", "handle too long"))
305305- | _ ->
306306- Ok ()
290290+ let front =
291291+ String.sub handle 0 (String.length handle - (String.length Env.hostname + 1))
292292+ in
293293+ if String.contains front '.' then
294294+ Error
295295+ (Errors.InvalidRequestError
296296+ ("InvalidHandle", "invalid characters in handle") )
297297+ else
298298+ match String.length front with
299299+ | l when l < 3 ->
300300+ Error (Errors.InvalidRequestError ("InvalidHandle", "handle too short"))
301301+ | l when l > 18 ->
302302+ Error (Errors.InvalidRequestError ("InvalidHandle", "handle too long"))
303303+ | _ ->
304304+ Ok ()
307305308306let mkfile_p path ~perm =
309307 Core_unix.mkdir_p (Filename.dirname path) ~perm:0o755 ;
+8-8
pegasus/lib/xrpc.ml
···1212 let auth = Auth.Verifiers.of_t auth in
1313 match%lwt auth init with
1414 | Ok creds -> (
1515- try%lwt hdlr {req= init.req; db= init.db; auth= creds}
1616- with e ->
1717- ( match is_xrpc_error e with
1818- | true ->
1919- ()
2020- | false ->
2121- log_exn ~req:init.req e ) ;
2222- exn_to_response e )
1515+ try%lwt hdlr {req= init.req; db= init.db; auth= creds}
1616+ with e ->
1717+ ( match is_xrpc_error e with
1818+ | true ->
1919+ ()
2020+ | false ->
2121+ log_exn ~req:init.req e ) ;
2222+ exn_to_response e )
2323 | Error e ->
2424 exn_to_response e
2525