2024-05-25 11:25:13 +01:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Deref, derive_more::Display)]
|
|
|
|
pub struct WebhookAuth(ulid::Ulid);
|
|
|
|
impl WebhookAuth {
|
|
|
|
pub fn new(authorisation: &str) -> Result<Self, ulid::DecodeError> {
|
2024-06-03 07:38:59 +01:00
|
|
|
use std::str::FromStr as _;
|
2024-05-25 11:25:13 +01:00
|
|
|
let id = ulid::Ulid::from_str(authorisation)?;
|
|
|
|
tracing::info!("Parse auth token: {}", id);
|
|
|
|
Ok(Self(id))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn generate() -> Self {
|
|
|
|
Self(ulid::Ulid::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn header_value(&self) -> String {
|
|
|
|
format!("Basic {}", self)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const fn to_bytes(&self) -> [u8; 16] {
|
|
|
|
self.0.to_bytes()
|
|
|
|
}
|
|
|
|
}
|