mirror of
https://github.com/fluencelabs/rbac
synced 2025-05-29 02:51:20 +00:00
provider and verifier
This commit is contained in:
parent
888d7a8937
commit
213288ddbd
@ -1,6 +1,11 @@
|
|||||||
modules_dir = "artifacts/"
|
modules_dir = "artifacts/"
|
||||||
|
|
||||||
[[module]]
|
[[module]]
|
||||||
name = "rbac"
|
name = "rbac_verifier"
|
||||||
|
mem_pages_count = 1
|
||||||
|
logger_enabled = true
|
||||||
|
|
||||||
|
[[module]]
|
||||||
|
name = "rbac_provider"
|
||||||
mem_pages_count = 1
|
mem_pages_count = 1
|
||||||
logger_enabled = true
|
logger_enabled = true
|
||||||
|
Binary file not shown.
11
build.sh
11
build.sh
@ -1,2 +1,11 @@
|
|||||||
|
(
|
||||||
|
cd provider
|
||||||
fce build
|
fce build
|
||||||
cp target/wasm32-wasi/debug/rbac.wasm artifacts/
|
cp target/wasm32-wasi/debug/rbac_provider.wasm ../artifacts/
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
cd verifier
|
||||||
|
fce build
|
||||||
|
cp target/wasm32-wasi/debug/rbac_verifier.wasm ../artifacts/
|
||||||
|
)
|
@ -1,11 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasm-greeting"
|
name = "rbac_provider"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "rbac"
|
name = "rbac_provider"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
6
provider/Config.toml
Normal file
6
provider/Config.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
modules_dir = "artifacts/"
|
||||||
|
|
||||||
|
[[module]]
|
||||||
|
name = "rbac_provider"
|
||||||
|
mem_pages_count = 1
|
||||||
|
logger_enabled = true
|
@ -14,9 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#![feature(once_cell)]
|
|
||||||
|
|
||||||
use fluence::fce;
|
use fluence::fce;
|
||||||
use fluence::WasmLoggerBuilder;
|
use fluence::WasmLoggerBuilder;
|
||||||
|
|
||||||
@ -24,14 +21,14 @@ use std::collections::HashMap;
|
|||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
static INSTANCE: OnceCell<Mutex<HashMap<String, Status>>> = OnceCell::new();
|
|
||||||
|
|
||||||
#[fce]
|
#[fce]
|
||||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||||
pub struct Status {
|
pub struct Status {
|
||||||
pub is_registered: bool
|
pub is_registered: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static INSTANCE: OnceCell<Mutex<HashMap<String, Status>>> = OnceCell::new();
|
||||||
|
|
||||||
fn global_data() -> &'static Mutex<HashMap<String, Status>> {
|
fn global_data() -> &'static Mutex<HashMap<String, Status>> {
|
||||||
INSTANCE.get_or_init(|| {
|
INSTANCE.get_or_init(|| {
|
||||||
<_>::default()
|
<_>::default()
|
20
Cargo.lock → verifier/Cargo.lock
generated
20
Cargo.lock → verifier/Cargo.lock
generated
@ -198,6 +198,16 @@ dependencies = [
|
|||||||
"rand_core",
|
"rand_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rbac_verifier"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"fluence",
|
||||||
|
"log",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.1.57"
|
version = "0.1.57"
|
||||||
@ -285,16 +295,6 @@ version = "0.9.0+wasi-snapshot-preview1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-greeting"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"fluence",
|
|
||||||
"log",
|
|
||||||
"once_cell",
|
|
||||||
"parking_lot",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
15
verifier/Cargo.toml
Normal file
15
verifier/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "rbac_verifier"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Fluence Labs"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "rbac_verifier"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
fluence = { git = "https://github.com/fluencelabs/rust-sdk", features = ["logger"] }
|
||||||
|
log = "0.4.11"
|
||||||
|
once_cell = "1.5.2"
|
||||||
|
parking_lot = "0.11.1"
|
6
verifier/Config.toml
Normal file
6
verifier/Config.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
modules_dir = "artifacts/"
|
||||||
|
|
||||||
|
[[module]]
|
||||||
|
name = "rbac_verifier"
|
||||||
|
mem_pages_count = 1
|
||||||
|
logger_enabled = true
|
83
verifier/src/main.rs
Normal file
83
verifier/src/main.rs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Fluence Labs Limited
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#![feature(once_cell)]
|
||||||
|
|
||||||
|
use fluence::fce;
|
||||||
|
use fluence::WasmLoggerBuilder;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
use fluence::CallParameters;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
static INSTANCE: OnceCell<Mutex<Option<Tetraplet>>> = OnceCell::new();
|
||||||
|
|
||||||
|
#[fce]
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||||
|
pub struct Tetraplet {
|
||||||
|
pub peer_pk: String,
|
||||||
|
pub service_id: String,
|
||||||
|
pub fn_name: String,
|
||||||
|
pub json_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn global_data() -> &'static Mutex<Option<Tetraplet>> {
|
||||||
|
INSTANCE.get_or_init(|| {
|
||||||
|
<_>::default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
WasmLoggerBuilder::new()
|
||||||
|
.with_log_level(log::Level::Info)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[fce]
|
||||||
|
pub fn set_tetraplet(peer_id: String, service_id: String, fn_name: String, path: String) {
|
||||||
|
let mut data = global_data().lock();
|
||||||
|
|
||||||
|
let tetraplet = Tetraplet {
|
||||||
|
peer_pk: peer_id,
|
||||||
|
service_id,
|
||||||
|
fn_name,
|
||||||
|
json_path: path,
|
||||||
|
};
|
||||||
|
|
||||||
|
data.replace(tetraplet);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[fce]
|
||||||
|
pub fn is_authorized(auth: bool) -> bool {
|
||||||
|
let data = global_data().lock();
|
||||||
|
|
||||||
|
match data.deref() {
|
||||||
|
None => false,
|
||||||
|
Some(t) => {
|
||||||
|
let call_parameters: CallParameters = fluence::get_call_parameters();
|
||||||
|
let st = &call_parameters.tetraplets[0][0];
|
||||||
|
|
||||||
|
return st.peer_pk == t.peer_pk && st.function_name == t.fn_name
|
||||||
|
&& st.service_id == t.service_id &&
|
||||||
|
st.json_path == t.json_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user