diff --git a/Cargo.lock b/Cargo.lock index e07da7c80..f3ec0a55f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -610,6 +610,7 @@ dependencies = [ "napi", "napi-build", "napi-derive", + "tokio", ] [[package]] diff --git a/crates/bitwarden-c/Cargo.toml b/crates/bitwarden-c/Cargo.toml index 9e09641f6..e9a9bd257 100644 --- a/crates/bitwarden-c/Cargo.toml +++ b/crates/bitwarden-c/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["staticlib", "cdylib"] bench = false [target.'cfg(not(target_arch="wasm32"))'.dependencies] -tokio = { version = ">=1.28.2, <2.0", features = ["rt-multi-thread", "macros"] } +tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } bitwarden-json = { path = "../bitwarden-json", features = ["secrets"] } [dependencies] diff --git a/crates/bitwarden-c/src/c.rs b/crates/bitwarden-c/src/c.rs index 32abe3dc0..d523c39fe 100644 --- a/crates/bitwarden-c/src/c.rs +++ b/crates/bitwarden-c/src/c.rs @@ -23,16 +23,17 @@ pub async extern "C" fn run_command( // Init client, potential leak! You need to call free_mem after this! #[no_mangle] -pub extern "C" fn init(c_str_ptr: *const c_char) -> *mut Client { +#[tokio::main] +pub async extern "C" fn init(c_str_ptr: *const c_char) -> *mut Client { // This will only fail if another logger was already initialized, so we can ignore the result let _ = env_logger::try_init(); if c_str_ptr.is_null() { - box_ptr!(Client::new(None)) + box_ptr!(Client::new(None).await) } else { let input_string = str::from_utf8(unsafe { CStr::from_ptr(c_str_ptr) }.to_bytes()) .expect("Input should be a valid string") .to_owned(); - box_ptr!(Client::new(Some(input_string))) + box_ptr!(Client::new(Some(input_string)).await) } } diff --git a/crates/bitwarden-json/src/client.rs b/crates/bitwarden-json/src/client.rs index ad0865ac0..850dbd940 100644 --- a/crates/bitwarden-json/src/client.rs +++ b/crates/bitwarden-json/src/client.rs @@ -2,11 +2,7 @@ use bitwarden::secrets_manager::{ClientProjectsExt, ClientSecretsExt}; #[cfg(feature = "internal")] use bitwarden::vault::ClientVaultExt; -use bitwarden::{ - vault::{Cipher, CipherRepromptType, CipherType}, - ClientSettings, -}; -use uuid::Uuid; +use bitwarden::ClientSettings; #[cfg(feature = "secrets")] use crate::command::{ProjectsCommand, SecretsCommand}; @@ -54,34 +50,6 @@ impl Client { let client = &self.0; - let ciphers: Vec = (0..10).map(|_| Cipher { - id: Some(Uuid::new_v4()), - organization_id: None, - folder_id: None, - collection_ids: vec![], - key: None, - name: "2.pMS6/icTQABtulw52pq2lg==|XXbxKxDTh+mWiN1HjH2N1w==|Q6PkuT+KX/axrgN9ubD5Ajk2YNwxQkgs3WJM0S0wtG8=".parse().unwrap(), - notes: None, - r#type: CipherType::Login, - login: None, - identity: None, - card: None, - secure_note: None, - favorite: false, - reprompt: CipherRepromptType::None, - organization_use_totp: false, - edit: true, - view_password: true, - local_data: None, - attachments: None, - fields: None, - password_history: None, - creation_date: "2024-01-30T17:55:36.150Z".parse().unwrap(), - deleted_date: None, - revision_date: "2024-01-30T17:55:36.150Z".parse().unwrap(), - }).collect(); - client.vault().cipher_repository.replace_all(&ciphers).await; - match cmd { #[cfg(feature = "internal")] Command::PasswordLogin(req) => client.auth().login_password(&req).await.into_string(), diff --git a/crates/bitwarden-napi/Cargo.toml b/crates/bitwarden-napi/Cargo.toml index 7bcd54aad..6e3c6b935 100644 --- a/crates/bitwarden-napi/Cargo.toml +++ b/crates/bitwarden-napi/Cargo.toml @@ -25,6 +25,7 @@ env_logger = "0.11.1" log = "0.4.20" napi = { version = "2", features = ["async"] } napi-derive = "2" +tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } [build-dependencies] napi-build = "2.1.0" diff --git a/crates/bitwarden-napi/src/client.rs b/crates/bitwarden-napi/src/client.rs index f41d5c351..ccae8a35b 100644 --- a/crates/bitwarden-napi/src/client.rs +++ b/crates/bitwarden-napi/src/client.rs @@ -34,7 +34,7 @@ impl BitwardenClient { let _ = env_logger::Builder::from_default_env() .filter_level(convert_level(log_level.unwrap_or(LogLevel::Info))) .try_init(); - Self(bitwarden_json::client::Client::new(settings_input)) + Self(new(settings_input)) } #[napi] @@ -42,3 +42,8 @@ impl BitwardenClient { self.0.run_command(&command_input).await } } + +#[tokio::main] +async fn new(settings_string: Option) -> JsonClient { + JsonClient::new(settings_string).await +} diff --git a/crates/bitwarden-py/src/client.rs b/crates/bitwarden-py/src/client.rs index 510de1db4..7a10786db 100644 --- a/crates/bitwarden-py/src/client.rs +++ b/crates/bitwarden-py/src/client.rs @@ -13,7 +13,7 @@ impl BitwardenClient { // result let _ = pyo3_log::try_init(); - Self(JsonClient::new(settings_string)) + Self(new(settings_string)) } #[pyo3(text_signature = "($self, command_input)")] @@ -22,6 +22,11 @@ impl BitwardenClient { } } +#[tokio::main] +async fn new(settings_string: Option) -> JsonClient { + JsonClient::new(settings_string).await +} + #[tokio::main] async fn run_command(client: &JsonClient, input_str: &str) -> String { client.run_command(input_str).await