From 6e6924fb15e93aa7f1e84efd4efb8e9c95e391f3 Mon Sep 17 00:00:00 2001 From: sugyan Date: Mon, 27 May 2024 09:54:38 +0900 Subject: [PATCH 1/3] Add/Update AtpAgent configuration methods --- atrium-api/src/agent.rs | 6 +++++- atrium-api/src/agent/inner.rs | 24 ++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/atrium-api/src/agent.rs b/atrium-api/src/agent.rs index d01b2a6..738e150 100644 --- a/atrium-api/src/agent.rs +++ b/atrium-api/src/agent.rs @@ -107,8 +107,12 @@ where } } } + /// Set the current endpoint. + pub fn configure_endpoint(&self, endpoint: String) { + self.inner.configure_endpoint(endpoint); + } /// Configures the moderation services to be applied on requests. - pub fn configure_labelers_header(&self, labeler_dids: Option>) { + pub fn configure_labelers_header(&self, labeler_dids: Option>) { self.inner.configure_labelers_header(labeler_dids); } /// Configures the atproto-proxy header to be applied on requests. diff --git a/atrium-api/src/agent/inner.rs b/atrium-api/src/agent/inner.rs index 5f1faf4..8b8869f 100644 --- a/atrium-api/src/agent/inner.rs +++ b/atrium-api/src/agent/inner.rs @@ -23,12 +23,21 @@ impl WrapperClient { .expect("failed to write proxy header") .replace(value); } - fn configure_labelers_header(&self, labelers_dids: Option>) { + fn configure_labelers_header(&self, labelers_dids: Option>) { *self .labelers_header .write() - .expect("failed to write labelers header") = - labelers_dids.map(|dids| dids.iter().map(|did| did.as_ref().into()).collect()) + .expect("failed to write labelers header") = labelers_dids.map(|dids| { + dids.iter() + .map(|(did, redact)| { + if *redact { + format!("{};redact", did.as_ref()) + } else { + did.as_ref().into() + } + }) + .collect() + }) } } @@ -123,6 +132,13 @@ where notify: Arc::new(Notify::new()), } } + pub fn configure_endpoint(&self, endpoint: String) { + *self + .store + .endpoint + .write() + .expect("failed to write endpoint") = endpoint; + } pub fn configure_proxy_header(&self, did: Did, service_type: impl AsRef) { self.inner .configure_proxy_header(format!("{}#{}", did.as_ref(), service_type.as_ref())); @@ -134,7 +150,7 @@ where .configure_proxy_header(format!("{}#{}", did.as_ref(), service_type.as_ref())); cloned } - pub fn configure_labelers_header(&self, labeler_dids: Option>) { + pub fn configure_labelers_header(&self, labeler_dids: Option>) { self.inner.configure_labelers_header(labeler_dids); } pub async fn get_labelers_header(&self) -> Option> { From 7169450e1eb4eafdba483740ef3d629232f3b143 Mon Sep 17 00:00:00 2001 From: sugyan Date: Mon, 27 May 2024 09:55:33 +0900 Subject: [PATCH 2/3] Make the fields of UnknownData public --- atrium-api/src/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atrium-api/src/types.rs b/atrium-api/src/types.rs index dc0e194..5720193 100644 --- a/atrium-api/src/types.rs +++ b/atrium-api/src/types.rs @@ -99,9 +99,9 @@ pub enum Union { #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] pub struct UnknownData { #[serde(rename = "$type")] - r#type: String, + pub r#type: String, #[serde(flatten)] - data: Ipld, + pub data: Ipld, } impl Eq for UnknownData {} From 629d57ebf9f9e43877abf8667ebfa33f4ab0d3c9 Mon Sep 17 00:00:00 2001 From: sugyan Date: Mon, 27 May 2024 10:06:08 +0900 Subject: [PATCH 3/3] Fix tests --- atrium-api/src/agent.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/atrium-api/src/agent.rs b/atrium-api/src/agent.rs index 738e150..831acd1 100644 --- a/atrium-api/src/agent.rs +++ b/atrium-api/src/agent.rs @@ -625,9 +625,10 @@ mod tests { .expect("describe_server should be succeeded"); assert_eq!(headers.read().await.last(), Some(&HeaderMap::new())); - agent.configure_labelers_header(Some(vec!["did:plc:test1" - .parse() - .expect("did should be valid")])); + agent.configure_labelers_header(Some(vec![( + "did:plc:test1".parse().expect("did should be valid"), + false, + )])); agent .api .com @@ -645,8 +646,8 @@ mod tests { ); agent.configure_labelers_header(Some(vec![ - "did:plc:test1".parse().expect("did should be valid"), - "did:plc:test2".parse().expect("did should be valid"), + ("did:plc:test1".parse().expect("did should be valid"), true), + ("did:plc:test2".parse().expect("did should be valid"), false), ])); agent .api @@ -660,14 +661,14 @@ mod tests { headers.read().await.last(), Some(&HeaderMap::from_iter([( HeaderName::from_static("atproto-accept-labelers"), - HeaderValue::from_static("did:plc:test1, did:plc:test2"), + HeaderValue::from_static("did:plc:test1;redact, did:plc:test2"), )])) ); assert_eq!( agent.get_labelers_header().await, Some(vec![ - String::from("did:plc:test1"), + String::from("did:plc:test1;redact"), String::from("did:plc:test2") ]) );