···1414let handler =
1515 Xrpc.handler ~auth:Auth.Verifiers.authorization (fun ctx ->
1616 let%lwt input = Xrpc.parse_body ctx.req request_of_yojson in
1717- let%lwt input_did =
1818- if String.starts_with ~prefix:"did:" input.repo then
1919- Lwt.return input.repo
2020- else
2121- match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with
2222- | Some {did; _} ->
2323- Lwt.return did
2424- | None ->
2525- Errors.invalid_request "target repository not found"
2626- in
2727- let did =
2828- match ctx.auth with
2929- | Access {did} when did = input_did ->
3030- did
3131- | Admin ->
3232- input_did
3333- | _ ->
3434- Errors.auth_required
3535- "authentication does not match target repository"
3636- in
1717+ let%lwt did = Xrpc.resolve_repo_did_authed ctx input.repo in
3718 let%lwt repo = Repository.load did in
3819 let%lwt {commit= commit_cid, {rev; _}; results} =
3920 Repository.apply_writes repo input.writes
+1-20
pegasus/lib/api/repo/createRecord.ml
···2020let handler =
2121 Xrpc.handler ~auth:Auth.Verifiers.authorization (fun ctx ->
2222 let%lwt input = Xrpc.parse_body ctx.req request_of_yojson in
2323- let%lwt input_did =
2424- if String.starts_with ~prefix:"did:" input.repo then
2525- Lwt.return input.repo
2626- else
2727- match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with
2828- | Some {did; _} ->
2929- Lwt.return did
3030- | None ->
3131- Errors.invalid_request "target repository not found"
3232- in
3333- let did =
3434- match ctx.auth with
3535- | Access {did} when did = input_did ->
3636- did
3737- | Admin ->
3838- input_did
3939- | _ ->
4040- Errors.auth_required
4141- "authentication does not match target repository"
4242- in
2323+ let%lwt did = Xrpc.resolve_repo_did_authed ctx input.repo in
4324 let%lwt repo = Repository.load did in
4425 let write : Repository.repo_write =
4526 match input.swap_record with
+1-20
pegasus/lib/api/repo/deleteRecord.ml
···1313let handler =
1414 Xrpc.handler ~auth:Auth.Verifiers.authorization (fun ctx ->
1515 let%lwt input = Xrpc.parse_body ctx.req request_of_yojson in
1616- let%lwt input_did =
1717- if String.starts_with ~prefix:"did:" input.repo then
1818- Lwt.return input.repo
1919- else
2020- match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with
2121- | Some {did; _} ->
2222- Lwt.return did
2323- | None ->
2424- Errors.invalid_request "target repository not found"
2525- in
2626- let did =
2727- match ctx.auth with
2828- | Access {did} when did = input_did ->
2929- did
3030- | Admin ->
3131- input_did
3232- | _ ->
3333- Errors.auth_required
3434- "authentication does not match target repository"
3535- in
1616+ let%lwt did = Xrpc.resolve_repo_did_authed ctx input.repo in
3617 let%lwt repo = Repository.load did in
3718 let write : Repository.repo_write =
3819 Delete
+1-10
pegasus/lib/api/repo/getRecord.ml
···77let handler =
88 Xrpc.handler (fun ctx ->
99 let input = Xrpc.parse_query ctx.req query_of_yojson in
1010- let%lwt input_did =
1111- if String.starts_with ~prefix:"did:" input.repo then
1212- Lwt.return input.repo
1313- else
1414- match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with
1515- | Some {did; _} ->
1616- Lwt.return did
1717- | None ->
1818- Errors.invalid_request "target repository not found"
1919- in
1010+ let%lwt input_did = Xrpc.resolve_repo_did ctx input.repo in
2011 let%lwt repo = Repository.load input_did in
2112 let path = input.collection ^ "/" ^ input.rkey in
2213 let uri = "at://" ^ input_did ^ "/" ^ path in
+1-10
pegasus/lib/api/repo/listRecords.ml
···2222 | _ ->
2323 100
2424 in
2525- let%lwt input_did =
2626- if String.starts_with ~prefix:"did:" input.repo then
2727- Lwt.return input.repo
2828- else
2929- match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with
3030- | Some {did; _} ->
3131- Lwt.return did
3232- | None ->
3333- Errors.invalid_request "target repository not found"
3434- in
2525+ let%lwt input_did = Xrpc.resolve_repo_did ctx input.repo in
3526 let%lwt db = User_store.connect input_did in
3627 let%lwt results =
3728 User_store.list_records db ~limit ?cursor:input.cursor
+1-20
pegasus/lib/api/repo/putRecord.ml
···2020let handler =
2121 Xrpc.handler ~auth:Auth.Verifiers.authorization (fun ctx ->
2222 let%lwt input = Xrpc.parse_body ctx.req request_of_yojson in
2323- let%lwt input_did =
2424- if String.starts_with ~prefix:"did:" input.repo then
2525- Lwt.return input.repo
2626- else
2727- match%lwt Data_store.get_actor_by_identifier input.repo ctx.db with
2828- | Some {did; _} ->
2929- Lwt.return did
3030- | None ->
3131- Errors.invalid_request "target repository not found"
3232- in
3333- let did =
3434- match ctx.auth with
3535- | Access {did} when did = input_did ->
3636- did
3737- | Admin ->
3838- input_did
3939- | _ ->
4040- Errors.auth_required
4141- "authentication does not match target repository"
4242- in
2323+ let%lwt did = Xrpc.resolve_repo_did_authed ctx input.repo in
4324 let%lwt repo = Repository.load did in
4425 let write : Repository.repo_write =
4526 Update
+22
pegasus/lib/xrpc.ml
···123123 {req; db}
124124 | None ->
125125 inner_handler req
126126+127127+let resolve_repo_did ctx repo =
128128+ if String.starts_with ~prefix:"did:" repo then Lwt.return repo
129129+ else
130130+ match%lwt Data_store.get_actor_by_identifier repo ctx.db with
131131+ | Some {did; _} ->
132132+ Lwt.return did
133133+ | None ->
134134+ Errors.invalid_request "target repository not found"
135135+136136+let resolve_repo_did_authed ctx repo =
137137+ let%lwt input_did = resolve_repo_did ctx repo in
138138+ let did =
139139+ match ctx.auth with
140140+ | Access {did} when did = input_did ->
141141+ did
142142+ | Admin ->
143143+ input_did
144144+ | _ ->
145145+ Errors.auth_required "authentication does not match target repository"
146146+ in
147147+ Lwt.return did