bitwarden_api_api/apis/
trash_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 [`secrets_organization_id_trash_empty_post`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum SecretsOrganizationIdTrashEmptyPostError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`secrets_organization_id_trash_get`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum SecretsOrganizationIdTrashGetError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`secrets_organization_id_trash_restore_post`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum SecretsOrganizationIdTrashRestorePostError {
35    UnknownValue(serde_json::Value),
36}
37
38pub async fn secrets_organization_id_trash_empty_post(
39    configuration: &configuration::Configuration,
40    organization_id: uuid::Uuid,
41    uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
42) -> Result<(), Error<SecretsOrganizationIdTrashEmptyPostError>> {
43    // add a prefix to parameters to efficiently prevent name collisions
44    let p_organization_id = organization_id;
45    let p_uuid_colon_colon_uuid = uuid_colon_colon_uuid;
46
47    let uri_str = format!(
48        "{}/secrets/{organizationId}/trash/empty",
49        configuration.base_path,
50        organizationId = crate::apis::urlencode(p_organization_id.to_string())
51    );
52    let mut req_builder = configuration
53        .client
54        .request(reqwest::Method::POST, &uri_str);
55
56    if let Some(ref user_agent) = configuration.user_agent {
57        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
58    }
59    if let Some(ref token) = configuration.oauth_access_token {
60        req_builder = req_builder.bearer_auth(token.to_owned());
61    };
62    req_builder = req_builder.json(&p_uuid_colon_colon_uuid);
63
64    let req = req_builder.build()?;
65    let resp = configuration.client.execute(req).await?;
66
67    let status = resp.status();
68
69    if !status.is_client_error() && !status.is_server_error() {
70        Ok(())
71    } else {
72        let content = resp.text().await?;
73        let entity: Option<SecretsOrganizationIdTrashEmptyPostError> =
74            serde_json::from_str(&content).ok();
75        Err(Error::ResponseError(ResponseContent {
76            status,
77            content,
78            entity,
79        }))
80    }
81}
82
83pub async fn secrets_organization_id_trash_get(
84    configuration: &configuration::Configuration,
85    organization_id: uuid::Uuid,
86) -> Result<models::SecretWithProjectsListResponseModel, Error<SecretsOrganizationIdTrashGetError>>
87{
88    // add a prefix to parameters to efficiently prevent name collisions
89    let p_organization_id = organization_id;
90
91    let uri_str = format!(
92        "{}/secrets/{organizationId}/trash",
93        configuration.base_path,
94        organizationId = crate::apis::urlencode(p_organization_id.to_string())
95    );
96    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
97
98    if let Some(ref user_agent) = configuration.user_agent {
99        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100    }
101    if let Some(ref token) = configuration.oauth_access_token {
102        req_builder = req_builder.bearer_auth(token.to_owned());
103    };
104
105    let req = req_builder.build()?;
106    let resp = configuration.client.execute(req).await?;
107
108    let status = resp.status();
109    let content_type = resp
110        .headers()
111        .get("content-type")
112        .and_then(|v| v.to_str().ok())
113        .unwrap_or("application/octet-stream");
114    let content_type = super::ContentType::from(content_type);
115
116    if !status.is_client_error() && !status.is_server_error() {
117        let content = resp.text().await?;
118        match content_type {
119            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
120            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`"))),
121            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::SecretWithProjectsListResponseModel`")))),
122        }
123    } else {
124        let content = resp.text().await?;
125        let entity: Option<SecretsOrganizationIdTrashGetError> =
126            serde_json::from_str(&content).ok();
127        Err(Error::ResponseError(ResponseContent {
128            status,
129            content,
130            entity,
131        }))
132    }
133}
134
135pub async fn secrets_organization_id_trash_restore_post(
136    configuration: &configuration::Configuration,
137    organization_id: uuid::Uuid,
138    uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
139) -> Result<(), Error<SecretsOrganizationIdTrashRestorePostError>> {
140    // add a prefix to parameters to efficiently prevent name collisions
141    let p_organization_id = organization_id;
142    let p_uuid_colon_colon_uuid = uuid_colon_colon_uuid;
143
144    let uri_str = format!(
145        "{}/secrets/{organizationId}/trash/restore",
146        configuration.base_path,
147        organizationId = crate::apis::urlencode(p_organization_id.to_string())
148    );
149    let mut req_builder = configuration
150        .client
151        .request(reqwest::Method::POST, &uri_str);
152
153    if let Some(ref user_agent) = configuration.user_agent {
154        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
155    }
156    if let Some(ref token) = configuration.oauth_access_token {
157        req_builder = req_builder.bearer_auth(token.to_owned());
158    };
159    req_builder = req_builder.json(&p_uuid_colon_colon_uuid);
160
161    let req = req_builder.build()?;
162    let resp = configuration.client.execute(req).await?;
163
164    let status = resp.status();
165
166    if !status.is_client_error() && !status.is_server_error() {
167        Ok(())
168    } else {
169        let content = resp.text().await?;
170        let entity: Option<SecretsOrganizationIdTrashRestorePostError> =
171            serde_json::from_str(&content).ok();
172        Err(Error::ResponseError(ResponseContent {
173            status,
174            content,
175            entity,
176        }))
177    }
178}