mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
Add auth config
This commit is contained in:
@@ -25,8 +25,10 @@ pub fn configure_well_known(cfg: &mut web::ServiceConfig, caldav_root: String) {
|
||||
}
|
||||
|
||||
pub fn configure_dav<C: CalendarStore>(
|
||||
pub fn configure_dav<A: CheckAuthentication, C: CalendarStore>(
|
||||
cfg: &mut web::ServiceConfig,
|
||||
prefix: String,
|
||||
auth: Arc<A>,
|
||||
store: Arc<RwLock<C>>,
|
||||
) {
|
||||
let propfind_method = || Method::from_str("PROPFIND").unwrap();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use rustical_auth::{AuthProvider, HtpasswdAuthConfig};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
@@ -11,7 +12,26 @@ pub enum CalendarStoreConfig {
|
||||
Toml(TomlCalendarStoreConfig),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(tag = "backend", rename_all = "snake_case")]
|
||||
pub enum AuthConfig {
|
||||
Htpasswd(HtpasswdAuthConfig),
|
||||
None,
|
||||
}
|
||||
|
||||
impl From<AuthConfig> for AuthProvider {
|
||||
fn from(value: AuthConfig) -> Self {
|
||||
match value {
|
||||
AuthConfig::Htpasswd(config) => {
|
||||
Self::Htpasswd(rustical_auth::htpasswd::HtpasswdAuth { config })
|
||||
}
|
||||
AuthConfig::None => Self::None(rustical_auth::none::NoneAuth),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Config {
|
||||
pub calendar_store: CalendarStoreConfig,
|
||||
pub auth: AuthConfig,
|
||||
}
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -1,6 +1,3 @@
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::config::Config;
|
||||
use actix_web::middleware::{Logger, NormalizePath};
|
||||
use actix_web::{web, App, HttpServer};
|
||||
@@ -8,9 +5,12 @@ use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use config::{CalendarStoreConfig, TomlCalendarStoreConfig};
|
||||
use rustical_api::configure_api;
|
||||
use rustical_auth::AuthProvider;
|
||||
use rustical_dav::{configure_dav, configure_well_known};
|
||||
use rustical_frontend::configure_frontend;
|
||||
use rustical_store::calendar::TomlCalendarStore;
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
mod config;
|
||||
@@ -38,20 +38,16 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
}));
|
||||
|
||||
let auth = match config.auth {
|
||||
config::AuthConfig::Htpasswd(config) => 1,
|
||||
_ => panic!("invalid auth config"),
|
||||
};
|
||||
let auth: Arc<AuthProvider> = Arc::new(config.auth.into());
|
||||
|
||||
HttpServer::new(move || {
|
||||
let cal_store = cal_store.clone();
|
||||
App::new()
|
||||
.wrap(Logger::new("[%s] %r"))
|
||||
.wrap(NormalizePath::trim())
|
||||
.service(
|
||||
web::scope("/caldav")
|
||||
.configure(|cfg| configure_dav(cfg, "/caldav".to_string(), cal_store.clone())),
|
||||
)
|
||||
.service(web::scope("/caldav").configure(|cfg| {
|
||||
configure_dav(cfg, "/caldav".to_string(), auth.clone(), cal_store.clone())
|
||||
}))
|
||||
.service(
|
||||
web::scope("/.well-known")
|
||||
.configure(|cfg| configure_well_known(cfg, "/caldav".to_string())),
|
||||
|
||||
Reference in New Issue
Block a user