From d196050fe05602703ba7e4aaa8c7fd0faed53c9a Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Tue, 14 Feb 2023 16:58:23 +0100 Subject: [PATCH] prodable machines --- api/schema | 2 +- bffhd/capnp/machine.rs | 15 ++++++++++++++- bffhd/config/dhall.rs | 18 ++++++++++++++++++ examples/bffh.dhall | 7 +++++-- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/api/schema b/api/schema index 19f20f5..cde4677 160000 --- a/api/schema +++ b/api/schema @@ -1 +1 @@ -Subproject commit 19f20f5154f0eced6288ff56cac840025ee51da1 +Subproject commit cde4677575f8e133ac764663e131c80fc891d545 diff --git a/bffhd/capnp/machine.rs b/bffhd/capnp/machine.rs index d1c6bdf..2f72290 100644 --- a/bffhd/capnp/machine.rs +++ b/bffhd/capnp/machine.rs @@ -6,10 +6,12 @@ use api::general_capnp::optional; use api::machine_capnp::machine::{ 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, - 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::Error; use capnp_rpc::pry; +use api::machine_capnp::machine::prodable::{ProdWithDataParams, ProdWithDataResults}; #[derive(Clone)] pub struct Machine { @@ -67,6 +69,9 @@ impl Machine { ArchivedStatus::InUse(owner) => { if owner == &user { 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 } @@ -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 = pry!(pry!(params.get()).get_data()).to_vec(); + self.resource.send_raw(data); + Promise::ok(()) + } +} + impl CheckServer for Machine { fn check( &mut self, diff --git a/bffhd/config/dhall.rs b/bffhd/config/dhall.rs index efb1ecd..02c26b8 100644 --- a/bffhd/config/dhall.rs +++ b/bffhd/config/dhall.rs @@ -59,6 +59,16 @@ pub struct MachineDescription { /// The permission required #[serde(flatten)] 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)] @@ -116,6 +126,14 @@ pub struct ModuleConfig { pub params: HashMap, } +fn deser_bool<'de, D>(d: D) -> Result +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, D::Error> where D: serde::Deserializer<'de>, diff --git a/examples/bffh.dhall b/examples/bffh.dhall index 7d1afb2..45d70b8 100644 --- a/examples/bffh.dhall +++ b/examples/bffh.dhall @@ -57,7 +57,7 @@ -- -- If you want either parents or permissions to be empty its best to completely skip it: testrole = { - permissions = [ "lab.some.admin" ] + permissions = [ "lab.some.admin", "bffh.users.admin", "bffh.users.manage" ] }, somerole = { parents = ["testparent"], @@ -229,6 +229,9 @@ -- 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. -- 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" }] + + spacename = "foospace", + instanceurl = "https://example.com" }