prodable machines

This commit is contained in:
Nadja Reitzenstein 2023-02-14 16:58:23 +01:00
parent 198845f176
commit d196050fe0
4 changed files with 38 additions and 4 deletions

@ -1 +1 @@
Subproject commit 19f20f5154f0eced6288ff56cac840025ee51da1 Subproject commit cde4677575f8e133ac764663e131c80fc891d545

View File

@ -6,10 +6,12 @@ use api::general_capnp::optional;
use api::machine_capnp::machine::{ use api::machine_capnp::machine::{
self, admin, admin::Server as AdminServer, check, check::Server as CheckServer, self, admin, admin::Server as AdminServer, check, check::Server as CheckServer,
in_use as inuse, in_use::Server as InUseServer, info, info::Server as InfoServer, manage, in_use as inuse, in_use::Server as InUseServer, info, info::Server as InfoServer, manage,
manage::Server as ManageServer, use_, use_::Server as UseServer, MachineState, manage::Server as ManageServer, use_, use_::Server as UseServer, MachineState, prodable::Server as ProdableServer,
}; };
use capnp::capability::Promise; use capnp::capability::Promise;
use capnp::Error;
use capnp_rpc::pry; use capnp_rpc::pry;
use api::machine_capnp::machine::prodable::{ProdWithDataParams, ProdWithDataResults};
#[derive(Clone)] #[derive(Clone)]
pub struct Machine { pub struct Machine {
@ -67,6 +69,9 @@ impl Machine {
ArchivedStatus::InUse(owner) => { ArchivedStatus::InUse(owner) => {
if owner == &user { if owner == &user {
builder.set_inuse(capnp_rpc::new_client(self.clone())); builder.set_inuse(capnp_rpc::new_client(self.clone()));
if self.resource.get_description().prodable {
builder.set_prodable(capnp_rpc::new_client(self.clone()));
}
} }
MachineState::InUse MachineState::InUse
} }
@ -182,6 +187,14 @@ impl InUseServer for Machine {
} }
} }
impl ProdableServer for Machine {
fn prod_with_data(&mut self, mut params: ProdWithDataParams, _: ProdWithDataResults) -> Promise<(), Error> {
let data: Vec<u8> = pry!(pry!(params.get()).get_data()).to_vec();
self.resource.send_raw(data);
Promise::ok(())
}
}
impl CheckServer for Machine { impl CheckServer for Machine {
fn check( fn check(
&mut self, &mut self,

View File

@ -59,6 +59,16 @@ pub struct MachineDescription {
/// The permission required /// The permission required
#[serde(flatten)] #[serde(flatten)]
pub privs: PrivilegesBuf, pub privs: PrivilegesBuf,
#[serde(default = "default_prodable", skip_serializing_if = "bool_is_false", deserialize_with = "deser_bool")]
pub prodable: bool,
}
fn default_prodable() -> bool {
false
}
fn bool_is_false(b: &bool) -> bool {
!b
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -116,6 +126,14 @@ pub struct ModuleConfig {
pub params: HashMap<String, String>, pub params: HashMap<String, String>,
} }
fn deser_bool<'de, D>(d: D) -> Result<bool, D::Error>
where
D: serde::Deserializer<'de>,
{
Ok(bool::deserialize(d).unwrap_or(false))
}
pub(crate) fn deser_option<'de, D, T>(d: D) -> std::result::Result<Option<T>, D::Error> pub(crate) fn deser_option<'de, D, T>(d: D) -> std::result::Result<Option<T>, D::Error>
where where
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,

View File

@ -57,7 +57,7 @@
-- --
-- If you want either parents or permissions to be empty its best to completely skip it: -- If you want either parents or permissions to be empty its best to completely skip it:
testrole = { testrole = {
permissions = [ "lab.some.admin" ] permissions = [ "lab.some.admin", "bffh.users.admin", "bffh.users.manage" ]
}, },
somerole = { somerole = {
parents = ["testparent"], parents = ["testparent"],
@ -229,6 +229,9 @@
-- Linking up machines to initiators. Similar to actors a machine can have several initiators assigned but an -- Linking up machines to initiators. Similar to actors a machine can have several initiators assigned but an
-- initiator can only be assigned to one machine. -- initiator can only be assigned to one machine.
-- The below is once again how you have to define *no* initiators. -- The below is once again how you have to define *no* initiators.
init_connections = [] : List { machine : Text, initiator : Text } init_connections = [] : List { machine : Text, initiator : Text },
--init_connections = [{ machine = "Testmachine", initiator = "Initiator" }] --init_connections = [{ machine = "Testmachine", initiator = "Initiator" }]
spacename = "foospace",
instanceurl = "https://example.com"
} }