mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 14:57:56 +01:00
Fix Machines using their name instead of their id
This commit is contained in:
parent
fd7fec2cbe
commit
eeb0ff306b
@ -35,7 +35,7 @@
|
|||||||
{ description = Some "A test machine"
|
{ description = Some "A test machine"
|
||||||
, disclose = "lab.test.read"
|
, disclose = "lab.test.read"
|
||||||
, manage = "lab.test.admin"
|
, manage = "lab.test.admin"
|
||||||
, name = "Testmachine"
|
, name = "MachineA"
|
||||||
, read = "lab.test.read"
|
, read = "lab.test.read"
|
||||||
, write = "lab.test.write"
|
, write = "lab.test.write"
|
||||||
},
|
},
|
||||||
|
2
schema
2
schema
@ -1 +1 @@
|
|||||||
Subproject commit 743c18393c6e01edeec1e04ab8998176d78f9a04
|
Subproject commit c855646a90958ae575d58be074d187acb9f8f4fa
|
@ -74,7 +74,8 @@ impl machines::Server for Machines {
|
|||||||
let perms = Perms::get_for(&machine.desc.privs, permissions.iter());
|
let perms = Perms::get_for(&machine.desc.privs, permissions.iter());
|
||||||
|
|
||||||
let mut builder = machines.reborrow().get(i as u32);
|
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 {
|
if let Some(ref desc) = machine.desc.description {
|
||||||
builder.set_description(desc);
|
builder.set_description(desc);
|
||||||
}
|
}
|
||||||
@ -134,9 +135,9 @@ impl machines::Server for Machines {
|
|||||||
) -> Promise<(), capnp::Error> {
|
) -> Promise<(), capnp::Error> {
|
||||||
let rc = Rc::clone(&self.session);
|
let rc = Rc::clone(&self.session);
|
||||||
if self.session.borrow().is_some() {
|
if self.session.borrow().is_some() {
|
||||||
let name = {
|
let id = {
|
||||||
let params = pry!(params.get());
|
let params = pry!(params.get());
|
||||||
pry!(params.get_name()).to_string()
|
pry!(params.get_id()).to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let network = self.network.clone();
|
let network = self.network.clone();
|
||||||
@ -145,17 +146,18 @@ impl machines::Server for Machines {
|
|||||||
let user = &session.as_ref().unwrap().authzid;
|
let user = &session.as_ref().unwrap().authzid;
|
||||||
let permissions = &session.as_ref().unwrap().perms;
|
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 mut builder = results.get().init_machine();
|
||||||
let perms = Perms::get_for(&machine.desc.privs, permissions.iter());
|
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 {
|
if let Some(ref desc) = machine.desc.description {
|
||||||
builder.set_description(desc);
|
builder.set_description(desc);
|
||||||
}
|
}
|
||||||
if let Some(ref wiki) = machine.desc.wiki {
|
if let Some(ref wiki) = machine.desc.wiki {
|
||||||
builder.set_wiki(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 machineapi = Machine::new(user.clone(), perms, machine.clone());
|
||||||
let state = machine.get_status().await;
|
let state = machine.get_status().await;
|
||||||
|
@ -59,16 +59,16 @@ impl Index {
|
|||||||
// memory
|
// memory
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Machine {
|
pub struct Machine {
|
||||||
pub id: uuid::Uuid,
|
pub id: MachineIdentifier,
|
||||||
pub desc: MachineDescription,
|
pub desc: MachineDescription,
|
||||||
|
|
||||||
inner: Arc<Mutex<Inner>>,
|
inner: Arc<Mutex<Inner>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Machine {
|
impl Machine {
|
||||||
pub fn new(inner: Inner, desc: MachineDescription) -> Self {
|
pub fn new(inner: Inner, id: MachineIdentifier, desc: MachineDescription) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: uuid::Uuid::default(),
|
id,
|
||||||
inner: Arc::new(Mutex::new(inner)),
|
inner: Arc::new(Mutex::new(inner)),
|
||||||
desc,
|
desc,
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ impl Machine {
|
|||||||
db: Arc<MachineDB>,
|
db: Arc<MachineDB>,
|
||||||
) -> Machine
|
) -> 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)
|
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
|
// TODO: Read state from the state db
|
||||||
if let Some(state) = db.get(&k).unwrap() {
|
if let Some(state) = db.get(&k).unwrap() {
|
||||||
debug!(log, "Loading old state from db for {}: {:?}", &k, &state);
|
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 {
|
} else {
|
||||||
debug!(log, "No old state found in db for {}, creating new.", &k);
|
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()))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user