Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOD-7919 Expand redis_command! to support ACL #392

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["verify_key_access_for_user", verify_key_access_for_user, "", 0, 0, 0],
["get_current_user", get_current_user, "", 0, 0, 0],
["verify_key_access_for_user", verify_key_access_for_user, "", 0, 0, 0, ""],
["get_current_user", get_current_user, "", 0, 0, 0, ""],
],
}
2 changes: 1 addition & 1 deletion examples/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["block", block, "", 0, 0, 0],
["block", block, "", 0, 0, 0, ""],
],
}
6 changes: 3 additions & 3 deletions examples/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["call.test", call_test, "", 0, 0, 0],
["call.blocking", call_blocking, "", 0, 0, 0],
["call.blocking_from_detached_ctx", call_blocking_from_detach_ctx, "", 0, 0, 0],
["call.test", call_test, "", 0, 0, 0, ""],
["call.blocking", call_blocking, "", 0, 0, 0, ""],
["call.blocking_from_detached_ctx", call_blocking_from_detach_ctx, "", 0, 0, 0, ""],
],
}
2 changes: 1 addition & 1 deletion examples/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["configuration.num_changes", num_changes, "", 0, 0, 0],
["configuration.num_changes", num_changes, "", 0, 0, 0, ""],
],
configurations: [
i64: [
Expand Down
2 changes: 1 addition & 1 deletion examples/ctx_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["my_role", role, "readonly", 0, 0, 0],
["my_role", role, "readonly", 0, 0, 0, ""],
],
}
6 changes: 3 additions & 3 deletions examples/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ redis_module! {
MY_REDIS_TYPE,
],
commands: [
["alloc.set", alloc_set, "write", 1, 1, 1],
["alloc.get", alloc_get, "readonly", 1, 1, 1],
["alloc.defragstats", alloc_defragstats, "readonly", 0, 0, 0]
["alloc.set", alloc_set, "write", 1, 1, 1, ""],
["alloc.get", alloc_get, "readonly", 1, 1, 1, ""],
["alloc.defragstats", alloc_defragstats, "readonly", 0, 0, 0, ""],
],
}
6 changes: 3 additions & 3 deletions examples/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["events.send", event_send, "", 0, 0, 0],
["events.num_key_miss", num_key_miss, "", 0, 0, 0],
["events.num_keys", num_keys, "", 0, 0, 0],
["events.send", event_send, "", 0, 0, 0, ""],
["events.num_key_miss", num_key_miss, "", 0, 0, 0, ""],
["events.num_keys", num_keys, "", 0, 0, 0, ""],
],
event_handlers: [
[@STRING: on_event],
Expand Down
2 changes: 1 addition & 1 deletion examples/expire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["expire.cmd", expire_cmd, "write fast deny-oom", 1, 1, 1],
["expire.cmd", expire_cmd, "write fast deny-oom", 1, 1, 1, ""],
],
}
2 changes: 1 addition & 1 deletion examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["hello.mul", hello_mul, "", 0, 0, 0],
["hello.mul", hello_mul, "", 0, 0, 0, ""],
],
}
2 changes: 1 addition & 1 deletion examples/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["infoex", info_cmd, "", 0, 0, 0],
["infoex", info_cmd, "", 0, 0, 0, ""],
],
}
2 changes: 1 addition & 1 deletion examples/keys_pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["keys_pos", keys_pos, "getkeys-api", 1, 1, 1],
["keys_pos", keys_pos, "getkeys-api", 1, 1, 1, ""],
],
}
2 changes: 1 addition & 1 deletion examples/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["LPOPRPUSH", lpoprpush, "write fast deny-oom", 1, 2, 1],
["LPOPRPUSH", lpoprpush, "write fast deny-oom", 1, 2, 1, ""],
],
}
4 changes: 2 additions & 2 deletions examples/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["map.mget", map_mget, "readonly", 1, 1, 1],
["map.unique", map_unique, "readonly", 1, 1, 1],
["map.mget", map_mget, "readonly", 1, 1, 1, ""],
["map.unique", map_unique, "readonly", 1, 1, 1, ""],
],
}
2 changes: 1 addition & 1 deletion examples/scan_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["scan_keys", scan_keys, "readonly", 0, 0, 0],
["scan_keys", scan_keys, "readonly", 0, 0, 0, ""],
],
}
6 changes: 3 additions & 3 deletions examples/server_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["num_flushed", num_flushed, "readonly", 0, 0, 0],
["num_max_memory_changes", num_maxmemory_changes, "readonly", 0, 0, 0],
["num_crons", num_crons, "readonly", 0, 0, 0],
["num_flushed", num_flushed, "readonly", 0, 0, 0, ""],
["num_max_memory_changes", num_maxmemory_changes, "readonly", 0, 0, 0, ""],
["num_crons", num_crons, "readonly", 0, 0, 0, ""],
],
}
2 changes: 1 addition & 1 deletion examples/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["STREAM_POP", stream_read_from, "write", 1, 1, 1],
["STREAM_POP", stream_read_from, "write", 1, 1, 1, ""],
],
}
4 changes: 2 additions & 2 deletions examples/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["string.set", string_set, "write fast deny-oom", 1, 1, 1],
["string.get", string_get, "readonly", 1, 1, 1],
["string.set", string_set, "write fast deny-oom", 1, 1, 1, ""],
["string.get", string_get, "readonly", 1, 1, 1, ""],
],
}
8 changes: 4 additions & 4 deletions examples/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ redis_module! {
data_types: [],
info: add_info,
commands: [
["test_helper.version", test_helper_version, "", 0, 0, 0],
["test_helper._version_rm_call", test_helper_version_rm_call, "", 0, 0, 0],
["test_helper.name", test_helper_command_name, "", 0, 0, 0],
["test_helper.err", test_helper_err, "", 0, 0, 0],
["test_helper.version", test_helper_version, "", 0, 0, 0, ""],
["test_helper._version_rm_call", test_helper_version_rm_call, "", 0, 0, 0, ""],
["test_helper.name", test_helper_command_name, "", 0, 0, 0, ""],
["test_helper.err", test_helper_err, "", 0, 0, 0, ""],
],
}
8 changes: 4 additions & 4 deletions examples/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["threads", threads, "", 0, 0, 0],
["set_static_data", set_static_data, "", 0, 0, 0],
["get_static_data", get_static_data, "", 0, 0, 0],
["get_static_data_on_thread", get_static_data_on_thread, "", 0, 0, 0],
["threads", threads, "", 0, 0, 0, ""],
["set_static_data", set_static_data, "", 0, 0, 0, ""],
["get_static_data", get_static_data, "", 0, 0, 0, ""],
["get_static_data_on_thread", get_static_data_on_thread, "", 0, 0, 0, ""],
],
}
6 changes: 3 additions & 3 deletions examples/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ redis_module! {
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["timer.create", timer_create, "", 0, 0, 0],
["timer.info", timer_info, "", 0, 0, 0],
["timer.stop", timer_stop, "", 0, 0, 0],
["timer.create", timer_create, "", 0, 0, 0, ""],
["timer.info", timer_info, "", 0, 0, 0, ""],
["timer.stop", timer_stop, "", 0, 0, 0, ""],
],
}
32 changes: 27 additions & 5 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ macro_rules! redis_command {
$command_flags:expr,
$firstkey:expr,
$lastkey:expr,
$keystep:expr) => {{
$keystep:expr,
$acl_categories:expr) => {{
let name = CString::new($command_name).unwrap();
let flags = CString::new($command_flags).unwrap();

Expand Down Expand Up @@ -38,6 +39,26 @@ macro_rules! redis_command {
{
return $crate::raw::Status::Err as c_int;
}

if $acl_categories != "" {
let acl_categories = CString::new($acl_categories).unwrap();

let command =
unsafe { $crate::raw::RedisModule_GetCommand.unwrap()($ctx, name.as_ptr()) };
if command.is_null() {
return $crate::raw::Status::Err as c_int;
}

if unsafe {
$crate::raw::RedisModule_SetCommandACLCategories.unwrap()(
command,
acl_categories.as_ptr(),
)
} == $crate::raw::Status::Err as c_int
{
return $crate::raw::Status::Err as c_int;
}
}
}};
}

Expand Down Expand Up @@ -116,7 +137,8 @@ macro_rules! redis_module {
$flags:expr,
$firstkey:expr,
$lastkey:expr,
$keystep:expr
$keystep:expr,
$acl_categories:expr
]),* $(,)*
] $(,)*
$(event_handlers: [
Expand Down Expand Up @@ -241,7 +263,7 @@ macro_rules! redis_module {
)*

$(
$crate::redis_command!(ctx, $name, $command, $flags, $firstkey, $lastkey, $keystep);
$crate::redis_command!(ctx, $name, $command, $flags, $firstkey, $lastkey, $keystep, $acl_categories);
)*

if $crate::commands::register_commands(&context) == raw::Status::Err {
Expand Down Expand Up @@ -329,13 +351,13 @@ macro_rules! redis_module {
$(
$crate::redis_command!(ctx, $module_config_get_command, |ctx, args: Vec<RedisString>| {
module_config_get(ctx, args, $module_name)
}, "", 0, 0, 0);
}, "", 0, 0, 0, "");
)?

$(
$crate::redis_command!(ctx, $module_config_set_command, |ctx, args: Vec<RedisString>| {
module_config_set(ctx, args, $module_name)
}, "", 0, 0, 0);
}, "", 0, 0, 0, "");
)?
)?

Expand Down
Loading