hagrid-keyserver--hagrid/src/main.rs

89 lines
2.2 KiB
Rust
Raw Normal View History

2018-08-16 18:35:19 +00:00
#![feature(plugin, decl_macro, custom_derive)]
#![plugin(rocket_codegen)]
#![recursion_limit = "1024"]
#![feature(try_from)]
extern crate serde;
#[macro_use] extern crate serde_derive;
extern crate serde_json;
extern crate time;
extern crate url;
extern crate hex;
2018-09-19 20:24:38 +00:00
#[cfg(not(test))] extern crate rocket;
2018-08-16 18:35:19 +00:00
#[cfg(test)] extern crate rocket;
2018-09-19 20:24:38 +00:00
extern crate rocket_contrib;
2018-08-16 18:35:19 +00:00
extern crate multipart;
2018-09-19 20:24:38 +00:00
extern crate openpgp;
2018-08-16 18:35:19 +00:00
#[macro_use] extern crate error_chain;
#[macro_use] extern crate log;
extern crate rand;
extern crate tempfile;
extern crate parking_lot;
extern crate structopt;
extern crate lettre;
extern crate lettre_email;
2018-08-16 18:35:19 +00:00
mod web;
mod database;
mod types;
mod mail;
2018-08-16 18:35:19 +00:00
mod errors {
error_chain!{
foreign_links {
Fmt(::std::fmt::Error);
Io(::std::io::Error);
Json(::serde_json::Error);
Persist(::tempfile::PersistError);
2018-09-19 20:24:38 +00:00
RktConfig(::rocket::config::ConfigError);
StringUtf8Error(::std::string::FromUtf8Error);
StrUtf8Error(::std::str::Utf8Error);
HexError(::hex::FromHexError);
SendmailError(::lettre::sendmail::error::Error);
2018-08-16 18:35:19 +00:00
}
}
}
use errors::*;
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "garbage", about = "Garbage Pile - The verifying OpenPGP key server.")]
2018-09-19 20:24:38 +00:00
pub struct Opt {
/// More verbose output. Disabled when running as daemon.
2018-08-16 18:35:19 +00:00
#[structopt(short = "v", long = "verbose")]
2018-09-19 20:24:38 +00:00
verbose: bool,
/// Daemonize after startup.
2018-08-16 18:35:19 +00:00
#[structopt(short = "d", long = "daemon")]
daemon: bool,
/// Base directory
#[structopt(parse(from_os_str))]
base: PathBuf,
2018-09-19 20:24:38 +00:00
/// Port and address to listen on.
#[structopt(short = "l", long = "listen", default_value = "0.0.0.0:8080")]
2018-08-16 18:35:19 +00:00
listen: String,
/// FQDN of the server. Used in templates.
#[structopt(short = "D", long = "domain", default_value = "localhost")]
domain: String,
2018-08-16 18:35:19 +00:00
}
fn main() {
2018-09-19 20:24:38 +00:00
use database::{Filesystem, Polymorphic};
2018-08-16 18:35:19 +00:00
let opt = Opt::from_args();
2018-09-19 20:24:38 +00:00
println!("{:#?}", opt);
if !opt.base.is_absolute() {
panic!("Base directory must be absolute");
}
2018-08-16 18:35:19 +00:00
2018-09-19 20:24:38 +00:00
let db = Filesystem::new(opt.base.clone()).unwrap();
web::serve(&opt, Polymorphic::Filesystem(db)).unwrap();
}