summaryrefslogtreecommitdiff
path: root/src/repositories/mod.rs
blob: 1685fe0ddb750053793f86af1d701ec3fb9cb3a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::database::{DbAccessToken, DbAuditLog, DbAuthCode, DbOAuthClient};
use anyhow::Result;

pub mod sqlite;

pub use sqlite::{
    SqliteAuditRepository, SqliteAuthCodeRepository, SqliteClientRepository, SqliteRateRepository,
    SqliteTokenRepository,
};

/// Repository trait for OAuth client operations
pub trait ClientRepository: Send + Sync {
    fn get_client(&self, client_id: &str) -> Result<Option<DbOAuthClient>>;
    fn create_client(&self, client: &DbOAuthClient) -> Result<()>;
    fn update_client(&self, client: &DbOAuthClient) -> Result<()>;
    fn delete_client(&self, client_id: &str) -> Result<()>;
    fn list_clients(&self) -> Result<Vec<DbOAuthClient>>;
}

/// Repository trait for authorization code operations
pub trait AuthCodeRepository: Send + Sync {
    fn create_auth_code(&self, code: &DbAuthCode) -> Result<()>;
    fn get_auth_code(&self, code: &str) -> Result<Option<DbAuthCode>>;
    fn mark_auth_code_used(&self, code: &str) -> Result<()>;
    fn cleanup_expired_codes(&self) -> Result<()>;
}

/// Repository trait for access token operations
pub trait TokenRepository: Send + Sync {
    fn create_access_token(&self, token: &DbAccessToken) -> Result<()>;
    fn get_access_token(&self, token_hash: &str) -> Result<Option<DbAccessToken>>;
    fn revoke_access_token(&self, token_hash: &str) -> Result<()>;
    fn cleanup_expired_tokens(&self) -> Result<()>;
}

/// Repository trait for audit log operations
pub trait AuditRepository: Send + Sync {
    fn create_audit_log(&self, log: &DbAuditLog) -> Result<()>;
    fn get_audit_logs(&self, limit: Option<i32>) -> Result<Vec<DbAuditLog>>;
    fn cleanup_old_audit_logs(&self, days: i32) -> Result<()>;
}

/// Repository trait for rate limiting operations
pub trait RateRepository: Send + Sync {
    fn increment_rate_limit(
        &self,
        identifier: &str,
        endpoint: &str,
        window_size: i32,
    ) -> Result<i32>;
    fn cleanup_old_rate_limits(&self) -> Result<()>;
}