diff --git a/atrium-api/src/agent.rs b/atrium-api/src/agent.rs index d01b2a69..831acd10 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. @@ -621,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 @@ -641,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 @@ -656,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") ]) ); diff --git a/atrium-api/src/agent/inner.rs b/atrium-api/src/agent/inner.rs index 5f1faf4d..8b8869f5 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> { diff --git a/atrium-api/src/types.rs b/atrium-api/src/types.rs index dc0e1944..57201936 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 {}