Skip to content

Commit

Permalink
Release v2.0.0 (#204)
Browse files Browse the repository at this point in the history
* fix: bump version

Signed-off-by: Cheng JIANG <[email protected]>

* feat: add clear_policy & rustfmt.toml

Signed-off-by: Cheng JIANG <[email protected]>

* feat: rename all_roles to all_domains

Signed-off-by: Cheng JIANG <[email protected]>

* feat: add new_raw method which doesn't load policy automatically

Signed-off-by: Cheng JIANG <[email protected]>

* feat: make CoreApi being able to be made into object

Signed-off-by: Cheng JIANG <[email protected]>

* Fix: typo in example code

* fix: make IEnforcer interface being able to be made into object

* fix: don't remove all the policies if field_values is empty

Signed-off-by: Cheng JIANG <[email protected]>

* fix: run format

Signed-off-by: Cheng JIANG <[email protected]>

* feat: upgrade rhai version to 0.18.1

Signed-off-by: Cheng JIANG <[email protected]>

* feat: switch to lru-cache

Signed-off-by: Cheng JIANG <[email protected]>

* fix: remove unused ttl

Signed-off-by: Cheng JIANG <[email protected]>

* feat: bump deps' version

Signed-off-by: Cheng JIANG <[email protected]>

* feat: change cache interface to allow returning owned value

Signed-off-by: Cheng JIANG <[email protected]>

* feat: structrued logging

Signed-off-by: Cheng JIANG <[email protected]>

* improve: use static dispatchered cache in Rbac manager because we'll never replace it by custom cache

Signed-off-by: Cheng JIANG <[email protected]>

* improve: add unit test for escaping rule which sometimes needs to be evaluated

Signed-off-by: Cheng JIANG <[email protected]>

* upgrade rhai

Signed-off-by: Cheng JIANG <[email protected]>

* fix: potential dead lock in add_role fn

Signed-off-by: Cheng JIANG <[email protected]>

* improve: ignore add link request on same roles

* improve: remove unecessary pub(crate)

* improve: add is_enabled fn

* feature: add serde support

* fix: CI wasm check

* fix: remove unwanted dep

* improve: cached enforcer's bench

* improve: rbac cache perf

* improve: reset default features

* feature: pattern matching

* fix: missing serde

* fix: example code in README

* fix: example code
  • Loading branch information
GopherJ authored Aug 30, 2020
1 parent fd3ca65 commit 9c67ba4
Show file tree
Hide file tree
Showing 38 changed files with 2,071 additions and 1,049 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ jobs:
components: rustfmt, clippy
override: true

- name: Install wasm32-unknown-unknown for ${{ matrix.rust }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
target: wasm32-unknown-unknown
override: true

- name: Cache cargo registry
uses: actions/cache@v1
with:
Expand Down Expand Up @@ -73,9 +80,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: check
target: wasm32-unknown-unknown
override: true
args: --no-default-features --features runtime-async-std,cached,glob,ip,watcher,logging,incremental
args: --target wasm32-unknown-unknown --no-default-features --features runtime-async-std,cached,glob,ip,watcher,logging,incremental

- name: Clippy warnings
uses: actions-rs/cargo@v1
Expand Down
31 changes: 18 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "casbin"
version = "1.1.3"
version = "2.0.0"
authors = ["Joey <[email protected]>", "Cheng JIANG <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -14,27 +14,30 @@ keywords = ["auth", "authorization", "rbac", "acl", "abac"]

[dependencies]
regex = "1.3.9"
rhai = { version = "0.17.0", features = ["sync", "only_i32", "no_function", "no_float", "no_optimize", "no_module"] }
rhai = { version = "0.18.2", features = ["sync", "only_i32", "no_function", "no_float", "no_optimize", "no_module", "no_closure", "serde", "unchecked"] }
ip_network = { version = "0.3.4", optional = true }
ttl_cache = { version = "0.5.1", optional = true }
lru-cache = { version = "0.1.2", optional = true }
lazy_static = "1.4.0"
indexmap = "1.5.0"
async-std = { version = "1.6.2", optional = true }
async-trait = "0.1.35"
log = { version = "0.4.8", optional = true }
tokio = { version = "0.2.21", optional = true, default-features = false }
indexmap = "1.5.1"
async-std = { version = "1.6.3", optional = true }
async-trait = "0.1.37"
tokio = { version = "0.2.22", optional = true, default-features = false }
globset = { version = "0.4.5", optional = true }
thiserror = "1.0.20"
slog = { version = "2.5.2", optional = true }
slog-term = { version = "2.6.0", optional = true }
slog-async = { version = "2.5.0", optional = true }
serde = "1.0.115"

[features]
default = ["runtime-async-std", "incremental"]

runtime-tokio = ["tokio/fs", "tokio/io-util"]
runtime-async-std = ["async-std"]
logging = ["log"]
logging = ["slog", "slog-term", "slog-async"]
ip = ["ip_network"]
glob = ["globset"]
cached = ["ttl_cache"]
cached = ["lru-cache"]
watcher = []
incremental = []
explain = []
Expand All @@ -43,8 +46,10 @@ explain = []
opt-level = 0

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
async-std = { version = "1.6.1", features = [ "attributes" ] }
async-std = { version = "1.6.3", features = [ "attributes" ] }
serde = { version = "1.0.115", features = ["derive"] }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { version = "0.2.21", features = [ "full" ] }
async-std = { version = "1.6.1", features = [ "attributes" ] }
tokio = { version = "0.2.22", features = [ "full" ] }
async-std = { version = "1.6.3", features = [ "attributes" ] }
serde = { version = "1.0.115", features = ["derive"] }
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ Add this package to `Cargo.toml` of your project. (Check https://crates.io/crate

```toml
[dependencies]
casbin = { version = "1.1.3", default-features = false, features = ["runtime-async-std", "logging"] }
casbin = { version = "2.0.0", default-features = false, features = ["runtime-async-std", "logging"] }
async-std = { version = "1.5.0", features = ["attributes"] }
env_logger = "0.7.1"
```

## Get started
Expand All @@ -44,13 +43,10 @@ use casbin::prelude::*;

#[async_std::main]
async fn main() -> Result<()> {
::std::env::set_var("RUST_LOG", "casbin=info");
env_logger::init();

let mut e = Enforcer::new("examples/rbac_with_domains_model.conf", "examples/rbac_with_domains_policy.csv").await?;
e.enable_log(true);

e.enforce(&["alice", "domain1", "data1", "read"]).await?;
e.enforce(("alice", "domain1", "data1", "read"))?;
Ok(())
}
```
Expand All @@ -62,7 +58,7 @@ async fn main() -> Result<()> {
let obj = "data1"; // the resource that is going to be accessed.
let act = "read"; // the operation that the user performs on the resource.

if let Ok(authorized) = e.enforce(&[sub, obj, act]).await {
if let Ok(authorized) = e.enforce((sub, obj, act)) {
if authorized {
// permit alice to read data1
} else {
Expand Down
Loading

2 comments on commit 9c67ba4

@GopherJ
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: 9c67ba4 Previous: fd3ca65 Ratio
b_benchmark_abac_model 5447 ns/iter (± 867) 5982 ns/iter (± 1178) 0.91
b_benchmark_basic_model 6216 ns/iter (± 1031) 6417 ns/iter (± 1114) 0.97
b_benchmark_cached_abac_model 1149 ns/iter (± 268) 290 ns/iter (± 49) 3.96
b_benchmark_cached_key_match 567 ns/iter (± 139) 299 ns/iter (± 58) 1.90
b_benchmark_cached_priority_model 549 ns/iter (± 206) 294 ns/iter (± 60) 1.87
b_benchmark_cached_rbac_model 537 ns/iter (± 121) 290 ns/iter (± 46) 1.85
b_benchmark_cached_rbac_model_large 495 ns/iter (± 69) 310 ns/iter (± 52) 1.60
b_benchmark_cached_rbac_model_medium 551 ns/iter (± 102) 286 ns/iter (± 35) 1.93
b_benchmark_cached_rbac_model_small 576 ns/iter (± 111) 286 ns/iter (± 46) 2.01
b_benchmark_cached_rbac_model_with_domains 949 ns/iter (± 133) 338 ns/iter (± 45) 2.81
b_benchmark_cached_rbac_with_deny 587 ns/iter (± 92) 286 ns/iter (± 66) 2.05
b_benchmark_cached_rbac_with_resource_roles 595 ns/iter (± 83) 283 ns/iter (± 64) 2.10
b_benchmark_key_match 26783 ns/iter (± 3312) 24779 ns/iter (± 4504) 1.08
b_benchmark_priority_model 7252 ns/iter (± 1353) 6847 ns/iter (± 1194) 1.06
b_benchmark_raw 7 ns/iter (± 1) 7 ns/iter (± 1) 1
b_benchmark_rbac_model 9933 ns/iter (± 1916) 9324 ns/iter (± 1978) 1.07
b_benchmark_rbac_model_large 18030250 ns/iter (± 2233963) 19042842 ns/iter (± 2639852) 0.95
b_benchmark_rbac_model_medium 1822806 ns/iter (± 254048) 1896132 ns/iter (± 312519) 0.96
b_benchmark_rbac_model_small 182270 ns/iter (± 38924) 183917 ns/iter (± 29194) 0.99
b_benchmark_rbac_model_with_domains 9898 ns/iter (± 2079) 9259 ns/iter (± 1412) 1.07
b_benchmark_rbac_with_deny 13323 ns/iter (± 2028) 13408 ns/iter (± 2816) 0.99
b_benchmark_rbac_with_resource_roles 8019 ns/iter (± 2075) 7161 ns/iter (± 1148) 1.12
b_benchmark_role_manager_large 8640797 ns/iter (± 1005575) 8682064 ns/iter (± 1385016) 1.00
b_benchmark_role_manager_medium 700620 ns/iter (± 107941) 776090 ns/iter (± 174067) 0.90
b_benchmark_role_manager_small 76701 ns/iter (± 15764) 78286 ns/iter (± 13749) 0.98
b_benmark_cached_basic_model 596 ns/iter (± 115) 284 ns/iter (± 48) 2.10

This comment was automatically generated by workflow using github-action-benchmark.

@GopherJ
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

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.

Benchmark suite Current: 9c67ba4 Previous: fd3ca65 Ratio
b_benchmark_cached_abac_model 1149 ns/iter (± 268) 290 ns/iter (± 49) 3.96
b_benchmark_cached_key_match 567 ns/iter (± 139) 299 ns/iter (± 58) 1.90
b_benchmark_cached_priority_model 549 ns/iter (± 206) 294 ns/iter (± 60) 1.87
b_benchmark_cached_rbac_model 537 ns/iter (± 121) 290 ns/iter (± 46) 1.85
b_benchmark_cached_rbac_model_large 495 ns/iter (± 69) 310 ns/iter (± 52) 1.60
b_benchmark_cached_rbac_model_medium 551 ns/iter (± 102) 286 ns/iter (± 35) 1.93
b_benchmark_cached_rbac_model_small 576 ns/iter (± 111) 286 ns/iter (± 46) 2.01
b_benchmark_cached_rbac_model_with_domains 949 ns/iter (± 133) 338 ns/iter (± 45) 2.81
b_benchmark_cached_rbac_with_deny 587 ns/iter (± 92) 286 ns/iter (± 66) 2.05
b_benchmark_cached_rbac_with_resource_roles 595 ns/iter (± 83) 283 ns/iter (± 64) 2.10
b_benmark_cached_basic_model 596 ns/iter (± 115) 284 ns/iter (± 48) 2.10

This comment was automatically generated by workflow using github-action-benchmark.

CC: @GopherJ

Please sign in to comment.