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 d921392
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};

pub struct ClientExporters<'a> {
pub(crate) client: &'a crate::Client,
client: &'a crate::Client,
}

impl<'a> ClientExporters<'a> {
Expand Down
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
1 change: 1 addition & 0 deletions crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bitwarden-crypto = { workspace = true }
bitwarden-exporters = { workspace = true, optional = true }
bitwarden-generators = { workspace = true, optional = true }
bitwarden-sm = { workspace = true, optional = true }
uuid = ">=1.3.3, <2"

[lints]
workspace = true
97 changes: 97 additions & 0 deletions crates/bitwarden/src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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, ClientCrypto};

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

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

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 fn load_flags(&mut self, flags: std::collections::HashMap<String, bool>) {
self.0.load_flags(flags)
}

pub fn get_access_token_organization(&self) -> Option<Uuid> {
self.0.get_access_token_organization()
}

#[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(&self) -> ClientKdf {
self.0.kdf()
}

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

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

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

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

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

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

#[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
2 changes: 1 addition & 1 deletion crates/sdk-schemas/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ use bitwarden_json::response::Response;
#[derive(JsonSchema)]
struct SchemaTypes {
// Input types for new Client
client_settings: bitwarden::client::client_settings::ClientSettings,
client_settings: bitwarden::ClientSettings,

// Input types for Client::run_command
input_command: bitwarden_json::command::Command,
Expand Down

0 comments on commit d921392

Please sign in to comment.