From e385e9992a393221f837e98c8c99bb98d543357f Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 10 Nov 2022 19:33:42 -0800 Subject: pds: enforce invite code; implement describe --- adenosine-pds/src/lib.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs index 2f2c114..5794b95 100644 --- a/adenosine-pds/src/lib.rs +++ b/adenosine-pds/src/lib.rs @@ -422,6 +422,21 @@ fn xrpc_get_handler( )))?, } } + "com.atproto.repo.describe" => { + let did = Did::from_str(&xrpc_required_param(request, "user")?)?; + + let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; + let did_doc = srv.atp_db.get_did_doc(&did)?; + let collections: Vec = srv.repo.collections(&did)?; + let desc = RepoDescribe { + name: did.to_string(), // TODO: handle? + did: did.to_string(), + didDoc: did_doc, + collections: collections, + nameIsCorrect: true, + }; + Ok(json!(desc)) + } // =========== app.bsky methods "app.bsky.actor.getProfile" => { // TODO did or handle @@ -453,8 +468,9 @@ fn xrpc_get_handler( } fn xrpc_get_repo_handler(srv: &Mutex, request: &Request) -> Result> { - let did = Did::from_str(&xrpc_required_param(request, "user")?)?; + let did = Did::from_str(&xrpc_required_param(request, "did")?)?; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; + // TODO: don't unwrap here let commit_cid = srv.repo.lookup_commit(&did)?.unwrap(); Ok(srv.repo.export_car(&commit_cid, None)?) } @@ -535,6 +551,9 @@ fn xrpc_post_handler( .map_err(|e| XrpcError::BadRequest(format!("failed to parse JSON body: {}", e)))?; // TODO: validate handle, email, recoverykey let mut srv = srv.lock().unwrap(); + if srv.config.invite_code.is_some() && srv.config.invite_code != req.inviteCode { + Err(XrpcError::Forbidden("a valid invite code is required".to_string()))?; + }; let sess = create_account(&mut srv, &req, true)?; Ok(json!(sess)) } -- cgit v1.2.3