Skip to main content

hanzo_client/apis/
base_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 [`get_base_bases`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetBaseBasesError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_base_bases_by_org`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetBaseBasesByOrgError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_base_health`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetBaseHealthError {
36    UnknownValue(serde_json::Value),
37}
38
39
40/// Lists every Base the caller can reach, one per org their token carries.  The orgs come from IAM's signed membership set, so the list is exactly the orgs the caller is a member of and cannot be widened by asking. It is the account-wide view: a Base is per org, so this is one entry per org and there is nothing to page.  A caller with no membership set — a machine credential, an API key — reaches no Base and receives an empty list rather than a refusal, because holding no membership is an answer and not a failure.
41pub async fn get_base_bases(configuration: &configuration::Configuration, ) -> Result<Vec<models::BaseView>, Error<GetBaseBasesError>> {
42
43    let uri_str = format!("{}/v1/base/bases", configuration.base_path);
44    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
45
46    if let Some(ref user_agent) = configuration.user_agent {
47        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
48    }
49    if let Some(ref token) = configuration.bearer_access_token {
50        req_builder = req_builder.bearer_auth(token.to_owned());
51    };
52
53    let req = req_builder.build()?;
54    let resp = configuration.client.execute(req).await?;
55
56    let status = resp.status();
57    let content_type = resp
58        .headers()
59        .get("content-type")
60        .and_then(|v| v.to_str().ok())
61        .unwrap_or("application/octet-stream");
62    let content_type = super::ContentType::from(content_type);
63
64    if !status.is_client_error() && !status.is_server_error() {
65        let content = resp.text().await?;
66        match content_type {
67            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
68            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::BaseView&gt;`"))),
69            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::BaseView&gt;`")))),
70        }
71    } else {
72        let content = resp.text().await?;
73        let entity: Option<GetBaseBasesError> = serde_json::from_str(&content).ok();
74        Err(Error::ResponseError(ResponseContent { status, content, entity }))
75    }
76}
77
78/// Describes ONE org's Base — whether its store exists, and what it occupies.  The org must be one the caller's token carries; any other is not found, so this cannot be used to learn which orgs exist. That check is the same membership set the listing is built from, which is why the two can never disagree about what a caller may see.
79pub async fn get_base_bases_by_org(configuration: &configuration::Configuration, org: &str) -> Result<models::BaseView, Error<GetBaseBasesByOrgError>> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_org = org;
82
83    let uri_str = format!("{}/v1/base/bases/{org}", configuration.base_path, org=crate::apis::urlencode(p_org));
84    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
85
86    if let Some(ref user_agent) = configuration.user_agent {
87        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88    }
89    if let Some(ref token) = configuration.bearer_access_token {
90        req_builder = req_builder.bearer_auth(token.to_owned());
91    };
92
93    let req = req_builder.build()?;
94    let resp = configuration.client.execute(req).await?;
95
96    let status = resp.status();
97    let content_type = resp
98        .headers()
99        .get("content-type")
100        .and_then(|v| v.to_str().ok())
101        .unwrap_or("application/octet-stream");
102    let content_type = super::ContentType::from(content_type);
103
104    if !status.is_client_error() && !status.is_server_error() {
105        let content = resp.text().await?;
106        match content_type {
107            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
108            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BaseView`"))),
109            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::BaseView`")))),
110        }
111    } else {
112        let content = resp.text().await?;
113        let entity: Option<GetBaseBasesByOrgError> = serde_json::from_str(&content).ok();
114        Err(Error::ResponseError(ResponseContent { status, content, entity }))
115    }
116}
117
118/// Reports that the base subsystem is serving.  It is deliberately INDEPENDENT of whether this deployment actually embeds the Base engine: the route answers before the CLOUD_BASE_EMBED gate and before the /v1/base/_* wildcard, so a liveness probe measures the process rather than an optional feature, and the wildcard can never shadow it. It reads no tenant, so a prober that sends no principal is answered rather than refused.
119pub async fn get_base_health(configuration: &configuration::Configuration, ) -> Result<models::BaseHealth, Error<GetBaseHealthError>> {
120
121    let uri_str = format!("{}/v1/base/health", configuration.base_path);
122    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
123
124    if let Some(ref user_agent) = configuration.user_agent {
125        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
126    }
127    if let Some(ref token) = configuration.bearer_access_token {
128        req_builder = req_builder.bearer_auth(token.to_owned());
129    };
130
131    let req = req_builder.build()?;
132    let resp = configuration.client.execute(req).await?;
133
134    let status = resp.status();
135    let content_type = resp
136        .headers()
137        .get("content-type")
138        .and_then(|v| v.to_str().ok())
139        .unwrap_or("application/octet-stream");
140    let content_type = super::ContentType::from(content_type);
141
142    if !status.is_client_error() && !status.is_server_error() {
143        let content = resp.text().await?;
144        match content_type {
145            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
146            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BaseHealth`"))),
147            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::BaseHealth`")))),
148        }
149    } else {
150        let content = resp.text().await?;
151        let entity: Option<GetBaseHealthError> = serde_json::from_str(&content).ok();
152        Err(Error::ResponseError(ResponseContent { status, content, entity }))
153    }
154}
155