diff --git a/src/commands/check_access.rs b/src/commands/check_access.rs index 17571c0..2f2f64c 100644 --- a/src/commands/check_access.rs +++ b/src/commands/check_access.rs @@ -1,5 +1,5 @@ use anyhow::{Context, Error, Result}; -use itertools::{self, Itertools}; +use itertools::Itertools; use simplelog::info; use simplelog::*; use std::process::exit; @@ -18,7 +18,7 @@ pub fn run(profile: &str, kubernetes: &bool, frontend: &bool, registry: &bool) { p => vec![String::from(p)], }; - let results: Result<()> = to_check.into_iter().try_for_each(|p| { + let results: Result<(), Vec<_>> = to_check.into_iter().try_for_each(|p| { check_profile( &p, *kubernetes || check_all, @@ -30,33 +30,40 @@ pub fn run(profile: &str, kubernetes: &bool, frontend: &bool, registry: &bool) { // die if there were any errors match results { Ok(_) => info!(" all good!"), - Err(err) => { - error!("{err:?}"); + Err(errs) => { + error!("Error checking profile {profile}:"); + errs.iter().for_each(|e| error!("{e:?}\n")); exit(1) } } } /// checks a single profile (`profile`) for the given accesses -fn check_profile(name: &str, kubernetes: bool, frontend: bool, registry: bool) -> Result<()> { +fn check_profile( + name: &str, + kubernetes: bool, + frontend: bool, + registry: bool, +) -> Result<(), Vec> { info!("checking profile {name}..."); - // todo: this works but ehhh let mut results = vec![]; if kubernetes { - results.push(access::kube::check(name)); + results.push(access::kube::check(name).context("could not access kubernetes cluster")); } if frontend { - results.push(access::frontend::check(name)); + results.push(access::frontend::check(name).context("could not access frontend")); } if registry { - results.push(access::docker::check(name)); + results.push(access::docker::check(name).context("could not access container registry")); } - // takes first Err in vec as Result() return - results - .into_iter() - .collect::>() - .with_context(|| format!("Error in profile '{name}'")) + let (ok, errs): (Vec<_>, Vec<_>) = results.into_iter().partition_result(); + + if !errs.is_empty() { + Err(errs) + } else { + Ok(()) + } }