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::from_client(&self.client)
42    }
43
44    /// Folder related operations.
45    pub fn folders(&self) -> FoldersClient {
46        FoldersClient::from_client(&self.client)
47    }
48
49    /// TOTP related operations.
50    pub fn totp(&self) -> TotpClient {
51        TotpClient {
52            client: self.client.clone(),
53        }
54    }
55
56    /// Collection related operations.
57    pub fn collections(&self) -> CollectionsClient {
58        CollectionsClient {
59            client: self.client.clone(),
60        }
61    }
62
63    /// Cipher risk evaluation operations.
64    pub fn cipher_risk(&self) -> CipherRiskClient {
65        CipherRiskClient {
66            client: self.client.clone(),
67        }
68    }
69}
70
71#[allow(missing_docs)]
72pub trait VaultClientExt {
73    fn vault(&self) -> VaultClient;
74}
75
76impl VaultClientExt for Client {
77    fn vault(&self) -> VaultClient {
78        VaultClient::new(self.clone())
79    }
80}