-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* basic implementation of effector stream on runtime-async-std, runtime-tokio * resolve runtime-async-std warnings * resolve runtime-tokio warnings * fix casbin::error::Error * bump version
- Loading branch information
Showing
5 changed files
with
127 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "casbin" | ||
version = "0.7.6" | ||
version = "0.8.0" | ||
authors = ["Joey <[email protected]>", "Cheng JIANG <[email protected]>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
|
@@ -29,8 +29,8 @@ thiserror = "1.0.14" | |
[features] | ||
default = ["runtime-async-std", "incremental"] | ||
|
||
runtime-tokio = ["tokio/fs", "tokio/io-util"] | ||
runtime-async-std = ["async-std"] | ||
runtime-tokio = ["tokio/fs", "tokio/io-util", "tokio/sync"] | ||
runtime-async-std = ["async-std/std", "async-std/unstable"] | ||
logging = ["log"] | ||
ip = ["ip_network"] | ||
glob = ["globset"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,90 @@ | ||
use async_trait::async_trait; | ||
|
||
#[cfg(feature = "runtime-async-std")] | ||
use async_std::{sync::Receiver, task}; | ||
|
||
#[cfg(feature = "runtime-tokio")] | ||
use tokio::{sync::mpsc::Receiver, task}; | ||
|
||
#[async_trait] | ||
pub trait Effector: Send + Sync { | ||
fn merge_effects(&self, expr: &str, effects: Vec<EffectKind>) -> bool; | ||
#[allow(unused_mut)] | ||
async fn merge_effects(&self, expr: &str, rx: Receiver<EffectKind>) -> bool; | ||
fn clone_box(&self) -> Box<dyn Effector>; | ||
} | ||
|
||
#[derive(PartialEq, Clone)] | ||
#[derive(PartialEq, Clone, Debug)] | ||
pub enum EffectKind { | ||
Allow = 0, | ||
Indeterminate = 1, | ||
Deny = 2, | ||
} | ||
|
||
#[derive(Default)] | ||
#[derive(Default, Clone)] | ||
pub struct DefaultEffector; | ||
|
||
#[async_trait] | ||
impl Effector for DefaultEffector { | ||
fn merge_effects(&self, expr: &str, effects: Vec<EffectKind>) -> bool { | ||
if expr == "some(where (p_eft == allow))" { | ||
let mut result = false; | ||
for eft in effects { | ||
if eft == EffectKind::Allow { | ||
result = true; | ||
break; | ||
} | ||
} | ||
|
||
result | ||
} else if expr == "!some(where (p_eft == deny))" { | ||
let mut result = true; | ||
for eft in effects { | ||
if eft == EffectKind::Deny { | ||
result = false; | ||
break; | ||
} | ||
} | ||
|
||
result | ||
} else if expr == "some(where (p_eft == allow)) && !some(where (p_eft == deny))" { | ||
let mut result = false; | ||
for eft in effects { | ||
if eft == EffectKind::Allow { | ||
result = true; | ||
} else if eft == EffectKind::Deny { | ||
result = false; | ||
break; | ||
} | ||
} | ||
#[allow(unused_mut)] | ||
async fn merge_effects(&self, expr: &str, mut rx: Receiver<EffectKind>) -> bool { | ||
let expr = expr.to_string(); | ||
let fut = task::spawn(async move { | ||
let mut result = match &*expr { | ||
"some(where (p_eft == allow))" | ||
| "some(where (p_eft == allow)) && !some(where (p_eft == deny))" | ||
| "priority(p_eft) || deny" => false, | ||
"!some(where (p_eft == deny))" => true, | ||
_ => panic!("unsupported effect: `{}`", expr), | ||
}; | ||
|
||
result | ||
} else if expr == "priority(p_eft) || deny" { | ||
let mut result = false; | ||
for eft in effects { | ||
if eft != EffectKind::Indeterminate { | ||
while let Some(eft) = rx.recv().await { | ||
if &expr == "some(where (p_eft == allow))" { | ||
if eft == EffectKind::Allow { | ||
result = true; | ||
break; | ||
} | ||
} else if &expr == "!some(where (p_eft == deny))" { | ||
if eft == EffectKind::Deny { | ||
result = false; | ||
break; | ||
} | ||
} else if &expr == "some(where (p_eft == allow)) && !some(where (p_eft == deny))" { | ||
if eft == EffectKind::Allow { | ||
result = true | ||
} else { | ||
result = false | ||
result = true; | ||
} else if eft == EffectKind::Deny { | ||
result = false; | ||
break; | ||
} | ||
} else if &expr == "priority(p_eft) || deny" { | ||
if eft != EffectKind::Indeterminate { | ||
if eft == EffectKind::Allow { | ||
result = true | ||
} else { | ||
result = false | ||
} | ||
break; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
result | ||
} else { | ||
panic!("unsupported effect: `{}`", expr); | ||
}); | ||
|
||
#[cfg(feature = "runtime-async-std")] | ||
{ | ||
fut.await | ||
} | ||
|
||
#[cfg(feature = "runtime-tokio")] | ||
{ | ||
match fut.await { | ||
Ok(result) => result, | ||
Err(err) => panic!("effector stream error: {}", err), | ||
} | ||
} | ||
} | ||
|
||
fn clone_box(&self) -> Box<dyn Effector> { | ||
Box::new(self.clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1b0c794
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust Benchmark
b_benchmark_abac_model
58061
ns/iter (± 6369
)6143
ns/iter (± 983
)9.45
b_benchmark_basic_model
60557
ns/iter (± 17608
)5965
ns/iter (± 1255
)10.15
b_benchmark_key_match
106008
ns/iter (± 28468
)20185
ns/iter (± 4410
)5.25
b_benchmark_priority_model
79210
ns/iter (± 14248
)8437
ns/iter (± 1596
)9.39
b_benchmark_raw
6
ns/iter (± 0
)7
ns/iter (± 2
)0.86
b_benchmark_rbac_model
63522
ns/iter (± 21054
)21118
ns/iter (± 5128
)3.01
b_benchmark_rbac_model_large
53207476
ns/iter (± 21292239
)64145865
ns/iter (± 12196460
)0.83
b_benchmark_rbac_model_medium
5759372
ns/iter (± 1906025
)6331317
ns/iter (± 815518
)0.91
b_benchmark_rbac_model_small
586894
ns/iter (± 96950
)601976
ns/iter (± 58379
)0.97
b_benchmark_rbac_model_with_domains
72156
ns/iter (± 13846
)12762
ns/iter (± 2115
)5.65
b_benchmark_rbac_with_deny
68315
ns/iter (± 13559
)35346
ns/iter (± 5259
)1.93
b_benchmark_rbac_with_resource_roles
68146
ns/iter (± 21408
)9205
ns/iter (± 1085
)7.40
This comment was automatically generated by workflow using github-action-benchmark.
1b0c794
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.50
.b_benchmark_abac_model
58061
ns/iter (± 6369
)6143
ns/iter (± 983
)9.45
b_benchmark_basic_model
60557
ns/iter (± 17608
)5965
ns/iter (± 1255
)10.15
b_benchmark_key_match
106008
ns/iter (± 28468
)20185
ns/iter (± 4410
)5.25
b_benchmark_priority_model
79210
ns/iter (± 14248
)8437
ns/iter (± 1596
)9.39
b_benchmark_rbac_model
63522
ns/iter (± 21054
)21118
ns/iter (± 5128
)3.01
b_benchmark_rbac_model_with_domains
72156
ns/iter (± 13846
)12762
ns/iter (± 2115
)5.65
b_benchmark_rbac_with_deny
68315
ns/iter (± 13559
)35346
ns/iter (± 5259
)1.93
b_benchmark_rbac_with_resource_roles
68146
ns/iter (± 21408
)9205
ns/iter (± 1085
)7.40
This comment was automatically generated by workflow using github-action-benchmark.
CC: @GopherJ