-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hackerchai/master
Version 0.1.0
- Loading branch information
Showing
6 changed files
with
351 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
language: rust | ||
sudo: required | ||
dist: trusty | ||
addons: | ||
apt: | ||
packages: | ||
- libssl-dev | ||
cache: cargo | ||
rust: | ||
- stable | ||
- nightly | ||
matrix: | ||
allow_failures: | ||
- rust: nightly | ||
before_script: | ||
- rustup component add rustfmt | ||
- rustup component add clippy | ||
script: | ||
- cargo clean | ||
- cargo build | ||
- cargo test --no-default-features --features runtime-tokio | ||
- cargo test --no-default-features --features runtime-async-std | ||
- cargo clippy -- -D warnings | ||
- cargo fmt --all -- --check | ||
|
||
after_success: | | ||
if [[ "$TRAVIS_RUST_VERSION" == stable ]]; then | ||
# upload report to codecov | ||
docker run --security-opt seccomp=unconfined -v "$PWD:/volume" xd009642/tarpaulin sh -c "cargo tarpaulin --out Xml" | ||
bash <(curl -s https://codecov.io/bash) | ||
fi |
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,2 +1,63 @@ | ||
# actix-casbin | ||
casbin as an actor | ||
# Actix casbin | ||
|
||
[![Crates.io](https://img.shields.io/crates/v/actix-casbin.svg)](https://crates.io/crates/actix-casbin) | ||
[![Docs](https://docs.rs/actix-casbin/badge.svg)](https://docs.rs/actix-casbin) | ||
[![Build Status](https://travis-ci.org/casbin-rs/actix-casbin.svg?branch=master)](https://travis-ci.org/casbin-rs/actix-casbin) | ||
[![codecov](https://codecov.io/gh/casbin-rs/actix-casbin/branch/master/graph/badge.svg)](https://codecov.io/gh/casbin-rs/actix-casbin) | ||
|
||
[Casbin](https://github.com/casbin/casbin-rs) intergration for [actix](https://github.com/actix/actix) framework | ||
|
||
## Install | ||
|
||
Add it to `Cargo.toml` | ||
|
||
```rust | ||
casbin = "0.6.0" | ||
actix-casbin = "0.1.0" | ||
actix-rt = "1.1.0" | ||
``` | ||
|
||
|
||
# Example | ||
|
||
```rust | ||
use actix_casbin::{CasbinActor, CasbinCmd, CasbinResult}; | ||
use casbin::prelude::*; | ||
|
||
#[actix_rt::main] | ||
async fn main() -> Result<()> { | ||
let m = DefaultModel::from_file("examples/rbac_model.conf") | ||
.await | ||
.unwrap(); | ||
let a = FileAdapter::new("examples/rbac_policy.csv"); | ||
|
||
let addr = CasbinActor::new(m, a).await.unwrap(); | ||
|
||
if let CasbinResult::Enforce(test_enforce) = addr | ||
.send(CasbinCmd::Enforce( | ||
vec!["alice", "data1", "read"] | ||
.iter() | ||
.map(|s| s.to_string()) | ||
.collect(), | ||
)) | ||
.await | ||
.unwrap() | ||
.unwrap() | ||
{ | ||
if test_enforce { | ||
println!("Enforce Pass"); | ||
} else { | ||
println!("Enforce Fail"); | ||
} | ||
Ok(()) | ||
} else { | ||
panic!("Actor Error"); | ||
} | ||
} | ||
``` | ||
|
||
## License | ||
|
||
This project is licensed under | ||
|
||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
p, alice, data1, read | ||
p, bob, data2, write | ||
p, data1_admin, data1, read | ||
p, data1_admin, data1, write | ||
p, data2_admin, data2, read | ||
p, data2_admin, data2, write | ||
|
||
g, alice, admin | ||
g, admin, data1_admin | ||
g, admin, data2_admin |
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
Oops, something went wrong.