Skip to main content

bitwarden_api_api/apis/
secrets_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 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 SecretsApi: Send + Sync {
29    /// POST /secrets/delete
30    async fn bulk_delete<'a>(
31        &self,
32        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
33    ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error>;
34
35    /// POST /organizations/{organizationId}/secrets
36    async fn create<'a>(
37        &self,
38        organization_id: uuid::Uuid,
39        secret_create_request_model: Option<models::SecretCreateRequestModel>,
40    ) -> Result<models::SecretResponseModel, Error>;
41
42    /// GET /secrets/{id}
43    async fn get<'a>(&self, id: uuid::Uuid) -> Result<models::SecretResponseModel, Error>;
44
45    /// POST /secrets/get-by-ids
46    async fn get_secrets_by_ids<'a>(
47        &self,
48        get_secrets_request_model: Option<models::GetSecretsRequestModel>,
49    ) -> Result<models::BaseSecretResponseModelListResponseModel, Error>;
50
51    /// GET /projects/{projectId}/secrets
52    async fn get_secrets_by_project<'a>(
53        &self,
54        project_id: uuid::Uuid,
55    ) -> Result<models::SecretWithProjectsListResponseModel, Error>;
56
57    /// GET /organizations/{organizationId}/secrets/sync
58    async fn get_secrets_sync<'a>(
59        &self,
60        organization_id: uuid::Uuid,
61        last_synced_date: Option<String>,
62    ) -> Result<models::SecretsSyncResponseModel, Error>;
63
64    /// GET /organizations/{organizationId}/secrets
65    async fn list_by_organization<'a>(
66        &self,
67        organization_id: uuid::Uuid,
68    ) -> Result<models::SecretWithProjectsListResponseModel, Error>;
69
70    /// PUT /secrets/{id}
71    async fn update_secret<'a>(
72        &self,
73        id: uuid::Uuid,
74        secret_update_request_model: Option<models::SecretUpdateRequestModel>,
75    ) -> Result<models::SecretResponseModel, Error>;
76}
77
78pub struct SecretsApiClient {
79    configuration: Arc<configuration::Configuration>,
80}
81
82impl SecretsApiClient {
83    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
84        Self { configuration }
85    }
86}
87
88#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
89#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
90impl SecretsApi for SecretsApiClient {
91    async fn bulk_delete<'a>(
92        &self,
93        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
94    ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error> {
95        let local_var_configuration = &self.configuration;
96
97        let local_var_client = &local_var_configuration.client;
98
99        let local_var_uri_str = format!("{}/secrets/delete", local_var_configuration.base_path);
100        let mut local_var_req_builder =
101            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
102
103        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
104        local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
105
106        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
107    }
108
109    async fn create<'a>(
110        &self,
111        organization_id: uuid::Uuid,
112        secret_create_request_model: Option<models::SecretCreateRequestModel>,
113    ) -> Result<models::SecretResponseModel, Error> {
114        let local_var_configuration = &self.configuration;
115
116        let local_var_client = &local_var_configuration.client;
117
118        let local_var_uri_str = format!(
119            "{}/organizations/{organizationId}/secrets",
120            local_var_configuration.base_path,
121            organizationId = organization_id
122        );
123        let mut local_var_req_builder =
124            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
125
126        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
127        local_var_req_builder = local_var_req_builder.json(&secret_create_request_model);
128
129        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
130    }
131
132    async fn get<'a>(&self, id: uuid::Uuid) -> Result<models::SecretResponseModel, Error> {
133        let local_var_configuration = &self.configuration;
134
135        let local_var_client = &local_var_configuration.client;
136
137        let local_var_uri_str = format!(
138            "{}/secrets/{id}",
139            local_var_configuration.base_path,
140            id = id
141        );
142        let mut local_var_req_builder =
143            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
144
145        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
146
147        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
148    }
149
150    async fn get_secrets_by_ids<'a>(
151        &self,
152        get_secrets_request_model: Option<models::GetSecretsRequestModel>,
153    ) -> Result<models::BaseSecretResponseModelListResponseModel, Error> {
154        let local_var_configuration = &self.configuration;
155
156        let local_var_client = &local_var_configuration.client;
157
158        let local_var_uri_str = format!("{}/secrets/get-by-ids", local_var_configuration.base_path);
159        let mut local_var_req_builder =
160            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
161
162        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
163        local_var_req_builder = local_var_req_builder.json(&get_secrets_request_model);
164
165        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
166    }
167
168    async fn get_secrets_by_project<'a>(
169        &self,
170        project_id: uuid::Uuid,
171    ) -> Result<models::SecretWithProjectsListResponseModel, Error> {
172        let local_var_configuration = &self.configuration;
173
174        let local_var_client = &local_var_configuration.client;
175
176        let local_var_uri_str = format!(
177            "{}/projects/{projectId}/secrets",
178            local_var_configuration.base_path,
179            projectId = project_id
180        );
181        let mut local_var_req_builder =
182            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
183
184        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
185
186        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
187    }
188
189    async fn get_secrets_sync<'a>(
190        &self,
191        organization_id: uuid::Uuid,
192        last_synced_date: Option<String>,
193    ) -> Result<models::SecretsSyncResponseModel, Error> {
194        let local_var_configuration = &self.configuration;
195
196        let local_var_client = &local_var_configuration.client;
197
198        let local_var_uri_str = format!(
199            "{}/organizations/{organizationId}/secrets/sync",
200            local_var_configuration.base_path,
201            organizationId = organization_id
202        );
203        let mut local_var_req_builder =
204            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
205
206        if let Some(ref param_value) = last_synced_date {
207            local_var_req_builder =
208                local_var_req_builder.query(&[("lastSyncedDate", &param_value.to_string())]);
209        }
210        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
211
212        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
213    }
214
215    async fn list_by_organization<'a>(
216        &self,
217        organization_id: uuid::Uuid,
218    ) -> Result<models::SecretWithProjectsListResponseModel, Error> {
219        let local_var_configuration = &self.configuration;
220
221        let local_var_client = &local_var_configuration.client;
222
223        let local_var_uri_str = format!(
224            "{}/organizations/{organizationId}/secrets",
225            local_var_configuration.base_path,
226            organizationId = organization_id
227        );
228        let mut local_var_req_builder =
229            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
230
231        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
232
233        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
234    }
235
236    async fn update_secret<'a>(
237        &self,
238        id: uuid::Uuid,
239        secret_update_request_model: Option<models::SecretUpdateRequestModel>,
240    ) -> Result<models::SecretResponseModel, Error> {
241        let local_var_configuration = &self.configuration;
242
243        let local_var_client = &local_var_configuration.client;
244
245        let local_var_uri_str = format!(
246            "{}/secrets/{id}",
247            local_var_configuration.base_path,
248            id = id
249        );
250        let mut local_var_req_builder =
251            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
252
253        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
254        local_var_req_builder = local_var_req_builder.json(&secret_update_request_model);
255
256        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
257    }
258}