use std::{net::IpAddr, time::Instant};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AuthInfo {
pub ip: IpAddr,
pub valid_until: Instant,
pub targets: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct AuthService {
auth_duration: std::time::Duration,
}
impl AuthService {
pub fn new(auth_duration: std::time::Duration) -> Self {
Self { auth_duration }
}
pub fn authenticate(&self, now: Instant, ip: IpAddr, targets: &[&str]) -> AuthInfo {
let valid_until = now + self.auth_duration;
AuthInfo {
ip,
targets: targets.iter().map(|s| s.to_string()).collect(),
valid_until,
}
}
}