main.rs
use clap::*;
use elpe::*;
use serde_derive::*;
use std::path::PathBuf;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
mod server;
#[derive(Deserialize)]
pub struct Config {
pgp_home: PathBuf,
store_path: PathBuf,
package_index: String,
user: String,
}
/// Elpe
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Path to the configuration file
#[arg(short, long)]
config: PathBuf,
}
fn main() {
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| String::new().into()),
)
.with(tracing_subscriber::fmt::layer())
.init();
let args = Args::parse();
let config: Config = toml::from_str(&std::fs::read_to_string(&args.config).unwrap()).unwrap();
let container_channel = crate::container::serve(&config.user, &config.store_path);
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async move {
privdrop::PrivDrop::default()
.user(&config.user)
.apply()
.unwrap();
let elpe = server::Elpe::new(
Client::new(&config.pgp_home, &config.store_path, &config.package_index),
container_channel,
);
let addr = "0.0.0.0:50051".parse().unwrap();
elpe.serve(addr).await
})
}