Skip to content

Commit

Permalink
Merge pull request fdo-rs#671 from runcom/store-agnostic-ovs
Browse files Browse the repository at this point in the history
chore(store): make the store OVs agnostic
  • Loading branch information
runcom authored Sep 18, 2024
2 parents dac66e8 + 85ce5c7 commit 95af64f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 42 deletions.
5 changes: 2 additions & 3 deletions store/src/directory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use fdo_data_formats::ownershipvoucher::OwnershipVoucher;
use std::collections::HashSet;
use std::convert::TryInto;
use std::fs::{self, File};
Expand Down Expand Up @@ -298,15 +297,15 @@ where
}))
}

async fn query_ovs_db(&self) -> Result<Vec<OwnershipVoucher>, StoreError> {
async fn query_ovs_db(&self) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db_to2_performed_to0_less_than(
&self,
_to2: bool,
_to0_max: i64,
) -> Result<Vec<OwnershipVoucher>, StoreError> {
) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

Expand Down
10 changes: 3 additions & 7 deletions store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::pin::Pin;
use serde::{Deserialize, Serialize};
use thiserror::Error;

use fdo_data_formats::{ownershipvoucher::OwnershipVoucher, Serializable};
use fdo_data_formats::Serializable;

#[derive(Debug, Error)]
pub enum StoreError {
Expand Down Expand Up @@ -190,9 +190,7 @@ pub trait Store<OT: StoreOpenMode, K, V, MKT: MetadataLocalKey>: Send + Sync {

fn query_ovs_db<'life0, 'async_trait>(
&'life0 self,
) -> Pin<
Box<dyn Future<Output = Result<Vec<OwnershipVoucher>, StoreError>> + 'async_trait + Send>,
>
) -> Pin<Box<dyn Future<Output = Result<Vec<V>, StoreError>> + 'async_trait + Send>>
where
'life0: 'async_trait,
Self: 'async_trait;
Expand All @@ -201,9 +199,7 @@ pub trait Store<OT: StoreOpenMode, K, V, MKT: MetadataLocalKey>: Send + Sync {
&'life0 self,
to2: bool,
to0_max: i64,
) -> Pin<
Box<dyn Future<Output = Result<Vec<OwnershipVoucher>, StoreError>> + 'async_trait + Send>,
>
) -> Pin<Box<dyn Future<Output = Result<Vec<V>, StoreError>> + 'async_trait + Send>>
where
'life0: 'async_trait,
Self: 'async_trait;
Expand Down
28 changes: 12 additions & 16 deletions store/src/pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ where
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db(&self) -> Result<Vec<OwnershipVoucher>, StoreError> {
async fn query_ovs_db(&self) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db_to2_performed_to0_less_than(
&self,
_to2: bool,
_to0_max: i64,
) -> Result<Vec<OwnershipVoucher>, StoreError> {
) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

Expand Down Expand Up @@ -332,7 +332,7 @@ where
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db(&self) -> Result<Vec<OwnershipVoucher>, StoreError> {
async fn query_ovs_db(&self) -> Result<Vec<V>, StoreError> {
let mut ret = vec![];
let conn = &mut self
.connection_pool
Expand All @@ -350,11 +350,9 @@ where
))
})?;
for db_ov in db_ovs {
ret.push(
OwnershipVoucher::from_pem_or_raw(&db_ov.contents).map_err(|e| {
StoreError::Unspecified(format!("Error parsing OV contents from DB: {e:?}"))
})?,
);
ret.push(V::deserialize_data(&db_ov.contents).map_err(|e| {
StoreError::Unspecified(format!("Error deserializing value: {e:?}"))
})?);
}
Ok(ret)
}
Expand All @@ -363,7 +361,7 @@ where
&self,
to2: bool,
to0_max: i64,
) -> Result<Vec<OwnershipVoucher>, StoreError> {
) -> Result<Vec<V>, StoreError> {
let mut ret = vec![];
let conn = &mut self
.connection_pool
Expand All @@ -379,11 +377,9 @@ where
))
})?;
for db_ov in db_ovs {
ret.push(
OwnershipVoucher::from_pem_or_raw(&db_ov.contents).map_err(|e| {
StoreError::Unspecified(format!("Error parsing OV contents from DB: {e:?}"))
})?,
);
ret.push(V::deserialize_data(&db_ov.contents).map_err(|e| {
StoreError::Unspecified(format!("Error deserializing value: {e:?}"))
})?);
}
Ok(ret)
}
Expand Down Expand Up @@ -529,15 +525,15 @@ where
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db(&self) -> Result<Vec<OwnershipVoucher>, StoreError> {
async fn query_ovs_db(&self) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db_to2_performed_to0_less_than(
&self,
_to2: bool,
_to0_max: i64,
) -> Result<Vec<OwnershipVoucher>, StoreError> {
) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

Expand Down
28 changes: 12 additions & 16 deletions store/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ where
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db(&self) -> Result<Vec<OwnershipVoucher>, StoreError> {
async fn query_ovs_db(&self) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db_to2_performed_to0_less_than(
&self,
_to2: bool,
_to0_max: i64,
) -> Result<Vec<OwnershipVoucher>, StoreError> {
) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

Expand Down Expand Up @@ -331,7 +331,7 @@ where
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db(&self) -> Result<Vec<OwnershipVoucher>, StoreError> {
async fn query_ovs_db(&self) -> Result<Vec<V>, StoreError> {
let mut ret = vec![];
let conn = &mut self
.connection_pool
Expand All @@ -348,11 +348,9 @@ where
))
})?;
for db_ov in db_ovs {
ret.push(
OwnershipVoucher::from_pem_or_raw(&db_ov.contents).map_err(|e| {
StoreError::Unspecified(format!("Error parsing OV contents from DB: {e:?}"))
})?,
);
ret.push(V::deserialize_data(&db_ov.contents).map_err(|e| {
StoreError::Unspecified(format!("Error deserializing value: {e:?}"))
})?);
}
Ok(ret)
}
Expand All @@ -361,7 +359,7 @@ where
&self,
to2: bool,
to0_max: i64,
) -> Result<Vec<OwnershipVoucher>, StoreError> {
) -> Result<Vec<V>, StoreError> {
let mut ret = vec![];
let conn = &mut self
.connection_pool
Expand All @@ -376,11 +374,9 @@ where
))
})?;
for db_ov in db_ovs {
ret.push(
OwnershipVoucher::from_pem_or_raw(&db_ov.contents).map_err(|e| {
StoreError::Unspecified(format!("Error parsing OV contents from DB: {e:?}"))
})?,
);
ret.push(V::deserialize_data(&db_ov.contents).map_err(|e| {
StoreError::Unspecified(format!("Error deserializing value: {e:?}"))
})?);
}
Ok(ret)
}
Expand Down Expand Up @@ -526,15 +522,15 @@ where
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db(&self) -> Result<Vec<OwnershipVoucher>, StoreError> {
async fn query_ovs_db(&self) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

async fn query_ovs_db_to2_performed_to0_less_than(
&self,
_to2: bool,
_to0_max: i64,
) -> Result<Vec<OwnershipVoucher>, StoreError> {
) -> Result<Vec<V>, StoreError> {
Err(StoreError::MethodNotAvailable)
}

Expand Down

0 comments on commit 95af64f

Please sign in to comment.