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?;
let result = db::migration0(&old_brain_data).await?;
println!("{result:?}");
db::migration0(&old_brain_data).await?;
Ok(())
}

@ -315,13 +315,8 @@ impl NewVmResp {
if let Some(new_vm_req_notif) = new_vm_req_notif {
match new_vm_req_notif {
Ok(new_vm_req_notif) => {
match new_vm_req_notif.action {
surrealdb::Action::Update => {
if !new_vm_req_notif.data.error.is_empty() {
return Ok(Self::Error(vm_id.to_string(), new_vm_req_notif.data.error));
}
},
_ => {}
if new_vm_req_notif.action == surrealdb::Action::Update && !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()),
@ -332,11 +327,8 @@ impl NewVmResp {
if let Some(args_notif) = args_notif {
match args_notif {
Ok(args_notif) => {
match args_notif.action {
surrealdb::Action::Create => {
return Ok(Self::Args(vm_id.to_string(), args_notif.data));
},
_ => {}
if args_notif.action == surrealdb::Action::Create {
return Ok(Self::Args(vm_id.to_string(), args_notif.data));
};
},
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)?;
while let Some(result) = live_stream.next().await {
match result {
Ok(notification) => match notification.action {
surrealdb::Action::Create => tx.send(notification.data.into()).await?,
_ => {}
},
Ok(notification) => {
if notification.action == surrealdb::Action::Create {
tx.send(notification.data.into()).await?
}
}
Err(e) => {
log::warn!("listen_for_deletion DB stream failed for {node}: {e}");
return Err(Error::from(e));
@ -782,12 +775,13 @@ pub struct Operator {
impl Operator {
pub async fn list() -> Result<Vec<Self>, Error> {
let mut result = DB
.query(format!(
.query(
"array::distinct(array::flatten( [
(select operator from vm_node group by operator).operator,
(select operator from app_node group by operator).operator
]));"
))
.to_string(),
)
.await?;
let operator_accounts: Vec<RecordId> = result.take(0)?;
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() {
let mut mapped_ports = Vec::new();
for port in old_c.exposed_ports.iter() {
mapped_ports.push((*port, 8080 as u32));
mapped_ports.push((*port, 8080u32));
}
contracts.push(ActiveVm {
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!();
// self.data.submit_updatevm_resp(update_vm_resp).await;
}
@ -641,18 +641,14 @@ impl BrainVmCli for BrainVmCliForReal {
if !req.uuid.is_empty() {
if let Some(specific_contract) = db::ActiveVmWithNode::get_by_uuid(&req.uuid).await? {
if specific_contract.admin.key().to_string() == req.wallet {
contracts.push(specific_contract.into());
contracts.push(specific_contract);
}
// TODO: allow operator to inspect contracts
}
} else if req.as_operator {
contracts.append(&mut db::ActiveVmWithNode::list_by_operator(&req.wallet).await?);
} else {
if req.as_operator {
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());
}
contracts.append(&mut db::ActiveVmWithNode::list_by_admin(&req.wallet).await?);
}
let (tx, rx) = mpsc::channel(6);
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)
.map_err(|_| Status::unauthenticated("Coult not parse timestamp"))?;
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!(
"Date is not within 4 sec of the time of the server: CLI {} vs Server {}",
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)
.map_err(|_| Status::unauthenticated("the signature is not valid"))?;
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(
"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)
.map_err(|_| Status::unauthenticated("Coult not parse timestamp"))?;
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!(
"Date is not within 4 sec of the time of the server: CLI {} vs Server {}",
parsed_time, now