use std::time::{Duration, SystemTime};
use awaken_contract::secret::RedactedString;
#[derive(Debug, Clone)]
pub(crate) struct Token {
pub(crate) bearer: RedactedString,
pub(crate) expires_at: SystemTime,
}
impl Token {
pub(crate) fn is_near_expiry(&self, safety_window: Duration) -> bool {
match self.expires_at.duration_since(SystemTime::now()) {
Ok(remaining) => remaining <= safety_window,
Err(_) => true,
}
}
}
#[derive(Debug, Clone)]
pub struct IssuedToken {
bearer: RedactedString,
expires_at: SystemTime,
}
impl IssuedToken {
pub(crate) fn from_token(token: &Token) -> Self {
Self {
bearer: token.bearer.clone(),
expires_at: token.expires_at,
}
}
pub fn bearer(&self) -> &str {
self.bearer.expose_secret()
}
pub fn expires_at(&self) -> SystemTime {
self.expires_at
}
}