Skip to main content

bitwarden_core/global/
global_internal_client.rs

1use std::sync::Arc;
2
3use reqwest_middleware::ClientWithMiddleware;
4
5/// Internal state shared by all clones of a [`crate::GlobalClient`].
6///
7/// Holds the configured HTTP client and exposes factory methods that build
8/// per-call API clients targeting a caller-supplied base URL.
9pub struct GlobalInternalClient {
10    pub(crate) http_client: ClientWithMiddleware,
11}
12
13impl GlobalInternalClient {
14    /// Build an API client targeting `base_url`.
15    pub fn make_api_client(&self, base_url: String) -> bitwarden_api_api::apis::ApiClient {
16        let config = bitwarden_api_api::Configuration {
17            base_path: base_url,
18            client: self.http_client.clone(),
19        };
20        bitwarden_api_api::apis::ApiClient::new(&Arc::new(config))
21    }
22
23    /// Build an identity client targeting `base_url`.
24    pub fn make_identity_client(
25        &self,
26        base_url: String,
27    ) -> bitwarden_api_identity::apis::ApiClient {
28        let config = bitwarden_api_identity::Configuration {
29            base_path: base_url,
30            client: self.http_client.clone(),
31        };
32        bitwarden_api_identity::apis::ApiClient::new(&Arc::new(config))
33    }
34}