Skip to main content

hanzo_client/apis/
webhook_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`delete_webhook_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteWebhookByIdError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_webhook`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetWebhookError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_webhook_by_id`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetWebhookByIdError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_webhook_by_id_deliveries`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetWebhookByIdDeliveriesError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`post_webhook`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostWebhookError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`post_webhook_by_id_secret`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostWebhookByIdSecretError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`post_webhook_by_id_test`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum PostWebhookByIdTestError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`put_webhook_by_id`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum PutWebhookByIdError {
71    UnknownValue(serde_json::Value),
72}
73
74
75/// Removes one of the caller org's webhook endpoints and answers 204 with no body. Delivery stops immediately and the endpoint's signing secret is gone with it; its recorded delivery history goes too. An id another org owns reads as not found.
76pub async fn delete_webhook_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteWebhookByIdError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_id = id;
79
80    let uri_str = format!("{}/v1/webhook/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
81    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
82
83    if let Some(ref user_agent) = configuration.user_agent {
84        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85    }
86    if let Some(ref token) = configuration.bearer_access_token {
87        req_builder = req_builder.bearer_auth(token.to_owned());
88    };
89
90    let req = req_builder.build()?;
91    let resp = configuration.client.execute(req).await?;
92
93    let status = resp.status();
94
95    if !status.is_client_error() && !status.is_server_error() {
96        Ok(())
97    } else {
98        let content = resp.text().await?;
99        let entity: Option<DeleteWebhookByIdError> = serde_json::from_str(&content).ok();
100        Err(Error::ResponseError(ResponseContent { status, content, entity }))
101    }
102}
103
104/// Returns every webhook endpoint the caller's org has registered, newest first, each with its 7-day delivery and failure counts. Signing secrets are redacted here — a secret leaves the server only on create and on rotate. The listing is physically org-scoped, so another tenant's endpoints are not reachable from this route at all.
105pub async fn get_webhook(configuration: &configuration::Configuration, ) -> Result<models::EndpointList, Error<GetWebhookError>> {
106
107    let uri_str = format!("{}/v1/webhook", configuration.base_path);
108    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
109
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    if let Some(ref token) = configuration.bearer_access_token {
114        req_builder = req_builder.bearer_auth(token.to_owned());
115    };
116
117    let req = req_builder.build()?;
118    let resp = configuration.client.execute(req).await?;
119
120    let status = resp.status();
121    let content_type = resp
122        .headers()
123        .get("content-type")
124        .and_then(|v| v.to_str().ok())
125        .unwrap_or("application/octet-stream");
126    let content_type = super::ContentType::from(content_type);
127
128    if !status.is_client_error() && !status.is_server_error() {
129        let content = resp.text().await?;
130        match content_type {
131            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
132            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EndpointList`"))),
133            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EndpointList`")))),
134        }
135    } else {
136        let content = resp.text().await?;
137        let entity: Option<GetWebhookError> = serde_json::from_str(&content).ok();
138        Err(Error::ResponseError(ResponseContent { status, content, entity }))
139    }
140}
141
142/// Returns one of the caller org's webhook endpoints with its 7-day delivery and failure counts, signing secret redacted. An id another org owns reads as not found, so the response cannot confirm that it exists.
143pub async fn get_webhook_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Endpoint, Error<GetWebhookByIdError>> {
144    // add a prefix to parameters to efficiently prevent name collisions
145    let p_id = id;
146
147    let uri_str = format!("{}/v1/webhook/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
148    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
149
150    if let Some(ref user_agent) = configuration.user_agent {
151        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
152    }
153    if let Some(ref token) = configuration.bearer_access_token {
154        req_builder = req_builder.bearer_auth(token.to_owned());
155    };
156
157    let req = req_builder.build()?;
158    let resp = configuration.client.execute(req).await?;
159
160    let status = resp.status();
161    let content_type = resp
162        .headers()
163        .get("content-type")
164        .and_then(|v| v.to_str().ok())
165        .unwrap_or("application/octet-stream");
166    let content_type = super::ContentType::from(content_type);
167
168    if !status.is_client_error() && !status.is_server_error() {
169        let content = resp.text().await?;
170        match content_type {
171            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
172            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Endpoint`"))),
173            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Endpoint`")))),
174        }
175    } else {
176        let content = resp.text().await?;
177        let entity: Option<GetWebhookByIdError> = serde_json::from_str(&content).ok();
178        Err(Error::ResponseError(ResponseContent { status, content, entity }))
179    }
180}
181
182/// Returns one endpoint's per-attempt delivery log, newest first — the record of what was sent, what the subscriber answered, and how long it took. One event that retried three times appears as three rows sharing a delivery id. It is org-scoped exactly like every other route here: the endpoint lookup only ever finds THIS org's endpoint, so another org's id is a 404 and never a window onto its logs.
183pub async fn get_webhook_by_id_deliveries(configuration: &configuration::Configuration, id: &str, limit: Option<i32>, status: Option<&str>) -> Result<models::DeliveryList, Error<GetWebhookByIdDeliveriesError>> {
184    // add a prefix to parameters to efficiently prevent name collisions
185    let p_id = id;
186    let p_limit = limit;
187    let p_status = status;
188
189    let uri_str = format!("{}/v1/webhook/{id}/deliveries", configuration.base_path, id=crate::apis::urlencode(p_id));
190    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
191
192    if let Some(ref param_value) = p_limit {
193        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
194    }
195    if let Some(ref param_value) = p_status {
196        req_builder = req_builder.query(&[("status", &param_value.to_string())]);
197    }
198    if let Some(ref user_agent) = configuration.user_agent {
199        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
200    }
201    if let Some(ref token) = configuration.bearer_access_token {
202        req_builder = req_builder.bearer_auth(token.to_owned());
203    };
204
205    let req = req_builder.build()?;
206    let resp = configuration.client.execute(req).await?;
207
208    let status = resp.status();
209    let content_type = resp
210        .headers()
211        .get("content-type")
212        .and_then(|v| v.to_str().ok())
213        .unwrap_or("application/octet-stream");
214    let content_type = super::ContentType::from(content_type);
215
216    if !status.is_client_error() && !status.is_server_error() {
217        let content = resp.text().await?;
218        match content_type {
219            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
220            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeliveryList`"))),
221            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeliveryList`")))),
222        }
223    } else {
224        let content = resp.text().await?;
225        let entity: Option<GetWebhookByIdDeliveriesError> = serde_json::from_str(&content).ok();
226        Err(Error::ResponseError(ResponseContent { status, content, entity }))
227    }
228}
229
230/// Registers a new webhook subscription for the caller's org and answers 201 with the endpoint INCLUDING its freshly minted signing secret. This is one of only two responses that ever carry that secret (the other is rotate) — store it now, because no later read returns it. The org is stamped by the server from the validated principal, so a body can never register an endpoint in another tenant.
231pub async fn post_webhook(configuration: &configuration::Configuration, create_endpoint_in: models::CreateEndpointIn) -> Result<models::Endpoint, Error<PostWebhookError>> {
232    // add a prefix to parameters to efficiently prevent name collisions
233    let p_create_endpoint_in = create_endpoint_in;
234
235    let uri_str = format!("{}/v1/webhook", configuration.base_path);
236    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
237
238    if let Some(ref user_agent) = configuration.user_agent {
239        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
240    }
241    if let Some(ref token) = configuration.bearer_access_token {
242        req_builder = req_builder.bearer_auth(token.to_owned());
243    };
244    req_builder = req_builder.json(&p_create_endpoint_in);
245
246    let req = req_builder.build()?;
247    let resp = configuration.client.execute(req).await?;
248
249    let status = resp.status();
250    let content_type = resp
251        .headers()
252        .get("content-type")
253        .and_then(|v| v.to_str().ok())
254        .unwrap_or("application/octet-stream");
255    let content_type = super::ContentType::from(content_type);
256
257    if !status.is_client_error() && !status.is_server_error() {
258        let content = resp.text().await?;
259        match content_type {
260            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
261            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Endpoint`"))),
262            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Endpoint`")))),
263        }
264    } else {
265        let content = resp.text().await?;
266        let entity: Option<PostWebhookError> = serde_json::from_str(&content).ok();
267        Err(Error::ResponseError(ResponseContent { status, content, entity }))
268    }
269}
270
271/// Mints a NEW HMAC signing secret for the endpoint and answers the endpoint WITH it — the only other response besides create that ever carries a secret. The old secret stops working the instant this returns: every subsequent delivery signs with the new one, with no overlap window. Call it when the subscriber is ready to swap the value on its side, not before.
272pub async fn post_webhook_by_id_secret(configuration: &configuration::Configuration, id: &str) -> Result<models::Endpoint, Error<PostWebhookByIdSecretError>> {
273    // add a prefix to parameters to efficiently prevent name collisions
274    let p_id = id;
275
276    let uri_str = format!("{}/v1/webhook/{id}/secret", configuration.base_path, id=crate::apis::urlencode(p_id));
277    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
278
279    if let Some(ref user_agent) = configuration.user_agent {
280        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
281    }
282    if let Some(ref token) = configuration.bearer_access_token {
283        req_builder = req_builder.bearer_auth(token.to_owned());
284    };
285
286    let req = req_builder.build()?;
287    let resp = configuration.client.execute(req).await?;
288
289    let status = resp.status();
290    let content_type = resp
291        .headers()
292        .get("content-type")
293        .and_then(|v| v.to_str().ok())
294        .unwrap_or("application/octet-stream");
295    let content_type = super::ContentType::from(content_type);
296
297    if !status.is_client_error() && !status.is_server_error() {
298        let content = resp.text().await?;
299        match content_type {
300            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
301            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Endpoint`"))),
302            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Endpoint`")))),
303        }
304    } else {
305        let content = resp.text().await?;
306        let entity: Option<PostWebhookByIdSecretError> = serde_json::from_str(&content).ok();
307        Err(Error::ResponseError(ResponseContent { status, content, entity }))
308    }
309}
310
311/// Sends ONE signed test event to the endpoint right now and answers the outcome inline, so the console can show whether the subscriber is reachable without waiting for real traffic. It takes the same attempt path the bus dispatcher takes — one attempt, 10s timeout, no retry ladder — and records the result in the endpoint's delivery log. It works on a DISABLED endpoint too: validating one you have paused is the whole point.
312pub async fn post_webhook_by_id_test(configuration: &configuration::Configuration, id: &str) -> Result<models::TestResult, Error<PostWebhookByIdTestError>> {
313    // add a prefix to parameters to efficiently prevent name collisions
314    let p_id = id;
315
316    let uri_str = format!("{}/v1/webhook/{id}/test", configuration.base_path, id=crate::apis::urlencode(p_id));
317    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
318
319    if let Some(ref user_agent) = configuration.user_agent {
320        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
321    }
322    if let Some(ref token) = configuration.bearer_access_token {
323        req_builder = req_builder.bearer_auth(token.to_owned());
324    };
325
326    let req = req_builder.build()?;
327    let resp = configuration.client.execute(req).await?;
328
329    let status = resp.status();
330    let content_type = resp
331        .headers()
332        .get("content-type")
333        .and_then(|v| v.to_str().ok())
334        .unwrap_or("application/octet-stream");
335    let content_type = super::ContentType::from(content_type);
336
337    if !status.is_client_error() && !status.is_server_error() {
338        let content = resp.text().await?;
339        match content_type {
340            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
341            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TestResult`"))),
342            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TestResult`")))),
343        }
344    } else {
345        let content = resp.text().await?;
346        let entity: Option<PostWebhookByIdTestError> = serde_json::from_str(&content).ok();
347        Err(Error::ResponseError(ResponseContent { status, content, entity }))
348    }
349}
350
351/// Replaces the editable fields of one of the caller org's endpoints — url, events, status and description — and answers the stored row with its secret redacted. It is a full replace, not a patch: an omitted field is written as its empty value, and an omitted or empty events list resubscribes the endpoint to EVERY event. The signing secret and the creation time are immutable here; rotate the secret with POST /v1/webhook/{id}/secret.
352pub async fn put_webhook_by_id(configuration: &configuration::Configuration, id: &str, update_endpoint_in: models::UpdateEndpointIn) -> Result<models::Endpoint, Error<PutWebhookByIdError>> {
353    // add a prefix to parameters to efficiently prevent name collisions
354    let p_id = id;
355    let p_update_endpoint_in = update_endpoint_in;
356
357    let uri_str = format!("{}/v1/webhook/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
358    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
359
360    if let Some(ref user_agent) = configuration.user_agent {
361        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
362    }
363    if let Some(ref token) = configuration.bearer_access_token {
364        req_builder = req_builder.bearer_auth(token.to_owned());
365    };
366    req_builder = req_builder.json(&p_update_endpoint_in);
367
368    let req = req_builder.build()?;
369    let resp = configuration.client.execute(req).await?;
370
371    let status = resp.status();
372    let content_type = resp
373        .headers()
374        .get("content-type")
375        .and_then(|v| v.to_str().ok())
376        .unwrap_or("application/octet-stream");
377    let content_type = super::ContentType::from(content_type);
378
379    if !status.is_client_error() && !status.is_server_error() {
380        let content = resp.text().await?;
381        match content_type {
382            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
383            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Endpoint`"))),
384            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Endpoint`")))),
385        }
386    } else {
387        let content = resp.text().await?;
388        let entity: Option<PutWebhookByIdError> = serde_json::from_str(&content).ok();
389        Err(Error::ResponseError(ResponseContent { status, content, entity }))
390    }
391}
392