Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore using sqlite #652

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ bld/
.idea
xcuserdata/

# Added by cargo
#
# already existing elements were commented out
# Databases
*.sqlite

#/target
node_modules/
clients/python/env/

Expand Down
89 changes: 89 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/bitwarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ reqwest = { version = ">=0.12.5, <0.13", features = [
"http2",
"json",
], default-features = false }
rusqlite = ">=0.31.0, <0.32"
schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] }
serde = { version = ">=1.0, <2.0", features = ["derive"] }
serde_json = ">=1.0.96, <2.0"
Expand Down
12 changes: 8 additions & 4 deletions crates/bitwarden-core/src/client/client.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use std::sync::{Arc, RwLock};
use std::sync::{Arc, Mutex, RwLock};

use reqwest::header::{self, HeaderValue};

use super::internal::InternalClient;
#[cfg(feature = "internal")]
use crate::client::flags::Flags;
use crate::client::{
client_settings::ClientSettings,
internal::{ApiConfigurations, Tokens},
use crate::{
client::{
client_settings::ClientSettings,
internal::{ApiConfigurations, Tokens},
},
SqliteDatabase,
};

/// The main struct to interact with the Bitwarden SDK.
Expand Down Expand Up @@ -79,6 +82,7 @@
})),
external_client,
encryption_settings: RwLock::new(None),
db: Arc::new(Mutex::new(SqliteDatabase::default().unwrap())),

Check failure

Code scanning / clippy

used unwrap() on a Result value Error

used unwrap() on a Result value
},
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/bitwarden-core/src/client/internal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::{Arc, RwLock};
use std::sync::{Arc, Mutex, RwLock};

#[cfg(any(feature = "internal", feature = "secrets"))]
use bitwarden_crypto::SymmetricCryptoKey;
Expand All @@ -17,7 +17,7 @@ use crate::error::Error;
use crate::{
auth::renew::renew_token,
error::{Result, VaultLocked},
DeviceType,
DeviceType, SqliteDatabase,
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -57,6 +57,8 @@ pub struct InternalClient {
pub(crate) external_client: reqwest::Client,

pub(super) encryption_settings: RwLock<Option<Arc<EncryptionSettings>>>,

pub db: Arc<Mutex<SqliteDatabase>>,
}

impl InternalClient {
Expand Down
32 changes: 32 additions & 0 deletions crates/bitwarden-core/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
mod sqlite;
use std::borrow::Cow;

pub use sqlite::SqliteDatabase;
use thiserror::Error;

use crate::MissingFieldError;

#[derive(Debug, Error)]

Check warning on line 9 in crates/bitwarden-core/src/database/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-core/src/database/mod.rs#L9

Added line #L9 was not covered by tests
pub enum DatabaseError {
#[error("Database lock")]
DatabaseLock,

#[error("Failed to open connection to database")]
FailedToOpenConnection,

#[error(transparent)]
Migrator(#[from] MigratorError),

#[error(transparent)]
Rusqlite(#[from] rusqlite::Error),
#[error(transparent)]
SerdeJson(#[from] serde_json::Error),
#[error(transparent)]
MissingField(#[from] MissingFieldError),
}

#[derive(Debug, Error)]

Check warning on line 28 in crates/bitwarden-core/src/database/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-core/src/database/mod.rs#L28

Added line #L28 was not covered by tests
pub enum MigratorError {
#[error("Internal error: {0}")]
Internal(Cow<'static, str>),
}
Loading
Loading