mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2025-04-18 18:26: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
|
||||
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));
|
||||
}
|
||||
|
@ -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;
|
||||
@ -129,11 +129,17 @@ impl Default for Config {
|
||||
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()}),
|
||||
]
|
||||
}
|
||||
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(
|
||||
@ -141,12 +147,20 @@ impl Default for Config {
|
||||
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()})
|
||||
]
|
||||
}
|
||||
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())],
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -209,8 +209,10 @@ impl Difluoroborane {
|
||||
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 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())?;
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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<Environment>) -> Result<Self, StateDBError> {
|
||||
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,8 +116,11 @@ impl StateDB {
|
||||
pub fn dump_map(&self) -> miette::Result<std::collections::HashMap<String, State>> {
|
||||
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)
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use std::fmt;
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
|
@ -194,7 +194,7 @@ impl Users {
|
||||
}
|
||||
|
||||
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> {
|
||||
let path = Path::new(path_str);
|
||||
|
@ -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 {
|
||||
|
@ -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