use reqsign_core::SigningCredential;
use reqsign_core::time::Timestamp;
use reqsign_core::utils::Redact;
use std::fmt::{Debug, Formatter};
use std::time::Duration;
#[derive(Default, Clone)]
pub struct Credential {
pub tenancy: String,
pub user: String,
pub key_file: String,
pub fingerprint: String,
pub expires_in: Option<Timestamp>,
}
impl Debug for Credential {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Credential")
.field("tenancy", &self.tenancy)
.field("user", &self.user)
.field("key_file", &Redact::from(&self.key_file))
.field("fingerprint", &self.fingerprint)
.field("expires_in", &self.expires_in)
.finish()
}
}
impl SigningCredential for Credential {
fn is_valid(&self) -> bool {
if self.tenancy.is_empty()
|| self.user.is_empty()
|| self.key_file.is_empty()
|| self.fingerprint.is_empty()
{
return false;
}
if let Some(valid) = self
.expires_in
.map(|v| v > Timestamp::now() + Duration::from_secs(120))
{
return valid;
}
true
}
}