bitwarden_sm/secrets/
delete.rs1use bitwarden_api_api::models::{
2 BulkDeleteResponseModel, BulkDeleteResponseModelListResponseModel,
3};
4use bitwarden_core::{client::Client, require};
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7use uuid::Uuid;
8
9use crate::error::SecretsManagerError;
10
11#[derive(Serialize, Deserialize, Debug, JsonSchema)]
12#[serde(rename_all = "camelCase", deny_unknown_fields)]
13pub struct SecretsDeleteRequest {
14 pub ids: Vec<Uuid>,
16}
17
18pub(crate) async fn delete_secrets(
19 client: &Client,
20 input: SecretsDeleteRequest,
21) -> Result<SecretsDeleteResponse, SecretsManagerError> {
22 let config = client.internal.get_api_configurations().await;
23 let res =
24 bitwarden_api_api::apis::secrets_api::secrets_delete_post(&config.api, Some(input.ids))
25 .await?;
26
27 SecretsDeleteResponse::process_response(res)
28}
29
30#[derive(Serialize, Deserialize, Debug, JsonSchema)]
31#[serde(rename_all = "camelCase", deny_unknown_fields)]
32pub struct SecretsDeleteResponse {
33 pub data: Vec<SecretDeleteResponse>,
34}
35
36impl SecretsDeleteResponse {
37 pub(crate) fn process_response(
38 response: BulkDeleteResponseModelListResponseModel,
39 ) -> Result<SecretsDeleteResponse, SecretsManagerError> {
40 Ok(SecretsDeleteResponse {
41 data: response
42 .data
43 .unwrap_or_default()
44 .into_iter()
45 .map(SecretDeleteResponse::process_response)
46 .collect::<Result<_, _>>()?,
47 })
48 }
49}
50
51#[derive(Serialize, Deserialize, Debug, JsonSchema)]
52#[serde(rename_all = "camelCase", deny_unknown_fields)]
53pub struct SecretDeleteResponse {
54 pub id: Uuid,
55 pub error: Option<String>,
56}
57
58impl SecretDeleteResponse {
59 pub(crate) fn process_response(
60 response: BulkDeleteResponseModel,
61 ) -> Result<SecretDeleteResponse, SecretsManagerError> {
62 Ok(SecretDeleteResponse {
63 id: require!(response.id),
64 error: response.error,
65 })
66 }
67}