gitdataai/libs/config/lib.rs
ZhenYi db0a2eca16 feat(ssh): add complete SSH server implementation for Git operations
- Implement SSHandle struct with comprehensive Git service handling capabilities
- Add support for multiple authentication methods including password, public key and certificate
- Integrate Git command parsing and execution with proper channel management
- Implement branch protection rules enforcement during Git operations
- Add robust error handling and logging for SSH connections and Git processes
- Create secure Git command execution with environment isolation
- Implement proper resource cleanup for channels and subprocesses
- Add support for receive-pack, upload-pack and upload-archive services
- Integrate with existing authz and database services for permission checks
- Implement proper data forwarding between SSH channels and Git processes

fix(config): improve environment loading with error reporting

- Replace silent dotenv loading failures with informative error messages
- Handle global config race conditions safely during application startup
- Improve config loading reliability and debugging capabilities

fix(link-unfurl): handle server-side rendering compatibility

- Add undefined window object check for SSR environments
- Prevent client-side only code from breaking server-side rendering

refactor(agent): improve tool registry error handling

- Replace panics with graceful error logging for duplicate tool registrations
- Add proper error type definitions for tool registry operations
- Implement safe merging of registries with duplicate detection

fix(room-context): enhance WebSocket connection reliability

- Add proper error handling for room subscription operations
- Improve connection management with better error suppression
- Add console warnings for debugging connection issues

feat(ws-client): add comprehensive WebSocket client implementation

- Create RoomWsClient class with complete WebSocket communication layer
- Implement request-response pattern with timeout handling
- Add support for various room-related events and actions
- Include proper connection status tracking and management
- Implement callback system for different event types
- Add automatic reconnection and error recovery mechanisms
2026-04-28 21:29:34 +08:00

54 lines
1.7 KiB
Rust

use std::collections::HashMap;
use std::sync::OnceLock;
pub static GLOBAL_CONFIG: OnceLock<AppConfig> = OnceLock::new();
#[derive(Clone, Debug)]
pub struct AppConfig {
pub env: HashMap<String, String>,
}
impl AppConfig {
const ENV_FILES: &'static [&'static str] = &[".env", ".env.local"];
pub fn load() -> AppConfig {
let mut env = HashMap::new();
for env_file in AppConfig::ENV_FILES {
if let Err(e) = dotenvy::from_path(env_file) {
eprintln!("dotenv skipped: {} ({})", env_file, e);
}
if let Ok(env_file_content) = std::fs::read_to_string(env_file) {
for line in env_file_content.lines() {
if let Some((key, value)) = line.split_once('=') {
env.insert(key.to_string(), value.to_string());
}
}
}
}
// Environment variables (e.g. K8s injected APP_DOMAIN_URL) take precedence over .env files
env = std::env::vars().chain(env).collect();
let this = AppConfig { env };
// Handle the race condition: if another thread already set the global, return it.
// This is safe because config is immutable after load.
if GLOBAL_CONFIG.get().is_some() {
GLOBAL_CONFIG.get().unwrap().clone()
} else {
let _ = GLOBAL_CONFIG.set(this);
GLOBAL_CONFIG.get().expect("global config should be set after load").clone()
}
}
}
pub mod ai;
pub mod app;
pub mod avatar;
pub mod database;
pub mod domain;
pub mod embed;
pub mod hook;
pub mod logs;
pub mod qdrant;
pub mod redis;
pub mod smtp;
pub mod ssh;
pub mod storage;