bitwarden_api_api/apis/
projects_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`organizations_organization_id_projects_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum OrganizationsOrganizationIdProjectsGetError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`organizations_organization_id_projects_post`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum OrganizationsOrganizationIdProjectsPostError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`projects_delete_post`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum ProjectsDeletePostError {
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`projects_id_get`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum ProjectsIdGetError {
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`projects_id_put`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum ProjectsIdPutError {
49    UnknownValue(serde_json::Value),
50}
51
52pub async fn organizations_organization_id_projects_get(
53    configuration: &configuration::Configuration,
54    organization_id: uuid::Uuid,
55) -> Result<
56    models::ProjectResponseModelListResponseModel,
57    Error<OrganizationsOrganizationIdProjectsGetError>,
58> {
59    // add a prefix to parameters to efficiently prevent name collisions
60    let p_organization_id = organization_id;
61
62    let uri_str = format!(
63        "{}/organizations/{organizationId}/projects",
64        configuration.base_path,
65        organizationId = crate::apis::urlencode(p_organization_id.to_string())
66    );
67    let mut req_builder = configuration.client.request(reqwest::Method::GET, &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 token) = configuration.oauth_access_token {
73        req_builder = req_builder.bearer_auth(token.to_owned());
74    };
75
76    let req = req_builder.build()?;
77    let resp = configuration.client.execute(req).await?;
78
79    let status = resp.status();
80    let content_type = resp
81        .headers()
82        .get("content-type")
83        .and_then(|v| v.to_str().ok())
84        .unwrap_or("application/octet-stream");
85    let content_type = super::ContentType::from(content_type);
86
87    if !status.is_client_error() && !status.is_server_error() {
88        let content = resp.text().await?;
89        match content_type {
90            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
91            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModelListResponseModel`"))),
92            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::ProjectResponseModelListResponseModel`")))),
93        }
94    } else {
95        let content = resp.text().await?;
96        let entity: Option<OrganizationsOrganizationIdProjectsGetError> =
97            serde_json::from_str(&content).ok();
98        Err(Error::ResponseError(ResponseContent {
99            status,
100            content,
101            entity,
102        }))
103    }
104}
105
106pub async fn organizations_organization_id_projects_post(
107    configuration: &configuration::Configuration,
108    organization_id: uuid::Uuid,
109    project_create_request_model: Option<models::ProjectCreateRequestModel>,
110) -> Result<models::ProjectResponseModel, Error<OrganizationsOrganizationIdProjectsPostError>> {
111    // add a prefix to parameters to efficiently prevent name collisions
112    let p_organization_id = organization_id;
113    let p_project_create_request_model = project_create_request_model;
114
115    let uri_str = format!(
116        "{}/organizations/{organizationId}/projects",
117        configuration.base_path,
118        organizationId = crate::apis::urlencode(p_organization_id.to_string())
119    );
120    let mut req_builder = configuration
121        .client
122        .request(reqwest::Method::POST, &uri_str);
123
124    if let Some(ref user_agent) = configuration.user_agent {
125        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
126    }
127    if let Some(ref token) = configuration.oauth_access_token {
128        req_builder = req_builder.bearer_auth(token.to_owned());
129    };
130    req_builder = req_builder.json(&p_project_create_request_model);
131
132    let req = req_builder.build()?;
133    let resp = configuration.client.execute(req).await?;
134
135    let status = resp.status();
136    let content_type = resp
137        .headers()
138        .get("content-type")
139        .and_then(|v| v.to_str().ok())
140        .unwrap_or("application/octet-stream");
141    let content_type = super::ContentType::from(content_type);
142
143    if !status.is_client_error() && !status.is_server_error() {
144        let content = resp.text().await?;
145        match content_type {
146            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
147            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`"))),
148            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::ProjectResponseModel`")))),
149        }
150    } else {
151        let content = resp.text().await?;
152        let entity: Option<OrganizationsOrganizationIdProjectsPostError> =
153            serde_json::from_str(&content).ok();
154        Err(Error::ResponseError(ResponseContent {
155            status,
156            content,
157            entity,
158        }))
159    }
160}
161
162pub async fn projects_delete_post(
163    configuration: &configuration::Configuration,
164    uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
165) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<ProjectsDeletePostError>> {
166    // add a prefix to parameters to efficiently prevent name collisions
167    let p_uuid_colon_colon_uuid = uuid_colon_colon_uuid;
168
169    let uri_str = format!("{}/projects/delete", configuration.base_path);
170    let mut req_builder = configuration
171        .client
172        .request(reqwest::Method::POST, &uri_str);
173
174    if let Some(ref user_agent) = configuration.user_agent {
175        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
176    }
177    if let Some(ref token) = configuration.oauth_access_token {
178        req_builder = req_builder.bearer_auth(token.to_owned());
179    };
180    req_builder = req_builder.json(&p_uuid_colon_colon_uuid);
181
182    let req = req_builder.build()?;
183    let resp = configuration.client.execute(req).await?;
184
185    let status = resp.status();
186    let content_type = resp
187        .headers()
188        .get("content-type")
189        .and_then(|v| v.to_str().ok())
190        .unwrap_or("application/octet-stream");
191    let content_type = super::ContentType::from(content_type);
192
193    if !status.is_client_error() && !status.is_server_error() {
194        let content = resp.text().await?;
195        match content_type {
196            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
197            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`"))),
198            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::BulkDeleteResponseModelListResponseModel`")))),
199        }
200    } else {
201        let content = resp.text().await?;
202        let entity: Option<ProjectsDeletePostError> = serde_json::from_str(&content).ok();
203        Err(Error::ResponseError(ResponseContent {
204            status,
205            content,
206            entity,
207        }))
208    }
209}
210
211pub async fn projects_id_get(
212    configuration: &configuration::Configuration,
213    id: uuid::Uuid,
214) -> Result<models::ProjectResponseModel, Error<ProjectsIdGetError>> {
215    // add a prefix to parameters to efficiently prevent name collisions
216    let p_id = id;
217
218    let uri_str = format!(
219        "{}/projects/{id}",
220        configuration.base_path,
221        id = crate::apis::urlencode(p_id.to_string())
222    );
223    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
224
225    if let Some(ref user_agent) = configuration.user_agent {
226        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
227    }
228    if let Some(ref token) = configuration.oauth_access_token {
229        req_builder = req_builder.bearer_auth(token.to_owned());
230    };
231
232    let req = req_builder.build()?;
233    let resp = configuration.client.execute(req).await?;
234
235    let status = resp.status();
236    let content_type = resp
237        .headers()
238        .get("content-type")
239        .and_then(|v| v.to_str().ok())
240        .unwrap_or("application/octet-stream");
241    let content_type = super::ContentType::from(content_type);
242
243    if !status.is_client_error() && !status.is_server_error() {
244        let content = resp.text().await?;
245        match content_type {
246            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
247            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`"))),
248            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::ProjectResponseModel`")))),
249        }
250    } else {
251        let content = resp.text().await?;
252        let entity: Option<ProjectsIdGetError> = serde_json::from_str(&content).ok();
253        Err(Error::ResponseError(ResponseContent {
254            status,
255            content,
256            entity,
257        }))
258    }
259}
260
261pub async fn projects_id_put(
262    configuration: &configuration::Configuration,
263    id: uuid::Uuid,
264    project_update_request_model: Option<models::ProjectUpdateRequestModel>,
265) -> Result<models::ProjectResponseModel, Error<ProjectsIdPutError>> {
266    // add a prefix to parameters to efficiently prevent name collisions
267    let p_id = id;
268    let p_project_update_request_model = project_update_request_model;
269
270    let uri_str = format!(
271        "{}/projects/{id}",
272        configuration.base_path,
273        id = crate::apis::urlencode(p_id.to_string())
274    );
275    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
276
277    if let Some(ref user_agent) = configuration.user_agent {
278        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
279    }
280    if let Some(ref token) = configuration.oauth_access_token {
281        req_builder = req_builder.bearer_auth(token.to_owned());
282    };
283    req_builder = req_builder.json(&p_project_update_request_model);
284
285    let req = req_builder.build()?;
286    let resp = configuration.client.execute(req).await?;
287
288    let status = resp.status();
289    let content_type = resp
290        .headers()
291        .get("content-type")
292        .and_then(|v| v.to_str().ok())
293        .unwrap_or("application/octet-stream");
294    let content_type = super::ContentType::from(content_type);
295
296    if !status.is_client_error() && !status.is_server_error() {
297        let content = resp.text().await?;
298        match content_type {
299            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
300            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`"))),
301            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::ProjectResponseModel`")))),
302        }
303    } else {
304        let content = resp.text().await?;
305        let entity: Option<ProjectsIdPutError> = serde_json::from_str(&content).ok();
306        Err(Error::ResponseError(ResponseContent {
307            status,
308            content,
309            entity,
310        }))
311    }
312}