objective categorical abstract machine language personal data server
65
fork

Configure Feed

Select the types of activity you want to include in your feed.

Factor out repo->did resolution

futurGH f803bf88 6372383c

+28 -100
+1 -20
pegasus/lib/api/repo/applyWrites.ml
··· 14 14 let handler = 15 15 Xrpc.handler ~auth:Auth.Verifiers.authorization (fun ctx -> 16 16 let%lwt input = Xrpc.parse_body ctx.req request_of_yojson in 17 - let%lwt input_did = 18 - if String.starts_with ~prefix:"did:" input.repo then 19 - Lwt.return input.repo 20 - else 21 - match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with 22 - | Some {did; _} -> 23 - Lwt.return did 24 - | None -> 25 - Errors.invalid_request "target repository not found" 26 - in 27 - let did = 28 - match ctx.auth with 29 - | Access {did} when did = input_did -> 30 - did 31 - | Admin -> 32 - input_did 33 - | _ -> 34 - Errors.auth_required 35 - "authentication does not match target repository" 36 - in 17 + let%lwt did = Xrpc.resolve_repo_did_authed ctx input.repo in 37 18 let%lwt repo = Repository.load did in 38 19 let%lwt {commit= commit_cid, {rev; _}; results} = 39 20 Repository.apply_writes repo input.writes
+1 -20
pegasus/lib/api/repo/createRecord.ml
··· 20 20 let handler = 21 21 Xrpc.handler ~auth:Auth.Verifiers.authorization (fun ctx -> 22 22 let%lwt input = Xrpc.parse_body ctx.req request_of_yojson in 23 - let%lwt input_did = 24 - if String.starts_with ~prefix:"did:" input.repo then 25 - Lwt.return input.repo 26 - else 27 - match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with 28 - | Some {did; _} -> 29 - Lwt.return did 30 - | None -> 31 - Errors.invalid_request "target repository not found" 32 - in 33 - let did = 34 - match ctx.auth with 35 - | Access {did} when did = input_did -> 36 - did 37 - | Admin -> 38 - input_did 39 - | _ -> 40 - Errors.auth_required 41 - "authentication does not match target repository" 42 - in 23 + let%lwt did = Xrpc.resolve_repo_did_authed ctx input.repo in 43 24 let%lwt repo = Repository.load did in 44 25 let write : Repository.repo_write = 45 26 match input.swap_record with
+1 -20
pegasus/lib/api/repo/deleteRecord.ml
··· 13 13 let handler = 14 14 Xrpc.handler ~auth:Auth.Verifiers.authorization (fun ctx -> 15 15 let%lwt input = Xrpc.parse_body ctx.req request_of_yojson in 16 - let%lwt input_did = 17 - if String.starts_with ~prefix:"did:" input.repo then 18 - Lwt.return input.repo 19 - else 20 - match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with 21 - | Some {did; _} -> 22 - Lwt.return did 23 - | None -> 24 - Errors.invalid_request "target repository not found" 25 - in 26 - let did = 27 - match ctx.auth with 28 - | Access {did} when did = input_did -> 29 - did 30 - | Admin -> 31 - input_did 32 - | _ -> 33 - Errors.auth_required 34 - "authentication does not match target repository" 35 - in 16 + let%lwt did = Xrpc.resolve_repo_did_authed ctx input.repo in 36 17 let%lwt repo = Repository.load did in 37 18 let write : Repository.repo_write = 38 19 Delete
+1 -10
pegasus/lib/api/repo/getRecord.ml
··· 7 7 let handler = 8 8 Xrpc.handler (fun ctx -> 9 9 let input = Xrpc.parse_query ctx.req query_of_yojson in 10 - let%lwt input_did = 11 - if String.starts_with ~prefix:"did:" input.repo then 12 - Lwt.return input.repo 13 - else 14 - match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with 15 - | Some {did; _} -> 16 - Lwt.return did 17 - | None -> 18 - Errors.invalid_request "target repository not found" 19 - in 10 + let%lwt input_did = Xrpc.resolve_repo_did ctx input.repo in 20 11 let%lwt repo = Repository.load input_did in 21 12 let path = input.collection ^ "/" ^ input.rkey in 22 13 let uri = "at://" ^ input_did ^ "/" ^ path in
+1 -10
pegasus/lib/api/repo/listRecords.ml
··· 22 22 | _ -> 23 23 100 24 24 in 25 - let%lwt input_did = 26 - if String.starts_with ~prefix:"did:" input.repo then 27 - Lwt.return input.repo 28 - else 29 - match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with 30 - | Some {did; _} -> 31 - Lwt.return did 32 - | None -> 33 - Errors.invalid_request "target repository not found" 34 - in 25 + let%lwt input_did = Xrpc.resolve_repo_did ctx input.repo in 35 26 let%lwt db = User_store.connect input_did in 36 27 let%lwt results = 37 28 User_store.list_records db ~limit ?cursor:input.cursor
+1 -20
pegasus/lib/api/repo/putRecord.ml
··· 20 20 let handler = 21 21 Xrpc.handler ~auth:Auth.Verifiers.authorization (fun ctx -> 22 22 let%lwt input = Xrpc.parse_body ctx.req request_of_yojson in 23 - let%lwt input_did = 24 - if String.starts_with ~prefix:"did:" input.repo then 25 - Lwt.return input.repo 26 - else 27 - match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with 28 - | Some {did; _} -> 29 - Lwt.return did 30 - | None -> 31 - Errors.invalid_request "target repository not found" 32 - in 33 - let did = 34 - match ctx.auth with 35 - | Access {did} when did = input_did -> 36 - did 37 - | Admin -> 38 - input_did 39 - | _ -> 40 - Errors.auth_required 41 - "authentication does not match target repository" 42 - in 23 + let%lwt did = Xrpc.resolve_repo_did_authed ctx input.repo in 43 24 let%lwt repo = Repository.load did in 44 25 let write : Repository.repo_write = 45 26 Update
+22
pegasus/lib/xrpc.ml
··· 123 123 {req; db} 124 124 | None -> 125 125 inner_handler req 126 + 127 + let resolve_repo_did ctx repo = 128 + if String.starts_with ~prefix:"did:" repo then Lwt.return repo 129 + else 130 + match%lwt Data_store.get_actor_by_identifier repo ctx.db with 131 + | Some {did; _} -> 132 + Lwt.return did 133 + | None -> 134 + Errors.invalid_request "target repository not found" 135 + 136 + let resolve_repo_did_authed ctx repo = 137 + let%lwt input_did = resolve_repo_did ctx repo in 138 + let did = 139 + match ctx.auth with 140 + | Access {did} when did = input_did -> 141 + did 142 + | Admin -> 143 + input_did 144 + | _ -> 145 + Errors.auth_required "authentication does not match target repository" 146 + in 147 + Lwt.return did