Skip to main content

hanzo_client/apis/
reference_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_clear_reference`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum RiskClearReferenceError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`risk_reference`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum RiskReferenceError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`risk_reference_sets`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum RiskReferenceSetsError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`risk_refresh_reference`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum RiskRefreshReferenceError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`risk_resolve_reference`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum RiskResolveReferenceError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`risk_set_reference`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum RiskSetReferenceError {
57    UnknownValue(serde_json::Value),
58}
59
60
61/// Removes one of your organisation's overrides.  It removes an entry your organisation wrote, never a baseline member: the published set is not writable from here, so a removal can only ever restore the baseline's own answer.
62pub async fn risk_clear_reference(configuration: &configuration::Configuration, set: &str, key: Option<&str>) -> Result<models::ClearReferenceOut, Error<RiskClearReferenceError>> {
63    // add a prefix to parameters to efficiently prevent name collisions
64    let p_set = set;
65    let p_key = key;
66
67    let uri_str = format!("{}/v1/reference/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
68    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
69
70    if let Some(ref param_value) = p_key {
71        req_builder = req_builder.query(&[("key", &param_value.to_string())]);
72    }
73    if let Some(ref user_agent) = configuration.user_agent {
74        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75    }
76    if let Some(ref token) = configuration.bearer_access_token {
77        req_builder = req_builder.bearer_auth(token.to_owned());
78    };
79
80    let req = req_builder.build()?;
81    let resp = configuration.client.execute(req).await?;
82
83    let status = resp.status();
84    let content_type = resp
85        .headers()
86        .get("content-type")
87        .and_then(|v| v.to_str().ok())
88        .unwrap_or("application/octet-stream");
89    let content_type = super::ContentType::from(content_type);
90
91    if !status.is_client_error() && !status.is_server_error() {
92        let content = resp.text().await?;
93        match content_type {
94            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
95            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClearReferenceOut`"))),
96            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::ClearReferenceOut`")))),
97        }
98    } else {
99        let content = resp.text().await?;
100        let entity: Option<RiskClearReferenceError> = serde_json::from_str(&content).ok();
101        Err(Error::ResponseError(ResponseContent { status, content, entity }))
102    }
103}
104
105/// Reference describes one set and lists your org's overrides in it.  The set half is public data about a published list — its version, its publishers, their licences and how current each one is. The overrides half is yours alone: it is read from your organisation's own store, and no other organisation's entries can appear in it.
106pub async fn risk_reference(configuration: &configuration::Configuration, set: &str, after: Option<&str>, limit: Option<i32>) -> Result<models::ReferenceOut, Error<RiskReferenceError>> {
107    // add a prefix to parameters to efficiently prevent name collisions
108    let p_set = set;
109    let p_after = after;
110    let p_limit = limit;
111
112    let uri_str = format!("{}/v1/reference/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
113    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
114
115    if let Some(ref param_value) = p_after {
116        req_builder = req_builder.query(&[("after", &param_value.to_string())]);
117    }
118    if let Some(ref param_value) = p_limit {
119        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
120    }
121    if let Some(ref user_agent) = configuration.user_agent {
122        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
123    }
124    if let Some(ref token) = configuration.bearer_access_token {
125        req_builder = req_builder.bearer_auth(token.to_owned());
126    };
127
128    let req = req_builder.build()?;
129    let resp = configuration.client.execute(req).await?;
130
131    let status = resp.status();
132    let content_type = resp
133        .headers()
134        .get("content-type")
135        .and_then(|v| v.to_str().ok())
136        .unwrap_or("application/octet-stream");
137    let content_type = super::ContentType::from(content_type);
138
139    if !status.is_client_error() && !status.is_server_error() {
140        let content = resp.text().await?;
141        match content_type {
142            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
143            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReferenceOut`"))),
144            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::ReferenceOut`")))),
145        }
146    } else {
147        let content = resp.text().await?;
148        let entity: Option<RiskReferenceError> = serde_json::from_str(&content).ok();
149        Err(Error::ResponseError(ResponseContent { status, content, entity }))
150    }
151}
152
153/// Lists every set this plane publishes, with its version and how fresh it is.  Read the Stale and Refused lists first: they are the two ways this plane can be quietly wrong, and they are reported rather than inferred. A set in Refused answers nothing — it has never loaded, it is held by another component, or it names a source we hold no licence for.
154pub async fn risk_reference_sets(configuration: &configuration::Configuration, ) -> Result<models::ReferenceSetsOut, Error<RiskReferenceSetsError>> {
155
156    let uri_str = format!("{}/v1/reference", configuration.base_path);
157    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
158
159    if let Some(ref user_agent) = configuration.user_agent {
160        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161    }
162    if let Some(ref token) = configuration.bearer_access_token {
163        req_builder = req_builder.bearer_auth(token.to_owned());
164    };
165
166    let req = req_builder.build()?;
167    let resp = configuration.client.execute(req).await?;
168
169    let status = resp.status();
170    let content_type = resp
171        .headers()
172        .get("content-type")
173        .and_then(|v| v.to_str().ok())
174        .unwrap_or("application/octet-stream");
175    let content_type = super::ContentType::from(content_type);
176
177    if !status.is_client_error() && !status.is_server_error() {
178        let content = resp.text().await?;
179        match content_type {
180            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
181            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReferenceSetsOut`"))),
182            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::ReferenceSetsOut`")))),
183        }
184    } else {
185        let content = resp.text().await?;
186        let entity: Option<RiskReferenceSetsError> = serde_json::from_str(&content).ok();
187        Err(Error::ResponseError(ResponseContent { status, content, entity }))
188    }
189}
190
191/// Takes a new version of one set. SuperAdmin only.  It is platform work, not tenant work: it writes the shared baseline every organisation reads, so it is gated to the platform's own identity. Nothing here can write an organisation's overrides, and nothing an organisation sends can reach this route.  Idempotent. A version is the content digest of what was taken, so refreshing an unchanged publisher writes no rows and reports unchanged. Resumable: a run that died half-way is continued from where it stopped rather than restarted.  A set whose source needs a licence we do not hold is refused with the reason, rather than being quietly skipped.
192pub async fn risk_refresh_reference(configuration: &configuration::Configuration, refresh_reference_in: models::RefreshReferenceIn) -> Result<models::RefreshReferenceOut, Error<RiskRefreshReferenceError>> {
193    // add a prefix to parameters to efficiently prevent name collisions
194    let p_refresh_reference_in = refresh_reference_in;
195
196    let uri_str = format!("{}/v1/reference/refresh", configuration.base_path);
197    let mut req_builder = configuration.client.request(reqwest::Method::POST, &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    req_builder = req_builder.json(&p_refresh_reference_in);
206
207    let req = req_builder.build()?;
208    let resp = configuration.client.execute(req).await?;
209
210    let status = resp.status();
211    let content_type = resp
212        .headers()
213        .get("content-type")
214        .and_then(|v| v.to_str().ok())
215        .unwrap_or("application/octet-stream");
216    let content_type = super::ContentType::from(content_type);
217
218    if !status.is_client_error() && !status.is_server_error() {
219        let content = resp.text().await?;
220        match content_type {
221            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
222            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RefreshReferenceOut`"))),
223            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::RefreshReferenceOut`")))),
224        }
225    } else {
226        let content = resp.text().await?;
227        let entity: Option<RiskRefreshReferenceError> = serde_json::from_str(&content).ok();
228        Err(Error::ResponseError(ResponseContent { status, content, entity }))
229    }
230}
231
232/// Looks keys up against the reference plane.  Your organisation's own overrides are consulted FIRST and win outright; the shared baseline answers everything they do not cover. Every answer names the version that produced it, when that version was current and whether it is stale, so a decision can record exactly what it consulted.  Read Refusal before reading Hit. A set that has never loaded, one held by the component that screens against it, and one whose source needs a licence we do not hold all answer with a refusal — and a miss on a refusing set means nothing is known, not that the key is clean.
233pub async fn risk_resolve_reference(configuration: &configuration::Configuration, resolve_reference_in: models::ResolveReferenceIn) -> Result<models::ResolveReferenceOut, Error<RiskResolveReferenceError>> {
234    // add a prefix to parameters to efficiently prevent name collisions
235    let p_resolve_reference_in = resolve_reference_in;
236
237    let uri_str = format!("{}/v1/reference/resolve", configuration.base_path);
238    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
239
240    if let Some(ref user_agent) = configuration.user_agent {
241        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
242    }
243    if let Some(ref token) = configuration.bearer_access_token {
244        req_builder = req_builder.bearer_auth(token.to_owned());
245    };
246    req_builder = req_builder.json(&p_resolve_reference_in);
247
248    let req = req_builder.build()?;
249    let resp = configuration.client.execute(req).await?;
250
251    let status = resp.status();
252    let content_type = resp
253        .headers()
254        .get("content-type")
255        .and_then(|v| v.to_str().ok())
256        .unwrap_or("application/octet-stream");
257    let content_type = super::ContentType::from(content_type);
258
259    if !status.is_client_error() && !status.is_server_error() {
260        let content = resp.text().await?;
261        match content_type {
262            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
263            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ResolveReferenceOut`"))),
264            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::ResolveReferenceOut`")))),
265        }
266    } else {
267        let content = resp.text().await?;
268        let entity: Option<RiskResolveReferenceError> = serde_json::from_str(&content).ok();
269        Err(Error::ResponseError(ResponseContent { status, content, entity }))
270    }
271}
272
273/// Writes your organisation's own allow and deny entries over a set.  Idempotent on the key: writing the same entry twice is one entry, and writing it again replaces the verdict and the note. The whole batch is one transaction, so a batch that would cross the per-set bound writes nothing rather than half of itself — a half-applied deny list is worse than a refused one, because nobody can tell which half applied.  Your entries are held in your organisation's own store and are never visible to another organisation, and they never change what any other organisation sees. The shared baseline is not writable from here at all.
274pub async fn risk_set_reference(configuration: &configuration::Configuration, set: &str, set_reference_in: models::SetReferenceIn) -> Result<models::SetReferenceOut, Error<RiskSetReferenceError>> {
275    // add a prefix to parameters to efficiently prevent name collisions
276    let p_set = set;
277    let p_set_reference_in = set_reference_in;
278
279    let uri_str = format!("{}/v1/reference/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
280    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
281
282    if let Some(ref user_agent) = configuration.user_agent {
283        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
284    }
285    if let Some(ref token) = configuration.bearer_access_token {
286        req_builder = req_builder.bearer_auth(token.to_owned());
287    };
288    req_builder = req_builder.json(&p_set_reference_in);
289
290    let req = req_builder.build()?;
291    let resp = configuration.client.execute(req).await?;
292
293    let status = resp.status();
294    let content_type = resp
295        .headers()
296        .get("content-type")
297        .and_then(|v| v.to_str().ok())
298        .unwrap_or("application/octet-stream");
299    let content_type = super::ContentType::from(content_type);
300
301    if !status.is_client_error() && !status.is_server_error() {
302        let content = resp.text().await?;
303        match content_type {
304            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
305            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SetReferenceOut`"))),
306            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::SetReferenceOut`")))),
307        }
308    } else {
309        let content = resp.text().await?;
310        let entity: Option<RiskSetReferenceError> = serde_json::from_str(&content).ok();
311        Err(Error::ResponseError(ResponseContent { status, content, entity }))
312    }
313}
314