provider and verifier

This commit is contained in:
DieMyst 2020-12-23 18:41:37 +03:00
parent 888d7a8937
commit 213288ddbd
10 changed files with 140 additions and 19 deletions

View File

@ -1,6 +1,11 @@
modules_dir = "artifacts/"
[[module]]
name = "rbac"
name = "rbac_verifier"
mem_pages_count = 1
logger_enabled = true
[[module]]
name = "rbac_provider"
mem_pages_count = 1
logger_enabled = true

Binary file not shown.

View File

@ -1,2 +1,11 @@
(
cd provider
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/
)

View File

@ -1,11 +1,11 @@
[package]
name = "wasm-greeting"
name = "rbac_provider"
version = "0.1.0"
authors = ["Fluence Labs"]
edition = "2018"
[[bin]]
name = "rbac"
name = "rbac_provider"
path = "src/main.rs"
[dependencies]

6
provider/Config.toml Normal file
View File

@ -0,0 +1,6 @@
modules_dir = "artifacts/"
[[module]]
name = "rbac_provider"
mem_pages_count = 1
logger_enabled = true

View File

@ -14,9 +14,6 @@
* limitations under the License.
*/
#![feature(once_cell)]
use fluence::fce;
use fluence::WasmLoggerBuilder;
@ -24,14 +21,14 @@ use std::collections::HashMap;
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
static INSTANCE: OnceCell<Mutex<HashMap<String, Status>>> = OnceCell::new();
#[fce]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Status {
pub is_registered: bool
}
static INSTANCE: OnceCell<Mutex<HashMap<String, Status>>> = OnceCell::new();
fn global_data() -> &'static Mutex<HashMap<String, Status>> {
INSTANCE.get_or_init(|| {
<_>::default()

View File

@ -198,6 +198,16 @@ dependencies = [
"rand_core",
]
[[package]]
name = "rbac_verifier"
version = "0.1.0"
dependencies = [
"fluence",
"log",
"once_cell",
"parking_lot",
]
[[package]]
name = "redox_syscall"
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"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasm-greeting"
version = "0.1.0"
dependencies = [
"fluence",
"log",
"once_cell",
"parking_lot",
]
[[package]]
name = "winapi"
version = "0.3.9"

15
verifier/Cargo.toml Normal file
View 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
View 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
View 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;
}
}
}