mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 20:32:48 +00:00
Breaking changes to auth provider, principal store outsourced to new config file
This commit is contained in:
@@ -5,7 +5,7 @@ use actix_web::{web, App};
|
||||
use rustical_caldav::caldav_service;
|
||||
use rustical_carddav::carddav_service;
|
||||
use rustical_frontend::{configure_frontend, FrontendConfig};
|
||||
use rustical_store::auth::{AuthenticationProvider, UserStore};
|
||||
use rustical_store::auth::AuthenticationProvider;
|
||||
use rustical_store::{AddressbookStore, CalendarStore, SubscriptionStore};
|
||||
use std::sync::Arc;
|
||||
use tracing_actix_web::TracingLogger;
|
||||
@@ -15,7 +15,6 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
||||
cal_store: Arc<CS>,
|
||||
subscription_store: Arc<S>,
|
||||
auth_provider: Arc<impl AuthenticationProvider>,
|
||||
user_store: Arc<impl UserStore>,
|
||||
frontend_config: FrontendConfig,
|
||||
) -> App<
|
||||
impl ServiceFactory<
|
||||
@@ -31,7 +30,6 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
||||
.wrap(TracingLogger::default())
|
||||
.wrap(NormalizePath::trim())
|
||||
.service(web::scope("/caldav").service(caldav_service(
|
||||
user_store.clone(),
|
||||
auth_provider.clone(),
|
||||
cal_store.clone(),
|
||||
addr_store.clone(),
|
||||
@@ -39,7 +37,6 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
||||
)))
|
||||
.service(web::scope("/carddav").service(carddav_service(
|
||||
auth_provider.clone(),
|
||||
user_store.clone(),
|
||||
addr_store.clone(),
|
||||
subscription_store,
|
||||
)))
|
||||
|
||||
@@ -4,7 +4,7 @@ use password_hash::PasswordHasher;
|
||||
use pbkdf2::Params;
|
||||
use rand::{rngs::OsRng, RngCore};
|
||||
use rustical_frontend::FrontendConfig;
|
||||
use rustical_store::auth::{StaticUserStoreConfig, User};
|
||||
use rustical_store::auth::TomlUserStoreConfig;
|
||||
|
||||
use crate::config::{
|
||||
AuthConfig, Config, DataStoreConfig, DavPushConfig, HttpConfig, SqliteDataStoreConfig,
|
||||
@@ -25,22 +25,8 @@ pub fn generate_frontend_secret() -> [u8; 64] {
|
||||
pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
|
||||
let config = Config {
|
||||
http: HttpConfig::default(),
|
||||
auth: AuthConfig::Static(StaticUserStoreConfig {
|
||||
users: vec![User {
|
||||
id: "default".to_owned(),
|
||||
displayname: Some("Default user".to_owned()),
|
||||
user_type: Default::default(),
|
||||
password: Some(
|
||||
"generate a password hash with rustical pwhash --algorithm argon2".to_owned(),
|
||||
),
|
||||
app_tokens: vec![
|
||||
"generate an app token hash with rustical pwhash --algorithm pbkdf2".to_owned(),
|
||||
],
|
||||
memberships: vec![
|
||||
"Here you can specify other principals this principal should be a member of"
|
||||
.to_owned(),
|
||||
],
|
||||
}],
|
||||
auth: AuthConfig::Toml(TomlUserStoreConfig {
|
||||
path: "/etc/rustical/principals.toml".to_owned(),
|
||||
}),
|
||||
data_store: DataStoreConfig::Sqlite(SqliteDataStoreConfig {
|
||||
db_url: "".to_owned(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use rustical_frontend::FrontendConfig;
|
||||
use rustical_store::auth::StaticUserStoreConfig;
|
||||
use rustical_store::auth::TomlUserStoreConfig;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
@@ -35,7 +35,7 @@ pub enum DataStoreConfig {
|
||||
#[serde(tag = "backend", rename_all = "snake_case")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub enum AuthConfig {
|
||||
Static(StaticUserStoreConfig),
|
||||
Toml(TomlUserStoreConfig),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
|
||||
21
src/main.rs
21
src/main.rs
@@ -7,7 +7,7 @@ use clap::{Parser, Subcommand};
|
||||
use commands::{cmd_gen_config, cmd_pwhash};
|
||||
use config::{DataStoreConfig, SqliteDataStoreConfig};
|
||||
use rustical_dav::push::push_notifier;
|
||||
use rustical_store::auth::StaticUserStore;
|
||||
use rustical_store::auth::TomlPrincipalStore;
|
||||
use rustical_store::{AddressbookStore, CalendarStore, CollectionOperation, SubscriptionStore};
|
||||
use rustical_store_sqlite::addressbook_store::SqliteAddressbookStore;
|
||||
use rustical_store_sqlite::calendar_store::SqliteCalendarStore;
|
||||
@@ -90,9 +90,9 @@ async fn main() -> Result<()> {
|
||||
));
|
||||
}
|
||||
|
||||
let user_store = Arc::new(match config.auth {
|
||||
config::AuthConfig::Static(config) => StaticUserStore::new(config),
|
||||
});
|
||||
let user_store = match config.auth {
|
||||
config::AuthConfig::Toml(config) => Arc::new(TomlPrincipalStore::new(config)?),
|
||||
};
|
||||
|
||||
HttpServer::new(move || {
|
||||
make_app(
|
||||
@@ -100,7 +100,6 @@ async fn main() -> Result<()> {
|
||||
cal_store.clone(),
|
||||
subscription_store.clone(),
|
||||
user_store.clone(),
|
||||
user_store.clone(),
|
||||
config.frontend.clone(),
|
||||
)
|
||||
})
|
||||
@@ -122,24 +121,21 @@ mod tests {
|
||||
use actix_web::{http::StatusCode, test::TestRequest};
|
||||
use async_trait::async_trait;
|
||||
use rustical_frontend::FrontendConfig;
|
||||
use rustical_store::auth::{AuthenticationProvider, UserStore};
|
||||
use rustical_store::auth::AuthenticationProvider;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct MockUserStore;
|
||||
|
||||
#[async_trait]
|
||||
impl UserStore for MockUserStore {
|
||||
async fn get_user(
|
||||
impl AuthenticationProvider for MockUserStore {
|
||||
async fn get_principal(
|
||||
&self,
|
||||
id: &str,
|
||||
) -> Result<Option<rustical_store::auth::User>, rustical_store::Error> {
|
||||
Err(rustical_store::Error::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl AuthenticationProvider for MockUserStore {
|
||||
async fn validate_user_token(
|
||||
&self,
|
||||
user_id: &str,
|
||||
@@ -151,7 +147,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_main() {
|
||||
let (addr_store, cal_store, subscription_store, update_recv) = get_data_stores(
|
||||
let (addr_store, cal_store, subscription_store, _update_recv) = get_data_stores(
|
||||
true,
|
||||
&crate::config::DataStoreConfig::Sqlite(crate::config::SqliteDataStoreConfig {
|
||||
db_url: "".to_owned(),
|
||||
@@ -166,7 +162,6 @@ mod tests {
|
||||
addr_store,
|
||||
cal_store,
|
||||
subscription_store,
|
||||
user_store.clone(),
|
||||
user_store,
|
||||
FrontendConfig {
|
||||
enabled: false,
|
||||
|
||||
Reference in New Issue
Block a user