mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-12-22 11:43:49 +01:00
DB Refactor
This commit is contained in:
parent
b16c660058
commit
26b2888a09
106
Cargo.lock
generated
106
Cargo.lock
generated
@ -241,6 +241,17 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-rustls"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c86f33abd5a4f3e2d6d9251a9e0c6a7e52eb1113caf893dae8429bf4a53f378"
|
||||
dependencies = [
|
||||
"futures-lite",
|
||||
"rustls 0.19.1",
|
||||
"webpki 0.21.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-std"
|
||||
version = "1.10.0"
|
||||
@ -828,6 +839,7 @@ dependencies = [
|
||||
"async-channel",
|
||||
"async-native-tls",
|
||||
"async-oneshot",
|
||||
"async-rustls",
|
||||
"async-trait",
|
||||
"bincode",
|
||||
"capnp",
|
||||
@ -843,6 +855,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"lmdb-rkv",
|
||||
"once_cell",
|
||||
"pin-utils",
|
||||
"ptr_meta",
|
||||
"rand",
|
||||
@ -851,6 +864,7 @@ dependencies = [
|
||||
"rkyv_typename",
|
||||
"rsasl",
|
||||
"rust-argon2",
|
||||
"rustls 0.20.2",
|
||||
"serde",
|
||||
"serde_dhall",
|
||||
"serde_json",
|
||||
@ -2019,6 +2033,21 @@ dependencies = [
|
||||
"bytecheck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.16.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"spin",
|
||||
"untrusted",
|
||||
"web-sys",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rkyv"
|
||||
version = "0.7.20"
|
||||
@ -2127,6 +2156,31 @@ dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"log",
|
||||
"ring",
|
||||
"sct 0.6.1",
|
||||
"webpki 0.21.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d37e5e2290f3e040b594b1a9e04377c2c671f1a1cfd9bfdef82106ac1c113f84"
|
||||
dependencies = [
|
||||
"log",
|
||||
"ring",
|
||||
"sct 0.7.0",
|
||||
"webpki 0.22.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
@ -2158,6 +2212,26 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "sct"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sct"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sdk"
|
||||
version = "0.1.0"
|
||||
@ -2356,6 +2430,12 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "stable_deref_trait"
|
||||
version = "1.2.0"
|
||||
@ -2615,6 +2695,12 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "untrusted"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.2.2"
|
||||
@ -2764,6 +2850,26 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki"
|
||||
version = "0.21.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki"
|
||||
version = "0.22.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wepoll-ffi"
|
||||
version = "0.1.2"
|
||||
|
@ -78,6 +78,11 @@ erased-serde = "0.3"
|
||||
serde_dhall = { version = "0.10.1", default-features = false }
|
||||
serde_json = "1.0"
|
||||
|
||||
once_cell = "1.8"
|
||||
|
||||
rustls = "0.20"
|
||||
async-rustls = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
futures-test = "0.3.16"
|
||||
tempfile = "3.2"
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit f713df2221727f2f9535be4c4c9ae36de77c1a63
|
||||
Subproject commit a13478a3f00d6f00580dc344d3a697d90bc50377
|
18
bffhd/db.rs
18
bffhd/db.rs
@ -17,7 +17,7 @@ pub use lmdb::{
|
||||
use rkyv::{Fallible, Serialize, ser::serializers::AllocSerializer, AlignedVec, Archived};
|
||||
|
||||
mod raw;
|
||||
use raw::RawDB;
|
||||
pub use raw::RawDB;
|
||||
|
||||
mod typed;
|
||||
// re-exports
|
||||
@ -38,11 +38,6 @@ pub use hash::{
|
||||
mod fix;
|
||||
pub use fix::LMDBorrow;
|
||||
|
||||
pub mod state;
|
||||
pub use state::{
|
||||
StateDB,
|
||||
};
|
||||
|
||||
mod resources;
|
||||
pub use resources::{
|
||||
ResourceDB,
|
||||
@ -53,19 +48,14 @@ pub use pass::{
|
||||
PassDB,
|
||||
};
|
||||
|
||||
mod user;
|
||||
pub use user::{
|
||||
UserDB,
|
||||
};
|
||||
|
||||
use lmdb::Error;
|
||||
use rkyv::Deserialize;
|
||||
use rkyv::ser::serializers::AlignedSerializer;
|
||||
use std::sync::Arc;
|
||||
use std::path::Path;
|
||||
use crate::db::user::User;
|
||||
use crate::users::db::{User, UserDB};
|
||||
use std::collections::HashMap;
|
||||
use crate::resource::state::{OwnedEntry, State};
|
||||
use crate::resource::state::{OwnedEntry, State, db::StateDB};
|
||||
use std::iter::FromIterator;
|
||||
use std::ops::Deref;
|
||||
use crate::utils::oid::{ArchivedObjectIdentifier, ObjectIdentifier};
|
||||
@ -87,7 +77,7 @@ impl From<lmdb::Error> for DBError {
|
||||
|
||||
type Ser = AllocSerializer<1024>;
|
||||
#[derive(Clone)]
|
||||
struct AllocAdapter<V> {
|
||||
pub struct AllocAdapter<V> {
|
||||
phantom: PhantomData<V>,
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,12 @@ pub mod error;
|
||||
/// Policy decision engine
|
||||
pub mod permissions;
|
||||
|
||||
pub mod users;
|
||||
|
||||
/// Resources
|
||||
pub mod resource;
|
||||
pub mod resources;
|
||||
|
||||
pub mod server;
|
||||
|
||||
pub mod utils;
|
@ -6,13 +6,12 @@ use async_oneshot::Sender;
|
||||
use async_channel::Receiver;
|
||||
|
||||
use state::State;
|
||||
use crate::db::{
|
||||
state::StateAccessor,
|
||||
};
|
||||
use state::db::StateAccessor;
|
||||
|
||||
pub mod state;
|
||||
pub mod claim;
|
||||
|
||||
|
||||
/// A resource in BFFH has to contain several different parts;
|
||||
/// - Currently set state
|
||||
/// - Execution state of attached actors (⇒ BFFH's job)
|
||||
|
@ -5,7 +5,7 @@ use std::{
|
||||
|
||||
use rkyv::{Archived};
|
||||
|
||||
use super::{
|
||||
use crate::db::{
|
||||
DB,
|
||||
Environment,
|
||||
|
@ -26,6 +26,7 @@ use crate::utils::oid::ObjectIdentifier;
|
||||
use crate::resource::state::value::{DynOwnedVal, DynVal, TypeOid, };
|
||||
|
||||
pub mod value;
|
||||
pub mod db;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Archive, Serialize, Deserialize)]
|
||||
|
2
bffhd/server/mod.rs
Normal file
2
bffhd/server/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
mod tls;
|
0
bffhd/server/tls.rs
Normal file
0
bffhd/server/tls.rs
Normal file
@ -1,6 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
use super::{DB, AllocAdapter, Environment, Result};
|
||||
use crate::db::raw::RawDB;
|
||||
use crate::db::{RawDB, DB, AllocAdapter, Environment, Result};
|
||||
use crate::db::{DatabaseFlags, LMDBorrow, RoTransaction, WriteFlags, };
|
||||
|
||||
use rkyv::{Archive, Serialize, Deserialize, Archived};
|
2
bffhd/users/mod.rs
Normal file
2
bffhd/users/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
pub mod db;
|
61
bffhd/utils/l10nstring.rs
Normal file
61
bffhd/utils/l10nstring.rs
Normal file
@ -0,0 +1,61 @@
|
||||
use std::collections::HashMap;
|
||||
use capnp::capability::Promise;
|
||||
use capnp::Error;
|
||||
use capnp_rpc::pry;
|
||||
use once_cell::sync::Lazy;
|
||||
use api::utils::l10n_string as l10n;
|
||||
|
||||
struct Locales {
|
||||
map: HashMap<&'static str, HashMap<&'static str, &'static str>>
|
||||
}
|
||||
|
||||
impl Locales {
|
||||
pub fn get(&self, lang: &str, msg: &str)
|
||||
-> Option<(&'static str, &'static str)>
|
||||
{
|
||||
self.map.get(msg).and_then(|map| {
|
||||
map.get_key_value(lang).map(|(k,v)| (*k, *v))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn available(&self, _msg: &str) -> &[&'static str] {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
|
||||
static LANG: Lazy<Locales> = Lazy::new(|| {
|
||||
Locales { map: HashMap::new() }
|
||||
});
|
||||
|
||||
struct L10NString {
|
||||
msg: &'static str,
|
||||
}
|
||||
|
||||
impl l10n::Server for L10NString {
|
||||
fn get(&mut self, params: l10n::GetParams, mut results: l10n::GetResults)
|
||||
-> Promise<(), Error>
|
||||
{
|
||||
let lang = pry!(pry!(params.get()).get_lang());
|
||||
|
||||
if let Some((lang, content)) = LANG.get(lang, &self.msg) {
|
||||
let mut builder = results.get();
|
||||
builder.set_lang(lang);
|
||||
builder.set_content(content);
|
||||
}
|
||||
|
||||
Promise::ok(())
|
||||
}
|
||||
|
||||
fn available(&mut self, _: l10n::AvailableParams, mut results: l10n::AvailableResults)
|
||||
-> Promise<(), Error>
|
||||
{
|
||||
let langs = LANG.available(self.msg);
|
||||
let builder = results.get();
|
||||
let mut lb = builder.init_langs(langs.len() as u32);
|
||||
for (n, lang) in langs.into_iter().enumerate() {
|
||||
lb.reborrow().set(n as u32, *lang);
|
||||
}
|
||||
|
||||
Promise::ok(())
|
||||
}
|
||||
}
|
@ -2,4 +2,9 @@
|
||||
pub mod oid;
|
||||
|
||||
/// Variable sized integer types
|
||||
pub mod varint;
|
||||
pub mod varint;
|
||||
|
||||
/// Localization strings
|
||||
pub mod l10nstring;
|
||||
|
||||
pub mod uuid;
|
20
bffhd/utils/uuid.rs
Normal file
20
bffhd/utils/uuid.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use uuid::Uuid;
|
||||
use api::utils::uuid::{Builder, Reader};
|
||||
|
||||
pub fn uuid_to_api(uuid: Uuid, mut builder: Builder) {
|
||||
let [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p]
|
||||
= uuid.as_u128().to_ne_bytes();
|
||||
let lower = u64::from_ne_bytes([a,b,c,d,e,f,g,h]);
|
||||
let upper = u64::from_ne_bytes([i,j,k,l,m,n,o,p]);
|
||||
builder.set_lower(lower);
|
||||
builder.set_upper(upper);
|
||||
}
|
||||
|
||||
pub fn api_to_uuid(reader: Reader) -> Uuid {
|
||||
let lower: u64 = reader.reborrow().get_lower();
|
||||
let upper: u64 = reader.get_upper();
|
||||
let [a,b,c,d,e,f,g,h] = lower.to_ne_bytes();
|
||||
let [i,j,k,l,m,n,o,p] = upper.to_ne_bytes();
|
||||
let num = u128::from_ne_bytes([a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p]);
|
||||
Uuid::from_u128(num)
|
||||
}
|
Loading…
Reference in New Issue
Block a user