2 unstable releases
0.2.0 | Dec 5, 2021 |
---|---|
0.1.0 | Nov 30, 2021 |
#8 in #activitypub
Used in apub
62KB
2K
SLoC
An implementation of Client based on background_jobs
use apub_core::session::SessionFactory;
use apub_background_jobs::{JobClient, ClientFactory, DeliverJob};
use apub_openssl::OpenSsl;
use apub_reqwest::{ReqwestClient, SignatureConfig};
use background_jobs::{memory_storage::Storage, WorkerConfig};
use openssl::{pkey::PKey, rsa::Rsa};
use url::Url;
#[derive(Clone)]
struct State {
config: SignatureConfig,
client: reqwest::Client,
}
impl ClientFactory for State {
type Crypto = OpenSsl;
type Client = ReqwestClient<OpenSsl>;
fn build_client(&self, crypto: &Self::Crypto) -> Self::Client {
ReqwestClient::new(self.client.clone().into(), self.config.clone(), crypto.clone())
}
}
impl SessionFactory for State {
type Session = ();
fn build_session(&self) -> Self::Session {
()
}
}
#[actix_rt::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = SignatureConfig::default();
let http = reqwest::Client::new();
let manager = WorkerConfig::new_managed(Storage::new(), move |_| State {
config: config.clone(),
client: http.clone(),
})
.register::<DeliverJob<State, OpenSsl>>()
.start();
let private_key = PKey::from_rsa(Rsa::generate(1024)?)?;
let crypto = OpenSsl::new("key-id".to_string(), private_key);
let inbox: Url = "https://masto.asonix.dog/inbox".parse()?;
// let activity = /* ... */;
// JobClient::<State>::new(crypto, queue_handle.clone()).enqueue(inbox, &activity)?;
drop(manager);
Ok(())
}
Dependencies
~7–17MB
~206K SLoC