server/utils/mod.rs
1//! # Server Utilities Module
2//!
3//! Collection of server-side utility functions and helpers for the Quetty application.
4//! This module provides essential infrastructure utilities that support various aspects
5//! of the server-side operations including environment variable handling, configuration
6//! management, and common helper functions.
7//!
8//! ## Available Utilities
9//!
10//! ### Environment Variable Utilities
11//!
12//! The [`env`] module provides safe and validated access to environment variables:
13//!
14//! ```no_run
15//! use quetty_server::utils::env::EnvUtils;
16//!
17//! // Check if a variable exists and has a value
18//! if EnvUtils::has_non_empty_var("DATABASE_URL") {
19//! // Get the validated value
20//! let url = EnvUtils::get_validated_var("DATABASE_URL")?;
21//! println!("Database URL: {}", url);
22//! }
23//!
24//! // Get optional variables with defaults
25//! let debug_level = EnvUtils::get_optional_var("DEBUG_LEVEL")
26//! .unwrap_or_else(|| "info".to_string());
27//! ```
28//!
29//! ## Design Principles
30//!
31//! - **Safety First** - All utilities prioritize safe operations and proper error handling
32//! - **Validation** - Input validation and sanitization for all external inputs
33//! - **Error Handling** - Comprehensive error handling with detailed feedback
34//! - **Performance** - Efficient implementations suitable for server operations
35//! - **Reusability** - Functions designed for use across multiple server components
36//!
37//! ## Integration with Server Components
38//!
39//! These utilities are designed to integrate seamlessly with server components:
40//!
41//! - **Configuration Loading** - Safe environment variable access for configuration
42//! - **Service Initialization** - Reliable utilities for service startup procedures
43//! - **Error Reporting** - Structured error handling for operational feedback
44//! - **Resource Management** - Efficient resource handling and cleanup
45//!
46//! ## Usage in Authentication Systems
47//!
48//! Server utilities play a crucial role in authentication configuration:
49//!
50//! ```no_run
51//! use quetty_server::utils::env::EnvUtils;
52//!
53//! // Load authentication configuration from environment
54//! let tenant_id = EnvUtils::get_validated_var("AZURE_TENANT_ID")?;
55//! let client_id = EnvUtils::get_validated_var("AZURE_CLIENT_ID")?;
56//!
57//! // Optional configuration with fallbacks
58//! let token_cache_duration = EnvUtils::get_optional_var("TOKEN_CACHE_DURATION")
59//! .unwrap_or_else(|| "3600".to_string());
60//! ```
61
62pub mod env;