From 5ffc9b007ccbd8a4510b58de72aaee53291d7973 Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 11 Jun 2025 17:11:39 -0600 Subject: refactor: apply SOLID principles --- src/services/mod.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/services/mod.rs (limited to 'src/services/mod.rs') diff --git a/src/services/mod.rs b/src/services/mod.rs new file mode 100644 index 0000000..26d74e3 --- /dev/null +++ b/src/services/mod.rs @@ -0,0 +1,49 @@ +use anyhow::Result; +use std::collections::HashMap; + +/// Service trait for client authentication +pub trait ClientAuthenticator: Send + Sync { + fn authenticate( + &self, + params: &HashMap, + auth_header: Option<&str>, + ) -> Result<(String, String), String>; // Returns (client_id, client_secret) +} + +/// Service trait for rate limiting +pub trait RateLimiter: Send + Sync { + fn check_rate_limit(&self, identifier: &str, endpoint: &str) -> Result<()>; +} + +/// Service trait for audit logging +pub trait AuditLogger: Send + Sync { + fn log_event( + &self, + event_type: &str, + client_id: Option<&str>, + user_id: Option<&str>, + ip_address: Option<&str>, + success: bool, + details: Option<&str>, + ) -> Result<()>; +} + +/// Service trait for token generation +pub trait TokenGenerator: Send + Sync { + fn generate_access_token( + &self, + user_id: &str, + client_id: &str, + scope: &Option, + token_id: &str, + ) -> Result; + + fn generate_refresh_token( + &self, + client_id: &str, + user_id: &str, + scope: &Option, + ) -> Result; +} + +pub mod implementations; -- cgit v1.2.3