Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions src/commands/check_access.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand 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<Error>> {
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::<Result<_>>()
.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(())
}
}