Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions central/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{convert::Infallible, path::PathBuf};

use beam_lib::{reqwest::Url, AppId};
use clap::Parser;
use tracing::{debug, info, warn};
use shared::{OIDCConfig, RequestType, SecretResult};

use crate::auth::{
Expand Down Expand Up @@ -40,8 +41,9 @@ impl OIDCProvider {
match (KeyCloakConfig::try_parse(), AuthentikConfig::try_parse()) {
(Ok(key), _) => Some(OIDCProvider::Keycloak(key)),
(_, Ok(auth)) => Some(OIDCProvider::Authentik(auth)),
(Err(e), _) => {
eprintln!("{e:#?}");
(Err(e_authentik), Err(e_keycloak)) => {
warn!("No OIDC provider is configured");
debug!(?e_authentik, ?e_keycloak);
None
}
}
Expand Down Expand Up @@ -79,7 +81,7 @@ impl OIDCProvider {
}
}
.map_err(|e| {
println!("Failed to create client: {e}");
warn!("Failed to create client: {e:#?}");
"Error creating OIDC client".into()
})
}
Expand All @@ -95,18 +97,18 @@ impl OIDCProvider {
keycloak::validate_client(name, oidc_client_config, secret, conf)
.await
.map_err(|e| {
eprintln!("Failed to validate client {name}: {e}");
warn!("Failed to validate client {name}: {e:#?}");
"Failed to validate client. See upstrean logs.".into()
})
}
OIDCProvider::Authentik(conf) => {
authentik::validate_application(name, oidc_client_config, secret, conf)
.await
.map_err(|e| {
eprintln!("Failed to validate client {name}: {e}");
warn!("Failed to validate client {name}: {e:#?}");
"Failed to validate client. See upstrean logs.".into()
})
}
}
}
}
}
2 changes: 2 additions & 0 deletions local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ tokio = { workspace = true }
once_cell = { workspace = true }
shared = { workspace = true }
futures = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
3 changes: 2 additions & 1 deletion local/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{collections::HashMap, fs, io, ops::DerefMut, path::Path};
use tracing::warn;

pub struct Cache(HashMap<String, String>);

Expand All @@ -19,7 +20,7 @@ impl DerefMut for Cache {
impl Cache {
pub fn open(path: impl AsRef<Path>) -> Cache {
let Ok(file) = fs::read_to_string(path) else {
eprintln!("Cached secrets not found creating");
warn!("Cached secrets not found creating");
return Self(HashMap::new());
};
Self(
Expand Down
20 changes: 11 additions & 9 deletions local/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use clap::Parser;
use config::{Config, SecretArg};
use futures::TryFutureExt;
use once_cell::sync::Lazy;
use tracing::{info, warn};
use shared::{RequestType, SecretRequest, SecretResult, SecretType};

mod cache;
Expand All @@ -24,6 +25,7 @@ pub static BEAM_CLIENT: Lazy<BeamClient> =

#[tokio::main]
async fn main() -> ExitCode {
tracing_subscriber::fmt::init();
let mut cache = Cache::open(&CONFIG.cache_path);
let tasks: Vec<_> = CONFIG
.secret_definitions
Expand All @@ -44,15 +46,15 @@ async fn main() -> ExitCode {
})
.collect();
if tasks.is_empty() {
println!("No secrets to generate");
info!("No secrets to generate");
return ExitCode::SUCCESS;
} else {
println!("Generating {} secrets", tasks.len());
info!("Generating {} secrets", tasks.len());
}
let results = match send_secret_request(tasks).await {
Ok(results) => results,
Err(e) => {
eprintln!("Failed to send secret sync task: {e}");
warn!("Failed to send secret sync task: {e}");
return ExitCode::FAILURE;
}
};
Expand All @@ -63,33 +65,33 @@ async fn main() -> ExitCode {
{
match result {
Ok(SecretResult::AlreadyValid) => {
println!("{name} was cached correctly.")
info!("{name} was cached correctly.")
}
Ok(SecretResult::Created(secret)) => {
cache.entry(name.to_string())
.and_modify(|v| {
println!("{name} was cached locally but did not exist centrally so it was created.");
info!("{name} was cached locally but did not exist centrally so it was created.");
*v = secret.clone()
}).or_insert_with(|| {
println!("{name} has been created.");
info!("{name} has been created.");
secret
});
}
Ok(SecretResult::AlreadyExisted(secret)) => {
cache
.entry(name.to_string())
.and_modify(|v| {
println!("{name} was cached but needed to be updated.");
info!("{name} was cached but needed to be updated.");
*v = secret.clone()
})
.or_insert_with(|| {
println!("{name} already existed but was not cached.");
info!("{name} already existed but was not cached.");
secret
});
}
Err(e) => {
exit_code = ExitCode::FAILURE;
println!("Failed to validate or create secret for {name}: {e}")
warn!("Failed to validate or create secret for {name}: {e}")
}
}
}
Expand Down