Skip to main content

hanzo_client/apis/
template_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_template_by_slug`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteTemplateBySlugError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_template`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetTemplateError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_template_by_slug`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetTemplateBySlugError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`post_template`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostTemplateError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`put_template_by_slug`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PutTemplateBySlugError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// Deletes the caller org's OWN starter kit. A slug they do not own is a 404, never a delete: the DELETE binds org.
55pub async fn delete_template_by_slug(configuration: &configuration::Configuration, slug: &str) -> Result<(), Error<DeleteTemplateBySlugError>> {
56    // add a prefix to parameters to efficiently prevent name collisions
57    let p_slug = slug;
58
59    let uri_str = format!("{}/v1/template/{slug}", configuration.base_path, slug=crate::apis::urlencode(p_slug));
60    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
61
62    if let Some(ref user_agent) = configuration.user_agent {
63        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64    }
65    if let Some(ref token) = configuration.bearer_access_token {
66        req_builder = req_builder.bearer_auth(token.to_owned());
67    };
68
69    let req = req_builder.build()?;
70    let resp = configuration.client.execute(req).await?;
71
72    let status = resp.status();
73
74    if !status.is_client_error() && !status.is_server_error() {
75        Ok(())
76    } else {
77        let content = resp.text().await?;
78        let entity: Option<DeleteTemplateBySlugError> = serde_json::from_str(&content).ok();
79        Err(Error::ResponseError(ResponseContent { status, content, entity }))
80    }
81}
82
83/// Lists the public starter-kit catalog plus, for a validated caller, that org's own private kits. No request field can widen the scope: the org comes from the validated principal, so an anonymous or cross-org caller structurally sees the public catalog only.
84pub async fn get_template(configuration: &configuration::Configuration, ) -> Result<models::KitList, Error<GetTemplateError>> {
85
86    let uri_str = format!("{}/v1/template", configuration.base_path);
87    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
88
89    if let Some(ref user_agent) = configuration.user_agent {
90        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
91    }
92    if let Some(ref token) = configuration.bearer_access_token {
93        req_builder = req_builder.bearer_auth(token.to_owned());
94    };
95
96    let req = req_builder.build()?;
97    let resp = configuration.client.execute(req).await?;
98
99    let status = resp.status();
100    let content_type = resp
101        .headers()
102        .get("content-type")
103        .and_then(|v| v.to_str().ok())
104        .unwrap_or("application/octet-stream");
105    let content_type = super::ContentType::from(content_type);
106
107    if !status.is_client_error() && !status.is_server_error() {
108        let content = resp.text().await?;
109        match content_type {
110            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
111            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KitList`"))),
112            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::KitList`")))),
113        }
114    } else {
115        let content = resp.text().await?;
116        let entity: Option<GetTemplateError> = serde_json::from_str(&content).ok();
117        Err(Error::ResponseError(ResponseContent { status, content, entity }))
118    }
119}
120
121/// Returns one starter kit: the caller org's own by that slug, else the public catalog's. A slug another org owns reads as not found.
122pub async fn get_template_by_slug(configuration: &configuration::Configuration, slug: &str) -> Result<models::StarterKit, Error<GetTemplateBySlugError>> {
123    // add a prefix to parameters to efficiently prevent name collisions
124    let p_slug = slug;
125
126    let uri_str = format!("{}/v1/template/{slug}", configuration.base_path, slug=crate::apis::urlencode(p_slug));
127    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
128
129    if let Some(ref user_agent) = configuration.user_agent {
130        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
131    }
132    if let Some(ref token) = configuration.bearer_access_token {
133        req_builder = req_builder.bearer_auth(token.to_owned());
134    };
135
136    let req = req_builder.build()?;
137    let resp = configuration.client.execute(req).await?;
138
139    let status = resp.status();
140    let content_type = resp
141        .headers()
142        .get("content-type")
143        .and_then(|v| v.to_str().ok())
144        .unwrap_or("application/octet-stream");
145    let content_type = super::ContentType::from(content_type);
146
147    if !status.is_client_error() && !status.is_server_error() {
148        let content = resp.text().await?;
149        match content_type {
150            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
151            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StarterKit`"))),
152            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::StarterKit`")))),
153        }
154    } else {
155        let content = resp.text().await?;
156        let entity: Option<GetTemplateBySlugError> = serde_json::from_str(&content).ok();
157        Err(Error::ResponseError(ResponseContent { status, content, entity }))
158    }
159}
160
161/// Creates a starter kit PRIVATE to the caller's org and answers 201 with the stored kit. The owner is stamped by the server, so a body \"org\" is never trusted; publishing over a public-catalog slug is 409, so a slug still names exactly one kit.
162pub async fn post_template(configuration: &configuration::Configuration, publish_kit_in: models::PublishKitIn) -> Result<models::StarterKit, Error<PostTemplateError>> {
163    // add a prefix to parameters to efficiently prevent name collisions
164    let p_publish_kit_in = publish_kit_in;
165
166    let uri_str = format!("{}/v1/template", configuration.base_path);
167    let mut req_builder = configuration.client.request(reqwest::Method::POST, &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    req_builder = req_builder.json(&p_publish_kit_in);
176
177    let req = req_builder.build()?;
178    let resp = configuration.client.execute(req).await?;
179
180    let status = resp.status();
181    let content_type = resp
182        .headers()
183        .get("content-type")
184        .and_then(|v| v.to_str().ok())
185        .unwrap_or("application/octet-stream");
186    let content_type = super::ContentType::from(content_type);
187
188    if !status.is_client_error() && !status.is_server_error() {
189        let content = resp.text().await?;
190        match content_type {
191            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StarterKit`"))),
193            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::StarterKit`")))),
194        }
195    } else {
196        let content = resp.text().await?;
197        let entity: Option<PostTemplateError> = serde_json::from_str(&content).ok();
198        Err(Error::ResponseError(ResponseContent { status, content, entity }))
199    }
200}
201
202/// Overwrites the caller org's OWN starter kit at the path slug, answering the stored kit. A slug they do not own is 404, never a create: the UPDATE binds org, so a PUT can never reach another org's kit.
203pub async fn put_template_by_slug(configuration: &configuration::Configuration, slug: &str, replace_kit_in: models::ReplaceKitIn) -> Result<models::StarterKit, Error<PutTemplateBySlugError>> {
204    // add a prefix to parameters to efficiently prevent name collisions
205    let p_slug = slug;
206    let p_replace_kit_in = replace_kit_in;
207
208    let uri_str = format!("{}/v1/template/{slug}", configuration.base_path, slug=crate::apis::urlencode(p_slug));
209    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
210
211    if let Some(ref user_agent) = configuration.user_agent {
212        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213    }
214    if let Some(ref token) = configuration.bearer_access_token {
215        req_builder = req_builder.bearer_auth(token.to_owned());
216    };
217    req_builder = req_builder.json(&p_replace_kit_in);
218
219    let req = req_builder.build()?;
220    let resp = configuration.client.execute(req).await?;
221
222    let status = resp.status();
223    let content_type = resp
224        .headers()
225        .get("content-type")
226        .and_then(|v| v.to_str().ok())
227        .unwrap_or("application/octet-stream");
228    let content_type = super::ContentType::from(content_type);
229
230    if !status.is_client_error() && !status.is_server_error() {
231        let content = resp.text().await?;
232        match content_type {
233            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
234            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StarterKit`"))),
235            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::StarterKit`")))),
236        }
237    } else {
238        let content = resp.text().await?;
239        let entity: Option<PutTemplateBySlugError> = serde_json::from_str(&content).ok();
240        Err(Error::ResponseError(ResponseContent { status, content, entity }))
241    }
242}
243