tembo_api_client/apis/
stack_api.rs1use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum GetAllEntitiesError {
20 Status401(models::ErrorResponseSchema),
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum GetEntityError {
28 Status400(serde_json::Value),
29 Status401(models::ErrorResponseSchema),
30 UnknownValue(serde_json::Value),
31}
32
33pub async fn get_all_entities(
35 configuration: &configuration::Configuration,
36) -> Result<Vec<serde_json::Value>, Error<GetAllEntitiesError>> {
37 let uri_str = format!("{}/api/v1/stacks", configuration.base_path);
38 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
39
40 if let Some(ref user_agent) = configuration.user_agent {
41 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
42 }
43 if let Some(ref token) = configuration.bearer_access_token {
44 req_builder = req_builder.bearer_auth(token.to_owned());
45 };
46
47 let req = req_builder.build()?;
48 let resp = configuration.client.execute(req).await?;
49
50 let status = resp.status();
51
52 if !status.is_client_error() && !status.is_server_error() {
53 let content = resp.text().await?;
54 serde_json::from_str(&content).map_err(Error::from)
55 } else {
56 let content = resp.text().await?;
57 let entity: Option<GetAllEntitiesError> = serde_json::from_str(&content).ok();
58 Err(Error::ResponseError(ResponseContent {
59 status,
60 content,
61 entity,
62 }))
63 }
64}
65
66pub async fn get_entity(
68 configuration: &configuration::Configuration,
69 r#type: models::StackType,
70) -> Result<serde_json::Value, Error<GetEntityError>> {
71 let p_type = r#type;
73
74 let uri_str =
75 format!("{}/api/v1/stacks/{type}", configuration.base_path, type=p_type.to_string());
76 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
77
78 if let Some(ref user_agent) = configuration.user_agent {
79 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
80 }
81 if let Some(ref token) = configuration.bearer_access_token {
82 req_builder = req_builder.bearer_auth(token.to_owned());
83 };
84
85 let req = req_builder.build()?;
86 let resp = configuration.client.execute(req).await?;
87
88 let status = resp.status();
89
90 if !status.is_client_error() && !status.is_server_error() {
91 let content = resp.text().await?;
92 serde_json::from_str(&content).map_err(Error::from)
93 } else {
94 let content = resp.text().await?;
95 let entity: Option<GetEntityError> = serde_json::from_str(&content).ok();
96 Err(Error::ResponseError(ResponseContent {
97 status,
98 content,
99 entity,
100 }))
101 }
102}