Skip to main content

hanzo_client/apis/
destination_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_destination_by_platform`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteDestinationByPlatformError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_destination`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetDestinationError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_destination_by_platform`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetDestinationByPlatformError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`post_destination_by_platform`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostDestinationByPlatformError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`post_destination_by_platform_test`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostDestinationByPlatformTestError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// Forgets a destination for the caller's org: every credential held in KMS, then the stored config. Idempotent, and it requires org admin.
55pub async fn delete_destination_by_platform(configuration: &configuration::Configuration, platform: &str) -> Result<models::DestinationDisconnected, Error<DeleteDestinationByPlatformError>> {
56    // add a prefix to parameters to efficiently prevent name collisions
57    let p_platform = platform;
58
59    let uri_str = format!("{}/v1/destination/{platform}", configuration.base_path, platform=crate::apis::urlencode(p_platform));
60    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
61
62    if let Some(ref user_agent) = configuration.user_agent {
63        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64    }
65    if let Some(ref token) = configuration.bearer_access_token {
66        req_builder = req_builder.bearer_auth(token.to_owned());
67    };
68
69    let req = req_builder.build()?;
70    let resp = configuration.client.execute(req).await?;
71
72    let status = resp.status();
73    let content_type = resp
74        .headers()
75        .get("content-type")
76        .and_then(|v| v.to_str().ok())
77        .unwrap_or("application/octet-stream");
78    let content_type = super::ContentType::from(content_type);
79
80    if !status.is_client_error() && !status.is_server_error() {
81        let content = resp.text().await?;
82        match content_type {
83            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
84            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DestinationDisconnected`"))),
85            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::DestinationDisconnected`")))),
86        }
87    } else {
88        let content = resp.text().await?;
89        let entity: Option<DeleteDestinationByPlatformError> = serde_json::from_str(&content).ok();
90        Err(Error::ResponseError(ResponseContent { status, content, entity }))
91    }
92}
93
94/// Reports every destination this deployment can forward to, each with the caller org's connection state: whether it is connected, whether it is enabled, whether a credential resolves right now, and the config fields the console renders for it.
95pub async fn get_destination(configuration: &configuration::Configuration, ) -> Result<models::DestinationList, Error<GetDestinationError>> {
96
97    let uri_str = format!("{}/v1/destination", configuration.base_path);
98    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
99
100    if let Some(ref user_agent) = configuration.user_agent {
101        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
102    }
103    if let Some(ref token) = configuration.bearer_access_token {
104        req_builder = req_builder.bearer_auth(token.to_owned());
105    };
106
107    let req = req_builder.build()?;
108    let resp = configuration.client.execute(req).await?;
109
110    let status = resp.status();
111    let content_type = resp
112        .headers()
113        .get("content-type")
114        .and_then(|v| v.to_str().ok())
115        .unwrap_or("application/octet-stream");
116    let content_type = super::ContentType::from(content_type);
117
118    if !status.is_client_error() && !status.is_server_error() {
119        let content = resp.text().await?;
120        match content_type {
121            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
122            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DestinationList`"))),
123            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::DestinationList`")))),
124        }
125    } else {
126        let content = resp.text().await?;
127        let entity: Option<GetDestinationError> = serde_json::from_str(&content).ok();
128        Err(Error::ResponseError(ResponseContent { status, content, entity }))
129    }
130}
131
132/// Reports one destination's card for the caller's org — its config fields, its connection state, and whether a credential resolves right now. A platform this deployment does not carry is not found.
133pub async fn get_destination_by_platform(configuration: &configuration::Configuration, platform: &str) -> Result<models::DestinationStatus, Error<GetDestinationByPlatformError>> {
134    // add a prefix to parameters to efficiently prevent name collisions
135    let p_platform = platform;
136
137    let uri_str = format!("{}/v1/destination/{platform}", configuration.base_path, platform=crate::apis::urlencode(p_platform));
138    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
139
140    if let Some(ref user_agent) = configuration.user_agent {
141        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142    }
143    if let Some(ref token) = configuration.bearer_access_token {
144        req_builder = req_builder.bearer_auth(token.to_owned());
145    };
146
147    let req = req_builder.build()?;
148    let resp = configuration.client.execute(req).await?;
149
150    let status = resp.status();
151    let content_type = resp
152        .headers()
153        .get("content-type")
154        .and_then(|v| v.to_str().ok())
155        .unwrap_or("application/octet-stream");
156    let content_type = super::ContentType::from(content_type);
157
158    if !status.is_client_error() && !status.is_server_error() {
159        let content = resp.text().await?;
160        match content_type {
161            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DestinationStatus`"))),
163            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::DestinationStatus`")))),
164        }
165    } else {
166        let content = resp.text().await?;
167        let entity: Option<GetDestinationByPlatformError> = serde_json::from_str(&content).ok();
168        Err(Error::ResponseError(ResponseContent { status, content, entity }))
169    }
170}
171
172/// Stores the addressed platform's non-secret ids (its measurement, pixel or dataset ids) and seals its API credential into KMS under a path scoped to the caller's own org, then answers the same status card the read routes do — with live telling you whether the credential actually resolves right now. The body's property NAMES are the platform's own: each field the platform declares, plus each secret under its camelCase name, so the accepted keys differ per platform and a missing REQUIRED field is refused. Connecting is an ORG ADMIN action — a validated member without the admin bit gets 403 — and it fails closed with 503 when the KMS master key is unavailable rather than persisting a destination whose secret was never sealed. The secret itself never appears in the response, in the store, or in a log line; only its NAME is ever published. Set enabled to false to keep the connection but stop the analytics fan-out to it.
173pub async fn post_destination_by_platform(configuration: &configuration::Configuration, platform: &str, request_body: Option<std::collections::HashMap<String, serde_json::Value>>) -> Result<models::DestinationStatus, Error<PostDestinationByPlatformError>> {
174    // add a prefix to parameters to efficiently prevent name collisions
175    let p_platform = platform;
176    let p_request_body = request_body;
177
178    let uri_str = format!("{}/v1/destination/{platform}", configuration.base_path, platform=crate::apis::urlencode(p_platform));
179    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
180
181    if let Some(ref user_agent) = configuration.user_agent {
182        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
183    }
184    if let Some(ref token) = configuration.bearer_access_token {
185        req_builder = req_builder.bearer_auth(token.to_owned());
186    };
187    req_builder = req_builder.json(&p_request_body);
188
189    let req = req_builder.build()?;
190    let resp = configuration.client.execute(req).await?;
191
192    let status = resp.status();
193    let content_type = resp
194        .headers()
195        .get("content-type")
196        .and_then(|v| v.to_str().ok())
197        .unwrap_or("application/octet-stream");
198    let content_type = super::ContentType::from(content_type);
199
200    if !status.is_client_error() && !status.is_server_error() {
201        let content = resp.text().await?;
202        match content_type {
203            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
204            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DestinationStatus`"))),
205            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::DestinationStatus`")))),
206        }
207    } else {
208        let content = resp.text().await?;
209        let entity: Option<PostDestinationByPlatformError> = serde_json::from_str(&content).ok();
210        Err(Error::ResponseError(ResponseContent { status, content, entity }))
211    }
212}
213
214/// Sends ONE synthetic pageview through the connected destination end to end and reports what the platform said. A send the platform refuses is reported as data — {\"ok\": false, \"error\": …} at 200 — so the console shows the platform's own words rather than an error about Hanzo. It requires org admin.
215pub async fn post_destination_by_platform_test(configuration: &configuration::Configuration, platform: &str) -> Result<models::DestinationTest, Error<PostDestinationByPlatformTestError>> {
216    // add a prefix to parameters to efficiently prevent name collisions
217    let p_platform = platform;
218
219    let uri_str = format!("{}/v1/destination/{platform}/test", configuration.base_path, platform=crate::apis::urlencode(p_platform));
220    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
221
222    if let Some(ref user_agent) = configuration.user_agent {
223        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
224    }
225    if let Some(ref token) = configuration.bearer_access_token {
226        req_builder = req_builder.bearer_auth(token.to_owned());
227    };
228
229    let req = req_builder.build()?;
230    let resp = configuration.client.execute(req).await?;
231
232    let status = resp.status();
233    let content_type = resp
234        .headers()
235        .get("content-type")
236        .and_then(|v| v.to_str().ok())
237        .unwrap_or("application/octet-stream");
238    let content_type = super::ContentType::from(content_type);
239
240    if !status.is_client_error() && !status.is_server_error() {
241        let content = resp.text().await?;
242        match content_type {
243            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DestinationTest`"))),
245            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::DestinationTest`")))),
246        }
247    } else {
248        let content = resp.text().await?;
249        let entity: Option<PostDestinationByPlatformTestError> = serde_json::from_str(&content).ok();
250        Err(Error::ResponseError(ResponseContent { status, content, entity }))
251    }
252}
253