Add Redis username detection logging without URL correction

This commit is contained in:
2025-09-02 18:42:41 +03:00
parent 74855e1f14
commit 57b1dc1786

View File

@@ -26,12 +26,6 @@ impl AppState {
Self::new_with_config(security_config).await Self::new_with_config(security_config).await
} }
/// Инициализация с кастомной конфигурацией безопасности и исправленным URL.
async fn new_with_config_and_url(security_config: SecurityConfig, redis_url: String) -> Self {
log::warn!("🔧 Creating AppState with corrected Redis URL");
Self::create_app_state_with_redis_url(security_config, redis_url).await
}
/// Инициализация с кастомной конфигурацией безопасности. /// Инициализация с кастомной конфигурацией безопасности.
pub async fn new_with_config(security_config: SecurityConfig) -> Self { pub async fn new_with_config(security_config: SecurityConfig) -> Self {
log::warn!("🚀 Starting AppState initialization..."); log::warn!("🚀 Starting AppState initialization...");
@@ -63,7 +57,7 @@ impl AppState {
let username = parsed_url.username(); let username = parsed_url.username();
let password = parsed_url.password(); let password = parsed_url.password();
// Определяем правильное имя пользователя // Определяем правильное имя пользователя для диагностики
let effective_username = if username.is_empty() && password.is_some() { let effective_username = if username.is_empty() && password.is_some() {
"redis" // Дефолтное имя пользователя для Redis "redis" // Дефолтное имя пользователя для Redis
} else { } else {
@@ -73,11 +67,8 @@ impl AppState {
log::warn!(" Username: '{}' (effective: '{}')", username, effective_username); log::warn!(" Username: '{}' (effective: '{}')", username, effective_username);
log::warn!(" Password: {}", if password.is_some() { "***" } else { "none" }); log::warn!(" Password: {}", if password.is_some() { "***" } else { "none" });
// Если нужно, исправляем URL с правильным именем пользователя
if username.is_empty() && password.is_some() { if username.is_empty() && password.is_some() {
let corrected_url = redis_url.replace("redis://:", &format!("redis://{}:", effective_username)); log::warn!(" Redis client will use default username 'redis' for authentication");
log::warn!("🔧 Using corrected Redis URL: {}", corrected_url.replace(&corrected_url.split('@').nth(0).unwrap_or(""), "***"));
return Self::new_with_config_and_url(security_config, corrected_url).await;
} }
} }
Err(e) => { Err(e) => {
@@ -86,11 +77,7 @@ impl AppState {
} }
} }
Self::create_app_state_with_redis_url(security_config, redis_url).await
}
/// Создает AppState с указанным Redis URL.
async fn create_app_state_with_redis_url(security_config: SecurityConfig, redis_url: String) -> Self {
let redis_client = match RedisClient::open(redis_url) { let redis_client = match RedisClient::open(redis_url) {
Ok(client) => { Ok(client) => {
log::warn!("✅ Redis client created successfully"); log::warn!("✅ Redis client created successfully");