Skip to content

Commit

Permalink
Pass profile name instead of profile config struct
Browse files Browse the repository at this point in the history
Makes testing easier, and stuff still needs to fetch stuff from the full
config sometimes anyway.

Signed-off-by: Robert Detjens <[email protected]>
  • Loading branch information
detjensrobert committed Aug 24, 2024
1 parent 98bf272 commit c660a4f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/access_handlers/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ use itertools::Itertools;
use simplelog::*;
use tokio;

use crate::configparser::{config, get_config};
use crate::configparser::{get_config, get_profile_config};

/// container registry / daemon access checks
#[tokio::main(flavor = "current_thread")] // make this a sync function
pub async fn check(profile: &config::ProfileConfig) -> Result<()> {
pub async fn check(profile_name: &str) -> Result<()> {
// docker / podman does not keep track of whether registry credentials are
// valid or not. to check if we do have valid creds, we need to do something
// to present creds, like pulling an image.

let profile = get_profile_config(profile_name)?;

let client = client()
.await
// truncate error chain with new error (returned error is way too verbose)
Expand Down
5 changes: 3 additions & 2 deletions src/access_handlers/frontend.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::{Error, Result};

use crate::configparser::{config, CONFIG};
use crate::configparser::{get_config, get_profile_config};

/// frontend dashbard access checks
pub fn check(profile: &config::ProfileConfig) -> Result<()> {
pub fn check(profile_name: &str) -> Result<()> {
let profile = get_profile_config(profile_name)?;
Ok(())
}
6 changes: 4 additions & 2 deletions src/access_handlers/kube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ use kube;
use simplelog::*;
use tokio;

use crate::configparser::{config, CONFIG};
use crate::configparser::{config, get_config, get_profile_config};

/// kubernetes access checks
#[tokio::main(flavor = "current_thread")] // make this a sync function
pub async fn check(profile: &config::ProfileConfig) -> Result<()> {
pub async fn check(profile_name: &str) -> Result<()> {
let profile = get_profile_config(profile_name)?;

// we need to make sure that:
// a) can talk to the cluster
// b) have the right permissions (a la `kubectl auth can-i`)
Expand Down
5 changes: 3 additions & 2 deletions src/access_handlers/s3.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::{Error, Result};

use crate::configparser::{config, CONFIG};
use crate::configparser::{get_config, get_profile_config};

/// s3 bucket access checks
pub fn check(profile: &config::ProfileConfig) -> Result<()> {
pub fn check(profile_name: &str) -> Result<()> {
let profile = get_profile_config(profile_name)?;
Ok(())
}
18 changes: 6 additions & 12 deletions src/commands/check_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,25 @@ pub fn run(profile: &str, kubernetes: &bool, frontend: &bool, registry: &bool) {
}

/// checks a single profile (`profile`) for the given accesses
fn check_profile(
profile_name: &str,
kubernetes: bool,
frontend: bool,
registry: bool,
) -> Result<()> {
let profile = get_profile_config(profile_name)?;
info!("checking profile {profile_name}...");
fn check_profile(name: &str, kubernetes: bool, frontend: bool, registry: bool) -> Result<()> {
info!("checking profile {name}...");

// todo: this works but ehhh
let mut results = vec![];

if kubernetes {
results.push(access::kube::check(profile));
results.push(access::kube::check(name));
}
if frontend {
results.push(access::frontend::check(profile));
results.push(access::frontend::check(name));
}
if registry {
results.push(access::docker::check(profile));
results.push(access::docker::check(name));
}

// takes first Err in vec as Result() return
results
.into_iter()
.collect::<Result<_>>()
.with_context(|| format!("Error in profile '{profile_name}'"))
.with_context(|| format!("Error in profile '{name}'"))
}

0 comments on commit c660a4f

Please sign in to comment.