-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
86 lines (75 loc) · 1.98 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use std::fs::File;
use std::net::SocketAddr;
use std::path::PathBuf;
use clap::Parser;
use crate::db::AtomicDatabase;
use crate::server::{Tls, UserConfig};
mod db;
mod error;
mod isbn;
mod mail;
mod provider;
mod server;
mod util;
/// Schiller Library Backend
#[derive(Parser)]
struct Args {
/// Ip and port for the webserver
host: SocketAddr,
/// Externally visible domain of this webserver
#[arg(long)]
domain: Option<String>,
/// Path to the oauth config
#[arg(long)]
auth: Option<PathBuf>,
/// Directory for the static assets
#[arg(short, long, default_value = "lib-view/build")]
assets: PathBuf,
/// Path to the database
#[arg(short, long, default_value = "lib.json")]
db: PathBuf,
/// Path to the users file
#[arg(long)]
user_file: Option<PathBuf>,
/// CSV row delimiter for the users file
#[arg(long, default_value_t = ',')]
user_delimiter: char,
/// Path to the TLS certificate
#[arg(long)]
cert: PathBuf,
/// Path to the TLS key
#[arg(long)]
key: PathBuf,
}
#[tokio::main]
async fn main() {
util::logging();
let Args {
host,
domain,
auth,
assets,
db,
user_file,
user_delimiter,
cert,
key,
} = Args::parse();
let auth = auth.map(|auth| {
serde_json::from_reader(File::open(auth).expect("No OAuth Config found")).unwrap()
});
assert!(user_delimiter.is_ascii());
let delimiter = user_delimiter as u8;
if let Some(user_file) = &user_file {
assert!(user_file.exists(), "User file not found: {user_file:?}");
}
let user = user_file.map(|file| UserConfig { file, delimiter });
let domain = domain.unwrap_or_else(|| host.to_string());
let db = if db.exists() {
AtomicDatabase::load(&db).unwrap()
} else {
AtomicDatabase::create(&db).unwrap()
};
let tls = Tls { cert, key };
server::start(host, &domain, db, assets, tls, auth, user).await;
}