gitbundle_sdk/apis/
system_api.rs1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum GetConfigError {
21 Status400(models::JsonErrorResponseNull),
22 Status401(models::JsonErrorResponseNull),
23 Status403(models::JsonErrorResponseNull),
24 Status404(models::JsonErrorResponseNull),
25 Status409(models::JsonErrorResponseNull),
26 Status429(models::JsonErrorResponseNull),
27 Status500(models::JsonErrorResponseNull),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetHealthError {
35 Status400(models::JsonErrorResponseNull),
36 Status401(models::JsonErrorResponseNull),
37 Status403(models::JsonErrorResponseNull),
38 Status404(models::JsonErrorResponseNull),
39 Status409(models::JsonErrorResponseNull),
40 Status429(models::JsonErrorResponseNull),
41 Status500(models::JsonErrorResponseNull),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetVersionError {
49 Status400(models::JsonErrorResponseNull),
50 Status401(models::JsonErrorResponseNull),
51 Status403(models::JsonErrorResponseNull),
52 Status404(models::JsonErrorResponseNull),
53 Status409(models::JsonErrorResponseNull),
54 Status429(models::JsonErrorResponseNull),
55 Status500(models::JsonErrorResponseNull),
56 UnknownValue(serde_json::Value),
57}
58
59pub async fn get_config(
60 configuration: &configuration::Configuration,
61) -> Result<models::SystemConfig, Error<GetConfigError>> {
62 let uri_str = format!("{}/system/config", configuration.base_path);
63 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
64
65 if let Some(ref user_agent) = configuration.user_agent {
66 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
67 }
68
69 let req = req_builder.build()?;
70 let resp = configuration.client.execute(req).await?;
71
72 let status = resp.status();
73 let content_type = resp
74 .headers()
75 .get("content-type")
76 .and_then(|v| v.to_str().ok())
77 .unwrap_or("application/octet-stream");
78 let content_type = super::ContentType::from(content_type);
79
80 if !status.is_client_error() && !status.is_server_error() {
81 let content = resp.text().await?;
82 match content_type {
83 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
84 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SystemConfig`"))),
85 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SystemConfig`")))),
86 }
87 } else {
88 let content = resp.text().await?;
89 let entity: Option<GetConfigError> = serde_json::from_str(&content).ok();
90 Err(Error::ResponseError(ResponseContent {
91 status,
92 content,
93 entity,
94 }))
95 }
96}
97
98pub async fn get_health(
99 configuration: &configuration::Configuration,
100) -> Result<String, Error<GetHealthError>> {
101 let uri_str = format!("{}/system/health", configuration.base_path);
102 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
103
104 if let Some(ref user_agent) = configuration.user_agent {
105 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
106 }
107
108 let req = req_builder.build()?;
109 let resp = configuration.client.execute(req).await?;
110
111 let status = resp.status();
112 let content_type = resp
113 .headers()
114 .get("content-type")
115 .and_then(|v| v.to_str().ok())
116 .unwrap_or("application/octet-stream");
117 let content_type = super::ContentType::from(content_type);
118
119 if !status.is_client_error() && !status.is_server_error() {
120 let content = resp.text().await?;
121 match content_type {
122 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
123 ContentType::Text => Ok(content),
124 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
125 }
126 } else {
127 let content = resp.text().await?;
128 let entity: Option<GetHealthError> = serde_json::from_str(&content).ok();
129 Err(Error::ResponseError(ResponseContent {
130 status,
131 content,
132 entity,
133 }))
134 }
135}
136
137pub async fn get_version(
138 configuration: &configuration::Configuration,
139) -> Result<String, Error<GetVersionError>> {
140 let uri_str = format!("{}/system/version", configuration.base_path);
141 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
142
143 if let Some(ref user_agent) = configuration.user_agent {
144 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
145 }
146
147 let req = req_builder.build()?;
148 let resp = configuration.client.execute(req).await?;
149
150 let status = resp.status();
151 let content_type = resp
152 .headers()
153 .get("content-type")
154 .and_then(|v| v.to_str().ok())
155 .unwrap_or("application/octet-stream");
156 let content_type = super::ContentType::from(content_type);
157
158 if !status.is_client_error() && !status.is_server_error() {
159 let content = resp.text().await?;
160 match content_type {
161 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162 ContentType::Text => Ok(content),
163 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
164 }
165 } else {
166 let content = resp.text().await?;
167 let entity: Option<GetVersionError> = serde_json::from_str(&content).ok();
168 Err(Error::ResponseError(ResponseContent {
169 status,
170 content,
171 entity,
172 }))
173 }
174}