#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
mod erase;
mod handlers;
mod provider;
use cratefield_core::{ConfigError, Migrations, Module, ModuleContext, Port};
use std::sync::Arc;
pub use provider::{HttpProvider, SIGNATURE_HEADER};
#[derive(Clone, Debug, Default)]
pub struct Privacy {
providers: Arc<Vec<HttpProvider>>,
}
impl Privacy {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn provider(mut self, provider: HttpProvider) -> Self {
Arc::make_mut(&mut self.providers).push(provider);
self
}
}
impl Module for Privacy {
fn name(&self) -> &'static str {
"privacy"
}
fn version(&self) -> &'static str {
env!("CARGO_PKG_VERSION")
}
fn requires(&self) -> &'static [Port] {
if self.providers.is_empty() {
&[Port::Db, Port::Signer]
} else {
&[Port::Db, Port::Signer, Port::HttpClient, Port::Defer]
}
}
fn tables(&self) -> &'static [&'static str] {
&[]
}
fn migrations(&self) -> Migrations {
Migrations::EMPTY
}
fn validate_config(&self, _cfg: &dyn cratefield_core::Config) -> Result<(), ConfigError> {
Ok(())
}
fn router(&self, ctx: ModuleContext) -> axum::Router {
handlers::router(Arc::new(ctx), Arc::clone(&self.providers))
}
}