1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AdminPruneCreateRunError {
22 Status400(models::PbsError),
23 Status401(models::PbsError),
24 Status403(models::PbsError),
25 Status404(models::PbsError),
26 Status500(models::PbsError),
27 Status501(models::PbsError),
28 Status503(models::PbsError),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AdminPruneGetAdminPruneByIdError {
36 Status400(models::PbsError),
37 Status401(models::PbsError),
38 Status403(models::PbsError),
39 Status404(models::PbsError),
40 Status500(models::PbsError),
41 Status501(models::PbsError),
42 Status503(models::PbsError),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum AdminPruneGetPruneError {
50 Status400(models::PbsError),
51 Status401(models::PbsError),
52 Status403(models::PbsError),
53 Status404(models::PbsError),
54 Status500(models::PbsError),
55 Status501(models::PbsError),
56 Status503(models::PbsError),
57 UnknownValue(serde_json::Value),
58}
59
60
61pub async fn admin_prune_create_run(configuration: &configuration::Configuration, id: &str) -> Result<models::AdminPruneCreateRunResponse, Error<AdminPruneCreateRunError>> {
63 let p_path_id = id;
65
66 let uri_str = format!("{}/admin/prune/{id}/run", configuration.base_path, id=crate::apis::urlencode(p_path_id));
67 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
68
69 if let Some(ref user_agent) = configuration.user_agent {
70 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71 }
72 if let Some(ref apikey) = configuration.api_key {
73 let key = apikey.key.clone();
74 let value = match apikey.prefix {
75 Some(ref prefix) => format!("{} {}", prefix, key),
76 None => key,
77 };
78 req_builder = req_builder.header("Authorization", value);
79 };
80 if let Some(ref apikey) = configuration.api_key {
81 let key = apikey.key.clone();
82 let value = match apikey.prefix {
83 Some(ref prefix) => format!("{} {}", prefix, key),
84 None => key,
85 };
86 req_builder = req_builder.header("CSRFPreventionToken", value);
87 };
88
89 let req = req_builder.build()?;
90 let resp = configuration.client.execute(req).await?;
91
92 let status = resp.status();
93 let content_type = resp
94 .headers()
95 .get("content-type")
96 .and_then(|v| v.to_str().ok())
97 .unwrap_or("application/octet-stream");
98 let content_type = super::ContentType::from(content_type);
99
100 if !status.is_client_error() && !status.is_server_error() {
101 let content = resp.text().await?;
102 match content_type {
103 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
104 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminPruneCreateRunResponse`"))),
105 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::AdminPruneCreateRunResponse`")))),
106 }
107 } else {
108 let content = resp.text().await?;
109 let entity: Option<AdminPruneCreateRunError> = serde_json::from_str(&content).ok();
110 Err(Error::ResponseError(ResponseContent { status, content, entity }))
111 }
112}
113
114pub async fn admin_prune_get_admin_prune_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::AdminPruneGetAdminPruneByIdResponse, Error<AdminPruneGetAdminPruneByIdError>> {
116 let p_path_id = id;
118
119 let uri_str = format!("{}/admin/prune/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
120 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
121
122 if let Some(ref user_agent) = configuration.user_agent {
123 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124 }
125 if let Some(ref apikey) = configuration.api_key {
126 let key = apikey.key.clone();
127 let value = match apikey.prefix {
128 Some(ref prefix) => format!("{} {}", prefix, key),
129 None => key,
130 };
131 req_builder = req_builder.header("Authorization", value);
132 };
133 if let Some(ref apikey) = configuration.api_key {
134 let key = apikey.key.clone();
135 let value = match apikey.prefix {
136 Some(ref prefix) => format!("{} {}", prefix, key),
137 None => key,
138 };
139 req_builder = req_builder.header("CSRFPreventionToken", value);
140 };
141
142 let req = req_builder.build()?;
143 let resp = configuration.client.execute(req).await?;
144
145 let status = resp.status();
146 let content_type = resp
147 .headers()
148 .get("content-type")
149 .and_then(|v| v.to_str().ok())
150 .unwrap_or("application/octet-stream");
151 let content_type = super::ContentType::from(content_type);
152
153 if !status.is_client_error() && !status.is_server_error() {
154 let content = resp.text().await?;
155 match content_type {
156 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
157 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminPruneGetAdminPruneByIdResponse`"))),
158 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::AdminPruneGetAdminPruneByIdResponse`")))),
159 }
160 } else {
161 let content = resp.text().await?;
162 let entity: Option<AdminPruneGetAdminPruneByIdError> = serde_json::from_str(&content).ok();
163 Err(Error::ResponseError(ResponseContent { status, content, entity }))
164 }
165}
166
167pub async fn admin_prune_get_prune(configuration: &configuration::Configuration, store: Option<&str>) -> Result<models::AdminPruneGetPruneResponse, Error<AdminPruneGetPruneError>> {
169 let p_query_store = store;
171
172 let uri_str = format!("{}/admin/prune", configuration.base_path);
173 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
174
175 if let Some(ref param_value) = p_query_store {
176 req_builder = req_builder.query(&[("store", ¶m_value.to_string())]);
177 }
178 if let Some(ref user_agent) = configuration.user_agent {
179 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
180 }
181 if let Some(ref apikey) = configuration.api_key {
182 let key = apikey.key.clone();
183 let value = match apikey.prefix {
184 Some(ref prefix) => format!("{} {}", prefix, key),
185 None => key,
186 };
187 req_builder = req_builder.header("Authorization", value);
188 };
189 if let Some(ref apikey) = configuration.api_key {
190 let key = apikey.key.clone();
191 let value = match apikey.prefix {
192 Some(ref prefix) => format!("{} {}", prefix, key),
193 None => key,
194 };
195 req_builder = req_builder.header("CSRFPreventionToken", value);
196 };
197
198 let req = req_builder.build()?;
199 let resp = configuration.client.execute(req).await?;
200
201 let status = resp.status();
202 let content_type = resp
203 .headers()
204 .get("content-type")
205 .and_then(|v| v.to_str().ok())
206 .unwrap_or("application/octet-stream");
207 let content_type = super::ContentType::from(content_type);
208
209 if !status.is_client_error() && !status.is_server_error() {
210 let content = resp.text().await?;
211 match content_type {
212 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
213 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminPruneGetPruneResponse`"))),
214 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::AdminPruneGetPruneResponse`")))),
215 }
216 } else {
217 let content = resp.text().await?;
218 let entity: Option<AdminPruneGetPruneError> = serde_json::from_str(&content).ok();
219 Err(Error::ResponseError(ResponseContent { status, content, entity }))
220 }
221}
222