mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 19:22:26 +00:00
51 lines
1.6 KiB
Rust
51 lines
1.6 KiB
Rust
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
|
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
|
use axum::{Extension, Router};
|
|
use derive_more::Constructor;
|
|
use principal::PrincipalResourceService;
|
|
use rustical_dav::resource::{PrincipalUri, ResourceService};
|
|
use rustical_dav::resources::RootResourceService;
|
|
use rustical_store::auth::middleware::AuthenticationLayer;
|
|
use rustical_store::auth::{AuthenticationProvider, Principal};
|
|
use rustical_store::{CalendarStore, SubscriptionStore};
|
|
use std::sync::Arc;
|
|
|
|
pub mod calendar;
|
|
pub mod calendar_object;
|
|
pub mod error;
|
|
pub mod principal;
|
|
pub use error::Error;
|
|
|
|
#[derive(Debug, Clone, Constructor)]
|
|
pub struct CalDavPrincipalUri(&'static str);
|
|
|
|
impl PrincipalUri for CalDavPrincipalUri {
|
|
fn principal_collection(&self) -> String {
|
|
format!("{}/principal/", self.0)
|
|
}
|
|
fn principal_uri(&self, principal: &str) -> String {
|
|
format!("{}{}/", self.principal_collection(), principal)
|
|
}
|
|
}
|
|
|
|
pub fn caldav_router<AP: AuthenticationProvider, C: CalendarStore, S: SubscriptionStore>(
|
|
prefix: &'static str,
|
|
auth_provider: Arc<AP>,
|
|
store: Arc<C>,
|
|
subscription_store: Arc<S>,
|
|
simplified_home_set: bool,
|
|
) -> Router {
|
|
Router::new().nest(
|
|
prefix,
|
|
RootResourceService::<_, Principal, CalDavPrincipalUri>::new(PrincipalResourceService {
|
|
auth_provider: auth_provider.clone(),
|
|
sub_store: subscription_store,
|
|
cal_store: store,
|
|
simplified_home_set,
|
|
})
|
|
.axum_router()
|
|
.layer(AuthenticationLayer::new(auth_provider))
|
|
.layer(Extension(CalDavPrincipalUri(prefix))),
|
|
)
|
|
}
|