Expand description
Role builder from markdown tables.
This crate provides utilities to generate Rust code for role-based access control (RBAC) from markdown tables defined in documentation. It parses markdown files containing user groups and role mappings, then generates Rust code that can be used in your application.
§Input Format
The input markdown file should contain two tables:
- User Groups Table - defines available user groups and their paths
- Role Mappings Table - maps user groups to roles
§Example Input
```markdown
§User Groups user_groups
| Name | Path | Display Name | Allowed Types |
|---|---|---|---|
| Admin | /administration_owner | Admin | none |
| CustomerOwner | /customer_owner | Owner of Customer | none |
§Role Mappings roles
| Roles | Admin | InstitutionOwner | Reader |
|---|---|---|---|
| administration | x | ||
| user:list | x | ||
| ``` |
§Usage
ⓘ
use qm_role_build::generate;
fn main() -> anyhow::Result<()> {
generate("path/to/roles.md")?;
Ok(())
}§Output
The generated code creates a RoleMapping struct containing the user group
to roles mapping that can be used for authorization decisions.
Functions§
- generate
- Generate role mapping code from a markdown file.
- generate_
to_ writer - Generate role mapping code to a custom writer.