Skip to content

Commit

Permalink
Use a client wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed May 27, 2024
1 parent 83818b9 commit 4252875
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 13 deletions.
6 changes: 1 addition & 5 deletions crates/bitwarden-json/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use async_lock::Mutex;
use bitwarden::client::client_settings::ClientSettings;
use bitwarden::ClientSettings;

#[cfg(feature = "secrets")]
use crate::command::{ProjectsCommand, SecretsCommand};
use crate::{
command::Command,
response::{Response, ResponseIntoString},
};
#[cfg(feature = "secrets")]
use bitwarden::ClientProjectsExt;
#[cfg(feature = "secrets")]
use bitwarden::ClientSecretsExt;

pub struct Client(Mutex<bitwarden::Client>);

Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden-sm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ mod client_secrets;
pub mod projects;
pub mod secrets;

pub use client_projects::ClientProjectsExt;
pub use client_secrets::ClientSecretsExt;
pub use client_projects::{ClientProjects, ClientProjectsExt};
pub use client_secrets::{ClientSecrets, ClientSecretsExt};

macro_rules! require {
($val:expr) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;

use async_lock::RwLock;
use auth::ClientAuth;
use bitwarden::client::client_settings::ClientSettings;
use bitwarden::ClientSettings;

pub mod auth;
pub mod crypto;
Expand Down
1 change: 0 additions & 1 deletion crates/bitwarden-uniffi/src/tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use bitwarden::{
generators::{PassphraseGeneratorRequest, PasswordGeneratorRequest, UsernameGeneratorRequest},
tool::ExportFormat,
vault::{Cipher, Collection, Folder},
ClientGeneratorExt,
};

use crate::{error::Result, Client};
Expand Down
76 changes: 76 additions & 0 deletions crates/bitwarden/src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use bitwarden_core::{
auth::client_auth::ClientAuth,
client::client_settings::ClientSettings,
error::Error,
mobile::ClientKdf,
platform::{SyncRequest, SyncResponse},
};

#[cfg(feature = "secrets")]
use bitwarden_sm::{ClientProjects, ClientProjectsExt, ClientSecrets, ClientSecretsExt};

#[cfg(feature = "mobile")]
use bitwarden_core::mobile::vault::ClientVault;

#[cfg(feature = "internal")]
use bitwarden_core::platform::{
client_platform::ClientPlatform, SecretVerificationRequest, UserApiKeyResponse,
};

#[cfg(feature = "internal")]
use bitwarden_generators::{ClientGenerator, ClientGeneratorExt};

pub struct Client(bitwarden_core::Client);

impl Client {
pub fn new(settings: Option<ClientSettings>) -> Self {
Self(bitwarden_core::Client::new(settings))
}

#[cfg(feature = "internal")]
pub async fn sync(&mut self, input: &SyncRequest) -> Result<SyncResponse, Error> {
self.0.sync(input).await
}

#[cfg(feature = "internal")]
pub async fn get_user_api_key(
&mut self,
input: SecretVerificationRequest,
) -> Result<UserApiKeyResponse, Error> {
self.0.get_user_api_key(input).await
}

#[cfg(feature = "mobile")]
pub fn kdf(&mut self) -> ClientKdf {
self.0.kdf()
}

pub fn auth(&mut self) -> ClientAuth {
self.0.auth()
}

#[cfg(feature = "mobile")]
pub fn vault(&mut self) -> ClientVault {
self.0.vault()
}

#[cfg(feature = "internal")]
pub fn platform(&mut self) -> ClientPlatform {
self.0.platform()
}

#[cfg(feature = "internal")]
pub fn generator(&mut self) -> ClientGenerator {
self.0.generator()
}

#[cfg(feature = "secrets")]
pub fn secrets(&mut self) -> ClientSecrets {
self.0.secrets()
}

#[cfg(feature = "secrets")]
pub fn projects(&mut self) -> ClientProjects {
self.0.projects()
}
}
5 changes: 5 additions & 0 deletions crates/bitwarden/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#[allow(hidden_glob_reexports)]
mod client;
pub use client::Client;

pub use bitwarden_core::client::client_settings::ClientSettings;
pub use bitwarden_core::*;

#[cfg(feature = "internal")]
Expand Down
3 changes: 1 addition & 2 deletions crates/bw/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use bitwarden::{
auth::RegisterRequest,
client::client_settings::ClientSettings,
generators::{PassphraseGeneratorRequest, PasswordGeneratorRequest},
ClientGeneratorExt,
ClientSettings,
};
use bitwarden_cli::{install_color_eyre, text_prompt_when_none, Color};
use bitwarden_crypto::SensitiveString;
Expand Down
3 changes: 1 addition & 2 deletions crates/bws/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{path::PathBuf, process, str::FromStr};

use bitwarden::{
auth::{login::AccessTokenLoginRequest, AccessToken},
client::client_settings::ClientSettings,
secrets_manager::{
projects::{
ProjectCreateRequest, ProjectGetRequest, ProjectPutRequest, ProjectsDeleteRequest,
Expand All @@ -13,7 +12,7 @@ use bitwarden::{
SecretIdentifiersRequest, SecretPutRequest, SecretsDeleteRequest, SecretsGetRequest,
},
},
ClientProjectsExt, ClientSecretsExt,
ClientSettings,
};
use bitwarden_cli::install_color_eyre;
use clap::{CommandFactory, Parser};
Expand Down

0 comments on commit 4252875

Please sign in to comment.