From eeb0ff306b4518b45a26ca45b1b9519d0a77c661 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Sun, 5 Dec 2021 18:53:02 +0100 Subject: [PATCH] Fix Machines using their name instead of their id --- examples/bffh.dhall | 2 +- schema | 2 +- src/api/machines.rs | 14 ++++++++------ src/machine.rs | 12 ++++++------ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/bffh.dhall b/examples/bffh.dhall index 308f19f..e85c3ac 100644 --- a/examples/bffh.dhall +++ b/examples/bffh.dhall @@ -35,7 +35,7 @@ { description = Some "A test machine" , disclose = "lab.test.read" , manage = "lab.test.admin" - , name = "Testmachine" + , name = "MachineA" , read = "lab.test.read" , write = "lab.test.write" }, diff --git a/schema b/schema index 743c183..c855646 160000 --- a/schema +++ b/schema @@ -1 +1 @@ -Subproject commit 743c18393c6e01edeec1e04ab8998176d78f9a04 +Subproject commit c855646a90958ae575d58be074d187acb9f8f4fa diff --git a/src/api/machines.rs b/src/api/machines.rs index d251ba5..43ae558 100644 --- a/src/api/machines.rs +++ b/src/api/machines.rs @@ -74,7 +74,8 @@ impl machines::Server for Machines { let perms = Perms::get_for(&machine.desc.privs, permissions.iter()); let mut builder = machines.reborrow().get(i as u32); - builder.set_name(&name); + builder.set_id(&name); + builder.set_name(&machine.desc.name); if let Some(ref desc) = machine.desc.description { builder.set_description(desc); } @@ -134,9 +135,9 @@ impl machines::Server for Machines { ) -> Promise<(), capnp::Error> { let rc = Rc::clone(&self.session); if self.session.borrow().is_some() { - let name = { + let id = { let params = pry!(params.get()); - pry!(params.get_name()).to_string() + pry!(params.get_id()).to_string() }; let network = self.network.clone(); @@ -145,17 +146,18 @@ impl machines::Server for Machines { let user = &session.as_ref().unwrap().authzid; let permissions = &session.as_ref().unwrap().perms; - if let Some(machine) = network.machines.get(&name) { + if let Some(machine) = network.machines.get(&id) { let mut builder = results.get().init_machine(); let perms = Perms::get_for(&machine.desc.privs, permissions.iter()); - builder.set_name(&name); + builder.set_id(&id); + builder.set_name(&machine.desc.name); if let Some(ref desc) = machine.desc.description { builder.set_description(desc); } if let Some(ref wiki) = machine.desc.wiki { builder.set_wiki(wiki); } - builder.set_urn(&format!("urn:fabaccess:resource:{}", &name)); + builder.set_urn(&format!("urn:fabaccess:resource:{}", &id)); let machineapi = Machine::new(user.clone(), perms, machine.clone()); let state = machine.get_status().await; diff --git a/src/machine.rs b/src/machine.rs index 18f9afe..da2ed0f 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -59,16 +59,16 @@ impl Index { // memory #[derive(Debug, Clone)] pub struct Machine { - pub id: uuid::Uuid, + pub id: MachineIdentifier, pub desc: MachineDescription, inner: Arc>, } impl Machine { - pub fn new(inner: Inner, desc: MachineDescription) -> Self { + pub fn new(inner: Inner, id: MachineIdentifier, desc: MachineDescription) -> Self { Self { - id: uuid::Uuid::default(), + id, inner: Arc::new(Mutex::new(inner)), desc, } @@ -81,7 +81,7 @@ impl Machine { db: Arc, ) -> Machine { - Self::new(Inner::new(id, state, db), desc) + Self::new(Inner::new(id.clone(), state, db), id, desc) } pub fn do_state_change(&self, new_state: MachineState) @@ -284,10 +284,10 @@ pub fn load(config: &crate::config::Config, db: Databases, log: &Logger) // TODO: Read state from the state db if let Some(state) = db.get(&k).unwrap() { debug!(log, "Loading old state from db for {}: {:?}", &k, &state); - (v.name.clone(), Machine::construct(k, v, state, db.clone())) + (k.clone(), Machine::construct(k, v, state, db.clone())) } else { debug!(log, "No old state found in db for {}, creating new.", &k); - (v.name.clone(), Machine::construct(k, v, MachineState::new(), db.clone())) + (k.clone(), Machine::construct(k, v, MachineState::new(), db.clone())) } });