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

101 lines
2.4 KiB
Rust
Raw Normal View History

2018-12-25 21:35:04 +00:00
#![feature(proc_macro_hygiene, plugin, decl_macro)]
2018-08-16 18:35:19 +00:00
#![recursion_limit = "1024"]
#![feature(try_from)]
extern crate serde;
2019-02-07 19:58:31 +00:00
#[macro_use]
extern crate serde_derive;
2018-08-16 18:35:19 +00:00
extern crate serde_json;
2019-02-07 19:58:31 +00:00
extern crate hex;
2018-08-16 18:35:19 +00:00
extern crate time;
extern crate url;
2018-09-19 20:24:38 +00:00
2019-02-07 19:58:31 +00:00
#[macro_use]
extern crate rocket;
2018-08-16 18:35:19 +00:00
extern crate multipart;
2019-02-07 19:58:31 +00:00
extern crate rocket_contrib;
2018-09-19 20:24:38 +00:00
2018-11-25 14:03:27 +00:00
extern crate sequoia_openpgp;
2019-02-07 19:58:31 +00:00
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate log;
extern crate base64;
extern crate handlebars;
extern crate lettre;
extern crate lettre_email;
2019-02-07 19:58:31 +00:00
extern crate parking_lot;
extern crate rand;
extern crate structopt;
extern crate tempfile;
extern crate pathdiff;
2018-08-16 18:35:19 +00:00
mod database;
mod mail;
2019-02-07 19:58:31 +00:00
mod types;
mod web;
2018-08-16 18:35:19 +00:00
mod errors {
2019-02-07 19:58:31 +00:00
error_chain! {
2018-08-16 18:35:19 +00:00
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)]
2019-02-07 19:58:31 +00:00
#[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,
2019-02-07 19:58:31 +00:00
#[structopt(
short = "F",
long = "from",
default_value = "noreply@localhost"
)]
from: String,
2019-02-07 19:58:31 +00:00
}
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();
}