Skip to main content

hanzo_client/apis/
network_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_network`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetNetworkError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_network_by_id`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetNetworkByIdError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_network_routers`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetNetworkRoutersError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_network_services`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetNetworkServicesError {
43    UnknownValue(serde_json::Value),
44}
45
46
47/// Returns the caller's org overlay network on the Zero Trust fabric.  The org has at most ONE overlay, projected from the edge-routers tagged with its \"org-<org>\" role attribute: nodes is the real router count and status is \"connected\" once at least one router has dialed home, \"provisioning\" while none has. An org with no routers gets an empty list, never a fabricated network.  The read degrades rather than erroring: a deployment with no ZT credential, and a controller that cannot be reached, both answer 200 with an empty list so the console's Networks page renders a clean empty state instead of an error.
48pub async fn get_network(configuration: &configuration::Configuration, ) -> Result<models::NetworkList, Error<GetNetworkError>> {
49
50    let uri_str = format!("{}/v1/network", configuration.base_path);
51    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
52
53    if let Some(ref user_agent) = configuration.user_agent {
54        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
55    }
56    if let Some(ref token) = configuration.bearer_access_token {
57        req_builder = req_builder.bearer_auth(token.to_owned());
58    };
59
60    let req = req_builder.build()?;
61    let resp = configuration.client.execute(req).await?;
62
63    let status = resp.status();
64    let content_type = resp
65        .headers()
66        .get("content-type")
67        .and_then(|v| v.to_str().ok())
68        .unwrap_or("application/octet-stream");
69    let content_type = super::ContentType::from(content_type);
70
71    if !status.is_client_error() && !status.is_server_error() {
72        let content = resp.text().await?;
73        match content_type {
74            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
75            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NetworkList`"))),
76            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::NetworkList`")))),
77        }
78    } else {
79        let content = resp.text().await?;
80        let entity: Option<GetNetworkError> = serde_json::from_str(&content).ok();
81        Err(Error::ResponseError(ResponseContent { status, content, entity }))
82    }
83}
84
85/// Returns one overlay network by id, scoped to the caller's org.  The org has exactly one overlay network and its id is derived from the org, so any other id — another tenant's, or one that does not exist — is 404 rather than a peek across the tenant boundary. An org whose network exists but has no edge-routers is 404 too, for the same reason the list is empty: there is no overlay until something is on it.
86pub async fn get_network_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::NetworkView, Error<GetNetworkByIdError>> {
87    // add a prefix to parameters to efficiently prevent name collisions
88    let p_id = id;
89
90    let uri_str = format!("{}/v1/network/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
91    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
92
93    if let Some(ref user_agent) = configuration.user_agent {
94        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95    }
96    if let Some(ref token) = configuration.bearer_access_token {
97        req_builder = req_builder.bearer_auth(token.to_owned());
98    };
99
100    let req = req_builder.build()?;
101    let resp = configuration.client.execute(req).await?;
102
103    let status = resp.status();
104    let content_type = resp
105        .headers()
106        .get("content-type")
107        .and_then(|v| v.to_str().ok())
108        .unwrap_or("application/octet-stream");
109    let content_type = super::ContentType::from(content_type);
110
111    if !status.is_client_error() && !status.is_server_error() {
112        let content = resp.text().await?;
113        match content_type {
114            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
115            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NetworkView`"))),
116            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::NetworkView`")))),
117        }
118    } else {
119        let content = resp.text().await?;
120        let entity: Option<GetNetworkByIdError> = serde_json::from_str(&content).ok();
121        Err(Error::ResponseError(ResponseContent { status, content, entity }))
122    }
123}
124
125/// Returns the Zero Trust routers the caller's org owns.  One row per real ZT edge-router tagged with the org's \"org-<org>\" role attribute, carrying the controller's own health signal: \"online\" when connected, \"disabled\" when administratively disabled, \"offline\" otherwise. region is filled only from a \"region-<slug>\" role attribute and omitted when the router carries none, so the column renders \"—\" rather than a guess.  The read degrades rather than erroring: a deployment with no ZT credential, and a controller that cannot be reached, both answer 200 with an empty list.
126pub async fn get_network_routers(configuration: &configuration::Configuration, ) -> Result<models::RouterList, Error<GetNetworkRoutersError>> {
127
128    let uri_str = format!("{}/v1/network/routers", configuration.base_path);
129    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
130
131    if let Some(ref user_agent) = configuration.user_agent {
132        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
133    }
134    if let Some(ref token) = configuration.bearer_access_token {
135        req_builder = req_builder.bearer_auth(token.to_owned());
136    };
137
138    let req = req_builder.build()?;
139    let resp = configuration.client.execute(req).await?;
140
141    let status = resp.status();
142    let content_type = resp
143        .headers()
144        .get("content-type")
145        .and_then(|v| v.to_str().ok())
146        .unwrap_or("application/octet-stream");
147    let content_type = super::ContentType::from(content_type);
148
149    if !status.is_client_error() && !status.is_server_error() {
150        let content = resp.text().await?;
151        match content_type {
152            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
153            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RouterList`"))),
154            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::RouterList`")))),
155        }
156    } else {
157        let content = resp.text().await?;
158        let entity: Option<GetNetworkRoutersError> = serde_json::from_str(&content).ok();
159        Err(Error::ResponseError(ResponseContent { status, content, entity }))
160    }
161}
162
163/// Returns the Zero Trust edge services the caller's org owns.  One row per real ZT edge service tagged with the org's \"org-<org>\" role attribute: mtls is \"required\" when the service mandates end-to-end encryption and \"enabled\" otherwise (the fabric always mutually authenticates every link), and status is \"active\" because a listed service is a configured, dialable entry. A service tagged for another org, or tagged for none, is invisible here.  Unlike the network and router reads this does NOT degrade: an unconfigured deployment answers 503 and an unreachable controller surfaces the upstream's status, so a mesh page never renders \"no services\" for a fabric it simply could not read.
164pub async fn get_network_services(configuration: &configuration::Configuration, ) -> Result<models::MeshServiceList, Error<GetNetworkServicesError>> {
165
166    let uri_str = format!("{}/v1/network/services", configuration.base_path);
167    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
168
169    if let Some(ref user_agent) = configuration.user_agent {
170        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171    }
172    if let Some(ref token) = configuration.bearer_access_token {
173        req_builder = req_builder.bearer_auth(token.to_owned());
174    };
175
176    let req = req_builder.build()?;
177    let resp = configuration.client.execute(req).await?;
178
179    let status = resp.status();
180    let content_type = resp
181        .headers()
182        .get("content-type")
183        .and_then(|v| v.to_str().ok())
184        .unwrap_or("application/octet-stream");
185    let content_type = super::ContentType::from(content_type);
186
187    if !status.is_client_error() && !status.is_server_error() {
188        let content = resp.text().await?;
189        match content_type {
190            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
191            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MeshServiceList`"))),
192            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::MeshServiceList`")))),
193        }
194    } else {
195        let content = resp.text().await?;
196        let entity: Option<GetNetworkServicesError> = serde_json::from_str(&content).ok();
197        Err(Error::ResponseError(ResponseContent { status, content, entity }))
198    }
199}
200