CLI tool for migrating PDS
1use atrium_api::xrpc::{
2 http::{Request, Response},
3 types::AuthorizationToken,
4 HttpClient, XrpcClient,
5};
6use atrium_xrpc_client::reqwest::ReqwestClient;
7
8pub struct JwtAuthedClient {
9 token: String,
10 inner: ReqwestClient,
11}
12
13impl JwtAuthedClient {
14 pub fn new(base_uri: impl AsRef<str>, token: String) -> Self {
15 Self {
16 token,
17 inner: ReqwestClient::new(base_uri),
18 }
19 }
20}
21
22impl HttpClient for JwtAuthedClient {
23 async fn send_http(
24 &self,
25 request: Request<Vec<u8>>,
26 ) -> Result<Response<Vec<u8>>, Box<dyn std::error::Error + Send + Sync + 'static>> {
27 self.inner.send_http(request).await
28 }
29}
30
31impl XrpcClient for JwtAuthedClient {
32 fn base_uri(&self) -> String {
33 self.inner.base_uri()
34 }
35
36 async fn authorization_token(&self, _: bool) -> Option<AuthorizationToken> {
37 Some(AuthorizationToken::Bearer(self.token.clone()))
38 }
39}