pub trait BypassReason: Send + Sync {
fn name(&self) -> &'static str;
fn justification(&self) -> &'static str;
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BypassAudit {
pub reason: String,
pub justification: String,
pub approved_by: Option<String>,
}
impl BypassAudit {
pub fn new(reason: impl Into<String>, justification: impl Into<String>) -> Self {
Self {
reason: reason.into(),
justification: justification.into(),
approved_by: None,
}
}
pub fn with_approved_by(mut self, approver: impl Into<String>) -> Self {
self.approved_by = Some(approver.into());
self
}
}
pub struct BypassReceipt<T> {
pub(crate) payload: T,
pub(crate) reason: &'static str,
pub(crate) justification: &'static str,
pub(crate) approved_by: Option<String>,
}
impl<T> BypassReceipt<T> {
pub fn payload(&self) -> &T {
&self.payload
}
pub fn reason(&self) -> &'static str {
self.reason
}
pub fn justification(&self) -> &'static str {
self.justification
}
pub fn approved_by(&self) -> Option<&str> {
self.approved_by.as_deref()
}
pub fn with_approved_by(mut self, approver: impl Into<String>) -> Self {
self.approved_by = Some(approver.into());
self
}
pub fn into_payload(self) -> T {
self.payload
}
pub(crate) fn to_audit(&self) -> BypassAudit {
BypassAudit {
reason: self.reason.to_string(),
justification: self.justification.to_string(),
approved_by: self.approved_by.clone(),
}
}
}