Skip to content

Commit

Permalink
fix(store): rendezvous store_data stored item
Browse files Browse the repository at this point in the history
Signed-off-by: Irene Diez <[email protected]>
  • Loading branch information
7flying committed Nov 14, 2023
1 parent 8caa682 commit 1dec4cc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions store/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use async_trait::async_trait;
use fdo_data_formats::ownershipvoucher::OwnershipVoucher;
use fdo_data_formats::StoredItem;
use fdo_db::*;
use std::marker::PhantomData;

Expand Down Expand Up @@ -457,17 +458,18 @@ where
Err(StoreError::MethodNotAvailable)
}

async fn store_data(&self, _key: K, value: V) -> Result<(), StoreError> {
async fn store_data(&self, key: K, value: V) -> Result<(), StoreError> {
let pool = fdo_db::sqlite::SqliteRendezvousDB::get_conn_pool();
let conn = &mut pool.get().expect("Couldn't establish a connection");
let raw = V::serialize_data(&value).expect("Error serializing data");
let ov = OwnershipVoucher::from_pem_or_raw(&raw).expect("Error converting OV");
fdo_db::sqlite::SqliteRendezvousDB::insert_ov(&ov, None, conn).map_err(|e| {
StoreError::Database(format!(
"Error inserting OV with guid {}: {e:?}",
ov.header().guid().to_string()
))
})
let stored = StoredItem::deserialize_data(&raw).expect("Error converting StoredItem");
fdo_db::sqlite::SqliteRendezvousDB::insert_ov(&stored, &key.to_string(), None, conn)
.map_err(|e| {
StoreError::Database(format!(
"Error inserting StoredItem with guid {}: {e:?}",
&key.to_string()
))
})
}

async fn destroy_data(&self, key: &K) -> Result<(), StoreError> {
Expand Down

0 comments on commit 1dec4cc

Please sign in to comment.