Skip to main content

bitwarden_sm/
client.rs

1//! Client for the Bitwarden Secrets Manager API
2
3use std::sync::Arc;
4
5use bitwarden_auth::token_management::SecretsManagerTokenHandler;
6pub use bitwarden_core::ClientSettings;
7use bitwarden_core::{OrganizationId, auth::auth_client::AuthClient};
8use bitwarden_generators::GeneratorClientsExt;
9
10use crate::{ProjectsClient, SecretsClient};
11
12/// The main struct for interacting with the Secrets Manager service through the SM SDK.
13pub struct SecretsManagerClient {
14    client: bitwarden_core::Client,
15    token_handler: Arc<SecretsManagerTokenHandler>,
16}
17
18impl SecretsManagerClient {
19    /// Create a new SecretsManagerClient
20    pub fn new(settings: Option<ClientSettings>) -> Self {
21        let token_handler = Arc::new(SecretsManagerTokenHandler::default());
22        Self {
23            client: bitwarden_core::Client::new_with_token_handler(settings, token_handler.clone()),
24            token_handler,
25        }
26    }
27
28    /// Get access to the Projects API
29    pub fn projects(&self) -> ProjectsClient {
30        ProjectsClient::new(self.client.clone())
31    }
32
33    /// Get access to the Secrets API
34    pub fn secrets(&self) -> SecretsClient {
35        SecretsClient::new(self.client.clone())
36    }
37
38    /// Get access to the Auth API
39    pub fn auth(&self) -> AuthClient {
40        self.client.auth()
41    }
42
43    /// Get access to the Generators API
44    pub fn generator(&self) -> bitwarden_generators::GeneratorClient {
45        self.client.generator()
46    }
47
48    #[doc(hidden)]
49    pub fn get_access_token_organization(&self) -> Option<OrganizationId> {
50        self.token_handler.get_access_token_organization()
51    }
52}