Skip to main content

hanzo_client/apis/
dataset_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 [`risk_create_dataset`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum RiskCreateDatasetError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`risk_dataset`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum RiskDatasetError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`risk_dataset_lineage`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum RiskDatasetLineageError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`risk_datasets`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum RiskDatasetsError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`risk_delete_dataset`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum RiskDeleteDatasetError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`risk_export_dataset`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum RiskExportDatasetError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`risk_materialize_dataset`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum RiskMaterializeDatasetError {
64    UnknownValue(serde_json::Value),
65}
66
67
68/// Declares the next version of a dataset from a bound query over this org's own feature surface.  It mints a VERSION and writes no rows: a version is declared, then materialised once, then never rewritten. Version numbers are monotone and never reused, so \"version 3 of signups\" means one thing forever — which is the whole reason a model can cite one.  The window is bounded by the source's retention, the horizon by a year, the rows by the plane's cap, and the number of datasets and versions per org by their own limits. Every refusal names which bound it hit.
69pub async fn risk_create_dataset(configuration: &configuration::Configuration, risk_dataset_spec: models::RiskDatasetSpec) -> Result<models::RiskDataset, Error<RiskCreateDatasetError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    let p_risk_dataset_spec = risk_dataset_spec;
72
73    let uri_str = format!("{}/v1/dataset", configuration.base_path);
74    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
75
76    if let Some(ref user_agent) = configuration.user_agent {
77        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78    }
79    if let Some(ref token) = configuration.bearer_access_token {
80        req_builder = req_builder.bearer_auth(token.to_owned());
81    };
82    req_builder = req_builder.json(&p_risk_dataset_spec);
83
84    let req = req_builder.build()?;
85    let resp = configuration.client.execute(req).await?;
86
87    let status = resp.status();
88    let content_type = resp
89        .headers()
90        .get("content-type")
91        .and_then(|v| v.to_str().ok())
92        .unwrap_or("application/octet-stream");
93    let content_type = super::ContentType::from(content_type);
94
95    if !status.is_client_error() && !status.is_server_error() {
96        let content = resp.text().await?;
97        match content_type {
98            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
99            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RiskDataset`"))),
100            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::RiskDataset`")))),
101        }
102    } else {
103        let content = resp.text().await?;
104        let entity: Option<RiskCreateDatasetError> = serde_json::from_str(&content).ok();
105        Err(Error::ResponseError(ResponseContent { status, content, entity }))
106    }
107}
108
109/// Dataset describes every version of one dataset, newest first — the whole history, because the point of a version is that the older ones are still there and a model fitted last quarter cites one of them.  A name this org does not own answers 404, exactly as an unknown name does, so a probe learns nothing about another tenant's datasets.
110pub async fn risk_dataset(configuration: &configuration::Configuration, name: &str) -> Result<models::RiskDatasetVersions, Error<RiskDatasetError>> {
111    // add a prefix to parameters to efficiently prevent name collisions
112    let p_name = name;
113
114    let uri_str = format!("{}/v1/dataset/{name}", configuration.base_path, name=crate::apis::urlencode(p_name));
115    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
116
117    if let Some(ref user_agent) = configuration.user_agent {
118        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119    }
120    if let Some(ref token) = configuration.bearer_access_token {
121        req_builder = req_builder.bearer_auth(token.to_owned());
122    };
123
124    let req = req_builder.build()?;
125    let resp = configuration.client.execute(req).await?;
126
127    let status = resp.status();
128    let content_type = resp
129        .headers()
130        .get("content-type")
131        .and_then(|v| v.to_str().ok())
132        .unwrap_or("application/octet-stream");
133    let content_type = super::ContentType::from(content_type);
134
135    if !status.is_client_error() && !status.is_server_error() {
136        let content = resp.text().await?;
137        match content_type {
138            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
139            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RiskDatasetVersions`"))),
140            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::RiskDatasetVersions`")))),
141        }
142    } else {
143        let content = resp.text().await?;
144        let entity: Option<RiskDatasetError> = serde_json::from_str(&content).ok();
145        Err(Error::ResponseError(ResponseContent { status, content, entity }))
146    }
147}
148
149/// Shows where a version's rows came from and whether that can still be demonstrated.  The answer is MEASURED, not recalled: the plane asks the source the same bounded question again and compares it to the fingerprint taken when the version was built. Anything but exact agreement is reported as drift — the source is fed by a rollup that runs behind the events, so \"it holds more now\" is the ordinary case and it means re-running the spec would not reproduce this version. An admitted gap is actionable; an unfalsifiable claim is not.  IT IS A PRICED, BOUNDED READ, because it is the same statement a materialisation is charged for: an exact distinct-count over up to 400 days of this org's feature surface. It takes the org's ONE source-scan slot, so a tenant looping it spends one scan and not a thousand; it counts against the plane's ceiling, so the fleet's warehouse is bounded too; and it runs under this plane's own deadline rather than the caller's patience.
150pub async fn risk_dataset_lineage(configuration: &configuration::Configuration, name: &str, version: Option<i32>) -> Result<models::RiskLineage, Error<RiskDatasetLineageError>> {
151    // add a prefix to parameters to efficiently prevent name collisions
152    let p_name = name;
153    let p_version = version;
154
155    let uri_str = format!("{}/v1/dataset/{name}/lineage", configuration.base_path, name=crate::apis::urlencode(p_name));
156    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
157
158    if let Some(ref param_value) = p_version {
159        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
160    }
161    if let Some(ref user_agent) = configuration.user_agent {
162        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
163    }
164    if let Some(ref token) = configuration.bearer_access_token {
165        req_builder = req_builder.bearer_auth(token.to_owned());
166    };
167
168    let req = req_builder.build()?;
169    let resp = configuration.client.execute(req).await?;
170
171    let status = resp.status();
172    let content_type = resp
173        .headers()
174        .get("content-type")
175        .and_then(|v| v.to_str().ok())
176        .unwrap_or("application/octet-stream");
177    let content_type = super::ContentType::from(content_type);
178
179    if !status.is_client_error() && !status.is_server_error() {
180        let content = resp.text().await?;
181        match content_type {
182            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
183            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RiskLineage`"))),
184            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::RiskLineage`")))),
185        }
186    } else {
187        let content = resp.text().await?;
188        let entity: Option<RiskDatasetLineageError> = serde_json::from_str(&content).ok();
189        Err(Error::ResponseError(ResponseContent { status, content, entity }))
190    }
191}
192
193/// Datasets lists this org's datasets, each with its newest version. An org that has declared none gets an empty list; a store that cannot be reached gets a refusal, never an empty list, because the two read identically and only one of them is true.
194pub async fn risk_datasets(configuration: &configuration::Configuration, ) -> Result<models::RiskDatasetList, Error<RiskDatasetsError>> {
195
196    let uri_str = format!("{}/v1/dataset", configuration.base_path);
197    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
198
199    if let Some(ref user_agent) = configuration.user_agent {
200        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
201    }
202    if let Some(ref token) = configuration.bearer_access_token {
203        req_builder = req_builder.bearer_auth(token.to_owned());
204    };
205
206    let req = req_builder.build()?;
207    let resp = configuration.client.execute(req).await?;
208
209    let status = resp.status();
210    let content_type = resp
211        .headers()
212        .get("content-type")
213        .and_then(|v| v.to_str().ok())
214        .unwrap_or("application/octet-stream");
215    let content_type = super::ContentType::from(content_type);
216
217    if !status.is_client_error() && !status.is_server_error() {
218        let content = resp.text().await?;
219        match content_type {
220            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
221            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RiskDatasetList`"))),
222            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::RiskDatasetList`")))),
223        }
224    } else {
225        let content = resp.text().await?;
226        let entity: Option<RiskDatasetsError> = serde_json::from_str(&content).ok();
227        Err(Error::ResponseError(ResponseContent { status, content, entity }))
228    }
229}
230
231/// Disposes of one dataset and every version of it: the rows are dropped and the register is marked with what went.  This is the ONLY expiry in this plane. Neither table carries a TTL, deliberately: a table TTL is a fleet-wide clock no tenant can hold longer or shorten, which is the opposite of a retention decision belonging to the tenant whose records they are. The drop is a partition drop on (org, dataset), so the tenant is the first component of the thing being dropped and a disposal cannot be spelled across one.  The BYTES are what goes. The register keeps one `disposed` row per version — the name, the number, the spec, the digest and who disposed of it when — for two reasons: a retention obligation is answered by a record of the deletion, not by silence; and version numbers must stay monotone, so that after `orders` is disposed of and declared again the next version is 4 and not 1. A number that could be reused would make every citation of `orders v3` ambiguous forever.  It is not reversible and there is no soft state in between. A version a model cited has no rows once this returns, and every read of it says so.
232pub async fn risk_delete_dataset(configuration: &configuration::Configuration, name: &str) -> Result<models::RiskDatasetDisposal, Error<RiskDeleteDatasetError>> {
233    // add a prefix to parameters to efficiently prevent name collisions
234    let p_name = name;
235
236    let uri_str = format!("{}/v1/dataset/{name}", configuration.base_path, name=crate::apis::urlencode(p_name));
237    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
238
239    if let Some(ref user_agent) = configuration.user_agent {
240        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
241    }
242    if let Some(ref token) = configuration.bearer_access_token {
243        req_builder = req_builder.bearer_auth(token.to_owned());
244    };
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::RiskDatasetDisposal`"))),
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::RiskDatasetDisposal`")))),
263        }
264    } else {
265        let content = resp.text().await?;
266        let entity: Option<RiskDeleteDatasetError> = serde_json::from_str(&content).ok();
267        Err(Error::ResponseError(ResponseContent { status, content, entity }))
268    }
269}
270
271/// Reads a published version's rows back, one bounded page at a time, in the version's own stable row order.  Only a published version can be exported. Rows written by an attempt that never completed are inert — no register row names them — and they are disposed of with the dataset.
272pub async fn risk_export_dataset(configuration: &configuration::Configuration, name: &str, version: Option<i32>, split: Option<&str>, offset: Option<i32>, limit: Option<i32>) -> Result<models::RiskDatasetRows, Error<RiskExportDatasetError>> {
273    // add a prefix to parameters to efficiently prevent name collisions
274    let p_name = name;
275    let p_version = version;
276    let p_split = split;
277    let p_offset = offset;
278    let p_limit = limit;
279
280    let uri_str = format!("{}/v1/dataset/{name}/export", configuration.base_path, name=crate::apis::urlencode(p_name));
281    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
282
283    if let Some(ref param_value) = p_version {
284        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
285    }
286    if let Some(ref param_value) = p_split {
287        req_builder = req_builder.query(&[("split", &param_value.to_string())]);
288    }
289    if let Some(ref param_value) = p_offset {
290        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
291    }
292    if let Some(ref param_value) = p_limit {
293        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
294    }
295    if let Some(ref user_agent) = configuration.user_agent {
296        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
297    }
298    if let Some(ref token) = configuration.bearer_access_token {
299        req_builder = req_builder.bearer_auth(token.to_owned());
300    };
301
302    let req = req_builder.build()?;
303    let resp = configuration.client.execute(req).await?;
304
305    let status = resp.status();
306    let content_type = resp
307        .headers()
308        .get("content-type")
309        .and_then(|v| v.to_str().ok())
310        .unwrap_or("application/octet-stream");
311    let content_type = super::ContentType::from(content_type);
312
313    if !status.is_client_error() && !status.is_server_error() {
314        let content = resp.text().await?;
315        match content_type {
316            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
317            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RiskDatasetRows`"))),
318            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::RiskDatasetRows`")))),
319        }
320    } else {
321        let content = resp.text().await?;
322        let entity: Option<RiskExportDatasetError> = serde_json::from_str(&content).ok();
323        Err(Error::ResponseError(ResponseContent { status, content, entity }))
324    }
325}
326
327/// Builds the declared version into immutable rows and answers 202 as soon as the attempt is on record.  It never holds the request open for the work: a materialisation is a bounded warehouse scan, and letting an HTTP client's timeout be a data plane's timeout is how one tenant's retry loop becomes everyone's outage. ONE materialisation runs per org at a time; a second is refused rather than queued, because a queue admits the same work later and the honest answer to \"again\" while one is running is that one is running.  Only a DECLARED version is admitted. A published version is immutable, and a version whose earlier attempt did not complete is never re-attempted — that would union two runs' rows under one number and make the digest a lie. In both cases the answer is to declare a new version, which is what a second run over a moving source honestly is.
328pub async fn risk_materialize_dataset(configuration: &configuration::Configuration, name: &str) -> Result<models::RiskDataset, Error<RiskMaterializeDatasetError>> {
329    // add a prefix to parameters to efficiently prevent name collisions
330    let p_name = name;
331
332    let uri_str = format!("{}/v1/dataset/{name}/materialize", configuration.base_path, name=crate::apis::urlencode(p_name));
333    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
334
335    if let Some(ref user_agent) = configuration.user_agent {
336        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
337    }
338    if let Some(ref token) = configuration.bearer_access_token {
339        req_builder = req_builder.bearer_auth(token.to_owned());
340    };
341
342    let req = req_builder.build()?;
343    let resp = configuration.client.execute(req).await?;
344
345    let status = resp.status();
346    let content_type = resp
347        .headers()
348        .get("content-type")
349        .and_then(|v| v.to_str().ok())
350        .unwrap_or("application/octet-stream");
351    let content_type = super::ContentType::from(content_type);
352
353    if !status.is_client_error() && !status.is_server_error() {
354        let content = resp.text().await?;
355        match content_type {
356            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
357            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RiskDataset`"))),
358            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::RiskDataset`")))),
359        }
360    } else {
361        let content = resp.text().await?;
362        let entity: Option<RiskMaterializeDatasetError> = serde_json::from_str(&content).ok();
363        Err(Error::ResponseError(ResponseContent { status, content, entity }))
364    }
365}
366