git_next_core/config/webhook/
auth.rs1use crate::newtype;
3
4newtype!(
5 WebhookAuth,
6 ulid::Ulid,
7 derive_more::Display,
8 r#"The unique token authorisation for the webhook.
9
10Each monitored repository has it's own unique token, and it is different each time `git-next` runs."#
11);
12impl WebhookAuth {
13 pub fn try_new(authorisation: &str) -> Result<Self, ulid::DecodeError> {
19 use std::str::FromStr as _;
20 let id = ulid::Ulid::from_str(authorisation)?;
21 tracing::info!("Parse auth token: {}", id);
22 Ok(Self(id))
23 }
24
25 #[must_use]
26 pub fn generate() -> Self {
27 Self(ulid::Ulid::new())
28 }
29
30 #[must_use]
31 pub fn header_value(&self) -> String {
32 format!("Basic {self}")
33 }
34
35 #[cfg(test)]
36 pub(crate) const fn to_bytes(&self) -> [u8; 16] {
37 self.0.to_bytes()
38 }
39}