-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathacl.rs
50 lines (45 loc) · 1.69 KB
/
acl.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use valkey_module::alloc::ValkeyAlloc;
use valkey_module::{
valkey_module, AclPermissions, Context, NextArg, ValkeyError, ValkeyResult, ValkeyString,
ValkeyValue, VALKEY_OK,
};
fn verify_key_access_for_user(ctx: &Context, args: Vec<ValkeyString>) -> ValkeyResult {
let mut args = args.into_iter().skip(1);
let user = args.next_arg()?;
let key = args.next_arg()?;
let res = ctx.acl_check_key_permission(&user, &key, &AclPermissions::all());
if let Err(err) = res {
return Err(ValkeyError::String(format!("Err {err}")));
}
Ok(ValkeyValue::SimpleStringStatic("OK"))
}
fn get_current_user(ctx: &Context, _args: Vec<ValkeyString>) -> ValkeyResult {
Ok(ValkeyValue::BulkValkeyString(ctx.get_current_user()))
}
fn custom_category(_ctx: &Context, _args: Vec<ValkeyString>) -> ValkeyResult {
VALKEY_OK
}
fn custom_categories(_ctx: &Context, _args: Vec<ValkeyString>) -> ValkeyResult {
VALKEY_OK
}
fn existing_categories(_ctx: &Context, _args: Vec<ValkeyString>) -> ValkeyResult {
VALKEY_OK
}
//////////////////////////////////////////////////////
valkey_module! {
name: "acl",
version: 1,
allocator: (ValkeyAlloc, ValkeyAlloc),
data_types: [],
acl_categories: [
"custom_acl_one",
"custom_acl_two"
]
commands: [
["verify_key_access_for_user", verify_key_access_for_user, "", 0, 0, 0],
["get_current_user", get_current_user, "", 0, 0, 0],
["custom_category", custom_category, "write", 0, 0, 0, "custom_acl_one"],
["custom_categories", custom_categories, "", 0, 0, 0, "custom_acl_one custom_acl_two"],
["existing_categories", existing_categories, "write", 0, 0, 0, "read fast admin"],
],
}