From c12b9cde6cfbd528599bb27ba27830b012ce22f6 Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Mon, 6 Nov 2023 16:48:13 -0600 Subject: [PATCH] feat: added spinners Signed-off-by: Alex Jones --- Cargo.lock | 170 ++++++++++++++++++++++++++++++----- Cargo.toml | 1 + src/analyze/mod.rs | 39 +++++--- src/analyzer/ebs_analyzer.rs | 6 -- src/analyzer/rds_analyzer.rs | 6 -- src/analyzer/s3_analyzer.rs | 6 -- src/analyzer/sts_analyzer.rs | 7 -- 7 files changed, 176 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c693d4..199bc24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,7 +61,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -71,7 +71,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1049,7 +1049,20 @@ checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" dependencies = [ "is-terminal", "lazy_static", - "windows-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "console" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.45.0", ] [[package]] @@ -1128,6 +1141,12 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "errno" version = "0.3.5" @@ -1135,7 +1154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1421,6 +1440,28 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "indicatif" +version = "0.17.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb28741c9db9a713d93deb3bb9515c20788cef5815265bee4980e87bde7e0f25" +dependencies = [ + "console", + "instant", + "number_prefix", + "portable-atomic", + "unicode-width", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "is-terminal" version = "0.4.9" @@ -1429,12 +1470,12 @@ checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", "rustix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] name = "isotope" -version = "0.0.5" +version = "0.0.6" dependencies = [ "async-trait", "aws-config", @@ -1454,6 +1495,7 @@ dependencies = [ "clap", "colored", "futures", + "indicatif", "serde", "serde_json", "simple-home-dir", @@ -1544,7 +1586,7 @@ checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1576,6 +1618,12 @@ dependencies = [ "libc", ] +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + [[package]] name = "object" version = "0.32.1" @@ -1623,7 +1671,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -1664,6 +1712,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "portable-atomic" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bccab0e7fd7cc19f820a1c8c91720af652d0c88dc9664dd72aef2614f04af3b" + [[package]] name = "proc-macro2" version = "1.0.69" @@ -1746,7 +1800,7 @@ dependencies = [ "libc", "spin 0.9.8", "untrusted 0.9.0", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1774,7 +1828,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1832,7 +1886,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1948,7 +2002,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "509fcbd8f28460b50b91c057bbc479dc0257f470f94c4564beb38c22c19fdaae" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1983,7 +2037,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2079,7 +2133,7 @@ dependencies = [ "signal-hook-registry", "socket2 0.5.4", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2228,6 +2282,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + [[package]] name = "untrusted" version = "0.7.1" @@ -2388,13 +2448,37 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", ] [[package]] @@ -2403,51 +2487,93 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index 7d50e6a..45a86fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,7 @@ aws-sdk-rds = "0.34.0" aws-sdk-ebs = "0.35.0" aws-sdk-ec2 = "0.35.0" aws-types = "0.57.1" +indicatif = "0.17.7" # Config for 'cargo dist' [workspace.metadata.dist] diff --git a/src/analyze/mod.rs b/src/analyze/mod.rs index 9a9e01c..5811ddd 100644 --- a/src/analyze/mod.rs +++ b/src/analyze/mod.rs @@ -7,10 +7,12 @@ use aws_config::meta::region::{ProvideRegion, RegionProviderChain}; use colored::Colorize; use std::collections::hash_map::Entry; use std::collections::HashMap; - +use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use std::error::Error; use std::sync::mpsc; use std::sync::mpsc::{Receiver, Sender}; +use std::thread; +use std::time::Duration; pub async fn list_analyzers() -> Result<(), Box> { // Setup available providers @@ -38,20 +40,14 @@ pub async fn run_analysis( let config = aws_config::from_env().region(region_provider).load().await; // Setup bedrock let bedrock_client = bedrock::BedrockClient::new(config.clone()); - - println!( - "Current AWS region: {}", - RegionProviderChain::default_provider() - .region() - .await - .unwrap() - .as_ref() - .yellow() - ); // Create channels let (tx, rx): (Sender>, Receiver>) = mpsc::channel(); let analyzers: Vec> = analyzer::generate_analyzers(config.clone()); + // Progress bars + let m = MultiProgress::new(); + + match selected_analyzer { Some(analyzer_arg) => { let filtered_analyzer = &analyzers @@ -60,11 +56,12 @@ pub async fn run_analysis( match filtered_analyzer { Some(x) => { let thread_tx = tx.clone(); - let response = x.run().await; + match response { Some(resp_results) => { thread_tx.send(resp_results).unwrap(); + } None => { thread_tx.send(vec![AnalysisResults::new()]).unwrap(); @@ -78,21 +75,38 @@ pub async fn run_analysis( let mut tasks = vec![]; // Generate threads let mut count = 0; + let alen = analyzers.len(); for current_analyzer in analyzers { + let pb = m.add(ProgressBar::new(count)); + pb.enable_steady_tick(Duration::from_millis(200)); + pb.set_style( + ProgressStyle::with_template("{prefix:.dim.bold} {spinner} {wide_msg}") + .unwrap() + .tick_chars("/|\\- "), + ); + + pb.set_prefix(format!("[{}/{}]", count + 1, alen)); + pb.set_message(format!("Starting {} analyzer", current_analyzer.get_name())); + let thread_tx = tx.clone(); tasks.push(tokio::spawn(async move { + pb.inc(1); let response = current_analyzer.run().await; + pb.finish_with_message("done..."); match response { Some(resp_results) => { thread_tx.send(resp_results).unwrap(); + pb.finish(); } None => { thread_tx.send(vec![AnalysisResults::new()]).unwrap(); + } } })); count += 1; } + let mut results: Vec = vec![]; // Aggregate results for _n in 0..count { @@ -102,6 +116,7 @@ pub async fn run_analysis( for task in tasks { task.await.unwrap(); } + m.clear().unwrap(); let mut processed_results: HashMap> = HashMap::new(); // generate Vectors aligned to each analyzer type diff --git a/src/analyzer/ebs_analyzer.rs b/src/analyzer/ebs_analyzer.rs index 683efde..bc877eb 100644 --- a/src/analyzer/ebs_analyzer.rs +++ b/src/analyzer/ebs_analyzer.rs @@ -13,12 +13,6 @@ pub struct EbsAnalyzer { #[async_trait] impl analyzer_trait::Analyzer for EbsAnalyzer { async fn run(&self) -> Option> { - println!( - "{} {} {}", - "Running".green(), - "EBS Volume".blue(), - "analyzer".green() - ); let mut results = Vec::new(); // TODO: Weird idiosyncrasy of the EC2 client let config = aws_types::sdk_config::SdkConfig::builder().build(); diff --git a/src/analyzer/rds_analyzer.rs b/src/analyzer/rds_analyzer.rs index 30cbade..65ba994 100644 --- a/src/analyzer/rds_analyzer.rs +++ b/src/analyzer/rds_analyzer.rs @@ -12,12 +12,6 @@ pub struct RDSAnalyzer { #[async_trait] impl analyzer_trait::Analyzer for RDSAnalyzer { async fn run(&self) -> Option> { - println!( - "{} {} {}", - "Running".green(), - "RDS".blue(), - "analyzer".green() - ); let mut results = Vec::new(); let rds = aws_sdk_rds::Client::new(&self.config); diff --git a/src/analyzer/s3_analyzer.rs b/src/analyzer/s3_analyzer.rs index ca16670..18d9a51 100644 --- a/src/analyzer/s3_analyzer.rs +++ b/src/analyzer/s3_analyzer.rs @@ -61,12 +61,6 @@ pub struct S3Analyzer { #[async_trait] impl analyzer_trait::Analyzer for S3Analyzer { async fn run(&self) -> Option> { - println!( - "{} {} {}", - "Running".green(), - "S3".blue(), - "analyzer".green() - ); let mut results = vec![AnalysisResults { message: "".to_string(), analyzer_name: self.get_name(), diff --git a/src/analyzer/sts_analyzer.rs b/src/analyzer/sts_analyzer.rs index 42729f6..8c4b913 100644 --- a/src/analyzer/sts_analyzer.rs +++ b/src/analyzer/sts_analyzer.rs @@ -13,13 +13,6 @@ pub struct STSAnalyzer { #[async_trait] impl analyzer_trait::Analyzer for STSAnalyzer { async fn run(&self) -> Option> { - println!( - "{} {} {}", - "Running".green(), - "STS".blue(), - "analyzer".green() - ); - let mut results = vec![AnalysisResults { message: "".to_string(), analyzer_name: "".to_string(),