Skip to content

Commit

Permalink
Fix compile for all crates
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Jul 29, 2024
1 parent c69e5e7 commit cd105f7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 39 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.

2 changes: 1 addition & 1 deletion crates/bitwarden-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions crates/bitwarden-c/src/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
34 changes: 1 addition & 33 deletions crates/bitwarden-json/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -54,34 +50,6 @@ impl Client {

let client = &self.0;

let ciphers: Vec<Cipher> = (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(),
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 6 additions & 1 deletion crates/bitwarden-napi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ 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]
pub async fn run_command(&self, command_input: String) -> String {
self.0.run_command(&command_input).await
}
}

#[tokio::main]
async fn new(settings_string: Option<String>) -> JsonClient {
JsonClient::new(settings_string).await
}
7 changes: 6 additions & 1 deletion crates/bitwarden-py/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)")]
Expand All @@ -22,6 +22,11 @@ impl BitwardenClient {
}
}

#[tokio::main]
async fn new(settings_string: Option<String>) -> JsonClient {
JsonClient::new(settings_string).await
}

#[tokio::main]
async fn run_command(client: &JsonClient, input_str: &str) -> String {
client.run_command(input_str).await
Expand Down

0 comments on commit cd105f7

Please sign in to comment.