Skip to main content

bitwarden_vault/
vault_client.rs

1use bitwarden_core::{Client, FromClient};
2#[cfg(feature = "wasm")]
3use wasm_bindgen::prelude::*;
4
5use crate::{
6    AttachmentsClient, CipherRiskClient, CiphersClient, FoldersClient, PasswordHistoryClient,
7    TotpClient, collection_client::CollectionsClient,
8};
9
10#[allow(missing_docs)]
11#[derive(Clone)]
12#[cfg_attr(feature = "wasm", wasm_bindgen)]
13pub struct VaultClient {
14    pub(crate) client: Client,
15}
16
17impl VaultClient {
18    fn new(client: Client) -> Self {
19        Self { client }
20    }
21
22    /// Password history related operations.
23    pub fn password_history(&self) -> PasswordHistoryClient {
24        PasswordHistoryClient {
25            client: self.client.clone(),
26        }
27    }
28}
29
30#[cfg_attr(feature = "wasm", wasm_bindgen)]
31impl VaultClient {
32    /// Attachment related operations.
33    pub fn attachments(&self) -> AttachmentsClient {
34        AttachmentsClient {
35            client: self.client.clone(),
36        }
37    }
38
39    /// Cipher related operations.
40    pub fn ciphers(&self) -> CiphersClient {
41        CiphersClient {
42            client: self.client.clone(),
43        }
44    }
45
46    /// Folder related operations.
47    pub fn folders(&self) -> FoldersClient {
48        FoldersClient::from_client(&self.client)
49    }
50
51    /// TOTP related operations.
52    pub fn totp(&self) -> TotpClient {
53        TotpClient {
54            client: self.client.clone(),
55        }
56    }
57
58    /// Collection related operations.
59    pub fn collections(&self) -> CollectionsClient {
60        CollectionsClient {
61            client: self.client.clone(),
62        }
63    }
64
65    /// Cipher risk evaluation operations.
66    pub fn cipher_risk(&self) -> CipherRiskClient {
67        CipherRiskClient {
68            client: self.client.clone(),
69        }
70    }
71}
72
73#[allow(missing_docs)]
74pub trait VaultClientExt {
75    fn vault(&self) -> VaultClient;
76}
77
78impl VaultClientExt for Client {
79    fn vault(&self) -> VaultClient {
80        VaultClient::new(self.clone())
81    }
82}