uselesskey_webhook/
model.rs1use std::collections::BTreeMap;
2use std::fmt;
3
4#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
6pub enum WebhookProfile {
7 GitHub,
9 Stripe,
11 Slack,
13}
14
15impl WebhookProfile {
16 pub(crate) fn stable_tag(self) -> &'static str {
17 match self {
18 Self::GitHub => "github",
19 Self::Stripe => "stripe",
20 Self::Slack => "slack",
21 }
22 }
23}
24
25#[derive(Clone, Debug, Eq, PartialEq)]
27pub enum WebhookPayloadSpec {
28 Canonical,
30 Raw(String),
32}
33
34impl WebhookPayloadSpec {
35 pub(crate) fn stable_bytes(&self) -> Vec<u8> {
36 match self {
37 Self::Canonical => b"canonical".to_vec(),
38 Self::Raw(payload) => {
39 let mut out = b"raw:".to_vec();
40 out.extend_from_slice(payload.as_bytes());
41 out
42 }
43 }
44 }
45}
46
47#[derive(Clone)]
49pub struct WebhookFixture {
50 pub profile: WebhookProfile,
52 pub secret: String,
54 pub payload: String,
56 pub headers: BTreeMap<String, String>,
58 pub timestamp: i64,
60 pub signature_input: String,
62}
63
64impl fmt::Debug for WebhookFixture {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 f.debug_struct("WebhookFixture")
67 .field("profile", &self.profile)
68 .field("payload", &self.payload)
69 .field("headers", &self.headers)
70 .field("timestamp", &self.timestamp)
71 .field("signature_input", &self.signature_input)
72 .finish_non_exhaustive()
73 }
74}
75
76#[derive(Clone)]
78pub struct NearMissWebhookFixture {
79 pub scenario: NearMissScenario,
81 pub profile: WebhookProfile,
83 pub secret: String,
85 pub payload: String,
87 pub headers: BTreeMap<String, String>,
89 pub timestamp: i64,
91 pub signature_input: String,
93}
94
95impl fmt::Debug for NearMissWebhookFixture {
96 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
97 f.debug_struct("NearMissWebhookFixture")
98 .field("scenario", &self.scenario)
99 .field("profile", &self.profile)
100 .field("payload", &self.payload)
101 .field("headers", &self.headers)
102 .field("timestamp", &self.timestamp)
103 .field("signature_input", &self.signature_input)
104 .finish_non_exhaustive()
105 }
106}
107
108#[derive(Clone, Copy, Debug, Eq, PartialEq)]
110pub enum NearMissScenario {
111 StaleTimestamp,
113 WrongSecret,
115 TamperedPayload,
117}