bffh/src/api/machine.rs

116 lines
2.8 KiB
Rust
Raw Normal View History

2020-11-20 13:06:55 +01:00
use std::sync::Arc;
2020-11-17 14:15:29 +01:00
use capnp::capability::Promise;
use capnp::Error;
use futures::FutureExt;
2021-09-18 17:01:35 +02:00
use crate::db::access::{PrivilegesBuf, PermRule};
use crate::db::machine::Status;
use crate::machine::Machine as NwMachine;
2021-09-09 21:50:11 +02:00
use crate::schema::machine_capnp::machine::*;
2020-11-17 14:15:29 +01:00
2021-09-18 17:01:35 +02:00
#[derive(Clone, Copy)]
pub struct Perms {
pub disclose: bool,
pub read: bool,
pub write: bool,
pub manage: bool,
2020-11-20 13:06:55 +01:00
}
2020-11-17 14:15:29 +01:00
2021-09-18 17:01:35 +02:00
impl Perms {
pub fn get_for<'a, I: Iterator<Item=&'a PermRule>>(privs: &'a PrivilegesBuf, rules: I) -> Self {
let mut disclose = false;
let mut read = false;
let mut write = false;
let mut manage = false;
for rule in rules {
if rule.match_perm(&privs.disclose) {
disclose = true;
}
if rule.match_perm(&privs.read) {
read = true;
}
if rule.match_perm(&privs.write) {
write = true;
}
if rule.match_perm(&privs.manage) {
manage = true;
}
}
2020-11-20 15:43:03 +01:00
2021-09-18 17:01:35 +02:00
Self { disclose, read, write, manage }
2020-11-20 15:43:03 +01:00
}
2020-11-17 14:28:04 +01:00
}
2021-09-18 17:01:35 +02:00
pub struct Machine {
perms: Perms,
machine: NwMachine,
}
2020-11-17 14:28:04 +01:00
2021-09-18 17:01:35 +02:00
impl Machine {
pub fn new(perms: Perms, machine: NwMachine) -> Self {
Self { perms, machine }
}
2020-11-17 14:15:29 +01:00
}
2021-09-18 17:01:35 +02:00
impl info::Server for Machine {
fn get_machine_info_extended(
&mut self,
_: info::GetMachineInfoExtendedParams,
_results: info::GetMachineInfoExtendedResults,
) -> capnp::capability::Promise<(), capnp::Error> {
/*if self.perms.manage {
let mut builder = results.get();
let mut extinfo = builder.init_machine_info_extended();
let mut current = extinfo.init_current_user();
// FIXME fill user
}
Promise::ok(())*/
Promise::err(capnp::Error::unimplemented("Extended Infos are unavailable".to_string()))
2021-01-20 11:55:15 +00:00
}
2021-09-18 17:01:35 +02:00
fn get_reservation_list(
&mut self,
_: info::GetReservationListParams,
mut results: info::GetReservationListResults,
) -> capnp::capability::Promise<(), capnp::Error> {
Promise::err(capnp::Error::unimplemented("Reservations are unavailable".to_string()))
2020-11-17 14:15:29 +01:00
}
2021-09-18 17:01:35 +02:00
fn get_property_list(
&mut self,
_: info::GetPropertyListParams,
mut results: info::GetPropertyListResults,
) -> capnp::capability::Promise<(), capnp::Error> {
Promise::err(capnp::Error::unimplemented("Extended Properties are unavailable".to_string()))
}
2021-09-09 21:50:11 +02:00
}
2021-09-18 17:01:35 +02:00
impl use_::Server for Machine {
fn use_(
&mut self,
_: use_::UseParams,
_: use_::UseResults
) -> capnp::capability::Promise<(), capnp::Error> {
Promise::ok(())
}
2020-11-17 14:15:29 +01:00
}
2021-09-18 17:01:35 +02:00
impl in_use::Server for Machine {
}
2020-11-17 14:28:04 +01:00
2021-09-18 17:01:35 +02:00
impl transfer::Server for Machine {
2020-11-17 14:15:29 +01:00
}
2021-09-18 17:01:35 +02:00
impl check::Server for Machine {
}
2020-11-17 14:28:04 +01:00
2021-09-18 17:01:35 +02:00
impl manage::Server for Machine {
}
2020-11-17 14:15:29 +01:00
2021-09-18 17:01:35 +02:00
impl admin::Server for Machine {
2020-11-17 14:15:29 +01:00
}