← history for src/main.rs
35bda350src/main.rs39 lines⬡ raw↓ download
 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
/**
 * Config Vault - cfgvault
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Paolo Lulli <kevwe.com>
 * @copyright Paolo Lulli 2026
 */

mod config;
mod handlers;
mod server;
mod tls;
mod vault;

use clap::Parser;
use std::net::TcpListener;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let args = config::Cli::parse();
    let filename = if args.config_file.is_empty() {
        env!("HOME").to_string() + "/.config/cfgvault.json"
    } else {
        args.config_file
    };

    println!("Use config file: {}", filename);
    let config = config::read_config(filename);

    vault::unlock(&config);

    let listener = TcpListener::bind(&config.endpoint).expect("Failed to bind port");

    let port = listener.local_addr()?.port();
    println!("Listen on port {}", port);
    server::run(config, listener)?.await
}