spawn_access_control/
lib.rs

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! # Spawn Access Control
//! 
//! Gelişmiş güvenlik ve erişim kontrolü için Rust tabanlı kütüphane.
//! 
//! ## Özellikler
//! 
//! - Role-based access control (RBAC)
//! - Davranışsal analiz ve anomali tespiti
//! - Makine öğrenimi destekli güvenlik
//! - Gerçek zamanlı alert sistemi
//! - Zaman serisi analizi ve tahminleme
//! - WebAssembly desteği

// Temel modüller
pub mod access_control;
pub mod access_manager;
pub mod alert_analyzer;
pub mod alert_ml;
pub mod alert_storage;
pub mod alert_system;
pub mod audit;
pub mod behavioral;
pub mod error;
pub mod geo_analyzer;
pub mod metrics;
pub mod ml_analyzer;
pub mod ml_metrics;
pub mod monitoring;
pub mod security_analyzer;
pub mod time_series_analyzer;
pub mod model_explainer;
pub mod model_optimizer;
pub mod metrics_exporter;

// Notification modülü
pub mod notification {
    pub mod email;
    pub mod slack;
    pub use email::EmailNotificationHandler;
    pub use slack::SlackNotificationHandler;
}

// WASM desteği
#[cfg(target_arch = "wasm32")]
mod wasm;

// Temel trait'ler ve tipler
pub use chrono::{DateTime, Utc, Duration, Timelike, Datelike};
pub use serde::{Serialize, Deserialize};
pub use async_trait::async_trait;
pub use std::hash::Hash;

// Re-exports
pub use crate::{
    access_control::{AccessControl, Permission, Role, Resource},
    access_manager::AccessManager,
    alert_analyzer::{AlertAnalyzer, AlertPattern, PatternType},
    alert_system::{AlertNotification, AlertSeverity, NotificationHandler, EscalationLevel},
    monitoring::{ModelHealth, HealthStatus, AlertSeverity as MonitoringAlertSeverity},
    security_analyzer::{SecurityAnalyzer, SecurityReport},
};

// Prelude modülü
pub mod prelude {
    pub use crate::{
        AccessControl, Permission, Role, Resource,
        AlertAnalyzer, AlertPattern, PatternType,
        AlertNotification, AlertSeverity, EscalationLevel,
        ModelHealth, HealthStatus,
        SecurityReport,
    };
}

// Error tipi
pub use error::Error;
pub type Result<T> = std::result::Result<T, Error>;

// Genel konfigürasyon yapısı
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
    pub database_url: String,
    #[serde(with = "duration_serde")]
    pub cache_ttl: Duration,
    pub max_retries: u32,
    pub alert_threshold: f64,
    pub enable_ml: bool,
}

// Duration serileştirme modülü
mod duration_serde {
    use chrono::Duration;
    use serde::{Deserialize, Deserializer, Serialize, Serializer};

    pub fn serialize<S>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        duration.num_seconds().serialize(serializer)
    }

    pub fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>
    where
        D: Deserializer<'de>,
    {
        let seconds = i64::deserialize(deserializer)?;
        Ok(Duration::seconds(seconds))
    }
}

impl Default for Config {
    fn default() -> Self {
        Self {
            database_url: "mongodb://localhost:27017".to_string(),
            cache_ttl: Duration::minutes(30),
            max_retries: 3,
            alert_threshold: 0.8,
            enable_ml: true,
        }
    }
}

// Error dönüşümleri için
impl From<serde_json::Error> for Error {
    fn from(err: serde_json::Error) -> Self {
        Error::Serialization(err.to_string())
    }
}

impl From<std::io::Error> for Error {
    fn from(err: std::io::Error) -> Self {
        Error::Io(err.to_string())
    }
}

impl From<Box<dyn std::error::Error>> for Error {
    fn from(err: Box<dyn std::error::Error>) -> Self {
        Error::Database(err.to_string())
    }
}

// Re-export if needed
pub use model_explainer::{SecurityImpactAnalysis, RiskFactor};