mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-11 01:53:23 +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",
|
"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]]
|
[[package]]
|
||||||
name = "async-std"
|
name = "async-std"
|
||||||
version = "1.10.0"
|
version = "1.10.0"
|
||||||
@ -828,6 +839,7 @@ dependencies = [
|
|||||||
"async-channel",
|
"async-channel",
|
||||||
"async-native-tls",
|
"async-native-tls",
|
||||||
"async-oneshot",
|
"async-oneshot",
|
||||||
|
"async-rustls",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"bincode",
|
"bincode",
|
||||||
"capnp",
|
"capnp",
|
||||||
@ -843,6 +855,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
"lmdb-rkv",
|
"lmdb-rkv",
|
||||||
|
"once_cell",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
"ptr_meta",
|
"ptr_meta",
|
||||||
"rand",
|
"rand",
|
||||||
@ -851,6 +864,7 @@ dependencies = [
|
|||||||
"rkyv_typename",
|
"rkyv_typename",
|
||||||
"rsasl",
|
"rsasl",
|
||||||
"rust-argon2",
|
"rust-argon2",
|
||||||
|
"rustls 0.20.2",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_dhall",
|
"serde_dhall",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -2019,6 +2033,21 @@ dependencies = [
|
|||||||
"bytecheck",
|
"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]]
|
[[package]]
|
||||||
name = "rkyv"
|
name = "rkyv"
|
||||||
version = "0.7.20"
|
version = "0.7.20"
|
||||||
@ -2127,6 +2156,31 @@ dependencies = [
|
|||||||
"semver",
|
"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]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.5"
|
version = "1.0.5"
|
||||||
@ -2158,6 +2212,26 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
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]]
|
[[package]]
|
||||||
name = "sdk"
|
name = "sdk"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -2356,6 +2430,12 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spin"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stable_deref_trait"
|
name = "stable_deref_trait"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@ -2615,6 +2695,12 @@ version = "0.2.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "untrusted"
|
||||||
|
version = "0.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "url"
|
name = "url"
|
||||||
version = "2.2.2"
|
version = "2.2.2"
|
||||||
@ -2764,6 +2850,26 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"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]]
|
[[package]]
|
||||||
name = "wepoll-ffi"
|
name = "wepoll-ffi"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
@ -78,6 +78,11 @@ erased-serde = "0.3"
|
|||||||
serde_dhall = { version = "0.10.1", default-features = false }
|
serde_dhall = { version = "0.10.1", default-features = false }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
||||||
|
once_cell = "1.8"
|
||||||
|
|
||||||
|
rustls = "0.20"
|
||||||
|
async-rustls = "0.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures-test = "0.3.16"
|
futures-test = "0.3.16"
|
||||||
tempfile = "3.2"
|
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};
|
use rkyv::{Fallible, Serialize, ser::serializers::AllocSerializer, AlignedVec, Archived};
|
||||||
|
|
||||||
mod raw;
|
mod raw;
|
||||||
use raw::RawDB;
|
pub use raw::RawDB;
|
||||||
|
|
||||||
mod typed;
|
mod typed;
|
||||||
// re-exports
|
// re-exports
|
||||||
@ -38,11 +38,6 @@ pub use hash::{
|
|||||||
mod fix;
|
mod fix;
|
||||||
pub use fix::LMDBorrow;
|
pub use fix::LMDBorrow;
|
||||||
|
|
||||||
pub mod state;
|
|
||||||
pub use state::{
|
|
||||||
StateDB,
|
|
||||||
};
|
|
||||||
|
|
||||||
mod resources;
|
mod resources;
|
||||||
pub use resources::{
|
pub use resources::{
|
||||||
ResourceDB,
|
ResourceDB,
|
||||||
@ -53,19 +48,14 @@ pub use pass::{
|
|||||||
PassDB,
|
PassDB,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod user;
|
|
||||||
pub use user::{
|
|
||||||
UserDB,
|
|
||||||
};
|
|
||||||
|
|
||||||
use lmdb::Error;
|
use lmdb::Error;
|
||||||
use rkyv::Deserialize;
|
use rkyv::Deserialize;
|
||||||
use rkyv::ser::serializers::AlignedSerializer;
|
use rkyv::ser::serializers::AlignedSerializer;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use crate::db::user::User;
|
use crate::users::db::{User, UserDB};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use crate::resource::state::{OwnedEntry, State};
|
use crate::resource::state::{OwnedEntry, State, db::StateDB};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use crate::utils::oid::{ArchivedObjectIdentifier, ObjectIdentifier};
|
use crate::utils::oid::{ArchivedObjectIdentifier, ObjectIdentifier};
|
||||||
@ -87,7 +77,7 @@ impl From<lmdb::Error> for DBError {
|
|||||||
|
|
||||||
type Ser = AllocSerializer<1024>;
|
type Ser = AllocSerializer<1024>;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct AllocAdapter<V> {
|
pub struct AllocAdapter<V> {
|
||||||
phantom: PhantomData<V>,
|
phantom: PhantomData<V>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,12 @@ pub mod error;
|
|||||||
/// Policy decision engine
|
/// Policy decision engine
|
||||||
pub mod permissions;
|
pub mod permissions;
|
||||||
|
|
||||||
|
pub mod users;
|
||||||
|
|
||||||
/// Resources
|
/// Resources
|
||||||
pub mod resource;
|
pub mod resource;
|
||||||
pub mod resources;
|
pub mod resources;
|
||||||
|
|
||||||
|
pub mod server;
|
||||||
|
|
||||||
pub mod utils;
|
pub mod utils;
|
@ -6,13 +6,12 @@ use async_oneshot::Sender;
|
|||||||
use async_channel::Receiver;
|
use async_channel::Receiver;
|
||||||
|
|
||||||
use state::State;
|
use state::State;
|
||||||
use crate::db::{
|
use state::db::StateAccessor;
|
||||||
state::StateAccessor,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub mod state;
|
pub mod state;
|
||||||
pub mod claim;
|
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)
|
||||||
|
@ -5,7 +5,7 @@ use std::{
|
|||||||
|
|
||||||
use rkyv::{Archived};
|
use rkyv::{Archived};
|
||||||
|
|
||||||
use super::{
|
use crate::db::{
|
||||||
DB,
|
DB,
|
||||||
Environment,
|
Environment,
|
||||||
|
|
@ -26,6 +26,7 @@ use crate::utils::oid::ObjectIdentifier;
|
|||||||
use crate::resource::state::value::{DynOwnedVal, DynVal, TypeOid, };
|
use crate::resource::state::value::{DynOwnedVal, DynVal, TypeOid, };
|
||||||
|
|
||||||
pub mod value;
|
pub mod value;
|
||||||
|
pub mod db;
|
||||||
|
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
#[derive(Archive, Serialize, 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 std::sync::Arc;
|
||||||
use super::{DB, AllocAdapter, Environment, Result};
|
use crate::db::{RawDB, DB, AllocAdapter, Environment, Result};
|
||||||
use crate::db::raw::RawDB;
|
|
||||||
use crate::db::{DatabaseFlags, LMDBorrow, RoTransaction, WriteFlags, };
|
use crate::db::{DatabaseFlags, LMDBorrow, RoTransaction, WriteFlags, };
|
||||||
|
|
||||||
use rkyv::{Archive, Serialize, Deserialize, Archived};
|
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(())
|
||||||
|
}
|
||||||
|
}
|
@ -3,3 +3,8 @@ pub mod oid;
|
|||||||
|
|
||||||
/// Variable sized integer types
|
/// 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