mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-26 00:24:55 +01:00
Clean up structure a bit
This commit is contained in:
parent
32894300f4
commit
b16c660058
@ -9,7 +9,9 @@ fn is_hidden(entry: &DirEntry) -> bool {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut compile_command = ::capnpc::CompilerCommand::new();
|
let mut compile_command = ::capnpc::CompilerCommand::new();
|
||||||
compile_command.src_prefix("schema");
|
compile_command
|
||||||
|
.src_prefix("schema")
|
||||||
|
.default_parent_module(vec!["schema".to_string()]);
|
||||||
|
|
||||||
for entry in WalkDir::new("schema")
|
for entry in WalkDir::new("schema")
|
||||||
.max_depth(2)
|
.max_depth(2)
|
||||||
@ -25,7 +27,8 @@ fn main() {
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
println!("Collecting schema file {}", entry.path().display());
|
println!("Collecting schema file {}", entry.path().display());
|
||||||
compile_command.file(entry.path());
|
compile_command
|
||||||
|
.file(entry.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Compiling schemas...");
|
println!("Compiling schemas...");
|
||||||
|
@ -1,41 +1,56 @@
|
|||||||
pub use capnpc::schema_capnp;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
//! FabAccess generated API bindings
|
||||||
pub mod auth_capnp {
|
//!
|
||||||
include!(concat!(env!("OUT_DIR"), "/auth_capnp.rs"));
|
//! This crate contains slightly nicer and better documented bindings for the FabAccess API.
|
||||||
|
|
||||||
|
|
||||||
|
mod schema;
|
||||||
|
|
||||||
|
/// Authentication subsystem
|
||||||
|
pub mod auth {
|
||||||
|
/// Session authentication
|
||||||
|
///
|
||||||
|
/// Authentication uses a SASL exchange. To bootstrap a connection you will need to call
|
||||||
|
/// `step` until you get a successful result
|
||||||
|
pub mod authentication {
|
||||||
|
pub use crate::schema::auth_capnp::authentication::*;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod response {
|
||||||
|
pub use crate::schema::auth_capnp::response::*;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
pub mod resource {
|
||||||
pub mod main_capnp {
|
pub use crate::schema::resource_capnp::*;
|
||||||
include!(concat!(env!("OUT_DIR"), "/main_capnp.rs"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
pub mod resources {
|
||||||
pub mod utils_capnp {
|
pub use crate::schema::resources_capnp::*;
|
||||||
include!(concat!(env!("OUT_DIR"), "/utils_capnp.rs"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
pub mod role {
|
||||||
pub mod resource_capnp {
|
pub use crate::schema::role_capnp::*;
|
||||||
include!(concat!(env!("OUT_DIR"), "/resource_capnp.rs"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
pub mod user {
|
||||||
pub mod resources_capnp {
|
pub use crate::schema::user_capnp::*;
|
||||||
include!(concat!(env!("OUT_DIR"), "/resources_capnp.rs"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
pub mod users {
|
||||||
pub mod role_capnp {
|
pub use crate::schema::users_capnp::*;
|
||||||
include!(concat!(env!("OUT_DIR"), "/role_capnp.rs"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
pub mod utils {
|
||||||
pub mod user_capnp {
|
pub mod uuid {
|
||||||
include!(concat!(env!("OUT_DIR"), "/user_capnp.rs"));
|
pub use crate::schema::utils_capnp::u_u_i_d::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
/// Localization String
|
||||||
pub mod users_capnp {
|
///
|
||||||
include!(concat!(env!("OUT_DIR"), "/users_capnp.rs"));
|
/// This is a specialized string that allows to access the string contents in different
|
||||||
|
/// languages
|
||||||
|
pub mod l10n_string {
|
||||||
|
pub use crate::schema::utils_capnp::l10_n_string::*;
|
||||||
|
}
|
||||||
}
|
}
|
41
api/src/schema.rs
Normal file
41
api/src/schema.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
pub use capnpc::schema_capnp;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod auth_capnp {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/auth_capnp.rs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod main_capnp {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/main_capnp.rs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod utils_capnp {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/utils_capnp.rs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod resource_capnp {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/resource_capnp.rs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod resources_capnp {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/resources_capnp.rs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod role_capnp {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/role_capnp.rs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod user_capnp {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/user_capnp.rs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod users_capnp {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/users_capnp.rs"));
|
||||||
|
}
|
@ -65,11 +65,11 @@ use std::sync::Arc;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use crate::db::user::User;
|
use crate::db::user::User;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use crate::state::{OwnedEntry, State};
|
use crate::resource::state::{OwnedEntry, State};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use crate::oid::{ArchivedObjectIdentifier, ObjectIdentifier};
|
use crate::utils::oid::{ArchivedObjectIdentifier, ObjectIdentifier};
|
||||||
use crate::state::value::SerializeValue;
|
use crate::resource::state::value::SerializeValue;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DBError {
|
pub enum DBError {
|
||||||
|
@ -24,7 +24,7 @@ use super::{
|
|||||||
LMDBorrow,
|
LMDBorrow,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::state::State;
|
use crate::resource::state::State;
|
||||||
|
|
||||||
type StateAdapter = AllocAdapter<State>;
|
type StateAdapter = AllocAdapter<State>;
|
||||||
|
|
||||||
@ -162,8 +162,8 @@ impl StateAccessor {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::state::value::Vec3u8;
|
use crate::resource::state::value::Vec3u8;
|
||||||
use crate::state::value::{OID_COLOUR, OID_POWERED, OID_INTENSITY};
|
use crate::resource::state::value::{OID_COLOUR, OID_POWERED, OID_INTENSITY};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
11
bffhd/lib.rs
11
bffhd/lib.rs
@ -11,14 +11,15 @@
|
|||||||
|
|
||||||
/// Internal Databases build on top of LMDB, a mmap()'ed B-tree DB optimized for reads
|
/// Internal Databases build on top of LMDB, a mmap()'ed B-tree DB optimized for reads
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|
||||||
/// Shared error type
|
/// Shared error type
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod oid;
|
|
||||||
/// Policy decision engine
|
/// Policy decision engine
|
||||||
pub mod permissions;
|
pub mod permissions;
|
||||||
|
|
||||||
/// Resources
|
/// Resources
|
||||||
pub mod resource;
|
pub mod resource;
|
||||||
/// State of Resources
|
pub mod resources;
|
||||||
pub mod state;
|
|
||||||
/// Varints
|
pub mod utils;
|
||||||
pub mod varint;
|
|
23
bffhd/resource/claim.rs
Normal file
23
bffhd/resource/claim.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
use async_channel::Sender;
|
||||||
|
use crate::resource::Update;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// A claim on a resource grants permission to update state
|
||||||
|
///
|
||||||
|
/// This permission is not necessarily exclusive, depending on the resource in question.
|
||||||
|
pub struct Claim {
|
||||||
|
/// Sending end that can be used to send state updates to a resource.
|
||||||
|
pub tx: Sender<Update>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// An interest on a resource indicates that an user wants a resource to be in a specific state
|
||||||
|
pub struct Interest {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// A notify indicates that an user wants to be informed about changes in a resources' state
|
||||||
|
pub struct Notify {
|
||||||
|
|
||||||
|
}
|
@ -5,11 +5,14 @@ use futures_signals::signal::Mutable;
|
|||||||
use async_oneshot::Sender;
|
use async_oneshot::Sender;
|
||||||
use async_channel::Receiver;
|
use async_channel::Receiver;
|
||||||
|
|
||||||
use crate::state::State;
|
use state::State;
|
||||||
use crate::db::{
|
use crate::db::{
|
||||||
state::StateAccessor,
|
state::StateAccessor,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub mod state;
|
||||||
|
pub mod claim;
|
||||||
|
|
||||||
/// A resource in BFFH has to contain several different parts;
|
/// A resource in BFFH has to contain several different parts;
|
||||||
/// - Currently set state
|
/// - Currently set state
|
||||||
/// - Execution state of attached actors (⇒ BFFH's job)
|
/// - Execution state of attached actors (⇒ BFFH's job)
|
||||||
@ -121,7 +124,7 @@ mod tests {
|
|||||||
|
|
||||||
#[futures_test::test]
|
#[futures_test::test]
|
||||||
async fn test_passthrough_is_id() {
|
async fn test_passthrough_is_id() {
|
||||||
let inp = crate::state::tests::gen_random();
|
let inp = state::tests::gen_random();
|
||||||
|
|
||||||
let mut res = Passthrough;
|
let mut res = Passthrough;
|
||||||
let out = res.on_update(&inp).await.unwrap();
|
let out = res.on_update(&inp).await.unwrap();
|
@ -1,34 +1,31 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
collections::hash_map::DefaultHasher,
|
||||||
fmt,
|
fmt,
|
||||||
|
|
||||||
collections::{
|
|
||||||
hash_map::DefaultHasher
|
|
||||||
},
|
|
||||||
hash::{
|
hash::{
|
||||||
Hash,
|
Hash,
|
||||||
Hasher
|
Hasher
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use std::fmt::Formatter;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
use rkyv::{
|
use rkyv::{
|
||||||
Archive,
|
Archive,
|
||||||
Archived,
|
Archived,
|
||||||
|
|
||||||
Serialize,
|
|
||||||
Deserialize,
|
Deserialize,
|
||||||
|
|
||||||
out_field,
|
out_field,
|
||||||
|
Serialize,
|
||||||
};
|
};
|
||||||
|
use serde::de::{Error, MapAccess};
|
||||||
|
use serde::Deserializer;
|
||||||
|
use serde::ser::SerializeMap;
|
||||||
|
|
||||||
|
use value::{RegisteredImpl, SerializeValue};
|
||||||
|
|
||||||
|
use crate::utils::oid::ObjectIdentifier;
|
||||||
|
use crate::resource::state::value::{DynOwnedVal, DynVal, TypeOid, };
|
||||||
|
|
||||||
pub mod value;
|
pub mod value;
|
||||||
use value::{SerializeValue, RegisteredImpl};
|
|
||||||
use crate::state::value::{TypeOid, DynVal, DynOwnedVal, };
|
|
||||||
use crate::oid::ObjectIdentifier;
|
|
||||||
use serde::ser::SerializeMap;
|
|
||||||
use std::ops::Deref;
|
|
||||||
use std::fmt::Formatter;
|
|
||||||
use serde::Deserializer;
|
|
||||||
use serde::de::{Error, MapAccess};
|
|
||||||
|
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
#[derive(Archive, Serialize, Deserialize)]
|
#[derive(Archive, Serialize, Deserialize)]
|
||||||
@ -177,14 +174,14 @@ impl<'de> serde::de::Visitor<'de> for OwnedEntryVisitor {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::state::value::*;
|
use super::value::*;
|
||||||
|
|
||||||
pub(crate) fn gen_random() -> State {
|
pub(crate) fn gen_random() -> State {
|
||||||
let amt: u8 = rand::random::<u8>() % 20;
|
let amt: u8 = rand::random::<u8>() % 20;
|
||||||
|
|
||||||
let mut sb = State::build();
|
let mut sb = State::build();
|
||||||
for _ in 0..amt {
|
for _ in 0..amt {
|
||||||
let oid = crate::oid::tests::gen_random();
|
let oid = crate::utils::oid::tests::gen_random();
|
||||||
sb = match rand::random::<u32>()%12 {
|
sb = match rand::random::<u32>()%12 {
|
||||||
0 => sb.add(oid, Box::new(rand::random::<bool>())),
|
0 => sb.add(oid, Box::new(rand::random::<bool>())),
|
||||||
1 => sb.add(oid, Box::new(rand::random::<u8>())),
|
1 => sb.add(oid, Box::new(rand::random::<u8>())),
|
@ -14,7 +14,7 @@ use rkyv_typename::TypeName;
|
|||||||
use ptr_meta::{DynMetadata, Pointee};
|
use ptr_meta::{DynMetadata, Pointee};
|
||||||
|
|
||||||
use inventory;
|
use inventory;
|
||||||
use crate::oid::{ObjectIdentifier};
|
use crate::utils::oid::{ObjectIdentifier};
|
||||||
use rkyv::ser::{Serializer, ScratchSpace};
|
use rkyv::ser::{Serializer, ScratchSpace};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
@ -577,10 +577,10 @@ oidvalue!(OID_VEC3U8, Vec3u8, ArchivedVec3u8);
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use super::*;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand::distributions::Standard;
|
use rand::distributions::Standard;
|
||||||
use rand::prelude::Distribution;
|
use rand::prelude::Distribution;
|
||||||
use crate::state::value::Vec3u8;
|
|
||||||
|
|
||||||
impl Distribution<Vec3u8> for Standard {
|
impl Distribution<Vec3u8> for Standard {
|
||||||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Vec3u8 {
|
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Vec3u8 {
|
5
bffhd/resources.rs
Normal file
5
bffhd/resources.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Resources {
|
||||||
|
|
||||||
|
}
|
5
bffhd/utils/mod.rs
Normal file
5
bffhd/utils/mod.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/// ITU Object Identifier implementation
|
||||||
|
pub mod oid;
|
||||||
|
|
||||||
|
/// Variable sized integer types
|
||||||
|
pub mod varint;
|
@ -1,4 +1,4 @@
|
|||||||
//! oid crate by <https://github.com/UnnecessaryEngineering/oid> turned into vendore'd module
|
//! oid crate by <https://github.com/UnnecessaryEngineering/oid> turned into vendored module
|
||||||
//!
|
//!
|
||||||
//! [Object Identifiers] are a standard of the [ITU] used to reference objects, things, and
|
//! [Object Identifiers] are a standard of the [ITU] used to reference objects, things, and
|
||||||
//! concepts in a globally unique way. This crate provides for data structures and methods
|
//! concepts in a globally unique way. This crate provides for data structures and methods
|
||||||
@ -61,7 +61,7 @@ use std::fmt;
|
|||||||
use std::fmt::Formatter;
|
use std::fmt::Formatter;
|
||||||
use rkyv::ser::Serializer;
|
use rkyv::ser::Serializer;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use crate::varint::VarU128;
|
use crate::utils::varint::VarU128;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
type Node = u128;
|
type Node = u128;
|
Loading…
Reference in New Issue
Block a user