diff --git a/src/encrypted_table/mod.rs b/src/encrypted_table/mod.rs index 25fc4222..1489fe11 100644 --- a/src/encrypted_table/mod.rs +++ b/src/encrypted_table/mod.rs @@ -23,7 +23,7 @@ use cipherstash_client::{ }, credentials::{auto_refresh::AutoRefresh, service_credentials::ServiceCredentials}, encryption::ScopedCipher, - zerokms::{ZeroKMS, ZeroKMSWithClientKey}, + zerokms::{ClientKey, ZeroKMS, ZeroKMSWithClientKey}, }; use log::info; use std::{ @@ -67,8 +67,6 @@ impl EncryptedTable { impl EncryptedTable { pub async fn init_headless() -> Result { - info!("Initializing..."); - let console_config = ConsoleConfig::builder().with_env().build()?; let cts_config = CtsConfig::builder().with_env().build()?; @@ -80,6 +78,14 @@ impl EncryptedTable { .cts_config(&cts_config) .build_with_client_key()?; + Self::init_headless_with_zerokms_config(zerokms_config).await + } + + pub async fn init_headless_with_zerokms_config( + zerokms_config: ZeroKMSConfig, + ) -> Result { + info!("Initializing..."); + let cipher = ZeroKMS::new_with_client_key( &zerokms_config.base_url(), AutoRefresh::new(zerokms_config.credentials()), @@ -413,6 +419,22 @@ impl EncryptedTable { }) } + pub async fn init_with_zerokms_config( + zerokms_config: ZeroKMSConfig, + db: aws_sdk_dynamodb::Client, + table_name: impl Into, + ) -> Result { + let table = EncryptedTable::init_headless_with_zerokms_config(zerokms_config).await?; + + Ok(Self { + db: Dynamo { + table_name: table_name.into(), + db, + }, + cipher: table.cipher, + }) + } + /// Get a record from the table by primary key from the default dataset. pub async fn get(&self, k: impl Into) -> Result, GetError> where