refactor db imports

usage of MeasurementArgs and VmNodeFilters from vm_proto
This commit is contained in:
Noor 2025-05-08 14:08:57 +05:30
parent 069bb27192
commit 771e68a4b6
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
2 changed files with 9 additions and 8 deletions

@ -31,7 +31,6 @@ pub mod prelude {
pub use super::general::*;
pub use super::vm::*;
pub use super::*;
pub use detee_shared::snp::pb::vm_proto::{MeasurementArgs, VmNodeFilters};
}
pub async fn db_connection(

@ -5,8 +5,9 @@ use super::Error;
use crate::constants::{
ACCOUNT, ACTIVE_VM, DELETED_VM, NEW_VM_REQ, UPDATE_VM_REQ, VM_NODE, VM_UPDATE_EVENT,
};
use crate::db::{Account, MeasurementArgs, Report, VmNodeFilters};
use crate::db::{Account, Report};
use crate::old_brain;
use detee_shared::vm_proto;
use serde::{Deserialize, Serialize};
use surrealdb::engine::remote::ws::Client;
use surrealdb::sql::Datetime;
@ -83,7 +84,7 @@ impl VmNodeWithReports {
// https://en.wikipedia.org/wiki/Dependency_inversion_principle
pub async fn find_by_filters(
db: &Surreal<Client>,
filters: VmNodeFilters,
filters: vm_proto::VmNodeFilters,
) -> Result<Vec<Self>, Error> {
let mut query = format!(
"select *, <-report.* as reports from {VM_NODE} where
@ -197,7 +198,7 @@ impl NewVmReq {
/// first string is the vm_id
pub enum WrappedMeasurement {
Args(String, MeasurementArgs),
Args(String, vm_proto::MeasurementArgs),
Error(String, String),
}
@ -224,9 +225,10 @@ impl WrappedMeasurement {
))
.await?;
let mut error_stream = resp.stream::<Notification<ErrorMessage>>(0)?;
let mut args_stream = resp.stream::<Notification<MeasurementArgs>>(1)?;
let mut args_stream = resp.stream::<Notification<vm_proto::MeasurementArgs>>(1)?;
let args: Option<MeasurementArgs> = db.delete(("measurement_args", vm_id)).await?;
let args: Option<vm_proto::MeasurementArgs> =
db.delete(("measurement_args", vm_id)).await?;
if let Some(args) = args {
return Ok(Self::Args(vm_id.to_string(), args));
}
@ -255,7 +257,7 @@ impl WrappedMeasurement {
match args_notif {
Ok(args_notif) => {
if args_notif.action == surrealdb::Action::Create {
let _: Option<MeasurementArgs> = db.delete(("measurement_args", vm_id)).await?;
let _: Option<vm_proto::MeasurementArgs> = db.delete(("measurement_args", vm_id)).await?;
return Ok(Self::Args(vm_id.to_string(), args_notif.data));
};
},
@ -318,7 +320,7 @@ impl ActiveVm {
pub async fn activate(
db: &Surreal<Client>,
id: &str,
args: MeasurementArgs,
args: vm_proto::MeasurementArgs,
) -> Result<(), Error> {
let new_vm_req = match NewVmReq::get(db, id).await? {
Some(r) => r,