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

```rust use dynamodbadapter::casbin::prelude::*; use dynamodbadapter::DynamoDBAdapter;

[tokio::main]

async fn main() -> Result<()> { let config = awsconfig::loadfromenv().await; let client = awssdk_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

shell docker pull amazon/dynamodb-local

shell docker run --rm -p 8000:8000 amazon/dynamodb-local

shell 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

shell aws dynamodb scan \ --endpoint-url http://localhost:8000 \ --table-name Casbin_Policies