mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 12:58:28 +00:00
Compare commits
5 Commits
v0.12.3
...
af60a446ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af60a446ad | ||
|
|
c763a682ed | ||
|
|
8ab9c61b0f | ||
|
|
8b2bb1b0d6 | ||
|
|
da72aa26cb |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,7 +3,7 @@ crates/*/target
|
||||
# For libraries ignore Cargo.lock
|
||||
crates/*/Cargo.lock
|
||||
|
||||
db.sqlite3*
|
||||
**/*.sqlite3*
|
||||
config.toml
|
||||
principals.toml
|
||||
|
||||
|
||||
@@ -32,8 +32,11 @@ opentelemetry = [
|
||||
"dep:tracing-opentelemetry",
|
||||
]
|
||||
|
||||
[profile.dev]
|
||||
debug = 0
|
||||
[lib]
|
||||
doc = true
|
||||
name = "rustical"
|
||||
path = "src/lib.rs"
|
||||
test = true
|
||||
|
||||
[workspace.dependencies]
|
||||
rustical_dav = { path = "./crates/dav/", features = ["ical"] }
|
||||
|
||||
@@ -24,6 +24,7 @@ a CalDAV/CardDAV server
|
||||
- Apple configuration profiles (skip copy-pasting passwords and instead generate the configuration in the frontend)
|
||||
- **OpenID Connect** support (with option to disable password login)
|
||||
- Group-based **sharing**
|
||||
- Partial [RFC 7809](https://datatracker.ietf.org/doc/html/rfc7809) support. RustiCal will accept timezones by reference and handle omitted timezones in objects.
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
||||
@@ -37,11 +37,11 @@ impl SqliteStore {
|
||||
}
|
||||
|
||||
pub async fn create_db_pool(db_url: &str, migrate: bool) -> Result<Pool<Sqlite>, sqlx::Error> {
|
||||
let options: SqliteConnectOptions = db_url.parse()?;
|
||||
|
||||
let db = SqlitePool::connect_with(
|
||||
SqliteConnectOptions::new()
|
||||
options
|
||||
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
|
||||
.synchronous(sqlx::sqlite::SqliteSynchronous::Normal)
|
||||
.filename(db_url)
|
||||
.create_if_missing(true),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
SqliteStore, addressbook_store::SqliteAddressbookStore, calendar_store::SqliteCalendarStore,
|
||||
principal_store::SqlitePrincipalStore,
|
||||
create_db_pool, principal_store::SqlitePrincipalStore,
|
||||
};
|
||||
use rstest::fixture;
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal, PrincipalType};
|
||||
@@ -9,12 +9,23 @@ use sqlx::SqlitePool;
|
||||
mod addressbook_store;
|
||||
mod calendar_store;
|
||||
|
||||
async fn get_test_db() -> SqlitePool {
|
||||
let db = SqlitePool::connect("sqlite::memory:").await.unwrap();
|
||||
sqlx::migrate!("./migrations").run(&db).await.unwrap();
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TestStoreContext {
|
||||
pub db: SqlitePool,
|
||||
pub addr_store: SqliteAddressbookStore,
|
||||
pub cal_store: SqliteCalendarStore,
|
||||
pub principal_store: SqlitePrincipalStore,
|
||||
pub sub_store: SqliteStore,
|
||||
}
|
||||
|
||||
#[fixture]
|
||||
pub async fn test_store_context() -> TestStoreContext {
|
||||
let (send_addr, _recv) = tokio::sync::mpsc::channel(1);
|
||||
let (send_cal, _recv) = tokio::sync::mpsc::channel(1);
|
||||
let db = create_db_pool(":memory:", true).await.unwrap();
|
||||
|
||||
// Populate with test data
|
||||
let principal_store = SqlitePrincipalStore::new(db.clone());
|
||||
// Populate with test data
|
||||
principal_store
|
||||
.insert_principal(
|
||||
Principal {
|
||||
@@ -33,28 +44,11 @@ async fn get_test_db() -> SqlitePool {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
db
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TestStoreContext {
|
||||
pub db: SqlitePool,
|
||||
pub addr_store: SqliteAddressbookStore,
|
||||
pub cal_store: SqliteCalendarStore,
|
||||
pub principal_store: SqlitePrincipalStore,
|
||||
pub sub_store: SqliteStore,
|
||||
}
|
||||
|
||||
#[fixture]
|
||||
pub async fn test_store_context() -> TestStoreContext {
|
||||
let (send_addr, _recv) = tokio::sync::mpsc::channel(1);
|
||||
let (send_cal, _recv) = tokio::sync::mpsc::channel(1);
|
||||
let db = get_test_db().await;
|
||||
TestStoreContext {
|
||||
db: db.clone(),
|
||||
addr_store: SqliteAddressbookStore::new(db.clone(), send_addr, false),
|
||||
cal_store: SqliteCalendarStore::new(db.clone(), send_cal, false),
|
||||
principal_store: SqlitePrincipalStore::new(db.clone()),
|
||||
principal_store,
|
||||
sub_store: SqliteStore::new(db),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,3 +48,26 @@ Since the app tokens are random they use the faster `pbkdf2` algorithm.
|
||||
```sh
|
||||
cargo install --locked --git https://github.com/lennart-k/rustical
|
||||
```
|
||||
|
||||
## NixOS (community-maintained by [@PopeRigby](https://github.com/PopeRigby))
|
||||
|
||||
!!! warning
|
||||
The NixOS package is not maintained by myself but since I appreciate [@PopeRigby](https://github.com/PopeRigby)'s work on it I want to mention it.
|
||||
Since rustical's development is still quite active I **strongly** recommend installing from the `nixpkgs-unstable` branch.
|
||||
|
||||
In the `nixpkgs-unstable` you'll find a `rustical` package you can install.
|
||||
|
||||
There's also a service that has not been merged yet. If you know how to add modules from PRs in Nix
|
||||
you can already install it <https://github.com/NixOS/nixpkgs/pull/424188>
|
||||
and then setup rustical as a service:
|
||||
|
||||
```nix title="In your configuration.nix"
|
||||
services.rustical = {
|
||||
enable = true;
|
||||
package = inputs.rustical.legacyPackages.${pkgs.stdenv.hostPlatform.system}.rustical;
|
||||
settings = {
|
||||
# Settings the same as in config.toml but in Nix syntax
|
||||
# http.port = 3002;
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
@@ -32,7 +32,8 @@ use tracing::field::display;
|
||||
#[allow(
|
||||
clippy::too_many_arguments,
|
||||
clippy::too_many_lines,
|
||||
clippy::cognitive_complexity
|
||||
clippy::cognitive_complexity,
|
||||
clippy::missing_panics_doc
|
||||
)]
|
||||
pub fn make_app<
|
||||
AS: AddressbookStore + PrefixedCalendarStore,
|
||||
@@ -109,9 +110,9 @@ pub fn make_app<
|
||||
options(async || {
|
||||
let mut resp = Response::builder().status(StatusCode::OK);
|
||||
resp.headers_mut()
|
||||
.unwrap()
|
||||
.expect("this always works")
|
||||
.insert("DAV", HeaderValue::from_static("1"));
|
||||
resp.body(Body::empty()).unwrap()
|
||||
resp.body(Body::empty()).expect("empty body always works")
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ pub struct HealthArgs {}
|
||||
|
||||
/// Healthcheck for running rustical instance
|
||||
/// Currently just pings to see if it's reachable via HTTP
|
||||
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
||||
pub async fn cmd_health(http_config: HttpConfig, _health_args: HealthArgs) -> anyhow::Result<()> {
|
||||
let client = reqwest::ClientBuilder::new().build().unwrap();
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ pub struct MembershipArgs {
|
||||
command: MembershipCommand,
|
||||
}
|
||||
|
||||
pub async fn handle_membership_command(
|
||||
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
||||
pub async fn cmd_membership(
|
||||
user_store: &impl AuthenticationProvider,
|
||||
MembershipArgs { command }: MembershipArgs,
|
||||
) -> anyhow::Result<()> {
|
||||
|
||||
@@ -6,13 +6,17 @@ use clap::Parser;
|
||||
use rustical_caldav::CalDavConfig;
|
||||
use rustical_frontend::FrontendConfig;
|
||||
|
||||
pub mod health;
|
||||
mod health;
|
||||
pub mod membership;
|
||||
pub mod principals;
|
||||
mod principals;
|
||||
|
||||
pub use health::{HealthArgs, cmd_health};
|
||||
pub use principals::{PrincipalsArgs, cmd_principals};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct GenConfigArgs {}
|
||||
|
||||
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
||||
pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
|
||||
let config = Config {
|
||||
http: HttpConfig::default(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::membership::{MembershipArgs, handle_membership_command};
|
||||
use crate::{config::Config, get_data_stores};
|
||||
use super::membership::MembershipArgs;
|
||||
use crate::{config::Config, get_data_stores, membership::cmd_membership};
|
||||
use clap::{Parser, Subcommand};
|
||||
use figment::{
|
||||
Figment,
|
||||
@@ -58,6 +58,7 @@ enum Command {
|
||||
Membership(MembershipArgs),
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
||||
pub async fn cmd_principals(args: PrincipalsArgs) -> anyhow::Result<()> {
|
||||
let config: Config = Figment::new()
|
||||
.merge(Toml::file(&args.config_file))
|
||||
@@ -152,7 +153,7 @@ pub async fn cmd_principals(args: PrincipalsArgs) -> anyhow::Result<()> {
|
||||
println!("Principal {id} updated");
|
||||
}
|
||||
Command::Membership(args) => {
|
||||
handle_membership_command(principal_store.as_ref(), args).await?;
|
||||
cmd_membership(principal_store.as_ref(), args).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar_import.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar_import.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar_import.rs
|
||||
expression: body
|
||||
---
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
PRODID:RustiCal
|
||||
BEGIN:VTIMEZONE
|
||||
LAST-MODIFIED:20040110T032845Z
|
||||
TZID:US/Eastern
|
||||
BEGIN:DAYLIGHT
|
||||
DTSTART:20000404T020000
|
||||
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
|
||||
TZNAME:EDT
|
||||
TZOFFSETFROM:-0500
|
||||
TZOFFSETTO:-0400
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
DTSTART:20001026T020000
|
||||
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
|
||||
TZNAME:EST
|
||||
TZOFFSETFROM:-0400
|
||||
TZOFFSETTO:-0500
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:20060206T001121Z
|
||||
DTSTART;TZID=US/Eastern:20060104T140000
|
||||
DURATION:PT1H
|
||||
RECURRENCE-ID;TZID=US/Eastern:20060104T120000
|
||||
SUMMARY:Event #2 bis
|
||||
UID:[UID]
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:20060206T001102Z
|
||||
DTSTART;TZID=US/Eastern:20060102T100000
|
||||
DURATION:PT1H
|
||||
SUMMARY:Event #1
|
||||
Description:Go Steelers!
|
||||
UID:[UID]
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:20060206T001121Z
|
||||
DTSTART;TZID=US/Eastern:20060102T120000
|
||||
DURATION:PT1H
|
||||
RRULE:FREQ=DAILY;COUNT=5
|
||||
SUMMARY:Event #2
|
||||
UID:[UID]
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:cyrus@example.com
|
||||
ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
|
||||
DTSTAMP:20060206T001220Z
|
||||
DTSTART;TZID=US/Eastern:20060104T100000
|
||||
DURATION:PT1H
|
||||
LAST-MODIFIED:20060206T001330Z
|
||||
ORGANIZER:mailto:cyrus@example.com
|
||||
SEQUENCE:1
|
||||
STATUS:TENTATIVE
|
||||
SUMMARY:Event #3
|
||||
UID:[UID]
|
||||
END:VEVENT
|
||||
BEGIN:VTODO
|
||||
DTSTAMP:20060205T235335Z
|
||||
DUE;VALUE=DATE:20060104
|
||||
STATUS:NEEDS-ACTION
|
||||
SUMMARY:Task #1
|
||||
UID:[UID]
|
||||
BEGIN:VALARM
|
||||
ACTION:AUDIO
|
||||
TRIGGER;RELATED=START:-PT10M
|
||||
END:VALARM
|
||||
END:VTODO
|
||||
BEGIN:VTODO
|
||||
DTSTAMP:20060205T235300Z
|
||||
DUE;VALUE=DATE:20060106
|
||||
LAST-MODIFIED:20060205T235308Z
|
||||
SEQUENCE:1
|
||||
STATUS:NEEDS-ACTION
|
||||
SUMMARY:Task #2
|
||||
UID:[UID]
|
||||
BEGIN:VALARM
|
||||
ACTION:AUDIO
|
||||
TRIGGER;RELATED=START:-PT10M
|
||||
END:VALARM
|
||||
END:VTODO
|
||||
BEGIN:VTODO
|
||||
COMPLETED:20051223T122322Z
|
||||
DTSTAMP:20060205T235400Z
|
||||
DUE;VALUE=DATE:20051225
|
||||
LAST-MODIFIED:20060205T235308Z
|
||||
SEQUENCE:1
|
||||
STATUS:COMPLETED
|
||||
SUMMARY:Task #3
|
||||
UID:[UID]
|
||||
END:VTODO
|
||||
BEGIN:VTODO
|
||||
DTSTAMP:20060205T235600Z
|
||||
DUE;VALUE=DATE:20060101
|
||||
LAST-MODIFIED:20060205T235308Z
|
||||
SEQUENCE:1
|
||||
STATUS:CANCELLED
|
||||
SUMMARY:Task #4
|
||||
UID:[UID]
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar_import.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/addressbook.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/addressbook.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/addressbook.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/addressbook_import.rs
|
||||
expression: body
|
||||
---
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
FN:Simon Perreault
|
||||
N:Perreault;Simon;;;ing. jr,M.Sc.
|
||||
BDAY:--0203
|
||||
GENDER:M
|
||||
EMAIL;TYPE=work:simon.perreault@viagenie.ca
|
||||
UID:[UID]
|
||||
END:VCARD
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/addressbook_import.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/mod.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/mod.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
154
src/lib.rs
Normal file
154
src/lib.rs
Normal file
@@ -0,0 +1,154 @@
|
||||
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
||||
use crate::config::Config;
|
||||
use anyhow::Result;
|
||||
use app::make_app;
|
||||
use axum::ServiceExt;
|
||||
use axum::extract::Request;
|
||||
use clap::{Parser, Subcommand};
|
||||
use config::{DataStoreConfig, SqliteDataStoreConfig};
|
||||
use rustical_dav_push::DavPushController;
|
||||
use rustical_store::auth::AuthenticationProvider;
|
||||
use rustical_store::{
|
||||
AddressbookStore, CalendarStore, CollectionOperation, PrefixedCalendarStore, SubscriptionStore,
|
||||
};
|
||||
use rustical_store_sqlite::addressbook_store::SqliteAddressbookStore;
|
||||
use rustical_store_sqlite::calendar_store::SqliteCalendarStore;
|
||||
use rustical_store_sqlite::principal_store::SqlitePrincipalStore;
|
||||
use rustical_store_sqlite::{SqliteStore, create_db_pool};
|
||||
use setup_tracing::setup_tracing;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
use tower::Layer;
|
||||
use tower_http::normalize_path::NormalizePathLayer;
|
||||
use tracing::{info, warn};
|
||||
|
||||
pub mod app;
|
||||
mod commands;
|
||||
pub use commands::*;
|
||||
pub mod config;
|
||||
mod setup_tracing;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Args {
|
||||
#[arg(short, long, env, default_value = "/etc/rustical/config.toml")]
|
||||
pub config_file: String,
|
||||
#[arg(long, env, help = "Do no run database migrations (only for sql store)")]
|
||||
pub no_migrations: bool,
|
||||
|
||||
#[command(subcommand)]
|
||||
pub command: Option<Command>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Command {
|
||||
GenConfig(commands::GenConfigArgs),
|
||||
Principals(PrincipalsArgs),
|
||||
#[command(
|
||||
about = "Healthcheck for running instance (Used for HEALTHCHECK in Docker container)"
|
||||
)]
|
||||
Health(HealthArgs),
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_errors_doc)]
|
||||
pub async fn get_data_stores(
|
||||
migrate: bool,
|
||||
config: &DataStoreConfig,
|
||||
) -> Result<(
|
||||
Arc<impl AddressbookStore + PrefixedCalendarStore>,
|
||||
Arc<impl CalendarStore>,
|
||||
Arc<impl SubscriptionStore>,
|
||||
Arc<impl AuthenticationProvider>,
|
||||
Receiver<CollectionOperation>,
|
||||
)> {
|
||||
Ok(match &config {
|
||||
DataStoreConfig::Sqlite(SqliteDataStoreConfig {
|
||||
db_url,
|
||||
run_repairs,
|
||||
skip_broken,
|
||||
}) => {
|
||||
let db = create_db_pool(db_url, migrate).await?;
|
||||
|
||||
// Channel to watch for changes (for DAV Push)
|
||||
let (send, recv) = tokio::sync::mpsc::channel(1000);
|
||||
|
||||
let addressbook_store = Arc::new(SqliteAddressbookStore::new(
|
||||
db.clone(),
|
||||
send.clone(),
|
||||
*skip_broken,
|
||||
));
|
||||
let cal_store = Arc::new(SqliteCalendarStore::new(db.clone(), send, *skip_broken));
|
||||
if *run_repairs {
|
||||
info!("Running repair tasks");
|
||||
addressbook_store.repair_orphans().await?;
|
||||
cal_store.repair_invalid_version_4_0().await?;
|
||||
cal_store.repair_orphans().await?;
|
||||
}
|
||||
let subscription_store = Arc::new(SqliteStore::new(db.clone()));
|
||||
let principal_store = Arc::new(SqlitePrincipalStore::new(db));
|
||||
|
||||
// Validate all calendar objects
|
||||
for principal in principal_store.get_principals().await? {
|
||||
cal_store.validate_objects(&principal.id).await?;
|
||||
addressbook_store.validate_objects(&principal.id).await?;
|
||||
}
|
||||
|
||||
(
|
||||
addressbook_store,
|
||||
cal_store,
|
||||
subscription_store,
|
||||
principal_store,
|
||||
recv,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
||||
pub async fn cmd_default(args: Args, config: Config) -> Result<()> {
|
||||
setup_tracing(&config.tracing);
|
||||
|
||||
let (addr_store, cal_store, subscription_store, principal_store, update_recv) =
|
||||
get_data_stores(!args.no_migrations, &config.data_store).await?;
|
||||
|
||||
let mut tasks = vec![];
|
||||
|
||||
if config.dav_push.enabled {
|
||||
let dav_push_controller = DavPushController::new(
|
||||
config.dav_push.allowed_push_servers,
|
||||
subscription_store.clone(),
|
||||
);
|
||||
tasks.push(tokio::spawn(async move {
|
||||
dav_push_controller.notifier(update_recv).await;
|
||||
}));
|
||||
}
|
||||
|
||||
let app = make_app(
|
||||
addr_store.clone(),
|
||||
cal_store.clone(),
|
||||
subscription_store.clone(),
|
||||
principal_store.clone(),
|
||||
config.frontend.clone(),
|
||||
config.oidc.clone(),
|
||||
config.caldav,
|
||||
&config.nextcloud_login,
|
||||
config.dav_push.enabled,
|
||||
config.http.session_cookie_samesite_strict,
|
||||
config.http.payload_limit_mb,
|
||||
);
|
||||
let app = ServiceExt::<Request>::into_make_service(
|
||||
NormalizePathLayer::trim_trailing_slash().layer(app),
|
||||
);
|
||||
|
||||
let address = format!("{}:{}", config.http.host, config.http.port);
|
||||
let listener = tokio::net::TcpListener::bind(&address).await?;
|
||||
tasks.push(tokio::spawn(async move {
|
||||
info!("RustiCal serving on http://{address}");
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}));
|
||||
|
||||
for task in tasks {
|
||||
task.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
163
src/main.rs
163
src/main.rs
@@ -1,112 +1,12 @@
|
||||
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
||||
use crate::commands::health::{HealthArgs, cmd_health};
|
||||
use crate::config::Config;
|
||||
use anyhow::Result;
|
||||
use app::make_app;
|
||||
use axum::ServiceExt;
|
||||
use axum::extract::Request;
|
||||
use clap::{Parser, Subcommand};
|
||||
use commands::cmd_gen_config;
|
||||
use commands::principals::{PrincipalsArgs, cmd_principals};
|
||||
use config::{DataStoreConfig, SqliteDataStoreConfig};
|
||||
use clap::Parser;
|
||||
use figment::Figment;
|
||||
use figment::providers::{Env, Format, Toml};
|
||||
use rustical_dav_push::DavPushController;
|
||||
use rustical_store::auth::AuthenticationProvider;
|
||||
use rustical_store::{
|
||||
AddressbookStore, CalendarStore, CollectionOperation, PrefixedCalendarStore, SubscriptionStore,
|
||||
};
|
||||
use rustical_store_sqlite::addressbook_store::SqliteAddressbookStore;
|
||||
use rustical_store_sqlite::calendar_store::SqliteCalendarStore;
|
||||
use rustical_store_sqlite::principal_store::SqlitePrincipalStore;
|
||||
use rustical_store_sqlite::{SqliteStore, create_db_pool};
|
||||
use setup_tracing::setup_tracing;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
use tower::Layer;
|
||||
use tower_http::normalize_path::NormalizePathLayer;
|
||||
use tracing::{info, warn};
|
||||
|
||||
mod app;
|
||||
mod commands;
|
||||
mod config;
|
||||
#[cfg(test)]
|
||||
pub mod integration_tests;
|
||||
mod setup_tracing;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
#[arg(short, long, env, default_value = "/etc/rustical/config.toml")]
|
||||
config_file: String,
|
||||
#[arg(long, env, help = "Do no run database migrations (only for sql store)")]
|
||||
no_migrations: bool,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Option<Command>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum Command {
|
||||
GenConfig(commands::GenConfigArgs),
|
||||
Principals(PrincipalsArgs),
|
||||
#[command(
|
||||
about = "Healthcheck for running instance (Used for HEALTHCHECK in Docker container)"
|
||||
)]
|
||||
Health(HealthArgs),
|
||||
}
|
||||
|
||||
async fn get_data_stores(
|
||||
migrate: bool,
|
||||
config: &DataStoreConfig,
|
||||
) -> Result<(
|
||||
Arc<impl AddressbookStore + PrefixedCalendarStore>,
|
||||
Arc<impl CalendarStore>,
|
||||
Arc<impl SubscriptionStore>,
|
||||
Arc<impl AuthenticationProvider>,
|
||||
Receiver<CollectionOperation>,
|
||||
)> {
|
||||
Ok(match &config {
|
||||
DataStoreConfig::Sqlite(SqliteDataStoreConfig {
|
||||
db_url,
|
||||
run_repairs,
|
||||
skip_broken,
|
||||
}) => {
|
||||
let db = create_db_pool(db_url, migrate).await?;
|
||||
// Channel to watch for changes (for DAV Push)
|
||||
let (send, recv) = tokio::sync::mpsc::channel(1000);
|
||||
|
||||
let addressbook_store = Arc::new(SqliteAddressbookStore::new(
|
||||
db.clone(),
|
||||
send.clone(),
|
||||
*skip_broken,
|
||||
));
|
||||
let cal_store = Arc::new(SqliteCalendarStore::new(db.clone(), send, *skip_broken));
|
||||
if *run_repairs {
|
||||
info!("Running repair tasks");
|
||||
addressbook_store.repair_orphans().await?;
|
||||
cal_store.repair_invalid_version_4_0().await?;
|
||||
cal_store.repair_orphans().await?;
|
||||
}
|
||||
let subscription_store = Arc::new(SqliteStore::new(db.clone()));
|
||||
let principal_store = Arc::new(SqlitePrincipalStore::new(db));
|
||||
|
||||
// Validate all calendar objects
|
||||
for principal in principal_store.get_principals().await? {
|
||||
cal_store.validate_objects(&principal.id).await?;
|
||||
addressbook_store.validate_objects(&principal.id).await?;
|
||||
}
|
||||
|
||||
(
|
||||
addressbook_store,
|
||||
cal_store,
|
||||
subscription_store,
|
||||
principal_store,
|
||||
recv,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
use rustical::config::Config;
|
||||
use rustical::{Args, Command};
|
||||
use rustical::{cmd_default, cmd_gen_config, cmd_health, cmd_principals};
|
||||
use tracing::warn;
|
||||
|
||||
#[tokio::main(flavor = "multi_thread")]
|
||||
async fn main() -> Result<()> {
|
||||
@@ -120,60 +20,15 @@ async fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
match args.command {
|
||||
Some(Command::GenConfig(gen_config_args)) => cmd_gen_config(gen_config_args)?,
|
||||
Some(Command::Principals(principals_args)) => cmd_principals(principals_args).await?,
|
||||
Some(Command::GenConfig(gen_config_args)) => cmd_gen_config(gen_config_args),
|
||||
Some(Command::Principals(principals_args)) => cmd_principals(principals_args).await,
|
||||
Some(Command::Health(health_args)) => {
|
||||
let config: Config = parse_config()?;
|
||||
cmd_health(config.http, health_args).await?;
|
||||
cmd_health(config.http, health_args).await
|
||||
}
|
||||
None => {
|
||||
let config: Config = parse_config()?;
|
||||
|
||||
setup_tracing(&config.tracing);
|
||||
|
||||
let (addr_store, cal_store, subscription_store, principal_store, update_recv) =
|
||||
get_data_stores(!args.no_migrations, &config.data_store).await?;
|
||||
|
||||
let mut tasks = vec![];
|
||||
|
||||
if config.dav_push.enabled {
|
||||
let dav_push_controller = DavPushController::new(
|
||||
config.dav_push.allowed_push_servers,
|
||||
subscription_store.clone(),
|
||||
);
|
||||
tasks.push(tokio::spawn(async move {
|
||||
dav_push_controller.notifier(update_recv).await;
|
||||
}));
|
||||
}
|
||||
|
||||
let app = make_app(
|
||||
addr_store.clone(),
|
||||
cal_store.clone(),
|
||||
subscription_store.clone(),
|
||||
principal_store.clone(),
|
||||
config.frontend.clone(),
|
||||
config.oidc.clone(),
|
||||
config.caldav,
|
||||
&config.nextcloud_login,
|
||||
config.dav_push.enabled,
|
||||
config.http.session_cookie_samesite_strict,
|
||||
config.http.payload_limit_mb,
|
||||
);
|
||||
let app = ServiceExt::<Request>::into_make_service(
|
||||
NormalizePathLayer::trim_trailing_slash().layer(app),
|
||||
);
|
||||
|
||||
let address = format!("{}:{}", config.http.host, config.http.port);
|
||||
let listener = tokio::net::TcpListener::bind(&address).await?;
|
||||
tasks.push(tokio::spawn(async move {
|
||||
info!("RustiCal serving on http://{address}");
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}));
|
||||
|
||||
for task in tasks {
|
||||
task.await?;
|
||||
}
|
||||
cmd_default(args, config).await
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
0
tests/common/mod.rs
Normal file
0
tests/common/mod.rs
Normal file
@@ -1,4 +1,4 @@
|
||||
use crate::integration_tests::{ResponseExtractString, get_app};
|
||||
use super::{ResponseExtractString, get_app};
|
||||
use axum::body::Body;
|
||||
use axum::extract::Request;
|
||||
use headers::{Authorization, HeaderMapExt};
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::integration_tests::{ResponseExtractString, get_app};
|
||||
use super::{ResponseExtractString, get_app};
|
||||
use axum::body::Body;
|
||||
use axum::extract::Request;
|
||||
use headers::{Authorization, HeaderMapExt};
|
||||
@@ -1,3 +1,4 @@
|
||||
use super::{ResponseExtractString, calendar::mkcalendar_template, get_app};
|
||||
use axum::body::Body;
|
||||
use headers::{Authorization, HeaderMapExt};
|
||||
use http::{Request, StatusCode};
|
||||
@@ -6,10 +7,6 @@ use rustical_store::CalendarMetadata;
|
||||
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
|
||||
use tower::ServiceExt;
|
||||
|
||||
use crate::integration_tests::{
|
||||
ResponseExtractString, caldav::calendar::mkcalendar_template, get_app,
|
||||
};
|
||||
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
async fn test_put_invalid(
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::integration_tests::{ResponseExtractString, get_app};
|
||||
use super::{ResponseExtractString, get_app};
|
||||
use axum::body::Body;
|
||||
use axum::extract::Request;
|
||||
use headers::{Authorization, HeaderMapExt};
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::integration_tests::{ResponseExtractString, get_app};
|
||||
use super::{ResponseExtractString, get_app};
|
||||
use axum::body::Body;
|
||||
use axum::extract::Request;
|
||||
use headers::{Authorization, HeaderMapExt};
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/caldav/calendar.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar.rs
|
||||
source: tests/integration_tests/caldav/calendar.rs
|
||||
expression: body
|
||||
---
|
||||
BEGIN:VCALENDAR
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/caldav/calendar.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar.rs
|
||||
source: tests/integration_tests/caldav/calendar.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar.rs
|
||||
source: tests/integration_tests/caldav/calendar.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar.rs
|
||||
source: tests/integration_tests/caldav/calendar.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar_import.rs
|
||||
source: tests/integration_tests/caldav/calendar_import.rs
|
||||
expression: body
|
||||
---
|
||||
BEGIN:VCALENDAR
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/caldav/calendar_import.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar_import.rs
|
||||
source: tests/integration_tests/caldav/calendar_import.rs
|
||||
expression: body
|
||||
---
|
||||
BEGIN:VCALENDAR
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/caldav/calendar_import.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar_report.rs
|
||||
source: tests/integration_tests/caldav/calendar_report.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar_report.rs
|
||||
source: tests/integration_tests/caldav/calendar_report.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/calendar_report.rs
|
||||
source: tests/integration_tests/caldav/calendar_report.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/mod.rs
|
||||
source: tests/integration_tests/caldav/mod.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/mod.rs
|
||||
source: tests/integration_tests/caldav/mod.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/caldav/mod.rs
|
||||
source: tests/integration_tests/caldav/mod.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::integration_tests::{ResponseExtractString, get_app};
|
||||
use super::{ResponseExtractString, get_app};
|
||||
use axum::body::Body;
|
||||
use axum::extract::Request;
|
||||
use headers::{Authorization, HeaderMapExt};
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::integration_tests::{ResponseExtractString, get_app};
|
||||
use super::{ResponseExtractString, get_app};
|
||||
use axum::body::Body;
|
||||
use axum::extract::Request;
|
||||
use headers::{Authorization, HeaderMapExt};
|
||||
@@ -27,11 +27,10 @@ async fn test_import(
|
||||
.body(Body::from(
|
||||
r"BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
FN:Simon Perreault
|
||||
N:Perreault;Simon;;;ing. jr,M.Sc.
|
||||
FN:John Doe
|
||||
N:Doe;John;;;,
|
||||
BDAY:--0203
|
||||
GENDER:M
|
||||
EMAIL;TYPE=work:simon.perreault@viagenie.ca
|
||||
END:VCARD",
|
||||
))
|
||||
.unwrap()
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::integration_tests::{ResponseExtractString, get_app};
|
||||
use super::{ResponseExtractString, get_app};
|
||||
use axum::body::Body;
|
||||
use axum::extract::Request;
|
||||
use headers::{Authorization, HeaderMapExt};
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/carddav/addressbook.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/carddav/addressbook.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/carddav/addressbook.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/addressbook.rs
|
||||
source: tests/integration_tests/carddav/addressbook.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/addressbook.rs
|
||||
source: tests/integration_tests/carddav/addressbook.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/addressbook.rs
|
||||
source: tests/integration_tests/carddav/addressbook.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
source: tests/integration_tests/carddav/addressbook_import.rs
|
||||
expression: body
|
||||
---
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
FN:John Doe
|
||||
N:Doe;John;;;,
|
||||
BDAY:--0203
|
||||
GENDER:M
|
||||
UID:[UID]
|
||||
END:VCARD
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/carddav/addressbook_import.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/carddav/mod.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: src/integration_tests/carddav/mod.rs
|
||||
source: tests/integration_tests/carddav/mod.rs
|
||||
expression: body
|
||||
---
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/integration_tests/carddav/mod.rs
|
||||
expression: body
|
||||
---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{app::make_app, config::NextcloudLoginConfig};
|
||||
use axum::extract::Request;
|
||||
use axum::{body::Body, response::Response};
|
||||
use rstest::rstest;
|
||||
use rustical::{app::make_app, config::NextcloudLoginConfig};
|
||||
use rustical_caldav::CalDavConfig;
|
||||
use rustical_frontend::FrontendConfig;
|
||||
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
|
||||
1
tests/light_integrations.rs
Normal file
1
tests/light_integrations.rs
Normal file
@@ -0,0 +1 @@
|
||||
mod integration_tests;
|
||||
Reference in New Issue
Block a user