clippy fix

This commit is contained in:
Noor 2025-04-28 18:49:24 +05:30
parent 5cd8317f91
commit 8536c85fd5
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
3 changed files with 22 additions and 34 deletions

@ -12,9 +12,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
init(DB_ADDRESS, DB_NS, DB_NAME).await?; init(DB_ADDRESS, DB_NS, DB_NAME).await?;
let result = db::migration0(&old_brain_data).await?; db::migration0(&old_brain_data).await?;
println!("{result:?}");
Ok(()) Ok(())
} }

@ -315,13 +315,8 @@ impl NewVmResp {
if let Some(new_vm_req_notif) = new_vm_req_notif { if let Some(new_vm_req_notif) = new_vm_req_notif {
match new_vm_req_notif { match new_vm_req_notif {
Ok(new_vm_req_notif) => { Ok(new_vm_req_notif) => {
match new_vm_req_notif.action { if new_vm_req_notif.action == surrealdb::Action::Update && !new_vm_req_notif.data.error.is_empty() {
surrealdb::Action::Update => { return Ok(Self::Error(vm_id.to_string(), new_vm_req_notif.data.error));
if !new_vm_req_notif.data.error.is_empty() {
return Ok(Self::Error(vm_id.to_string(), new_vm_req_notif.data.error));
}
},
_ => {}
}; };
}, },
Err(e) => return Err(e.into()), Err(e) => return Err(e.into()),
@ -332,11 +327,8 @@ impl NewVmResp {
if let Some(args_notif) = args_notif { if let Some(args_notif) = args_notif {
match args_notif { match args_notif {
Ok(args_notif) => { Ok(args_notif) => {
match args_notif.action { if args_notif.action == surrealdb::Action::Create {
surrealdb::Action::Create => { return Ok(Self::Args(vm_id.to_string(), args_notif.data));
return Ok(Self::Args(vm_id.to_string(), args_notif.data));
},
_ => {}
}; };
}, },
Err(e) => return Err(e.into()), Err(e) => return Err(e.into()),
@ -469,10 +461,11 @@ pub async fn listen_for_node<
let mut live_stream = resp.stream::<Notification<T>>(0)?; let mut live_stream = resp.stream::<Notification<T>>(0)?;
while let Some(result) = live_stream.next().await { while let Some(result) = live_stream.next().await {
match result { match result {
Ok(notification) => match notification.action { Ok(notification) => {
surrealdb::Action::Create => tx.send(notification.data.into()).await?, if notification.action == surrealdb::Action::Create {
_ => {} tx.send(notification.data.into()).await?
}, }
}
Err(e) => { Err(e) => {
log::warn!("listen_for_deletion DB stream failed for {node}: {e}"); log::warn!("listen_for_deletion DB stream failed for {node}: {e}");
return Err(Error::from(e)); return Err(Error::from(e));
@ -782,12 +775,13 @@ pub struct Operator {
impl Operator { impl Operator {
pub async fn list() -> Result<Vec<Self>, Error> { pub async fn list() -> Result<Vec<Self>, Error> {
let mut result = DB let mut result = DB
.query(format!( .query(
"array::distinct(array::flatten( [ "array::distinct(array::flatten( [
(select operator from vm_node group by operator).operator, (select operator from vm_node group by operator).operator,
(select operator from app_node group by operator).operator (select operator from app_node group by operator).operator
]));" ]));"
)) .to_string(),
)
.await?; .await?;
let operator_accounts: Vec<RecordId> = result.take(0)?; let operator_accounts: Vec<RecordId> = result.take(0)?;
let mut operators: Vec<Self> = Vec::new(); let mut operators: Vec<Self> = Vec::new();
@ -875,7 +869,7 @@ impl From<&old_brain::BrainData> for Vec<ActiveVm> {
for old_c in old_data.vm_contracts.iter() { for old_c in old_data.vm_contracts.iter() {
let mut mapped_ports = Vec::new(); let mut mapped_ports = Vec::new();
for port in old_c.exposed_ports.iter() { for port in old_c.exposed_ports.iter() {
mapped_ports.push((*port, 8080 as u32)); mapped_ports.push((*port, 8080u32));
} }
contracts.push(ActiveVm { contracts.push(ActiveVm {
id: RecordId::from((ACTIVE_VM, old_c.uuid.replace("-", ""))), id: RecordId::from((ACTIVE_VM, old_c.uuid.replace("-", ""))),

@ -375,7 +375,7 @@ impl BrainVmDaemon for BrainVmDaemonForReal {
} }
} }
} }
Some(vm_daemon_message::Msg::UpdateVmResp(update_vm_resp)) => { Some(vm_daemon_message::Msg::UpdateVmResp(_update_vm_resp)) => {
todo!(); todo!();
// self.data.submit_updatevm_resp(update_vm_resp).await; // self.data.submit_updatevm_resp(update_vm_resp).await;
} }
@ -641,18 +641,14 @@ impl BrainVmCli for BrainVmCliForReal {
if !req.uuid.is_empty() { if !req.uuid.is_empty() {
if let Some(specific_contract) = db::ActiveVmWithNode::get_by_uuid(&req.uuid).await? { if let Some(specific_contract) = db::ActiveVmWithNode::get_by_uuid(&req.uuid).await? {
if specific_contract.admin.key().to_string() == req.wallet { if specific_contract.admin.key().to_string() == req.wallet {
contracts.push(specific_contract.into()); contracts.push(specific_contract);
} }
// TODO: allow operator to inspect contracts // TODO: allow operator to inspect contracts
} }
} else if req.as_operator {
contracts.append(&mut db::ActiveVmWithNode::list_by_operator(&req.wallet).await?);
} else { } else {
if req.as_operator { contracts.append(&mut db::ActiveVmWithNode::list_by_admin(&req.wallet).await?);
contracts
.append(&mut db::ActiveVmWithNode::list_by_operator(&req.wallet).await?.into());
} else {
contracts
.append(&mut db::ActiveVmWithNode::list_by_admin(&req.wallet).await?.into());
}
} }
let (tx, rx) = mpsc::channel(6); let (tx, rx) = mpsc::channel(6);
tokio::spawn(async move { tokio::spawn(async move {
@ -754,7 +750,7 @@ fn check_sig_from_req<T: std::fmt::Debug + PubkeyGetter>(req: Request<T>) -> Res
let parsed_time = chrono::DateTime::parse_from_rfc3339(time) let parsed_time = chrono::DateTime::parse_from_rfc3339(time)
.map_err(|_| Status::unauthenticated("Coult not parse timestamp"))?; .map_err(|_| Status::unauthenticated("Coult not parse timestamp"))?;
let seconds_elapsed = now.signed_duration_since(parsed_time).num_seconds(); let seconds_elapsed = now.signed_duration_since(parsed_time).num_seconds();
if seconds_elapsed > 4 || seconds_elapsed < -4 { if !(-4..=4).contains(&seconds_elapsed) {
return Err(Status::unauthenticated(format!( return Err(Status::unauthenticated(format!(
"Date is not within 4 sec of the time of the server: CLI {} vs Server {}", "Date is not within 4 sec of the time of the server: CLI {} vs Server {}",
parsed_time, now parsed_time, now
@ -795,7 +791,7 @@ fn check_sig_from_req<T: std::fmt::Debug + PubkeyGetter>(req: Request<T>) -> Res
.verify(message.as_bytes(), &signature) .verify(message.as_bytes(), &signature)
.map_err(|_| Status::unauthenticated("the signature is not valid"))?; .map_err(|_| Status::unauthenticated("the signature is not valid"))?;
if let Some(req_pubkey) = req.get_pubkey() { if let Some(req_pubkey) = req.get_pubkey() {
if pubkey_value.to_str().unwrap().to_string() != req_pubkey { if *pubkey_value.to_str().unwrap() != req_pubkey {
return Err(Status::unauthenticated( return Err(Status::unauthenticated(
"pubkey of signature does not match pubkey of request", "pubkey of signature does not match pubkey of request",
)); ));
@ -809,7 +805,7 @@ fn check_sig_from_parts(pubkey: &str, time: &str, msg: &str, sig: &str) -> Resul
let parsed_time = chrono::DateTime::parse_from_rfc3339(time) let parsed_time = chrono::DateTime::parse_from_rfc3339(time)
.map_err(|_| Status::unauthenticated("Coult not parse timestamp"))?; .map_err(|_| Status::unauthenticated("Coult not parse timestamp"))?;
let seconds_elapsed = now.signed_duration_since(parsed_time).num_seconds(); let seconds_elapsed = now.signed_duration_since(parsed_time).num_seconds();
if seconds_elapsed > 4 || seconds_elapsed < -4 { if !(-4..=4).contains(&seconds_elapsed) {
return Err(Status::unauthenticated(format!( return Err(Status::unauthenticated(format!(
"Date is not within 4 sec of the time of the server: CLI {} vs Server {}", "Date is not within 4 sec of the time of the server: CLI {} vs Server {}",
parsed_time, now parsed_time, now