feat: add paris for pretty logging

This commit is contained in:
Bart van der Braak 2023-11-12 22:48:12 +01:00
parent 00de6f1e4f
commit ba0548febc
3 changed files with 19 additions and 3 deletions

7
Cargo.lock generated
View file

@ -860,6 +860,7 @@ dependencies = [
"clap",
"futures",
"openssl",
"paris",
"tokio",
]
@ -1063,6 +1064,12 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "paris"
version = "1.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fecab3723493c7851f292cb060f3ee1c42f19b8d749345d0d7eaf3fd19aa62d"
[[package]]
name = "parking"
version = "2.2.0"

View file

@ -15,6 +15,7 @@ azure_identity = "0.17.0"
azure_security_keyvault = "0.17.0"
clap = { version = "4.4.8", features = ["derive"] }
futures = "0.3.29"
paris = { version = "1.5.15", features = ["macros"] }
tokio = {version = "1.34.0", features = ["full"]}
[target.'cfg(all(target_os = "linux", any(target_env = "musl", target_arch = "arm", target_arch = "aarch64")))'.dependencies]

View file

@ -9,6 +9,8 @@ use std::io::Write;
use std::sync::Arc;
use tokio::sync::mpsc;
use tokio::sync::Semaphore;
use paris::Logger;
// use paris::error;
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
@ -147,18 +149,24 @@ mod tests {
#[tokio::main]
async fn main() -> Result<()> {
let opts: Opts = Opts::parse();
let mut log = Logger::new();
let vault_url = format!("https://{}.vault.azure.net", opts.vault_name);
println!("Fetching secrets from Key Vault: {}", opts.vault_name);
log.loading("Detecting credentials.");
let credential = DefaultAzureCredential::default();
let client = KeyvaultClient::new(&vault_url, std::sync::Arc::new(credential))
.context("Failed to create KeyvaultClient")?;
log.success("Detected credentials.");
log.loading(format!("Fetching secrets from Key Vault: <blue>{}</>", opts.vault_name));
let secrets = fetch_secrets_from_key_vault(&client, opts.filter.as_deref()).await?;
println!("Creating output file: {}", opts.output);
log.success(format!("Fetched secrets from Key Vault: <blue>{}</>", opts.vault_name));
log.loading(format!("Creating output file: <blue>{}</>", opts.output));
create_env_file(secrets, &opts.output)?;
log.success(format!("Created output file: <blue>{}</>", opts.output));
println!("Process completed successfully!");
log.success("Done.");
Ok(())
}