1 unstable release

0.1.0 Sep 20, 2022

#14 in #casbin

Custom license

30KB
710 lines

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

Dependencies

~28–39MB
~672K SLoC