Skip to content
Merged
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
28 changes: 25 additions & 3 deletions src/encrypted_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -67,8 +67,6 @@ impl<D> EncryptedTable<D> {

impl EncryptedTable<Headless> {
pub async fn init_headless() -> Result<Self, InitError> {
info!("Initializing...");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this was removed?


let console_config = ConsoleConfig::builder().with_env().build()?;

let cts_config = CtsConfig::builder().with_env().build()?;
Expand All @@ -80,6 +78,14 @@ impl EncryptedTable<Headless> {
.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<ClientKey>,
) -> Result<Self, InitError> {
info!("Initializing...");

let cipher = ZeroKMS::new_with_client_key(
&zerokms_config.base_url(),
AutoRefresh::new(zerokms_config.credentials()),
Expand Down Expand Up @@ -413,6 +419,22 @@ impl EncryptedTable<Dynamo> {
})
}

pub async fn init_with_zerokms_config(
zerokms_config: ZeroKMSConfig<ClientKey>,
db: aws_sdk_dynamodb::Client,
table_name: impl Into<String>,
) -> Result<Self, InitError> {
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<T>(&self, k: impl Into<T::PrimaryKey>) -> Result<Option<T>, GetError>
where
Expand Down
Loading