bitwarden_api_api/apis/
trash_api.rs1use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21 apis::{AuthRequired, ContentType, ResponseContent},
22 models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait TrashApi: Send + Sync {
29 async fn empty_trash<'a>(
31 &self,
32 organization_id: uuid::Uuid,
33 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
34 ) -> Result<(), Error<EmptyTrashError>>;
35
36 async fn list_by_organization<'a>(
38 &self,
39 organization_id: uuid::Uuid,
40 ) -> Result<models::SecretWithProjectsListResponseModel, Error<ListByOrganizationError>>;
41
42 async fn restore_trash<'a>(
44 &self,
45 organization_id: uuid::Uuid,
46 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
47 ) -> Result<(), Error<RestoreTrashError>>;
48}
49
50pub struct TrashApiClient {
51 configuration: Arc<configuration::Configuration>,
52}
53
54impl TrashApiClient {
55 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
56 Self { configuration }
57 }
58}
59
60#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
61#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
62impl TrashApi for TrashApiClient {
63 async fn empty_trash<'a>(
64 &self,
65 organization_id: uuid::Uuid,
66 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
67 ) -> Result<(), Error<EmptyTrashError>> {
68 let local_var_configuration = &self.configuration;
69
70 let local_var_client = &local_var_configuration.client;
71
72 let local_var_uri_str = format!(
73 "{}/secrets/{organizationId}/trash/empty",
74 local_var_configuration.base_path,
75 organizationId = organization_id
76 );
77 let mut local_var_req_builder =
78 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
79
80 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
81 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
82 };
83 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
84 local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
85
86 let local_var_req = local_var_req_builder.build()?;
87 let local_var_resp = local_var_client.execute(local_var_req).await?;
88
89 let local_var_status = local_var_resp.status();
90 let local_var_content = local_var_resp.text().await?;
91
92 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
93 Ok(())
94 } else {
95 let local_var_entity: Option<EmptyTrashError> =
96 serde_json::from_str(&local_var_content).ok();
97 let local_var_error = ResponseContent {
98 status: local_var_status,
99 content: local_var_content,
100 entity: local_var_entity,
101 };
102 Err(Error::ResponseError(local_var_error))
103 }
104 }
105
106 async fn list_by_organization<'a>(
107 &self,
108 organization_id: uuid::Uuid,
109 ) -> Result<models::SecretWithProjectsListResponseModel, Error<ListByOrganizationError>> {
110 let local_var_configuration = &self.configuration;
111
112 let local_var_client = &local_var_configuration.client;
113
114 let local_var_uri_str = format!(
115 "{}/secrets/{organizationId}/trash",
116 local_var_configuration.base_path,
117 organizationId = organization_id
118 );
119 let mut local_var_req_builder =
120 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
121
122 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
123 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
124 };
125 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
126
127 let local_var_req = local_var_req_builder.build()?;
128 let local_var_resp = local_var_client.execute(local_var_req).await?;
129
130 let local_var_status = local_var_resp.status();
131 let local_var_content_type = local_var_resp
132 .headers()
133 .get("content-type")
134 .and_then(|v| v.to_str().ok())
135 .unwrap_or("application/octet-stream");
136 let local_var_content_type = super::ContentType::from(local_var_content_type);
137 let local_var_content = local_var_resp.text().await?;
138
139 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
140 match local_var_content_type {
141 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
142 ContentType::Text => {
143 return Err(Error::from(serde_json::Error::custom(
144 "Received `text/plain` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`",
145 )));
146 }
147 ContentType::Unsupported(local_var_unknown_type) => {
148 return Err(Error::from(serde_json::Error::custom(format!(
149 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`"
150 ))));
151 }
152 }
153 } else {
154 let local_var_entity: Option<ListByOrganizationError> =
155 serde_json::from_str(&local_var_content).ok();
156 let local_var_error = ResponseContent {
157 status: local_var_status,
158 content: local_var_content,
159 entity: local_var_entity,
160 };
161 Err(Error::ResponseError(local_var_error))
162 }
163 }
164
165 async fn restore_trash<'a>(
166 &self,
167 organization_id: uuid::Uuid,
168 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
169 ) -> Result<(), Error<RestoreTrashError>> {
170 let local_var_configuration = &self.configuration;
171
172 let local_var_client = &local_var_configuration.client;
173
174 let local_var_uri_str = format!(
175 "{}/secrets/{organizationId}/trash/restore",
176 local_var_configuration.base_path,
177 organizationId = organization_id
178 );
179 let mut local_var_req_builder =
180 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
181
182 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
183 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
184 };
185 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
186 local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
187
188 let local_var_req = local_var_req_builder.build()?;
189 let local_var_resp = local_var_client.execute(local_var_req).await?;
190
191 let local_var_status = local_var_resp.status();
192 let local_var_content = local_var_resp.text().await?;
193
194 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
195 Ok(())
196 } else {
197 let local_var_entity: Option<RestoreTrashError> =
198 serde_json::from_str(&local_var_content).ok();
199 let local_var_error = ResponseContent {
200 status: local_var_status,
201 content: local_var_content,
202 entity: local_var_entity,
203 };
204 Err(Error::ResponseError(local_var_error))
205 }
206 }
207}
208
209#[derive(Debug, Clone, Serialize, Deserialize)]
211#[serde(untagged)]
212pub enum EmptyTrashError {
213 UnknownValue(serde_json::Value),
214}
215#[derive(Debug, Clone, Serialize, Deserialize)]
217#[serde(untagged)]
218pub enum ListByOrganizationError {
219 UnknownValue(serde_json::Value),
220}
221#[derive(Debug, Clone, Serialize, Deserialize)]
223#[serde(untagged)]
224pub enum RestoreTrashError {
225 UnknownValue(serde_json::Value),
226}