diff --git a/akd/Cargo.lock b/akd/Cargo.lock index c159373df9..aa2655f8bf 100644 --- a/akd/Cargo.lock +++ b/akd/Cargo.lock @@ -67,6 +67,7 @@ dependencies = [ "akd", "async-trait", "ms_database", + "serde", "thiserror 2.0.17", "tracing", ] @@ -144,6 +145,12 @@ version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" +[[package]] +name = "arraydeque" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" + [[package]] name = "arrayref" version = "0.3.9" @@ -370,6 +377,9 @@ name = "bitflags" version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" +dependencies = [ + "serde", +] [[package]] name = "bitwarden-akd-configuration" @@ -504,6 +514,19 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "common" +version = "0.1.0" +dependencies = [ + "akd", + "akd_storage", + "async-trait", + "config", + "serde", + "thiserror 2.0.17", + "tracing", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -513,6 +536,26 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "config" +version = "0.15.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e549344080374f9b32ed41bf3b6b57885ff6a289367b3dbc10eea8acc1918" +dependencies = [ + "async-trait", + "convert_case", + "json5", + "pathdiff", + "ron", + "rust-ini", + "serde-untagged", + "serde_core", + "serde_json", + "toml", + "winnow", + "yaml-rust2", +] + [[package]] name = "connection-string" version = "0.2.0" @@ -525,12 +568,41 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom 0.2.16", + "once_cell", + "tiny-keccak", +] + [[package]] name = "constant_time_eq" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -562,6 +634,12 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + [[package]] name = "crypto-common" version = "0.1.6" @@ -632,6 +710,15 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dlv-list" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" +dependencies = [ + "const-random", +] + [[package]] name = "ed25519" version = "2.2.3" @@ -698,6 +785,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "erased-serde" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "259d404d09818dec19332e31d94558aeb442fea04c817006456c24b5460bbd4b" +dependencies = [ + "serde", + "serde_core", + "typeid", +] + [[package]] name = "errno" version = "0.3.14" @@ -753,6 +851,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "futures-channel" version = "0.3.31" @@ -890,12 +994,30 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + [[package]] name = "hashbrown" version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + [[package]] name = "heck" version = "0.5.0" @@ -966,6 +1088,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + [[package]] name = "kv-log-macro" version = "1.0.7" @@ -1123,6 +1256,16 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" +[[package]] +name = "ordered-multimap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" +dependencies = [ + "dlv-list", + "hashbrown 0.14.5", +] + [[package]] name = "owo-colors" version = "4.2.3" @@ -1158,6 +1301,55 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "pathdiff" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" + +[[package]] +name = "pest" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "989e7521a040efde50c3ab6bbadafbe15ab6dc042686926be59ac35d74607df4" +dependencies = [ + "memchr", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187da9a3030dbafabbbfb20cb323b976dc7b7ce91fcd84f2f74d6e31d378e2de" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b401d98f5757ebe97a26085998d6c0eecec4995cad6ab7fc30ffdf4b052843" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "pest_meta" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f27a2cfee9f9039c4d86faa5af122a0ac3851441a34865b8a043b46be0065a" +dependencies = [ + "pest", + "sha2", +] + [[package]] name = "pin-project-lite" version = "0.2.16" @@ -1390,6 +1582,28 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "ron" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" +dependencies = [ + "base64", + "bitflags", + "serde", + "serde_derive", +] + +[[package]] +name = "rust-ini" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "796e8d2b6696392a43bea58116b667fb4c29727dc5abd27d6acf338bb4f688c7" +dependencies = [ + "cfg-if", + "ordered-multimap", +] + [[package]] name = "rustc-demangle" version = "0.1.26" @@ -1547,6 +1761,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ "serde_core", + "serde_derive", +] + +[[package]] +name = "serde-untagged" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9faf48a4a2d2693be24c6289dbe26552776eb7737074e6722891fadbe6c5058" +dependencies = [ + "erased-serde", + "serde", + "serde_core", + "typeid", ] [[package]] @@ -1808,6 +2035,15 @@ dependencies = [ "uuid", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tokio" version = "1.47.1" @@ -1979,18 +2215,36 @@ dependencies = [ "toml", ] +[[package]] +name = "typeid" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" + [[package]] name = "typenum" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + [[package]] name = "unicode-ident" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + [[package]] name = "untrusted" version = "0.9.0" @@ -2334,6 +2588,9 @@ name = "winnow" version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" +dependencies = [ + "memchr", +] [[package]] name = "wit-bindgen" @@ -2341,6 +2598,17 @@ version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" +[[package]] +name = "yaml-rust2" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2462ea039c445496d8793d052e13787f2b90e750b833afee748e601c17621ed9" +dependencies = [ + "arraydeque", + "encoding_rs", + "hashlink", +] + [[package]] name = "zerocopy" version = "0.8.27" diff --git a/akd/Cargo.toml b/akd/Cargo.toml index dc4b744628..77407b0f1b 100644 --- a/akd/Cargo.toml +++ b/akd/Cargo.toml @@ -15,6 +15,9 @@ unwrap_used = "deny" [workspace.dependencies] akd = "0.11.0" +async-trait = "0.1.89" +config = "0.15.18" +serde = { version = "1.0.228", features = ["derive"] } tokio = { version = "1.47.1", features = ["full"] } tracing = { version = "0.1.41" } tracing-subscriber = {version = "0.3.19" } diff --git a/akd/crates/akd_storage/Cargo.toml b/akd/crates/akd_storage/Cargo.toml index 202a6f72e7..dacfd6f56f 100644 --- a/akd/crates/akd_storage/Cargo.toml +++ b/akd/crates/akd_storage/Cargo.toml @@ -8,8 +8,9 @@ keywords.workspace = true [dependencies] akd = "0.11.0" -async-trait = "0.1.89" +async-trait = { workspace = true} ms_database = { path = "../ms_database" } +serde = { workspace = true } thiserror = "2.0.17" tracing.workspace = true diff --git a/akd/crates/akd_storage/src/akd_storage_config.rs b/akd/crates/akd_storage/src/akd_storage_config.rs new file mode 100644 index 0000000000..2c9d217766 --- /dev/null +++ b/akd/crates/akd_storage/src/akd_storage_config.rs @@ -0,0 +1,25 @@ +use serde::Deserialize; + +use crate::db_config::DbConfig; + +#[derive(Debug, Clone, Deserialize)] +pub struct AkdStorageConfig { + db_config: DbConfig, + /// Controls how long items stay in cache before being evicted (in milliseconds). Defaults to 30 seconds. + #[serde(default = "default_cache_item_lifetime_ms")] + cache_item_lifetime_ms: usize, + /// Controls the maximum size of the cache in bytes. Defaults to no limit. + #[serde(default)] + cache_limit_bytes: Option, + /// Controls how often the cache is cleaned (in milliseconds). Defaults to 15 seconds. + #[serde(default = "default_cache_clean_ms")] + cache_clean_ms: usize, +} + +fn default_cache_item_lifetime_ms() -> usize { + 30_000 +} + +fn default_cache_clean_ms() -> usize { + 15_000 +} diff --git a/akd/crates/akd_storage/src/db_config.rs b/akd/crates/akd_storage/src/db_config.rs new file mode 100644 index 0000000000..7311de4528 --- /dev/null +++ b/akd/crates/akd_storage/src/db_config.rs @@ -0,0 +1,31 @@ +use akd::errors::StorageError; +use serde::Deserialize; + +use crate::DatabaseType; + +#[derive(Debug, Clone, Deserialize)] +pub enum DbConfig { + MsSql { + connection_string: String, + pool_size: u32, + }, +} + +impl DbConfig { + pub async fn connect(&self) -> Result { + let db = match self { + DbConfig::MsSql { + connection_string, + pool_size, + } => { + let db = crate::ms_sql::MsSql::builder(connection_string.clone()) + .pool_size(pool_size.clone()) + .build() + .await?; + DatabaseType::MsSql(db) + } + }; + + Ok(db) + } +} diff --git a/akd/crates/akd_storage/src/lib.rs b/akd/crates/akd_storage/src/lib.rs index 6d33dfea5e..b6bc69bdba 100644 --- a/akd/crates/akd_storage/src/lib.rs +++ b/akd/crates/akd_storage/src/lib.rs @@ -1,6 +1,93 @@ +use std::collections::HashMap; + +use akd::{ + errors::StorageError, + storage::{ + types::{DbRecord, KeyData, ValueState, ValueStateRetrievalFlag}, + Database, DbSetState, Storable, + }, + AkdLabel, AkdValue, +}; +use async_trait::async_trait; + +use crate::ms_sql::MsSql; + mod migrations; -mod sql_params; -mod ms_sql_storable; pub mod ms_sql; +mod ms_sql_storable; +mod sql_params; mod tables; mod temp_table; +pub mod akd_storage_config; +pub mod db_config; + +#[derive(Debug, Clone)] +pub enum DatabaseType { + MsSql(MsSql), +} + +#[async_trait] +impl Database for DatabaseType { + async fn set(&self, record: DbRecord) -> Result<(), StorageError> { + match self { + DatabaseType::MsSql(db) => db.set(record).await, + } + } + + async fn batch_set( + &self, + records: Vec, + state: DbSetState, // TODO: unused in mysql example, but may be needed later + ) -> Result<(), StorageError> { + match self { + DatabaseType::MsSql(db) => db.batch_set(records, state).await, + } + } + + async fn get(&self, id: &St::StorageKey) -> Result { + match self { + DatabaseType::MsSql(db) => db.get::(id).await, + } + } + + async fn batch_get( + &self, + ids: &[St::StorageKey], + ) -> Result, StorageError> { + match self { + DatabaseType::MsSql(db) => db.batch_get::(ids).await, + } + } + + // Note: user and username here is the raw_label. The assumption is this is a single key for a single user, but that's + // too restrictive for what we want, so generalize the name a bit. + async fn get_user_data(&self, raw_label: &AkdLabel) -> Result { + match self { + DatabaseType::MsSql(db) => db.get_user_data(raw_label).await, + } + } + + // Note: user and username here is the raw_label. The assumption is this is a single key for a single user, but that's + // too restrictive for what we want, so generalize the name a bit. + async fn get_user_state( + &self, + raw_label: &AkdLabel, + flag: ValueStateRetrievalFlag, + ) -> Result { + match self { + DatabaseType::MsSql(db) => db.get_user_state(raw_label, flag).await, + } + } + + // Note: user and username here is the raw_label. The assumption is this is a single key for a single user, but that's + // too restrictive for what we want, so generalize the name a bit. + async fn get_user_state_versions( + &self, + raw_labels: &[AkdLabel], + flag: ValueStateRetrievalFlag, + ) -> Result, StorageError> { + match self { + DatabaseType::MsSql(db) => db.get_user_state_versions(raw_labels, flag).await, + } + } +} diff --git a/akd/crates/akd_storage/src/ms_sql.rs b/akd/crates/akd_storage/src/ms_sql.rs index 4e8b884b99..d6be230be2 100644 --- a/akd/crates/akd_storage/src/ms_sql.rs +++ b/akd/crates/akd_storage/src/ms_sql.rs @@ -50,7 +50,7 @@ impl MsSqlBuilder { } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct MsSql { pool: Arc, } diff --git a/akd/crates/akd_test_utility/Cargo.toml b/akd/crates/akd_test_utility/Cargo.toml index e7e4eefe69..64e233bfed 100644 --- a/akd/crates/akd_test_utility/Cargo.toml +++ b/akd/crates/akd_test_utility/Cargo.toml @@ -14,7 +14,7 @@ path = "src/main.rs" akd = { workspace = true } akd_storage = { path = "../akd_storage" } anyhow = "1" -async-trait = "0.1" +async-trait = { workspace = true } clap = { version = "4", features = ["derive"] } hex = "0.4" owo-colors = "4" diff --git a/akd/crates/akd_test_utility/src/commands.rs b/akd/crates/akd_test_utility/src/commands.rs index 2747e31000..51b4f3b25a 100644 --- a/akd/crates/akd_test_utility/src/commands.rs +++ b/akd/crates/akd_test_utility/src/commands.rs @@ -5,7 +5,6 @@ pub(crate) enum Command { Help, Exit, Clean, - Info, Directory(DirectoryCommand), InvalidArgs(String), Unknown(String), @@ -25,7 +24,6 @@ impl Command { "exit" | "x" => Command::Exit, "help" | "?" => Command::Help, "clean" => Command::Clean, - "info" => Command::Info, cmd => Command::handle_dir_cmd(cmd, parts, text), } } diff --git a/akd/crates/akd_test_utility/src/main.rs b/akd/crates/akd_test_utility/src/main.rs index 8c312f751a..f9d10c3c4b 100644 --- a/akd/crates/akd_test_utility/src/main.rs +++ b/akd/crates/akd_test_utility/src/main.rs @@ -1,6 +1,8 @@ use akd::ecvrf::HardCodedAkdVRF; use akd::storage::StorageManager; use akd::Directory; +use akd_storage::DatabaseType; +use akd_storage::db_config::DbConfig; use anyhow::{Context, Result}; use clap::{Parser, ValueEnum}; use commands::Command; @@ -149,12 +151,9 @@ async fn main() -> Result<()> { // Create database connection info!("Connecting to MS SQL database"); - let db = akd_storage::ms_sql::MsSql::builder(connection_string) - .pool_size(args.pool_size) - .build() - .await - .context("Failed to create MS SQL database connection")?; - + let config = DbConfig::MsSql { connection_string, pool_size: args.pool_size }; + let db = config.connect().await.context("Failed to connect to database")?; + // Handle pre-processing modes if let Some(()) = pre_process_mode(&args, &db).await? { return Ok(()); @@ -180,22 +179,22 @@ async fn main() -> Result<()> { // Process modes that run before creating the directory async fn pre_process_mode( args: &CliArgs, - db: &akd_storage::ms_sql::MsSql, + db: &DatabaseType, ) -> Result> { - match &args.mode { - Some(Mode::Drop) => { + match (db, &args.mode) { + (DatabaseType::MsSql(db), Some(Mode::Drop)) => { info!("Dropping database tables"); db.drop().await.context("Failed to drop tables")?; info!("Tables dropped successfully"); return Ok(Some(())); } - Some(Mode::Migrate) => { + (DatabaseType::MsSql(db), Some(Mode::Migrate)) => { info!("Running database migrations"); db.migrate().await.context("Failed to run migrations")?; info!("Migrations completed successfully"); return Ok(Some(())); } - Some(Mode::Clean) => { + (DatabaseType::MsSql(db), Some(Mode::Clean)) => { info!("Cleaning database (drop + migrate)"); db.drop().await.context("Failed to drop tables")?; info!("Tables dropped"); @@ -211,7 +210,7 @@ async fn pre_process_mode( async fn process_mode( args: &CliArgs, tx: &Sender, - db: &akd_storage::ms_sql::MsSql, + db: &DatabaseType, ) -> Result<()> { if let Some(mode) = &args.mode { match mode { @@ -250,7 +249,7 @@ async fn process_mode( Ok(()) } -async fn bench_db_insert(num_users: u64, db: &akd_storage::ms_sql::MsSql) -> Result<()> { +async fn bench_db_insert(num_users: u64, db: &DatabaseType) -> Result<()> { use owo_colors::OwoColorize; println!("{}", "======= Benchmark operation requested =======".cyan()); @@ -480,7 +479,7 @@ async fn bench_lookup( async fn repl_loop( args: &CliArgs, tx: &Sender, - db: &akd_storage::ms_sql::MsSql, + db: &DatabaseType, ) -> Result<()> { loop { println!("Please enter a command"); @@ -490,19 +489,19 @@ async fn repl_loop( let mut line = String::new(); stdin().read_line(&mut line)?; - match Command::parse(&mut line) { - Command::Unknown(other) => { + match (db, Command::parse(&mut line)) { + (_, Command::Unknown(other)) => { println!("Input '{}' is not supported, enter 'help' for the help menu", other) } - Command::InvalidArgs(message) => println!("Invalid arguments: {}", message), - Command::Exit => { + (_,Command::InvalidArgs(message)) => println!("Invalid arguments: {}", message), + (_, Command::Exit) => { info!("Exiting..."); break; } - Command::Help => { + (_, Command::Help) => { Command::print_help_menu(); } - Command::Clean => { + (DatabaseType::MsSql(db), Command::Clean) => { println!("Cleaning the database (drop + migrate)..."); match db.drop().await { Ok(_) => { @@ -521,14 +520,10 @@ async fn repl_loop( } } } - Command::Info => { - use owo_colors::OwoColorize; - println!("{}", "===== Auditable Key Directory Information =====".cyan()); - println!(" Connected to MS SQL database"); - println!(" Connection pool size: {}", args.pool_size); - println!(); + (_, Command::Clean) => { + println!("Clean command is only supported for MS SQL databases"); } - Command::Directory(cmd) => { + (_, Command::Directory(cmd)) => { let (rpc_tx, rpc_rx) = tokio::sync::oneshot::channel(); let rpc = directory_host::Rpc(cmd, Some(rpc_tx)); diff --git a/akd/crates/common/Cargo.toml b/akd/crates/common/Cargo.toml new file mode 100644 index 0000000000..739a0da0a7 --- /dev/null +++ b/akd/crates/common/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "common" +edition.workspace = true +version.workspace = true +authors.workspace = true +license-file.workspace = true +keywords.workspace = true + +[dependencies] +akd = "0.11.0" +async-trait = { workspace = true } +akd_storage = { path = "../akd_storage" } +config = { workspace = true } +serde = { workspace = true } +thiserror = "2.0.17" +tracing.workspace = true + +[lints] +workspace = true diff --git a/akd/crates/common/src/lib.rs b/akd/crates/common/src/lib.rs new file mode 100644 index 0000000000..1cf48c4fa8 --- /dev/null +++ b/akd/crates/common/src/lib.rs @@ -0,0 +1,3 @@ +mod vrf_type; + +pub use vrf_type::VrfStorageType; diff --git a/akd/crates/common/src/vrf_type.rs b/akd/crates/common/src/vrf_type.rs new file mode 100644 index 0000000000..75d18c61e1 --- /dev/null +++ b/akd/crates/common/src/vrf_type.rs @@ -0,0 +1,34 @@ +use akd::ecvrf::{HardCodedAkdVRF, VRFKeyStorage, VrfError}; +use async_trait::async_trait; +use serde::{Deserialize}; + +#[derive(Debug, Clone, Deserialize)] +pub enum VrfConfig { + HardCodedAkdVRF, +} + +impl From<&VrfConfig> for VrfStorageType { + fn from(config: &VrfConfig) -> Self { + match config { + VrfConfig::HardCodedAkdVRF => VrfStorageType::HardCodedAkdVRF, + } + } +} + +#[derive(Debug, Clone)] +pub enum VrfStorageType { + /// **WARNING**: Do not use this in production systems. This is only for testing and debugging. + /// This is a version of VRFKeyStorage for testing purposes, which uses the example from the VRF crate. + /// + /// const KEY_MATERIAL: &str = "c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721"; + HardCodedAkdVRF, +} + +#[async_trait] +impl VRFKeyStorage for VrfStorageType { + async fn retrieve(&self) -> Result, VrfError> { + match self { + VrfStorageType::HardCodedAkdVRF => HardCodedAkdVRF.retrieve().await, + } + } +} diff --git a/akd/crates/ms_database/Cargo.toml b/akd/crates/ms_database/Cargo.toml index 559866c5e4..ae6ae609d8 100644 --- a/akd/crates/ms_database/Cargo.toml +++ b/akd/crates/ms_database/Cargo.toml @@ -7,7 +7,7 @@ license-file.workspace = true keywords.workspace = true [dependencies] -async-trait = "0.1.89" +async-trait = {workspace = true } bb8 = "0.9.0" macros = { path = "../macros" } thiserror = "2.0.17"