2022-02-08 10:36:22 +00:00
|
|
|
mod controller;
|
2022-02-26 15:27:16 +00:00
|
|
|
mod database;
|
2022-05-27 07:48:32 +00:00
|
|
|
mod engine;
|
|
|
|
mod server;
|
2022-02-08 10:36:22 +00:00
|
|
|
|
2022-02-26 15:27:16 +00:00
|
|
|
use std::collections::HashMap;
|
2022-05-27 07:48:32 +00:00
|
|
|
use std::option::Option;
|
|
|
|
use std::process::{ExitCode, Termination};
|
2022-02-26 15:27:16 +00:00
|
|
|
|
|
|
|
use anyhow::Result;
|
2022-05-27 07:48:32 +00:00
|
|
|
use clap::{Parser, Subcommand};
|
2022-02-26 15:27:16 +00:00
|
|
|
use parking_lot::RwLock;
|
|
|
|
|
|
|
|
pub type CsrfMap = RwLock<HashMap<String, String>>;
|
2022-02-08 10:36:22 +00:00
|
|
|
|
2022-05-27 07:48:32 +00:00
|
|
|
#[repr(u8)]
|
|
|
|
enum ServerResult {
|
|
|
|
Success = 0,
|
|
|
|
Failure = 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Termination for ServerResult {
|
|
|
|
fn report(self) -> ExitCode {
|
|
|
|
ExitCode::from(self as u8)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 10:36:22 +00:00
|
|
|
#[derive(Parser)]
|
2022-05-27 07:48:32 +00:00
|
|
|
#[clap(version)]
|
2022-02-08 10:36:22 +00:00
|
|
|
struct Args {
|
2022-05-27 07:48:32 +00:00
|
|
|
#[clap(subcommand)]
|
|
|
|
command: Command,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
enum Command {
|
|
|
|
/// Start the server
|
|
|
|
Run {
|
|
|
|
#[clap(short, long)]
|
|
|
|
database: String,
|
|
|
|
|
|
|
|
#[clap(short, long)]
|
|
|
|
url: String,
|
|
|
|
|
|
|
|
#[clap(short, long)]
|
|
|
|
port: u16,
|
|
|
|
},
|
|
|
|
|
|
|
|
/// Initialize the database and/or regenerate public identities
|
|
|
|
Init {
|
|
|
|
#[clap(short, long)]
|
|
|
|
database: String,
|
|
|
|
},
|
2022-02-08 10:36:22 +00:00
|
|
|
|
2022-05-27 07:48:32 +00:00
|
|
|
/// Control API keys
|
|
|
|
Api {
|
|
|
|
#[clap(short, long)]
|
|
|
|
database: String,
|
|
|
|
|
|
|
|
#[clap(short, long)]
|
|
|
|
generate: bool,
|
|
|
|
|
|
|
|
#[clap(short, long)]
|
|
|
|
revoke: Option<String>,
|
|
|
|
|
|
|
|
#[clap(short = 'R', long)]
|
|
|
|
revoke_all: bool,
|
|
|
|
},
|
2022-02-26 15:27:16 +00:00
|
|
|
}
|
2022-02-08 10:36:22 +00:00
|
|
|
|
2022-02-26 15:27:16 +00:00
|
|
|
fn setup_default_subscriber() -> Result<()> {
|
2022-05-27 07:48:32 +00:00
|
|
|
tracing_subscriber::fmt().pretty().init();
|
|
|
|
|
|
|
|
std::panic::set_hook(Box::new(|panic| {
|
|
|
|
if let Some(location) = panic.location() {
|
|
|
|
tracing::error!(
|
|
|
|
message = %panic,
|
|
|
|
panic.file = location.file(),
|
|
|
|
panic.line = location.line(),
|
|
|
|
panic.column = location.column(),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
tracing::error!(message = %panic);
|
|
|
|
}
|
|
|
|
}));
|
2022-02-08 10:36:22 +00:00
|
|
|
|
2022-02-26 15:27:16 +00:00
|
|
|
Ok(())
|
2022-02-08 10:36:22 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 07:48:32 +00:00
|
|
|
fn main() -> ServerResult {
|
|
|
|
if setup_default_subscriber().is_err() {
|
|
|
|
return ServerResult::Failure;
|
|
|
|
}
|
2022-02-08 10:36:22 +00:00
|
|
|
|
2022-05-27 07:48:32 +00:00
|
|
|
let args = Args::parse();
|
2022-02-08 10:36:22 +00:00
|
|
|
|
2022-05-27 07:48:32 +00:00
|
|
|
match args.command {
|
|
|
|
Command::Init { database } => {}
|
|
|
|
Command::Run {
|
|
|
|
database,
|
|
|
|
port,
|
|
|
|
url,
|
|
|
|
} => {}
|
|
|
|
Command::Api {
|
|
|
|
database,
|
|
|
|
generate,
|
|
|
|
revoke,
|
|
|
|
revoke_all,
|
|
|
|
} => {}
|
|
|
|
}
|
2022-02-08 10:36:22 +00:00
|
|
|
|
2022-05-27 07:48:32 +00:00
|
|
|
ServerResult::Success
|
2022-02-08 10:36:22 +00:00
|
|
|
}
|