1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct AddProjectMetadatasParams {
20 pub project_name_or_id: String,
22 pub x_request_id: Option<String>,
24 pub x_is_resource_name: Option<bool>,
26 pub metadata: Option<std::collections::HashMap<String, String>>
27}
28
29#[derive(Clone, Debug)]
31pub struct DeleteProjectMetadataParams {
32 pub project_name_or_id: String,
34 pub meta_name: String,
36 pub x_request_id: Option<String>,
38 pub x_is_resource_name: Option<bool>
40}
41
42#[derive(Clone, Debug)]
44pub struct GetProjectMetadataParams {
45 pub project_name_or_id: String,
47 pub meta_name: String,
49 pub x_request_id: Option<String>,
51 pub x_is_resource_name: Option<bool>
53}
54
55#[derive(Clone, Debug)]
57pub struct ListProjectMetadatasParams {
58 pub project_name_or_id: String,
60 pub x_request_id: Option<String>,
62 pub x_is_resource_name: Option<bool>
64}
65
66#[derive(Clone, Debug)]
68pub struct UpdateProjectMetadataParams {
69 pub project_name_or_id: String,
71 pub meta_name: String,
73 pub x_request_id: Option<String>,
75 pub x_is_resource_name: Option<bool>,
77 pub metadata: Option<std::collections::HashMap<String, String>>
78}
79
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum AddProjectMetadatasError {
85 Status400(models::Errors),
86 Status401(models::Errors),
87 Status403(models::Errors),
88 Status404(models::Errors),
89 Status409(models::Errors),
90 Status500(models::Errors),
91 UnknownValue(serde_json::Value),
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum DeleteProjectMetadataError {
98 Status400(models::Errors),
99 Status401(models::Errors),
100 Status403(models::Errors),
101 Status404(models::Errors),
102 Status409(models::Errors),
103 Status500(models::Errors),
104 UnknownValue(serde_json::Value),
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetProjectMetadataError {
111 Status400(models::Errors),
112 Status401(models::Errors),
113 Status403(models::Errors),
114 Status404(models::Errors),
115 Status500(models::Errors),
116 UnknownValue(serde_json::Value),
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
121#[serde(untagged)]
122pub enum ListProjectMetadatasError {
123 Status400(models::Errors),
124 Status401(models::Errors),
125 Status403(models::Errors),
126 Status404(models::Errors),
127 Status500(models::Errors),
128 UnknownValue(serde_json::Value),
129}
130
131#[derive(Debug, Clone, Serialize, Deserialize)]
133#[serde(untagged)]
134pub enum UpdateProjectMetadataError {
135 Status400(models::Errors),
136 Status401(models::Errors),
137 Status403(models::Errors),
138 Status404(models::Errors),
139 Status409(models::Errors),
140 Status500(models::Errors),
141 UnknownValue(serde_json::Value),
142}
143
144
145pub async fn add_project_metadatas(configuration: &configuration::Configuration, params: AddProjectMetadatasParams) -> Result<(), Error<AddProjectMetadatasError>> {
147
148 let uri_str = format!("{}/projects/{project_name_or_id}/metadatas/", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
149 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
150
151 if let Some(ref user_agent) = configuration.user_agent {
152 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
153 }
154 if let Some(param_value) = params.x_request_id {
155 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
156 }
157 if let Some(param_value) = params.x_is_resource_name {
158 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
159 }
160 if let Some(ref auth_conf) = configuration.basic_auth {
161 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
162 };
163 req_builder = req_builder.json(¶ms.metadata);
164
165 let req = req_builder.build()?;
166 let resp = configuration.client.execute(req).await?;
167
168 let status = resp.status();
169
170 if !status.is_client_error() && !status.is_server_error() {
171 Ok(())
172 } else {
173 let content = resp.text().await?;
174 let entity: Option<AddProjectMetadatasError> = serde_json::from_str(&content).ok();
175 Err(Error::ResponseError(ResponseContent { status, content, entity }))
176 }
177}
178
179pub async fn delete_project_metadata(configuration: &configuration::Configuration, params: DeleteProjectMetadataParams) -> Result<(), Error<DeleteProjectMetadataError>> {
181
182 let uri_str = format!("{}/projects/{project_name_or_id}/metadatas/{meta_name}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), meta_name=crate::apis::urlencode(params.meta_name));
183 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
184
185 if let Some(ref user_agent) = configuration.user_agent {
186 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187 }
188 if let Some(param_value) = params.x_request_id {
189 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
190 }
191 if let Some(param_value) = params.x_is_resource_name {
192 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
193 }
194 if let Some(ref auth_conf) = configuration.basic_auth {
195 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
196 };
197
198 let req = req_builder.build()?;
199 let resp = configuration.client.execute(req).await?;
200
201 let status = resp.status();
202
203 if !status.is_client_error() && !status.is_server_error() {
204 Ok(())
205 } else {
206 let content = resp.text().await?;
207 let entity: Option<DeleteProjectMetadataError> = serde_json::from_str(&content).ok();
208 Err(Error::ResponseError(ResponseContent { status, content, entity }))
209 }
210}
211
212pub async fn get_project_metadata(configuration: &configuration::Configuration, params: GetProjectMetadataParams) -> Result<std::collections::HashMap<String, String>, Error<GetProjectMetadataError>> {
214
215 let uri_str = format!("{}/projects/{project_name_or_id}/metadatas/{meta_name}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), meta_name=crate::apis::urlencode(params.meta_name));
216 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
217
218 if let Some(ref user_agent) = configuration.user_agent {
219 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
220 }
221 if let Some(param_value) = params.x_request_id {
222 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
223 }
224 if let Some(param_value) = params.x_is_resource_name {
225 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
226 }
227 if let Some(ref auth_conf) = configuration.basic_auth {
228 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
229 };
230
231 let req = req_builder.build()?;
232 let resp = configuration.client.execute(req).await?;
233
234 let status = resp.status();
235 let content_type = resp
236 .headers()
237 .get("content-type")
238 .and_then(|v| v.to_str().ok())
239 .unwrap_or("application/octet-stream");
240 let content_type = super::ContentType::from(content_type);
241
242 if !status.is_client_error() && !status.is_server_error() {
243 let content = resp.text().await?;
244 match content_type {
245 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
246 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, String>`"))),
247 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, String>`")))),
248 }
249 } else {
250 let content = resp.text().await?;
251 let entity: Option<GetProjectMetadataError> = serde_json::from_str(&content).ok();
252 Err(Error::ResponseError(ResponseContent { status, content, entity }))
253 }
254}
255
256pub async fn list_project_metadatas(configuration: &configuration::Configuration, params: ListProjectMetadatasParams) -> Result<std::collections::HashMap<String, String>, Error<ListProjectMetadatasError>> {
258
259 let uri_str = format!("{}/projects/{project_name_or_id}/metadatas/", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
260 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
261
262 if let Some(ref user_agent) = configuration.user_agent {
263 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
264 }
265 if let Some(param_value) = params.x_request_id {
266 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
267 }
268 if let Some(param_value) = params.x_is_resource_name {
269 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
270 }
271 if let Some(ref auth_conf) = configuration.basic_auth {
272 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
273 };
274
275 let req = req_builder.build()?;
276 let resp = configuration.client.execute(req).await?;
277
278 let status = resp.status();
279 let content_type = resp
280 .headers()
281 .get("content-type")
282 .and_then(|v| v.to_str().ok())
283 .unwrap_or("application/octet-stream");
284 let content_type = super::ContentType::from(content_type);
285
286 if !status.is_client_error() && !status.is_server_error() {
287 let content = resp.text().await?;
288 match content_type {
289 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
290 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, String>`"))),
291 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, String>`")))),
292 }
293 } else {
294 let content = resp.text().await?;
295 let entity: Option<ListProjectMetadatasError> = serde_json::from_str(&content).ok();
296 Err(Error::ResponseError(ResponseContent { status, content, entity }))
297 }
298}
299
300pub async fn update_project_metadata(configuration: &configuration::Configuration, params: UpdateProjectMetadataParams) -> Result<(), Error<UpdateProjectMetadataError>> {
302
303 let uri_str = format!("{}/projects/{project_name_or_id}/metadatas/{meta_name}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), meta_name=crate::apis::urlencode(params.meta_name));
304 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
305
306 if let Some(ref user_agent) = configuration.user_agent {
307 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
308 }
309 if let Some(param_value) = params.x_request_id {
310 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
311 }
312 if let Some(param_value) = params.x_is_resource_name {
313 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
314 }
315 if let Some(ref auth_conf) = configuration.basic_auth {
316 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
317 };
318 req_builder = req_builder.json(¶ms.metadata);
319
320 let req = req_builder.build()?;
321 let resp = configuration.client.execute(req).await?;
322
323 let status = resp.status();
324
325 if !status.is_client_error() && !status.is_server_error() {
326 Ok(())
327 } else {
328 let content = resp.text().await?;
329 let entity: Option<UpdateProjectMetadataError> = serde_json::from_str(&content).ok();
330 Err(Error::ResponseError(ResponseContent { status, content, entity }))
331 }
332}
333