git-next/crates/config/src/webhook/auth.rs
Paul Campbell 717cc8b0bc
Some checks failed
ci/woodpecker/push/tag-created Pipeline is pending
ci/woodpecker/push/cron-docker-builder Pipeline was successful
Rust / build (push) Has been cancelled
ci/woodpecker/push/push-next Pipeline was successful
refactor: update macro signatures and add documentation support
2024-06-29 18:26:19 +01:00

24 lines
725 B
Rust

//
crate::newtype!(WebhookAuth: ulid::Ulid, derive_more::Display: r#"The unique token authorisation for the webhook.
Each monitored repository has it's own unique token, and it is different each time `git-next` runs."#);
impl WebhookAuth {
pub fn try_new(authorisation: &str) -> Result<Self, ulid::DecodeError> {
use std::str::FromStr as _;
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()
}
}