mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2025-04-20 11:16:26 +02:00
run cargo formatter
This commit is contained in:
parent
1406f38aa3
commit
1ab4d089a2
@ -143,7 +143,8 @@ impl admin::Server for User {
|
|||||||
// Only update if needed
|
// Only update if needed
|
||||||
if !target.userdata.roles.iter().any(|r| r.as_str() == rolename) {
|
if !target.userdata.roles.iter().any(|r| r.as_str() == rolename) {
|
||||||
target.userdata.roles.push(rolename.to_string());
|
target.userdata.roles.push(rolename.to_string());
|
||||||
pry!(self.session
|
pry!(self
|
||||||
|
.session
|
||||||
.users
|
.users
|
||||||
.put_user(self.user.get_username(), &target));
|
.put_user(self.user.get_username(), &target));
|
||||||
}
|
}
|
||||||
@ -168,7 +169,8 @@ impl admin::Server for User {
|
|||||||
// Only update if needed
|
// Only update if needed
|
||||||
if target.userdata.roles.iter().any(|r| r.as_str() == rolename) {
|
if target.userdata.roles.iter().any(|r| r.as_str() == rolename) {
|
||||||
target.userdata.roles.retain(|r| r.as_str() != rolename);
|
target.userdata.roles.retain(|r| r.as_str() != rolename);
|
||||||
pry!(self.session
|
pry!(self
|
||||||
|
.session
|
||||||
.users
|
.users
|
||||||
.put_user(self.user.get_username(), &target));
|
.put_user(self.user.get_username(), &target));
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::authorization::permissions::{PermissionBuf, PrivilegesBuf, PermRule};
|
use crate::authorization::permissions::{PermRule, PermissionBuf, PrivilegesBuf};
|
||||||
use crate::authorization::roles::Role;
|
use crate::authorization::roles::Role;
|
||||||
use crate::capnp::{Listen, TlsListen};
|
use crate::capnp::{Listen, TlsListen};
|
||||||
use crate::logging::LogConfig;
|
use crate::logging::LogConfig;
|
||||||
@ -129,11 +129,17 @@ impl Default for Config {
|
|||||||
Role {
|
Role {
|
||||||
parents: Vec::new(),
|
parents: Vec::new(),
|
||||||
permissions: vec![
|
permissions: vec![
|
||||||
PermRule::Base(PermissionBuf {inner: "bffh.users.info".to_string()}),
|
PermRule::Base(PermissionBuf {
|
||||||
PermRule::Base(PermissionBuf {inner: "bffh.users.manage".to_string()}),
|
inner: "bffh.users.info".to_string(),
|
||||||
PermRule::Base(PermissionBuf {inner: "bffh.users.admin".to_string()}),
|
}),
|
||||||
]
|
PermRule::Base(PermissionBuf {
|
||||||
}
|
inner: "bffh.users.manage".to_string(),
|
||||||
|
}),
|
||||||
|
PermRule::Base(PermissionBuf {
|
||||||
|
inner: "bffh.users.admin".to_string(),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
roles.insert(
|
roles.insert(
|
||||||
@ -141,12 +147,20 @@ impl Default for Config {
|
|||||||
Role {
|
Role {
|
||||||
parents: Vec::new(),
|
parents: Vec::new(),
|
||||||
permissions: vec![
|
permissions: vec![
|
||||||
PermRule::Base(PermissionBuf {inner: "lab.some.disclose".to_string()}),
|
PermRule::Base(PermissionBuf {
|
||||||
PermRule::Base(PermissionBuf {inner: "lab.some.read".to_string()}),
|
inner: "lab.some.disclose".to_string(),
|
||||||
PermRule::Base(PermissionBuf {inner: "lab.some.write".to_string()}),
|
}),
|
||||||
PermRule::Base(PermissionBuf {inner: "lab.some.manage".to_string()})
|
PermRule::Base(PermissionBuf {
|
||||||
]
|
inner: "lab.some.read".to_string(),
|
||||||
}
|
}),
|
||||||
|
PermRule::Base(PermissionBuf {
|
||||||
|
inner: "lab.some.write".to_string(),
|
||||||
|
}),
|
||||||
|
PermRule::Base(PermissionBuf {
|
||||||
|
inner: "lab.some.manage".to_string(),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
machines.insert(
|
machines.insert(
|
||||||
@ -157,12 +171,20 @@ impl Default for Config {
|
|||||||
wiki: Option::from("Some wiki url".to_string()),
|
wiki: Option::from("Some wiki url".to_string()),
|
||||||
category: Option::from("Some category".to_string()),
|
category: Option::from("Some category".to_string()),
|
||||||
privs: PrivilegesBuf {
|
privs: PrivilegesBuf {
|
||||||
disclose: PermissionBuf {inner: "lab.some.disclose".to_string()},
|
disclose: PermissionBuf {
|
||||||
read: PermissionBuf {inner: "lab.some.read".to_string()},
|
inner: "lab.some.disclose".to_string(),
|
||||||
write: PermissionBuf {inner: "lab.some.write".to_string()},
|
},
|
||||||
manage: PermissionBuf {inner: "lab.some.manage".to_string()},
|
read: PermissionBuf {
|
||||||
}
|
inner: "lab.some.read".to_string(),
|
||||||
}
|
},
|
||||||
|
write: PermissionBuf {
|
||||||
|
inner: "lab.some.write".to_string(),
|
||||||
|
},
|
||||||
|
manage: PermissionBuf {
|
||||||
|
inner: "lab.some.manage".to_string(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
machines.insert(
|
machines.insert(
|
||||||
@ -173,12 +195,20 @@ impl Default for Config {
|
|||||||
wiki: Option::from("Some wiki url".to_string()),
|
wiki: Option::from("Some wiki url".to_string()),
|
||||||
category: Option::from("Some category".to_string()),
|
category: Option::from("Some category".to_string()),
|
||||||
privs: PrivilegesBuf {
|
privs: PrivilegesBuf {
|
||||||
disclose: PermissionBuf {inner: "lab.some.disclose".to_string()},
|
disclose: PermissionBuf {
|
||||||
read: PermissionBuf {inner: "lab.some.read".to_string()},
|
inner: "lab.some.disclose".to_string(),
|
||||||
write: PermissionBuf {inner: "lab.some.write".to_string()},
|
},
|
||||||
manage: PermissionBuf {inner: "lab.some.manage".to_string()},
|
read: PermissionBuf {
|
||||||
}
|
inner: "lab.some.read".to_string(),
|
||||||
}
|
},
|
||||||
|
write: PermissionBuf {
|
||||||
|
inner: "lab.some.write".to_string(),
|
||||||
|
},
|
||||||
|
manage: PermissionBuf {
|
||||||
|
inner: "lab.some.manage".to_string(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
actors.insert(
|
actors.insert(
|
||||||
@ -221,8 +251,6 @@ impl Default for Config {
|
|||||||
actor_connections: vec![("actor_123".to_string(), "resource_a".to_string())],
|
actor_connections: vec![("actor_123".to_string(), "resource_a".to_string())],
|
||||||
initiators,
|
initiators,
|
||||||
init_connections: vec![("initiator_123".to_string(), "resource_b".to_string())],
|
init_connections: vec![("initiator_123".to_string(), "resource_b".to_string())],
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,7 @@ use crate::initiators::dummy::Dummy;
|
|||||||
use crate::initiators::process::Process;
|
use crate::initiators::process::Process;
|
||||||
use crate::resources::modules::fabaccess::Status;
|
use crate::resources::modules::fabaccess::Status;
|
||||||
use crate::session::SessionHandle;
|
use crate::session::SessionHandle;
|
||||||
use crate::{
|
use crate::{AuthenticationHandle, Config, Resource, ResourcesHandle, SessionManager};
|
||||||
AuthenticationHandle, Config, Resource, ResourcesHandle, SessionManager,
|
|
||||||
};
|
|
||||||
use executor::prelude::Executor;
|
use executor::prelude::Executor;
|
||||||
use futures_util::ready;
|
use futures_util::ready;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
11
bffhd/lib.rs
11
bffhd/lib.rs
@ -208,9 +208,11 @@ impl Difluoroborane {
|
|||||||
pub fn dump_db(&mut self, file: &str) -> Result<(), miette::Error> {
|
pub fn dump_db(&mut self, file: &str) -> Result<(), miette::Error> {
|
||||||
let users = self.users.dump_map()?;
|
let users = self.users.dump_map()?;
|
||||||
let state = self.statedb.dump_map()?;
|
let state = self.statedb.dump_map()?;
|
||||||
let dump = DatabaseDump{users, state};
|
let dump = DatabaseDump { users, state };
|
||||||
let data = toml::ser::to_vec(&dump).map_err(|e| miette::Error::msg(format!("Serializing database dump failed: {}", e)))?;
|
let data = toml::ser::to_vec(&dump)
|
||||||
std::fs::write(file, &data).map_err(|e| miette::Error::msg(format!("writing database dump failed: {}", e)))?;
|
.map_err(|e| miette::Error::msg(format!("Serializing database dump failed: {}", e)))?;
|
||||||
|
std::fs::write(file, &data)
|
||||||
|
.map_err(|e| miette::Error::msg(format!("writing database dump failed: {}", e)))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +238,8 @@ impl Difluoroborane {
|
|||||||
self.resources.clone(),
|
self.resources.clone(),
|
||||||
sessionmanager.clone(),
|
sessionmanager.clone(),
|
||||||
authentication.clone(),
|
authentication.clone(),
|
||||||
).expect("initializing initiators failed");
|
)
|
||||||
|
.expect("initializing initiators failed");
|
||||||
// TODO 0.5: error handling. Add variant to BFFHError
|
// TODO 0.5: error handling. Add variant to BFFHError
|
||||||
|
|
||||||
actors::load(self.executor.clone(), &self.config, self.resources.clone())?;
|
actors::load(self.executor.clone(), &self.config, self.resources.clone())?;
|
||||||
|
@ -90,7 +90,11 @@ impl Inner {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.log(self.id.as_str(), &format!("{}", state));
|
.log(self.id.as_str(), &format!("{}", state));
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
tracing::error!("Writing to the audit log failed for {} {}: {e}", self.id.as_str(), state);
|
tracing::error!(
|
||||||
|
"Writing to the audit log failed for {} {}: {e}",
|
||||||
|
self.id.as_str(),
|
||||||
|
state
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.signal.set(state);
|
self.signal.set(state);
|
||||||
@ -164,7 +168,9 @@ impl Resource {
|
|||||||
|
|
||||||
fn set_state(&self, state: MachineState) {
|
fn set_state(&self, state: MachineState) {
|
||||||
let mut serializer = AllocSerializer::<1024>::default();
|
let mut serializer = AllocSerializer::<1024>::default();
|
||||||
serializer.serialize_value(&state).expect("serializing a MachineState shoud be infallible");
|
serializer
|
||||||
|
.serialize_value(&state)
|
||||||
|
.expect("serializing a MachineState shoud be infallible");
|
||||||
let archived = ArchivedValue::new(serializer.into_serializer().into_inner());
|
let archived = ArchivedValue::new(serializer.into_serializer().into_inner());
|
||||||
self.inner.set_state(archived)
|
self.inner.set_state(archived)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use rkyv::ser::Serializer;
|
|
||||||
use rkyv::ser::serializers::AllocSerializer;
|
use rkyv::ser::serializers::AllocSerializer;
|
||||||
|
use rkyv::ser::Serializer;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::db;
|
use crate::db;
|
||||||
@ -54,8 +54,7 @@ impl StateDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_with_env(env: Arc<Environment>) -> Result<Self, StateDBError> {
|
pub fn open_with_env(env: Arc<Environment>) -> Result<Self, StateDBError> {
|
||||||
let db = RawDB::open(&env, Some("state"))
|
let db = RawDB::open(&env, Some("state")).map_err(|e| StateDBError::Open(e.into()))?;
|
||||||
.map_err(|e| StateDBError::Open(e.into()))?;
|
|
||||||
Ok(Self::new(env, db))
|
Ok(Self::new(env, db))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,8 +116,11 @@ impl StateDB {
|
|||||||
pub fn dump_map(&self) -> miette::Result<std::collections::HashMap<String, State>> {
|
pub fn dump_map(&self) -> miette::Result<std::collections::HashMap<String, State>> {
|
||||||
let mut map = std::collections::HashMap::new();
|
let mut map = std::collections::HashMap::new();
|
||||||
for (key, val) in self.get_all(&self.begin_ro_txn()?)? {
|
for (key, val) in self.get_all(&self.begin_ro_txn()?)? {
|
||||||
let key_str = core::str::from_utf8(&key).map_err(|_e| miette::Error::msg("state key not UTF8"))?.to_string();
|
let key_str = core::str::from_utf8(&key)
|
||||||
let val_state: State = rkyv::Deserialize::deserialize(val.as_ref(), &mut rkyv::Infallible).unwrap();
|
.map_err(|_e| miette::Error::msg("state key not UTF8"))?
|
||||||
|
.to_string();
|
||||||
|
let val_state: State =
|
||||||
|
rkyv::Deserialize::deserialize(val.as_ref(), &mut rkyv::Infallible).unwrap();
|
||||||
map.insert(key_str, val_state);
|
map.insert(key_str, val_state);
|
||||||
}
|
}
|
||||||
Ok(map)
|
Ok(map)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::fmt::{Debug, Display, Formatter};
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ impl Users {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_map(&mut self, dump: &HashMap<String,UserData>) -> miette::Result<()> {
|
pub fn load_map(&mut self, dump: &HashMap<String, UserData>) -> miette::Result<()> {
|
||||||
let mut txn = unsafe { self.userdb.get_rw_txn() }?;
|
let mut txn = unsafe { self.userdb.get_rw_txn() }?;
|
||||||
|
|
||||||
self.userdb.clear_txn(&mut txn)?;
|
self.userdb.clear_txn(&mut txn)?;
|
||||||
@ -194,7 +194,7 @@ impl Users {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn dump_map(&self) -> miette::Result<HashMap<String, UserData>> {
|
pub fn dump_map(&self) -> miette::Result<HashMap<String, UserData>> {
|
||||||
return Ok(self.userdb.get_all()?)
|
return Ok(self.userdb.get_all()?);
|
||||||
}
|
}
|
||||||
pub fn dump_file(&self, path_str: &str, force: bool) -> miette::Result<usize> {
|
pub fn dump_file(&self, path_str: &str, force: bool) -> miette::Result<usize> {
|
||||||
let path = Path::new(path_str);
|
let path = Path::new(path_str);
|
||||||
|
@ -122,9 +122,7 @@ fn main() -> miette::Result<()> {
|
|||||||
Err(error) => error.exit(),
|
Err(error) => error.exit(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let configpath = matches
|
let configpath = matches.value_of("config").unwrap_or("/etc/bffh/bffh.dhall");
|
||||||
.value_of("config")
|
|
||||||
.unwrap_or("/etc/bffh/bffh.dhall");
|
|
||||||
|
|
||||||
// Check for the --print-default option first because we don't need to do anything else in that
|
// Check for the --print-default option first because we don't need to do anything else in that
|
||||||
// case.
|
// case.
|
||||||
@ -187,9 +185,13 @@ fn main() -> miette::Result<()> {
|
|||||||
} else if matches.is_present("load-users") {
|
} else if matches.is_present("load-users") {
|
||||||
let bffh = Difluoroborane::new(config)?;
|
let bffh = Difluoroborane::new(config)?;
|
||||||
|
|
||||||
bffh.users.load_file(matches.value_of("load-users").unwrap())?;
|
bffh.users
|
||||||
|
.load_file(matches.value_of("load-users").unwrap())?;
|
||||||
|
|
||||||
tracing::info!("loaded users from {}", matches.value_of("load-users").unwrap());
|
tracing::info!(
|
||||||
|
"loaded users from {}",
|
||||||
|
matches.value_of("load-users").unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
cargo fmt --all
|
|
@ -1,12 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
echo -e "Checking code formatting:\n=========================\n\n" 1>&2
|
|
||||||
|
|
||||||
cargo fmt --check
|
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]
|
|
||||||
then
|
|
||||||
o=$?
|
|
||||||
echo -e "\n\nRun \`cargo fmt --all\` before pushing please." 1>&2
|
|
||||||
exit $o
|
|
||||||
fi
|
|
Loading…
x
Reference in New Issue
Block a user