Files
zesdex/apps/infrastructure/src/persistence/iam/oauth_repo.rs
T
asepharyana da2ed6da25 feat(tui): add usage overlay and sidebar for displaying usage statistics and tasks
feat(tui): implement status bar with connection and turn state indicators
feat(tui): create workflow panel for agent status and progress visualization
feat(web): introduce web frontend interface with static file serving
feat(ws): add WebSocket interface for real-time communication and session management
2026-07-20 09:04:57 +07:00

40 lines
1.2 KiB
Rust

//! Filesystem-backed `OAuthRepository` implementation.
//!
//! Tokens are stored as a single JSON file with write-then-rename + fsync
//! for crash safety, and restrictive owner-only mode `0o600` on Unix.
use std::path::Path;
use zesdex_domain::auth::{OAuthRepository, OAuthToken, RepositoryError};
use crate::utils::write_json_atomic;
/// Concrete filesystem OAuth token repository.
#[derive(Debug, Clone, Default)]
pub struct FileSystemOAuthRepository;
impl FileSystemOAuthRepository {
pub fn new() -> Self {
FileSystemOAuthRepository
}
}
impl OAuthRepository for FileSystemOAuthRepository {
fn save_token(&self, path: &Path, token: &OAuthToken) -> Result<(), RepositoryError> {
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
}
write_json_atomic(path, token, Some(0o600))?;
Ok(())
}
fn load_token(&self, path: &Path) -> Result<Option<OAuthToken>, RepositoryError> {
if !path.exists() {
return Ok(None);
}
let data = std::fs::read_to_string(path)?;
let token: OAuthToken = serde_json::from_str(&data)?;
Ok(Some(token))
}
}