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::{
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<u8> = pry!(pry!(params.get()).get_data()).to_vec();
self.resource.send_raw(data);
Promise::ok(())
}
}
impl CheckServer for Machine {
fn check(
&mut self,

View File

@ -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<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>
where
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:
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"
}