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 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_secrets_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum OrganizationsOrganizationIdSecretsGetError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`organizations_organization_id_secrets_post`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum OrganizationsOrganizationIdSecretsPostError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`organizations_organization_id_secrets_sync_get`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum OrganizationsOrganizationIdSecretsSyncGetError {
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`projects_project_id_secrets_get`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum ProjectsProjectIdSecretsGetError {
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`secrets_delete_post`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum SecretsDeletePostError {
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`secrets_get_by_ids_post`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum SecretsGetByIdsPostError {
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`secrets_id_get`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum SecretsIdGetError {
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`secrets_id_put`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum SecretsIdPutError {
70    UnknownValue(serde_json::Value),
71}
72
73pub async fn organizations_organization_id_secrets_get(
74    configuration: &configuration::Configuration,
75    organization_id: uuid::Uuid,
76) -> Result<
77    models::SecretWithProjectsListResponseModel,
78    Error<OrganizationsOrganizationIdSecretsGetError>,
79> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_organization_id = organization_id;
82
83    let uri_str = format!(
84        "{}/organizations/{organizationId}/secrets",
85        configuration.base_path,
86        organizationId = crate::apis::urlencode(p_organization_id.to_string())
87    );
88    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
89
90    if let Some(ref user_agent) = configuration.user_agent {
91        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92    }
93    if let Some(ref token) = configuration.oauth_access_token {
94        req_builder = req_builder.bearer_auth(token.to_owned());
95    };
96
97    let req = req_builder.build()?;
98    let resp = configuration.client.execute(req).await?;
99
100    let status = resp.status();
101    let content_type = resp
102        .headers()
103        .get("content-type")
104        .and_then(|v| v.to_str().ok())
105        .unwrap_or("application/octet-stream");
106    let content_type = super::ContentType::from(content_type);
107
108    if !status.is_client_error() && !status.is_server_error() {
109        let content = resp.text().await?;
110        match content_type {
111            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
112            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`"))),
113            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`")))),
114        }
115    } else {
116        let content = resp.text().await?;
117        let entity: Option<OrganizationsOrganizationIdSecretsGetError> =
118            serde_json::from_str(&content).ok();
119        Err(Error::ResponseError(ResponseContent {
120            status,
121            content,
122            entity,
123        }))
124    }
125}
126
127pub async fn organizations_organization_id_secrets_post(
128    configuration: &configuration::Configuration,
129    organization_id: uuid::Uuid,
130    secret_create_request_model: Option<models::SecretCreateRequestModel>,
131) -> Result<models::SecretResponseModel, Error<OrganizationsOrganizationIdSecretsPostError>> {
132    // add a prefix to parameters to efficiently prevent name collisions
133    let p_organization_id = organization_id;
134    let p_secret_create_request_model = secret_create_request_model;
135
136    let uri_str = format!(
137        "{}/organizations/{organizationId}/secrets",
138        configuration.base_path,
139        organizationId = crate::apis::urlencode(p_organization_id.to_string())
140    );
141    let mut req_builder = configuration
142        .client
143        .request(reqwest::Method::POST, &uri_str);
144
145    if let Some(ref user_agent) = configuration.user_agent {
146        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147    }
148    if let Some(ref token) = configuration.oauth_access_token {
149        req_builder = req_builder.bearer_auth(token.to_owned());
150    };
151    req_builder = req_builder.json(&p_secret_create_request_model);
152
153    let req = req_builder.build()?;
154    let resp = configuration.client.execute(req).await?;
155
156    let status = resp.status();
157    let content_type = resp
158        .headers()
159        .get("content-type")
160        .and_then(|v| v.to_str().ok())
161        .unwrap_or("application/octet-stream");
162    let content_type = super::ContentType::from(content_type);
163
164    if !status.is_client_error() && !status.is_server_error() {
165        let content = resp.text().await?;
166        match content_type {
167            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
168            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecretResponseModel`"))),
169            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::SecretResponseModel`")))),
170        }
171    } else {
172        let content = resp.text().await?;
173        let entity: Option<OrganizationsOrganizationIdSecretsPostError> =
174            serde_json::from_str(&content).ok();
175        Err(Error::ResponseError(ResponseContent {
176            status,
177            content,
178            entity,
179        }))
180    }
181}
182
183pub async fn organizations_organization_id_secrets_sync_get(
184    configuration: &configuration::Configuration,
185    organization_id: uuid::Uuid,
186    last_synced_date: Option<String>,
187) -> Result<models::SecretsSyncResponseModel, Error<OrganizationsOrganizationIdSecretsSyncGetError>>
188{
189    // add a prefix to parameters to efficiently prevent name collisions
190    let p_organization_id = organization_id;
191    let p_last_synced_date = last_synced_date;
192
193    let uri_str = format!(
194        "{}/organizations/{organizationId}/secrets/sync",
195        configuration.base_path,
196        organizationId = crate::apis::urlencode(p_organization_id.to_string())
197    );
198    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
199
200    if let Some(ref param_value) = p_last_synced_date {
201        req_builder = req_builder.query(&[("lastSyncedDate", &param_value.to_string())]);
202    }
203    if let Some(ref user_agent) = configuration.user_agent {
204        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
205    }
206    if let Some(ref token) = configuration.oauth_access_token {
207        req_builder = req_builder.bearer_auth(token.to_owned());
208    };
209
210    let req = req_builder.build()?;
211    let resp = configuration.client.execute(req).await?;
212
213    let status = resp.status();
214    let content_type = resp
215        .headers()
216        .get("content-type")
217        .and_then(|v| v.to_str().ok())
218        .unwrap_or("application/octet-stream");
219    let content_type = super::ContentType::from(content_type);
220
221    if !status.is_client_error() && !status.is_server_error() {
222        let content = resp.text().await?;
223        match content_type {
224            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
225            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecretsSyncResponseModel`"))),
226            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::SecretsSyncResponseModel`")))),
227        }
228    } else {
229        let content = resp.text().await?;
230        let entity: Option<OrganizationsOrganizationIdSecretsSyncGetError> =
231            serde_json::from_str(&content).ok();
232        Err(Error::ResponseError(ResponseContent {
233            status,
234            content,
235            entity,
236        }))
237    }
238}
239
240pub async fn projects_project_id_secrets_get(
241    configuration: &configuration::Configuration,
242    project_id: uuid::Uuid,
243) -> Result<models::SecretWithProjectsListResponseModel, Error<ProjectsProjectIdSecretsGetError>> {
244    // add a prefix to parameters to efficiently prevent name collisions
245    let p_project_id = project_id;
246
247    let uri_str = format!(
248        "{}/projects/{projectId}/secrets",
249        configuration.base_path,
250        projectId = crate::apis::urlencode(p_project_id.to_string())
251    );
252    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
253
254    if let Some(ref user_agent) = configuration.user_agent {
255        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
256    }
257    if let Some(ref token) = configuration.oauth_access_token {
258        req_builder = req_builder.bearer_auth(token.to_owned());
259    };
260
261    let req = req_builder.build()?;
262    let resp = configuration.client.execute(req).await?;
263
264    let status = resp.status();
265    let content_type = resp
266        .headers()
267        .get("content-type")
268        .and_then(|v| v.to_str().ok())
269        .unwrap_or("application/octet-stream");
270    let content_type = super::ContentType::from(content_type);
271
272    if !status.is_client_error() && !status.is_server_error() {
273        let content = resp.text().await?;
274        match content_type {
275            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
276            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`"))),
277            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`")))),
278        }
279    } else {
280        let content = resp.text().await?;
281        let entity: Option<ProjectsProjectIdSecretsGetError> = serde_json::from_str(&content).ok();
282        Err(Error::ResponseError(ResponseContent {
283            status,
284            content,
285            entity,
286        }))
287    }
288}
289
290pub async fn secrets_delete_post(
291    configuration: &configuration::Configuration,
292    uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
293) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<SecretsDeletePostError>> {
294    // add a prefix to parameters to efficiently prevent name collisions
295    let p_uuid_colon_colon_uuid = uuid_colon_colon_uuid;
296
297    let uri_str = format!("{}/secrets/delete", configuration.base_path);
298    let mut req_builder = configuration
299        .client
300        .request(reqwest::Method::POST, &uri_str);
301
302    if let Some(ref user_agent) = configuration.user_agent {
303        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
304    }
305    if let Some(ref token) = configuration.oauth_access_token {
306        req_builder = req_builder.bearer_auth(token.to_owned());
307    };
308    req_builder = req_builder.json(&p_uuid_colon_colon_uuid);
309
310    let req = req_builder.build()?;
311    let resp = configuration.client.execute(req).await?;
312
313    let status = resp.status();
314    let content_type = resp
315        .headers()
316        .get("content-type")
317        .and_then(|v| v.to_str().ok())
318        .unwrap_or("application/octet-stream");
319    let content_type = super::ContentType::from(content_type);
320
321    if !status.is_client_error() && !status.is_server_error() {
322        let content = resp.text().await?;
323        match content_type {
324            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
325            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`"))),
326            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`")))),
327        }
328    } else {
329        let content = resp.text().await?;
330        let entity: Option<SecretsDeletePostError> = serde_json::from_str(&content).ok();
331        Err(Error::ResponseError(ResponseContent {
332            status,
333            content,
334            entity,
335        }))
336    }
337}
338
339pub async fn secrets_get_by_ids_post(
340    configuration: &configuration::Configuration,
341    get_secrets_request_model: Option<models::GetSecretsRequestModel>,
342) -> Result<models::BaseSecretResponseModelListResponseModel, Error<SecretsGetByIdsPostError>> {
343    // add a prefix to parameters to efficiently prevent name collisions
344    let p_get_secrets_request_model = get_secrets_request_model;
345
346    let uri_str = format!("{}/secrets/get-by-ids", configuration.base_path);
347    let mut req_builder = configuration
348        .client
349        .request(reqwest::Method::POST, &uri_str);
350
351    if let Some(ref user_agent) = configuration.user_agent {
352        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
353    }
354    if let Some(ref token) = configuration.oauth_access_token {
355        req_builder = req_builder.bearer_auth(token.to_owned());
356    };
357    req_builder = req_builder.json(&p_get_secrets_request_model);
358
359    let req = req_builder.build()?;
360    let resp = configuration.client.execute(req).await?;
361
362    let status = resp.status();
363    let content_type = resp
364        .headers()
365        .get("content-type")
366        .and_then(|v| v.to_str().ok())
367        .unwrap_or("application/octet-stream");
368    let content_type = super::ContentType::from(content_type);
369
370    if !status.is_client_error() && !status.is_server_error() {
371        let content = resp.text().await?;
372        match content_type {
373            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
374            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BaseSecretResponseModelListResponseModel`"))),
375            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::BaseSecretResponseModelListResponseModel`")))),
376        }
377    } else {
378        let content = resp.text().await?;
379        let entity: Option<SecretsGetByIdsPostError> = serde_json::from_str(&content).ok();
380        Err(Error::ResponseError(ResponseContent {
381            status,
382            content,
383            entity,
384        }))
385    }
386}
387
388pub async fn secrets_id_get(
389    configuration: &configuration::Configuration,
390    id: uuid::Uuid,
391) -> Result<models::SecretResponseModel, Error<SecretsIdGetError>> {
392    // add a prefix to parameters to efficiently prevent name collisions
393    let p_id = id;
394
395    let uri_str = format!(
396        "{}/secrets/{id}",
397        configuration.base_path,
398        id = crate::apis::urlencode(p_id.to_string())
399    );
400    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
401
402    if let Some(ref user_agent) = configuration.user_agent {
403        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
404    }
405    if let Some(ref token) = configuration.oauth_access_token {
406        req_builder = req_builder.bearer_auth(token.to_owned());
407    };
408
409    let req = req_builder.build()?;
410    let resp = configuration.client.execute(req).await?;
411
412    let status = resp.status();
413    let content_type = resp
414        .headers()
415        .get("content-type")
416        .and_then(|v| v.to_str().ok())
417        .unwrap_or("application/octet-stream");
418    let content_type = super::ContentType::from(content_type);
419
420    if !status.is_client_error() && !status.is_server_error() {
421        let content = resp.text().await?;
422        match content_type {
423            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
424            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecretResponseModel`"))),
425            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::SecretResponseModel`")))),
426        }
427    } else {
428        let content = resp.text().await?;
429        let entity: Option<SecretsIdGetError> = serde_json::from_str(&content).ok();
430        Err(Error::ResponseError(ResponseContent {
431            status,
432            content,
433            entity,
434        }))
435    }
436}
437
438pub async fn secrets_id_put(
439    configuration: &configuration::Configuration,
440    id: uuid::Uuid,
441    secret_update_request_model: Option<models::SecretUpdateRequestModel>,
442) -> Result<models::SecretResponseModel, Error<SecretsIdPutError>> {
443    // add a prefix to parameters to efficiently prevent name collisions
444    let p_id = id;
445    let p_secret_update_request_model = secret_update_request_model;
446
447    let uri_str = format!(
448        "{}/secrets/{id}",
449        configuration.base_path,
450        id = crate::apis::urlencode(p_id.to_string())
451    );
452    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
453
454    if let Some(ref user_agent) = configuration.user_agent {
455        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
456    }
457    if let Some(ref token) = configuration.oauth_access_token {
458        req_builder = req_builder.bearer_auth(token.to_owned());
459    };
460    req_builder = req_builder.json(&p_secret_update_request_model);
461
462    let req = req_builder.build()?;
463    let resp = configuration.client.execute(req).await?;
464
465    let status = resp.status();
466    let content_type = resp
467        .headers()
468        .get("content-type")
469        .and_then(|v| v.to_str().ok())
470        .unwrap_or("application/octet-stream");
471    let content_type = super::ContentType::from(content_type);
472
473    if !status.is_client_error() && !status.is_server_error() {
474        let content = resp.text().await?;
475        match content_type {
476            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
477            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SecretResponseModel`"))),
478            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::SecretResponseModel`")))),
479        }
480    } else {
481        let content = resp.text().await?;
482        let entity: Option<SecretsIdPutError> = serde_json::from_str(&content).ok();
483        Err(Error::ResponseError(ResponseContent {
484            status,
485            content,
486            entity,
487        }))
488    }
489}