diff --git a/bffhd/capnp/user.rs b/bffhd/capnp/user.rs index 3ef26d9..b463b38 100644 --- a/bffhd/capnp/user.rs +++ b/bffhd/capnp/user.rs @@ -143,7 +143,8 @@ impl admin::Server for User { // Only update if needed if !target.userdata.roles.iter().any(|r| r.as_str() == rolename) { target.userdata.roles.push(rolename.to_string()); - pry!(self.session + pry!(self + .session .users .put_user(self.user.get_username(), &target)); } @@ -168,7 +169,8 @@ impl admin::Server for User { // Only update if needed if target.userdata.roles.iter().any(|r| r.as_str() == rolename) { target.userdata.roles.retain(|r| r.as_str() != rolename); - pry!(self.session + pry!(self + .session .users .put_user(self.user.get_username(), &target)); } diff --git a/bffhd/config/dhall.rs b/bffhd/config/dhall.rs index 262db61..c01637d 100644 --- a/bffhd/config/dhall.rs +++ b/bffhd/config/dhall.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; 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::capnp::{Listen, TlsListen}; use crate::logging::LogConfig; @@ -126,27 +126,41 @@ impl Default for Config { roles.insert( "admin".to_string(), - Role { - parents: Vec::new(), - permissions: vec![ - PermRule::Base(PermissionBuf {inner: "bffh.users.info".to_string()}), - PermRule::Base(PermissionBuf {inner: "bffh.users.manage".to_string()}), - PermRule::Base(PermissionBuf {inner: "bffh.users.admin".to_string()}), - ] - } + Role { + parents: Vec::new(), + permissions: vec![ + PermRule::Base(PermissionBuf { + inner: "bffh.users.info".to_string(), + }), + PermRule::Base(PermissionBuf { + inner: "bffh.users.manage".to_string(), + }), + PermRule::Base(PermissionBuf { + inner: "bffh.users.admin".to_string(), + }), + ], + }, ); roles.insert( "member".to_string(), - Role { - parents: Vec::new(), - permissions: vec![ - PermRule::Base(PermissionBuf {inner: "lab.some.disclose".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()}) - ] - } + Role { + parents: Vec::new(), + permissions: vec![ + PermRule::Base(PermissionBuf { + inner: "lab.some.disclose".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( @@ -157,12 +171,20 @@ impl Default for Config { wiki: Option::from("Some wiki url".to_string()), category: Option::from("Some category".to_string()), privs: PrivilegesBuf { - disclose: PermissionBuf {inner: "lab.some.disclose".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()}, - } - } + disclose: PermissionBuf { + inner: "lab.some.disclose".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( @@ -173,12 +195,20 @@ impl Default for Config { wiki: Option::from("Some wiki url".to_string()), category: Option::from("Some category".to_string()), privs: PrivilegesBuf { - disclose: PermissionBuf {inner: "lab.some.disclose".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()}, - } - } + disclose: PermissionBuf { + inner: "lab.some.disclose".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( @@ -221,8 +251,6 @@ impl Default for Config { actor_connections: vec![("actor_123".to_string(), "resource_a".to_string())], initiators, init_connections: vec![("initiator_123".to_string(), "resource_b".to_string())], - - } } } diff --git a/bffhd/initiators/mod.rs b/bffhd/initiators/mod.rs index 0b84195..e293927 100644 --- a/bffhd/initiators/mod.rs +++ b/bffhd/initiators/mod.rs @@ -2,9 +2,7 @@ use crate::initiators::dummy::Dummy; use crate::initiators::process::Process; use crate::resources::modules::fabaccess::Status; use crate::session::SessionHandle; -use crate::{ - AuthenticationHandle, Config, Resource, ResourcesHandle, SessionManager, -}; +use crate::{AuthenticationHandle, Config, Resource, ResourcesHandle, SessionManager}; use executor::prelude::Executor; use futures_util::ready; use std::collections::HashMap; diff --git a/bffhd/lib.rs b/bffhd/lib.rs index 6461f26..4c0bde6 100644 --- a/bffhd/lib.rs +++ b/bffhd/lib.rs @@ -208,9 +208,11 @@ impl Difluoroborane { pub fn dump_db(&mut self, file: &str) -> Result<(), miette::Error> { let users = self.users.dump_map()?; let state = self.statedb.dump_map()?; - let dump = DatabaseDump{users, state}; - let data = toml::ser::to_vec(&dump).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)))?; + let dump = DatabaseDump { users, state }; + let data = toml::ser::to_vec(&dump) + .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(()) } @@ -236,7 +238,8 @@ impl Difluoroborane { self.resources.clone(), sessionmanager.clone(), authentication.clone(), - ).expect("initializing initiators failed"); + ) + .expect("initializing initiators failed"); // TODO 0.5: error handling. Add variant to BFFHError actors::load(self.executor.clone(), &self.config, self.resources.clone())?; diff --git a/bffhd/resources/mod.rs b/bffhd/resources/mod.rs index 56dccf2..94c6d5d 100644 --- a/bffhd/resources/mod.rs +++ b/bffhd/resources/mod.rs @@ -90,7 +90,11 @@ impl Inner { .unwrap() .log(self.id.as_str(), &format!("{}", state)); 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); @@ -164,7 +168,9 @@ impl Resource { fn set_state(&self, state: MachineState) { 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()); self.inner.set_state(archived) } diff --git a/bffhd/resources/state/db.rs b/bffhd/resources/state/db.rs index d2237aa..9929ded 100644 --- a/bffhd/resources/state/db.rs +++ b/bffhd/resources/state/db.rs @@ -1,5 +1,5 @@ -use rkyv::ser::Serializer; use rkyv::ser::serializers::AllocSerializer; +use rkyv::ser::Serializer; use thiserror::Error; use crate::db; @@ -54,8 +54,7 @@ impl StateDB { } pub fn open_with_env(env: Arc) -> Result { - let db = RawDB::open(&env, Some("state")) - .map_err(|e| StateDBError::Open(e.into()))?; + let db = RawDB::open(&env, Some("state")).map_err(|e| StateDBError::Open(e.into()))?; Ok(Self::new(env, db)) } @@ -117,11 +116,14 @@ impl StateDB { pub fn dump_map(&self) -> miette::Result> { let mut map = std::collections::HashMap::new(); 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 val_state: State = rkyv::Deserialize::deserialize(val.as_ref(), &mut rkyv::Infallible).unwrap(); + let key_str = core::str::from_utf8(&key) + .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); } - Ok(map) + Ok(map) } } diff --git a/bffhd/resources/state/mod.rs b/bffhd/resources/state/mod.rs index efc38c3..05ba0be 100644 --- a/bffhd/resources/state/mod.rs +++ b/bffhd/resources/state/mod.rs @@ -1,5 +1,5 @@ -use std::fmt::{Debug, Display, Formatter}; use std::fmt; +use std::fmt::{Debug, Display, Formatter}; use std::ops::Deref; diff --git a/bffhd/users/mod.rs b/bffhd/users/mod.rs index ee4a6c5..ea316a7 100644 --- a/bffhd/users/mod.rs +++ b/bffhd/users/mod.rs @@ -173,7 +173,7 @@ impl Users { Ok(()) } - pub fn load_map(&mut self, dump: &HashMap) -> miette::Result<()> { + pub fn load_map(&mut self, dump: &HashMap) -> miette::Result<()> { let mut txn = unsafe { self.userdb.get_rw_txn() }?; self.userdb.clear_txn(&mut txn)?; @@ -194,7 +194,7 @@ impl Users { } pub fn dump_map(&self) -> miette::Result> { - return Ok(self.userdb.get_all()?) + return Ok(self.userdb.get_all()?); } pub fn dump_file(&self, path_str: &str, force: bool) -> miette::Result { let path = Path::new(path_str); diff --git a/bin/bffhd/main.rs b/bin/bffhd/main.rs index a3c92a6..6c89442 100644 --- a/bin/bffhd/main.rs +++ b/bin/bffhd/main.rs @@ -122,9 +122,7 @@ fn main() -> miette::Result<()> { Err(error) => error.exit(), }; - let configpath = matches - .value_of("config") - .unwrap_or("/etc/bffh/bffh.dhall"); + let configpath = matches.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 // case. @@ -187,9 +185,13 @@ fn main() -> miette::Result<()> { } else if matches.is_present("load-users") { 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(()); } else { diff --git a/hooks/git-pre-commit-hook b/hooks/pre-commit similarity index 100% rename from hooks/git-pre-commit-hook rename to hooks/pre-commit diff --git a/hooks/git-pre-push-hook b/hooks/pre-push similarity index 100% rename from hooks/git-pre-push-hook rename to hooks/pre-push diff --git a/tools/git-pre-commit-hook b/tools/git-pre-commit-hook deleted file mode 100755 index 246a0af..0000000 --- a/tools/git-pre-commit-hook +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -cargo fmt --all diff --git a/tools/git-pre-push-hook b/tools/git-pre-push-hook deleted file mode 100755 index b47425a..0000000 --- a/tools/git-pre-push-hook +++ /dev/null @@ -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