2024-09-06 17:59:04 +02:00
|
|
|
use anyhow::Result;
|
|
|
|
use clap::Parser;
|
|
|
|
use libpt::log::{debug, info};
|
|
|
|
|
|
|
|
use wooly_vault::config::ENV_SECRET;
|
|
|
|
use wooly_vault::{challenge::select_and_start, config::Config, vault::Vault};
|
2024-09-05 17:18:08 +02:00
|
|
|
|
|
|
|
#[tokio::main(flavor = "current_thread")]
|
2024-09-06 17:59:04 +02:00
|
|
|
async fn main() -> Result<()> {
|
|
|
|
let conf = Config::parse();
|
|
|
|
|
2024-09-05 17:18:08 +02:00
|
|
|
let _logger = libpt::log::Logger::builder()
|
2024-09-06 17:59:04 +02:00
|
|
|
.set_level(conf.verbosity.level())
|
2024-09-05 17:18:08 +02:00
|
|
|
.display_time(false)
|
|
|
|
.build()?;
|
2024-09-06 17:59:04 +02:00
|
|
|
debug!("logger active");
|
|
|
|
info!("Configuration: {conf:?}");
|
2024-09-05 17:18:08 +02:00
|
|
|
|
2024-09-06 17:59:04 +02:00
|
|
|
let secret = get_secret()?;
|
|
|
|
let v = Vault::new(&secret);
|
2024-09-05 17:18:08 +02:00
|
|
|
|
2024-09-06 17:59:04 +02:00
|
|
|
select_and_start(conf.challenge, conf, v).await?;
|
2024-09-05 17:18:08 +02:00
|
|
|
|
2024-09-06 17:59:04 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
2024-09-05 17:18:08 +02:00
|
|
|
|
2024-09-06 17:59:04 +02:00
|
|
|
fn get_secret() -> Result<String> {
|
|
|
|
if let Ok(v) = std::env::var(ENV_SECRET) {
|
|
|
|
return Ok(v);
|
|
|
|
}
|
2024-09-05 17:18:08 +02:00
|
|
|
|
2024-09-06 17:59:04 +02:00
|
|
|
println!("Input the secret and press enter");
|
|
|
|
let mut buf: String = String::new();
|
|
|
|
std::io::stdin().read_line(&mut buf)?;
|
|
|
|
Ok(buf.trim().to_string())
|
2024-09-05 17:18:08 +02:00
|
|
|
}
|
|
|
|
|
2024-09-06 17:59:04 +02:00
|
|
|
fn select_challenge() -> Result<u16> {
|
2024-09-05 17:18:08 +02:00
|
|
|
let mut buf: String = String::new();
|
|
|
|
std::io::stdin().read_line(&mut buf)?;
|
|
|
|
Ok(buf.trim().parse()?)
|
2024-09-05 15:49:56 +02:00
|
|
|
}
|