spawn-access-control 0.1.12

A Rust library for access control management with WebAssembly support, including role-based access control (RBAC), permissions, and audit logging.
Documentation
#[cfg(feature = "metrics")]
use prometheus::{
    IntCounter, IntGauge, Histogram, HistogramOpts,
    Registry, Opts
};

#[cfg(feature = "metrics")]
pub struct MetricsCollector {
    registry: Registry,
    access_counter: IntCounter,
    active_users: IntGauge,
    response_times: Histogram,
}

#[cfg(feature = "metrics")]
impl MetricsCollector {
    pub fn new() -> Self {
        let registry = Registry::new();
        
        let access_counter = IntCounter::new(
            "spawn_access_total",
            "Total number of access attempts"
        ).unwrap();

        let active_users = IntGauge::new(
            "spawn_active_users",
            "Number of currently active users"
        ).unwrap();

        let response_times = Histogram::with_opts(
            HistogramOpts::new(
                "spawn_response_times",
                "Response times in seconds"
            )
        ).unwrap();

        registry.register(Box::new(access_counter.clone())).unwrap();
        registry.register(Box::new(active_users.clone())).unwrap();
        registry.register(Box::new(response_times.clone())).unwrap();

        Self {
            registry,
            access_counter,
            active_users,
            response_times,
        }
    }

    pub fn record_access(&self) {
        self.access_counter.inc();
    }

    pub fn record_response_time(&self, duration_ms: f64) {
        self.response_times.observe(duration_ms);
    }
}

// Metrics özelliği devre dışıysa boş implementasyon
#[cfg(not(feature = "metrics"))]
pub struct MetricsCollector;

#[cfg(not(feature = "metrics"))]
impl MetricsCollector {
    pub fn new() -> Self {
        Self
    }

    pub fn record_access(&self) {}
    pub fn record_response_time(&self, _duration_ms: f64) {}
}