botserver/src/security/safe_unwrap.rs
Rodrigo Rodriguez e143968179 feat: Add JWT secret rotation and health verification
SEC-02: Implement credential rotation security improvements

- Add JWT secret rotation to rotate-secret command
- Generate 64-character HS512-compatible secrets
- Automatic .env backup with timestamp
- Atomic file updates via temp+rename pattern
- Add health verification for rotated credentials
- Route rotate-secret, rotate-secrets, vault commands in CLI
- Add verification attempts for database and JWT endpoints

Security improvements:
- JWT_SECRET now rotatable (previously impossible)
- Automatic rollback via backup files
- Health checks catch configuration errors
- Clear warnings about token invalidation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-19 19:42:41 +00:00

23 lines
675 B
Rust

pub fn safe_unwrap_or_default<T: Default>(result: Result<T, impl std::fmt::Display>, context: &str) -> T {
result.unwrap_or_else(|e| {
tracing::error!("{}: {}", context, e);
T::default()
})
}
pub fn safe_unwrap_or<T>(result: Result<T, impl std::fmt::Display>, context: &str, default: T) -> T {
result.unwrap_or_else(|e| {
tracing::error!("{}: {}", context, e);
default
})
}
pub fn safe_unwrap_none_or<T>(result: Result<T, impl std::fmt::Display>, context: &str, value: T) -> T {
match result {
Ok(v) => v,
Err(e) => {
tracing::error!("{}: {}", context, e);
value
}
}
}