diff options
Diffstat (limited to 'adenosine-pds/src')
-rw-r--r-- | adenosine-pds/src/bin/adenosine-pds.rs | 10 | ||||
-rw-r--r-- | adenosine-pds/src/db_bsky.rs | 60 | ||||
-rw-r--r-- | adenosine-pds/src/lib.rs | 46 |
3 files changed, 54 insertions, 62 deletions
diff --git a/adenosine-pds/src/bin/adenosine-pds.rs b/adenosine-pds/src/bin/adenosine-pds.rs index c004098..e92c131 100644 --- a/adenosine-pds/src/bin/adenosine-pds.rs +++ b/adenosine-pds/src/bin/adenosine-pds.rs @@ -148,7 +148,7 @@ fn main() -> Result<()> { }; // hyper logging is very verbose, so crank that down even if everything else is more verbose - let cli_filter = format!("{},hyper=error", log_level); + let cli_filter = format!("{log_level},hyper=error"); // defer to env var config, fallback to CLI settings let log_filter = std::env::var("RUST_LOG").unwrap_or(cli_filter); pretty_env_logger::formatted_timed_builder() @@ -174,12 +174,12 @@ fn main() -> Result<()> { Some(v) => Some(v), }; let public_url = match public_url { - None => format!("http://localhost:{}", port), - Some(v) if v.is_empty() => format!("http://localhost:{}", port), + None => format!("http://localhost:{port}"), + Some(v) if v.is_empty() => format!("http://localhost:{port}"), Some(v) => v, }; let config = AtpServiceConfig { - listen_host_port: format!("localhost:{}", port), + listen_host_port: format!("localhost:{port}"), public_url, registration_domain, invite_code, @@ -218,7 +218,7 @@ fn main() -> Result<()> { recoveryKey: recovery_key, }; let config = AtpServiceConfig { - public_url: public_url.unwrap_or(format!("https://{}", handle)), + public_url: public_url.unwrap_or(format!("https://{handle}")), ..Default::default() }; let keypair = KeyPair::from_hex(&pds_secret_key)?; diff --git a/adenosine-pds/src/db_bsky.rs b/adenosine-pds/src/db_bsky.rs index ee8e0f3..dfe8299 100644 --- a/adenosine-pds/src/db_bsky.rs +++ b/adenosine-pds/src/db_bsky.rs @@ -273,7 +273,7 @@ pub fn bsky_get_thread( // parse the URI let did = match uri.repository { DidOrHost::Did(ref did_type, ref did_body) => { - Did::from_str(&format!("did:{}:{}", did_type, did_body))? + Did::from_str(&format!("did:{did_type}:{did_body}"))? } _ => Err(anyhow!("expected a DID, not handle, in uri: {}", uri))?, }; @@ -412,7 +412,7 @@ fn test_bsky_profile() { ipld!({"subject": {"did": session.did}, "createdAt": created_at_now()}), ), Mutation::Create( - follow_nsid.clone(), + follow_nsid, srv.tid_gen.next_tid(), ipld!({"subject": {"did": "did:web:external.domain"}, "createdAt": created_at_now()}), ), @@ -427,7 +427,7 @@ fn test_bsky_profile() { ipld!({"text": "second post"}), ), Mutation::Create( - post_nsid.clone(), + post_nsid, srv.tid_gen.next_tid(), ipld!({"text": "third post"}), ), @@ -534,9 +534,9 @@ fn test_bsky_feeds() { // bob follows alice, likes first post, reposts second, replies third let alice_post3_uri = format!( "at://{}/{}/{}", - alice_did.to_string(), - post_nsid.to_string(), - alice_post3_tid.to_string() + alice_did, + post_nsid, + alice_post3_tid ); let mutations = vec![ Mutation::Create( @@ -545,19 +545,19 @@ fn test_bsky_feeds() { ipld!({"subject": {"did": alice_did.to_string()}, "createdAt": created_at_now()}), ), Mutation::Create( - like_nsid.clone(), + like_nsid, srv.tid_gen.next_tid(), - ipld!({"subject": {"uri": format!("at://{}/{}/{}", alice_did.to_string(), post_nsid.to_string(), alice_post1_tid.to_string())}, "createdAt": created_at_now()}), + ipld!({"subject": {"uri": format!("at://{}/{}/{}", alice_did, post_nsid, alice_post1_tid)}, "createdAt": created_at_now()}), ), Mutation::Create( - repost_nsid.clone(), + repost_nsid, srv.tid_gen.next_tid(), - ipld!({"subject": {"uri": format!("at://{}/{}/{}", alice_did.to_string(), post_nsid.to_string(), alice_post2_tid.to_string())}, "createdAt": created_at_now()}), + ipld!({"subject": {"uri": format!("at://{}/{}/{}", alice_did, post_nsid, alice_post2_tid)}, "createdAt": created_at_now()}), ), Mutation::Create( post_nsid.clone(), srv.tid_gen.next_tid(), - ipld!({"text": "bob comment on alice post3", "reply": {"parent": {"uri": alice_post3_uri.clone()}, "root": {"uri": alice_post3_uri.clone()}}}), + ipld!({"text": "bob comment on alice post3", "reply": {"parent": {"uri": alice_post3_uri.clone()}, "root": {"uri": alice_post3_uri}}}), ), ]; srv.repo @@ -567,7 +567,7 @@ fn test_bsky_feeds() { // carol follows bob let mutations = vec![Mutation::Create( - follow_nsid.clone(), + follow_nsid, srv.tid_gen.next_tid(), ipld!({"subject": {"did": bob_did.to_string()}, "createdAt": created_at_now()}), )]; @@ -584,7 +584,7 @@ fn test_bsky_feeds() { // test alice timeline: still empty (?) let alice_timeline = bsky_get_timeline(&mut srv, &alice_did).unwrap(); - println!("{:?}", alice_timeline); + println!("{alice_timeline:?}"); assert!(alice_timeline.feed.is_empty()); // test alice feed: should have 3 posts, with correct counts @@ -595,9 +595,9 @@ fn test_bsky_feeds() { alice_feed.feed[2].uri, format!( "at://{}/{}/{}", - alice_did.to_string(), - post_nsid.to_string(), - alice_post1_tid.to_string() + alice_did, + post_nsid, + alice_post1_tid ) ); // TODO: CID @@ -628,16 +628,16 @@ fn test_bsky_feeds() { let bob_timeline = bsky_get_timeline(&mut srv, &bob_did).unwrap(); println!("BOB TIMELINE ======"); for item in bob_timeline.feed.iter() { - println!("{:?}", item); + println!("{item:?}"); } assert_eq!(bob_timeline.feed.len(), 3); assert_eq!( bob_timeline.feed[2].uri, format!( "at://{}/{}/{}", - alice_did.to_string(), - post_nsid.to_string(), - alice_post1_tid.to_string() + alice_did, + post_nsid, + alice_post1_tid ) ); // TODO: CID @@ -718,9 +718,9 @@ fn test_bsky_thread() { bsky_mutate_db(&mut srv.atp_db, &alice_did, mutations).unwrap(); let alice_post1_uri = format!( "at://{}/{}/{}", - alice_did.to_string(), - post_nsid.to_string(), - alice_post1_tid.to_string() + alice_did, + post_nsid, + alice_post1_tid ); // bob likes and replies first post @@ -736,9 +736,9 @@ fn test_bsky_thread() { bsky_mutate_db(&mut srv.atp_db, &bob_did, mutations).unwrap(); let bob_post1_uri = format!( "at://{}/{}/{}", - bob_did.to_string(), - post_nsid.to_string(), - bob_post1_tid.to_string() + bob_did, + post_nsid, + bob_post1_tid ); // alice replies to bob reply @@ -746,7 +746,7 @@ fn test_bsky_thread() { let mutations = vec![Mutation::Create( post_nsid.clone(), alice_post2_tid.clone(), - ipld!({"text": "alice second post, replying to bob comment", "reply": {"parent": {"uri": bob_post1_uri.clone()}, "root": {"uri": alice_post1_uri.clone()}}}), + ipld!({"text": "alice second post, replying to bob comment", "reply": {"parent": {"uri": bob_post1_uri.clone()}, "root": {"uri": alice_post1_uri}}}), )]; srv.repo .mutate_repo(&alice_did, &mutations, &srv.pds_keypair) @@ -754,9 +754,9 @@ fn test_bsky_thread() { bsky_mutate_db(&mut srv.atp_db, &alice_did, mutations).unwrap(); let _alice_post2_uri = format!( "at://{}/{}/{}", - alice_did.to_string(), - post_nsid.to_string(), - alice_post2_tid.to_string() + alice_did, + post_nsid, + alice_post2_tid ); // get thread from bob's post diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs index cca9b0d..fb63a11 100644 --- a/adenosine-pds/src/lib.rs +++ b/adenosine-pds/src/lib.rs @@ -40,7 +40,7 @@ impl fmt::Display for XrpcError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::BadRequest(msg) | Self::NotFound(msg) | Self::Forbidden(msg) => { - write!(f, "{}", msg) + write!(f, "{msg}") } Self::MutexPoisoned => write!(f, "service mutex poisoned"), } @@ -255,8 +255,7 @@ impl AtpService { fn xrpc_required_param(request: &Request, key: &str) -> Result<String> { Ok(request.get_param(key).ok_or(XrpcError::BadRequest(format!( - "require '{}' query parameter", - key + "require '{key}' query parameter" )))?) } @@ -308,13 +307,12 @@ fn xrpc_get_handler( let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?; let rkey = Tid::from_str(&xrpc_required_param(request, "rkey")?)?; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; - let key = format!("/{}/{}", collection, rkey); + let key = format!("/{collection}/{rkey}"); match srv.repo.get_atp_record(&did, &collection, &rkey) { // TODO: format as JSON, not text debug Ok(Some(ipld)) => Ok(ipld_into_json_value(ipld)), Ok(None) => Err(anyhow!(XrpcError::NotFound(format!( - "could not find record: {}", - key + "could not find record: {key}" )))), Err(e) => Err(e), } @@ -325,7 +323,7 @@ fn xrpc_get_handler( srv.repo .lookup_commit(&did)? .map(|v| json!({ "root": v.to_string() })) - .ok_or(XrpcError::NotFound(format!("no repository found for DID: {}", did)).into()) + .ok_or(XrpcError::NotFound(format!("no repository found for DID: {did}")).into()) } "com.atproto.repo.listRecords" => { // TODO: limit, before, after, tid, reverse @@ -338,13 +336,13 @@ fn xrpc_get_handler( let commit_cid = &srv.repo.lookup_commit(&did)?.unwrap(); let last_commit = srv.repo.get_commit(commit_cid)?; let full_map = srv.repo.mst_to_map(&last_commit.mst_cid)?; - let prefix = format!("/{}/", collection); + let prefix = format!("/{collection}/"); for (mst_key, cid) in full_map.iter() { //debug!("{}", mst_key); if mst_key.starts_with(&prefix) { let record = srv.repo.get_ipld(cid)?; record_list.push(json!({ - "uri": format!("at://{}{}", did, mst_key), + "uri": format!("at://{did}{mst_key}"), "cid": cid.to_string(), "value": ipld_into_json_value(record), })); @@ -367,8 +365,7 @@ fn xrpc_get_handler( match srv.atp_db.resolve_handle(&handle)? { Some(did) => Ok(json!({"did": did.to_string()})), None => Err(XrpcError::NotFound(format!( - "could not resolve handle internally: {}", - handle + "could not resolve handle internally: {handle}" )))?, } } @@ -444,8 +441,7 @@ fn xrpc_get_handler( Ok(json!({"notifications": []})) } _ => Err(anyhow!(XrpcError::NotFound(format!( - "XRPC endpoint handler not found: {}", - method + "XRPC endpoint handler not found: {method}" )))), } } @@ -531,15 +527,14 @@ fn xrpc_post_handler( "com.atproto.account.create" => { // validate account request let req: com_atproto::AccountRequest = rouille::input::json_input(request) - .map_err(|e| XrpcError::BadRequest(format!("failed to parse JSON body: {}", e)))?; + .map_err(|e| XrpcError::BadRequest(format!("failed to parse JSON body: {e}")))?; // TODO: validate handle, email, recoverykey let mut srv = srv.lock().unwrap(); if let Some(ref domain) = srv.config.registration_domain { // TODO: better matching, should not allow arbitrary sub-domains if !req.handle.ends_with(domain) { Err(XrpcError::BadRequest(format!( - "handle is not under registration domain ({})", - domain + "handle is not under registration domain ({domain})" )))?; } } else { @@ -557,7 +552,7 @@ fn xrpc_post_handler( } "com.atproto.session.create" => { let req: com_atproto::SessionRequest = rouille::input::json_input(request) - .map_err(|e| XrpcError::BadRequest(format!("failed to parse JSON body: {}", e)))?; + .map_err(|e| XrpcError::BadRequest(format!("failed to parse JSON body: {e}")))?; let mut srv = srv.lock().unwrap(); let keypair = srv.pds_keypair.clone(); Ok(json!(srv.atp_db.create_session( @@ -721,8 +716,7 @@ fn xrpc_post_handler( Ok(json!({})) } _ => Err(anyhow!(XrpcError::NotFound(format!( - "XRPC endpoint handler not found: {}", - method + "XRPC endpoint handler not found: {method}" )))), } } @@ -773,8 +767,7 @@ fn account_view_handler( .atp_db .resolve_handle(handle)? .ok_or(XrpcError::NotFound(format!( - "no DID found for handle: {}", - handle + "no DID found for handle: {handle}" )))?; Ok(AccountView { @@ -799,7 +792,7 @@ fn thread_view_handler( let did = srv.atp_db.resolve_handle(handle)?.unwrap(); // TODO: could construct URI directly - let uri = AtUri::from_str(&format!("at://{}/{}/{}", did, collection, tid))?; + let uri = AtUri::from_str(&format!("at://{did}/{collection}/{tid}"))?; Ok(ThreadView { domain: host.to_string(), did, @@ -851,13 +844,13 @@ fn collection_view_handler( let commit_cid = &srv.repo.lookup_commit(&did)?.unwrap(); let last_commit = srv.repo.get_commit(commit_cid)?; let full_map = srv.repo.mst_to_map(&last_commit.mst_cid)?; - let prefix = format!("/{}/", collection); + let prefix = format!("/{collection}/"); for (mst_key, cid) in full_map.iter() { debug!("{}", mst_key); if mst_key.starts_with(&prefix) { let record = srv.repo.get_ipld(cid)?; record_list.push(json!({ - "uri": format!("at://{}{}", did, mst_key), + "uri": format!("at://{did}{mst_key}"), "tid": mst_key.split('/').nth(2).unwrap(), "cid": cid, "value": ipld_into_json_value(record), @@ -887,12 +880,11 @@ fn record_view_handler( let rkey = Tid::from_str(tid)?; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; - let key = format!("/{}/{}", collection, rkey); + let key = format!("/{collection}/{rkey}"); let record = match srv.repo.get_atp_record(&did, &collection, &rkey) { Ok(Some(ipld)) => ipld_into_json_value(ipld), Ok(None) => Err(anyhow!(XrpcError::NotFound(format!( - "could not find record: {}", - key + "could not find record: {key}" ))))?, Err(e) => Err(e)?, }; |