dynamodb-adapter

Crates.iodynamodb-adapter
lib.rsdynamodb-adapter
version0.1.0
sourcesrc
created_at2022-09-20 13:13:17.071528
updated_at2022-09-20 13:13:17.071528
descriptionAWS DynamoDB adapter for casbin-rs
homepagehttps://github.com/fospitia/dynamodb-adapter
repository
max_upload_size
id669898
size31,352
Fabio Ospitia Trujillo (fospitia)

documentation

README

dynamodb-adapter

AWS DynamoDB Adapter is the DynamoDB adapter for Casbin-rs. With this library, Casbin can load policy from DynamoDB database or save policy to it.

Based on Diesel adapter.

Install

Add it to Cargo.toml

aws-config = "0.48.0"
aws-sdk-dynamodb = "0.18.0"
dynamodb-adapter = "0.1.0"
tokio = { version = "1.21.1",  features = ["macros", "rt-multi-thread"] }

Example

use dynamodb_adapter::casbin::prelude::*;
use dynamodb_adapter::DynamoDBAdapter;

#[tokio::main]
async fn main() -> Result<()> {
    let config = aws_config::load_from_env().await;
    let client = aws_sdk_dynamodb::Client::new(&config);

    let m = DefaultModel::from_file("examples/rbac_model.conf").await?;
    let a = DynamoDBAdapter::new(&client, "Casbin_Policies")?;
    let _e = Enforcer::new(m, a).await?;
    Ok(())
}

Test with DynamoBD Local

docker pull amazon/dynamodb-local
docker run --rm -p 8000:8000 amazon/dynamodb-local
aws dynamodb create-table \
    --endpoint-url http://localhost:8000 \
    --table-name Casbin_Policies \
    --attribute-definitions \
        AttributeName=id,AttributeType=S \
    --key-schema \
        AttributeName=id,KeyType=HASH \
    --billing-mode PAY_PER_REQUEST
aws dynamodb scan \
    --endpoint-url http://localhost:8000 \
    --table-name Casbin_Policies
Commit count: 0

cargo fmt