Crates.io | spawn-access-control |
lib.rs | spawn-access-control |
version | 0.1.10 |
source | src |
created_at | 2024-09-06 04:07:01.794539 |
updated_at | 2024-09-11 03:02:31.963368 |
description | A Rust library for access control management with WebAssembly support, including role-based access control (RBAC), permissions, and audit logging. |
homepage | https://github.com/nzengi/access-control |
repository | https://github.com/nzengi/spawn-access-control |
max_upload_size | |
id | 1365499 |
size | 20,405 |
A comprehensive and extensible Access Control Management System written in Rust, supporting WebAssembly for cross-platform compatibility. This library provides advanced features such as role-based access control (RBAC), resource-based permissions, audit logging, session management, rate limiting, and more.
To use this library in your Rust project, add the following to your Cargo.toml
:
[dependencies]
spawn-access-control = "0.1.10"
use spawn_access_control::{Role, AccessManager, Resource};
fn main() {
let mut access_manager = AccessManager::new();
// Define roles
let admin_role = Role::new("admin", None);
let user_role = Role::new("user", None);
// Define a resource
let resource = Resource::new("file.txt", vec!["admin".to_string()]);
// Add a user and assign a role
access_manager.add_user("alice", admin_role.clone());
// Check if the user has access to the resource
if access_manager.check_access("alice", &resource) {
println!("Access granted!");
} else {
println!("Access denied!");
}
}
use spawn_access_control::{Permission, AccessManager, Resource};
fn main() {
let read_permission = Permission { name: "read".to_string(), resource: "file.txt".to_string(), condition: None };
let write_permission = Permission { name: "write".to_string(), resource: "file.txt".to_string(), condition: None };
// Use AccessManager to assign roles with permissions
// Example: Define specific permissions for users based on actions
}
use spawn_access_control::RateLimiter;
fn main() {
let mut rate_limiter = RateLimiter::new(5, 60); // 5 requests per minute
for _ in 0..5 {
if rate_limiter.is_within_limit() {
println!("Request allowed");
} else {
println!("Rate limit exceeded");
}
}
}
To compile this library to WebAssembly, use the following command:
wasm-pack build