Skip to main content

hanzo_client/apis/
flags_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_flags_defs_by_key`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteFlagsDefsByKeyError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_flags_activity`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetFlagsActivityError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_flags_defs`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetFlagsDefsError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_flags_defs_by_key`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetFlagsDefsByKeyError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_flags_health`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetFlagsHealthError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`post_flags`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostFlagsError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`post_flags_decide`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum PostFlagsDecideError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`put_flags_defs_by_key`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum PutFlagsDefsByKeyError {
71    UnknownValue(serde_json::Value),
72}
73
74
75/// Removes one flag definition by key and records the deletion in the change log. A key the caller's store does not hold is a 404.
76pub async fn delete_flags_defs_by_key(configuration: &configuration::Configuration, key: &str) -> Result<models::DeletedOut, Error<DeleteFlagsDefsByKeyError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_key = key;
79
80    let uri_str = format!("{}/v1/flags/defs/{key}", configuration.base_path, key=crate::apis::urlencode(p_key));
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    let content_type = resp
95        .headers()
96        .get("content-type")
97        .and_then(|v| v.to_str().ok())
98        .unwrap_or("application/octet-stream");
99    let content_type = super::ContentType::from(content_type);
100
101    if !status.is_client_error() && !status.is_server_error() {
102        let content = resp.text().await?;
103        match content_type {
104            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
105            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeletedOut`"))),
106            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::DeletedOut`")))),
107        }
108    } else {
109        let content = resp.text().await?;
110        let entity: Option<DeleteFlagsDefsByKeyError> = serde_json::from_str(&content).ok();
111        Err(Error::ResponseError(ResponseContent { status, content, entity }))
112    }
113}
114
115/// Returns the caller's flag change log newest-first: every create, update and delete, with the actor and the time.
116pub async fn get_flags_activity(configuration: &configuration::Configuration, limit: Option<i32>) -> Result<models::ActivityOut, Error<GetFlagsActivityError>> {
117    // add a prefix to parameters to efficiently prevent name collisions
118    let p_limit = limit;
119
120    let uri_str = format!("{}/v1/flags/activity", configuration.base_path);
121    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
122
123    if let Some(ref param_value) = p_limit {
124        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
125    }
126    if let Some(ref user_agent) = configuration.user_agent {
127        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
128    }
129    if let Some(ref token) = configuration.bearer_access_token {
130        req_builder = req_builder.bearer_auth(token.to_owned());
131    };
132
133    let req = req_builder.build()?;
134    let resp = configuration.client.execute(req).await?;
135
136    let status = resp.status();
137    let content_type = resp
138        .headers()
139        .get("content-type")
140        .and_then(|v| v.to_str().ok())
141        .unwrap_or("application/octet-stream");
142    let content_type = super::ContentType::from(content_type);
143
144    if !status.is_client_error() && !status.is_server_error() {
145        let content = resp.text().await?;
146        match content_type {
147            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
148            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ActivityOut`"))),
149            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::ActivityOut`")))),
150        }
151    } else {
152        let content = resp.text().await?;
153        let entity: Option<GetFlagsActivityError> = serde_json::from_str(&content).ok();
154        Err(Error::ResponseError(ResponseContent { status, content, entity }))
155    }
156}
157
158/// Returns every flag definition in the caller's (org, project) store, by key, with its version and who last changed it.
159pub async fn get_flags_defs(configuration: &configuration::Configuration, ) -> Result<models::DefsOut, Error<GetFlagsDefsError>> {
160
161    let uri_str = format!("{}/v1/flags/defs", configuration.base_path);
162    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
163
164    if let Some(ref user_agent) = configuration.user_agent {
165        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
166    }
167    if let Some(ref token) = configuration.bearer_access_token {
168        req_builder = req_builder.bearer_auth(token.to_owned());
169    };
170
171    let req = req_builder.build()?;
172    let resp = configuration.client.execute(req).await?;
173
174    let status = resp.status();
175    let content_type = resp
176        .headers()
177        .get("content-type")
178        .and_then(|v| v.to_str().ok())
179        .unwrap_or("application/octet-stream");
180    let content_type = super::ContentType::from(content_type);
181
182    if !status.is_client_error() && !status.is_server_error() {
183        let content = resp.text().await?;
184        match content_type {
185            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
186            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DefsOut`"))),
187            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::DefsOut`")))),
188        }
189    } else {
190        let content = resp.text().await?;
191        let entity: Option<GetFlagsDefsError> = serde_json::from_str(&content).ok();
192        Err(Error::ResponseError(ResponseContent { status, content, entity }))
193    }
194}
195
196/// Returns one flag definition by key, or 404 when the caller's store has none under that key.
197pub async fn get_flags_defs_by_key(configuration: &configuration::Configuration, key: &str) -> Result<models::DefRow, Error<GetFlagsDefsByKeyError>> {
198    // add a prefix to parameters to efficiently prevent name collisions
199    let p_key = key;
200
201    let uri_str = format!("{}/v1/flags/defs/{key}", configuration.base_path, key=crate::apis::urlencode(p_key));
202    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
203
204    if let Some(ref user_agent) = configuration.user_agent {
205        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
206    }
207    if let Some(ref token) = configuration.bearer_access_token {
208        req_builder = req_builder.bearer_auth(token.to_owned());
209    };
210
211    let req = req_builder.build()?;
212    let resp = configuration.client.execute(req).await?;
213
214    let status = resp.status();
215    let content_type = resp
216        .headers()
217        .get("content-type")
218        .and_then(|v| v.to_str().ok())
219        .unwrap_or("application/octet-stream");
220    let content_type = super::ContentType::from(content_type);
221
222    if !status.is_client_error() && !status.is_server_error() {
223        let content = resp.text().await?;
224        match content_type {
225            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
226            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DefRow`"))),
227            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::DefRow`")))),
228        }
229    } else {
230        let content = resp.text().await?;
231        let entity: Option<GetFlagsDefsByKeyError> = serde_json::from_str(&content).ok();
232        Err(Error::ResponseError(ResponseContent { status, content, entity }))
233    }
234}
235
236/// Health reports that the flag engine is serving. It is not gated: liveness must be probe-able without a token.
237pub async fn get_flags_health(configuration: &configuration::Configuration, ) -> Result<models::HealthOut, Error<GetFlagsHealthError>> {
238
239    let uri_str = format!("{}/v1/flags/health", configuration.base_path);
240    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
241
242    if let Some(ref user_agent) = configuration.user_agent {
243        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
244    }
245    if let Some(ref token) = configuration.bearer_access_token {
246        req_builder = req_builder.bearer_auth(token.to_owned());
247    };
248
249    let req = req_builder.build()?;
250    let resp = configuration.client.execute(req).await?;
251
252    let status = resp.status();
253    let content_type = resp
254        .headers()
255        .get("content-type")
256        .and_then(|v| v.to_str().ok())
257        .unwrap_or("application/octet-stream");
258    let content_type = super::ContentType::from(content_type);
259
260    if !status.is_client_error() && !status.is_server_error() {
261        let content = resp.text().await?;
262        match content_type {
263            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
264            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::HealthOut`"))),
265            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::HealthOut`")))),
266        }
267    } else {
268        let content = resp.text().await?;
269        let entity: Option<GetFlagsHealthError> = serde_json::from_str(&content).ok();
270        Err(Error::ResponseError(ResponseContent { status, content, entity }))
271    }
272}
273
274/// Evaluate runs the caller's flag definitions for one identity and returns the flag verdict: which flags are on (or which variant), their payloads, and whether any definition failed to compute. Evaluation is in-process over the caller's own (org, project) definitions — no network hop, no shared KV — so a tenant can only ever evaluate its own flags.
275pub async fn post_flags(configuration: &configuration::Configuration, evaluate_in: models::EvaluateIn) -> Result<serde_json::Value, Error<PostFlagsError>> {
276    // add a prefix to parameters to efficiently prevent name collisions
277    let p_evaluate_in = evaluate_in;
278
279    let uri_str = format!("{}/v1/flags", configuration.base_path);
280    let mut req_builder = configuration.client.request(reqwest::Method::POST, &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_evaluate_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 `serde_json::Value`"))),
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 `serde_json::Value`")))),
307        }
308    } else {
309        let content = resp.text().await?;
310        let entity: Option<PostFlagsError> = serde_json::from_str(&content).ok();
311        Err(Error::ResponseError(ResponseContent { status, content, entity }))
312    }
313}
314
315/// Evaluate runs the caller's flag definitions for one identity and returns the flag verdict: which flags are on (or which variant), their payloads, and whether any definition failed to compute. Evaluation is in-process over the caller's own (org, project) definitions — no network hop, no shared KV — so a tenant can only ever evaluate its own flags.
316pub async fn post_flags_decide(configuration: &configuration::Configuration, evaluate_in: models::EvaluateIn) -> Result<serde_json::Value, Error<PostFlagsDecideError>> {
317    // add a prefix to parameters to efficiently prevent name collisions
318    let p_evaluate_in = evaluate_in;
319
320    let uri_str = format!("{}/v1/flags/decide", configuration.base_path);
321    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
322
323    if let Some(ref user_agent) = configuration.user_agent {
324        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
325    }
326    if let Some(ref token) = configuration.bearer_access_token {
327        req_builder = req_builder.bearer_auth(token.to_owned());
328    };
329    req_builder = req_builder.json(&p_evaluate_in);
330
331    let req = req_builder.build()?;
332    let resp = configuration.client.execute(req).await?;
333
334    let status = resp.status();
335    let content_type = resp
336        .headers()
337        .get("content-type")
338        .and_then(|v| v.to_str().ok())
339        .unwrap_or("application/octet-stream");
340    let content_type = super::ContentType::from(content_type);
341
342    if !status.is_client_error() && !status.is_server_error() {
343        let content = resp.text().await?;
344        match content_type {
345            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
346            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
347            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
348        }
349    } else {
350        let content = resp.text().await?;
351        let entity: Option<PostFlagsDecideError> = serde_json::from_str(&content).ok();
352        Err(Error::ResponseError(ResponseContent { status, content, entity }))
353    }
354}
355
356/// Creates or replaces the flag definition at the path's key and returns the stored row. The BODY IS THE DEFINITION DOCUMENT — the flag-definition JSON object the evaluator consumes — and it is stored verbatim except that its \"key\" is forced to the key in the URL, so a document can never be filed under a name other than the one it was addressed by. Every write bumps the version and appends to the change log under the caller's identity.
357pub async fn put_flags_defs_by_key(configuration: &configuration::Configuration, key: &str, body: Option<serde_json::Value>) -> Result<models::DefRow, Error<PutFlagsDefsByKeyError>> {
358    // add a prefix to parameters to efficiently prevent name collisions
359    let p_key = key;
360    let p_body = body;
361
362    let uri_str = format!("{}/v1/flags/defs/{key}", configuration.base_path, key=crate::apis::urlencode(p_key));
363    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
364
365    if let Some(ref user_agent) = configuration.user_agent {
366        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
367    }
368    if let Some(ref token) = configuration.bearer_access_token {
369        req_builder = req_builder.bearer_auth(token.to_owned());
370    };
371    req_builder = req_builder.json(&p_body);
372
373    let req = req_builder.build()?;
374    let resp = configuration.client.execute(req).await?;
375
376    let status = resp.status();
377    let content_type = resp
378        .headers()
379        .get("content-type")
380        .and_then(|v| v.to_str().ok())
381        .unwrap_or("application/octet-stream");
382    let content_type = super::ContentType::from(content_type);
383
384    if !status.is_client_error() && !status.is_server_error() {
385        let content = resp.text().await?;
386        match content_type {
387            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
388            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DefRow`"))),
389            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::DefRow`")))),
390        }
391    } else {
392        let content = resp.text().await?;
393        let entity: Option<PutFlagsDefsByKeyError> = serde_json::from_str(&content).ok();
394        Err(Error::ResponseError(ResponseContent { status, content, entity }))
395    }
396}
397