fix: Replace Runtime::new().block_on() with thread::spawn in AuthConfig
Some checks failed
BotServer CI/CD / build (push) Failing after 1m14s

- AuthConfig::from_env() was creating a new Runtime and calling block_on
  directly, causing panic when main tokio runtime is already active
- Now uses std:🧵:spawn + new_current_thread().block_on() pattern
- Follows AGENTS.md pattern for async-from-sync bridges
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-04 08:25:43 -03:00
parent c0c06e92eb
commit 0d3cfbe0f7

View file

@ -54,26 +54,33 @@ impl AuthConfig {
if let Ok(secret) = std::env::var("VAULT_TOKEN") { if let Ok(secret) = std::env::var("VAULT_TOKEN") {
if !secret.is_empty() { if !secret.is_empty() {
let rt = tokio::runtime::Runtime::new().ok(); let sm = crate::core::shared::utils::get_secrets_manager_sync();
if let Some(rt) = rt { if let Some(sm) = sm {
let sm = crate::core::shared::utils::get_secrets_manager_sync(); let (tx, rx) = std::sync::mpsc::channel();
if let Some(sm) = sm { std::thread::spawn(move || {
if let Ok(secrets) = let rt = tokio::runtime::Builder::new_current_thread()
rt.block_on(sm.get_secret(crate::core::secrets::SecretPaths::JWT)) .enable_all()
{ .build();
if let Some(s) = secrets.get("secret") { let result = if let Ok(rt) = rt {
config.jwt_secret = Some(s.clone()); rt.block_on(async { sm.get_secret(crate::core::secrets::SecretPaths::JWT).await })
} } else {
if let Some(r) = secrets.get("require_auth") { Err("Failed to create runtime".into())
config.require_auth = r == "true" || r == "1"; };
} let _ = tx.send(result);
if let Some(p) = secrets.get("anonymous_paths") { });
config.allow_anonymous_paths = p if let Ok(Ok(secrets)) = rx.recv() {
.split(',') if let Some(s) = secrets.get("secret") {
.map(|s| s.trim().to_string()) config.jwt_secret = Some(s.clone());
.filter(|s| !s.is_empty()) }
.collect(); if let Some(r) = secrets.get("require_auth") {
} config.require_auth = r == "true" || r == "1";
}
if let Some(p) = secrets.get("anonymous_paths") {
config.allow_anonymous_paths = p
.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect();
} }
} }
} }