casbin-arangors-adapter

Crates.iocasbin-arangors-adapter
lib.rscasbin-arangors-adapter
version0.2.3
sourcesrc
created_at2023-02-04 17:03:09.207781
updated_at2023-02-05 21:56:56.551087
descriptionArangoRs adapter for casbin-rs
homepagehttps://github.com/LucaCoduriV/casbin-rs-anrangors-adapter
repository
max_upload_size
id776507
size39,766
Luca (LucaCoduriV)

documentation

README

Casbin-rs Arangors adapter

How to use

To make this crate work you need to create a collection named casbin. Don't forget to put The unique key index on columns ptype,v0,v1,v2,v3,v4,v5

In code example:

use casbin_arangors_adapter::ArangorsAdapter;

let conn = arangors::Connection::establish_jwt(
    constants::DB_ADDRESS.as_str(),
    constants::DB_USER.as_str(),
    constants::DB_PASSWORD.as_str(),
).await.unwrap();

let db = conn.db(constants::DB_NAME.as_str()).await.unwrap();


let adapter = ArangorsAdapter::new(db);
let mut e = Enforcer::new("./model.conf", adapter).await.unwrap();
e.add_policy(vec!["jack".to_owned(), "data4".to_owned(), "read".to_owned()]).await;

assert!(e.enforce(("jack", "data4", "read")).unwrap());
assert!(!e.enforce(("jack", "data4", "write")).unwrap());

Disclaimer

The crate is not 100% tested and will maybe have some bugs. Feel free to make a pull request to fix those bugs 😃.

The code can be improved for sure but it wasn't the main goal.

A lot of the code was taken from this repo: https://github.com/casbin-rs/diesel-adapter

Commit count: 0

cargo fmt