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-8036 Add tests for 393 and 394 #395

Merged
merged 9 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions examples/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ redis_module! {
version: 1,
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
acl_category: "acl",
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, "read"],
["get_current_user", get_current_user, "", 0, 0, 0, "read"],
],
}
27 changes: 19 additions & 8 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ macro_rules! redis_command {
$firstkey:expr,
$lastkey:expr,
$keystep:expr,
$acl_categories:expr) => {{
$acl_categories:expr
) => {{
let name = CString::new($command_name).unwrap();
let flags = CString::new($command_flags).unwrap();

Expand Down Expand Up @@ -134,7 +135,10 @@ macro_rules! redis_module {
data_types: [
$($data_type:ident),* $(,)*
],
$(acl_category: $acl_category:expr,)* $(,)*
// eg: `acl_category: "name_of_module_acl_category",`
// This will add the module to the specified (optional) ACL category.
// All commands will inherit this category.
$(acl_category: $module_acl_categories:expr,)?
$(init: $init_func:ident,)* $(,)*
$(deinit: $deinit_func:ident,)* $(,)*
$(info: $info_func:ident,)?
Expand All @@ -146,7 +150,7 @@ macro_rules! redis_module {
$firstkey:expr,
$lastkey:expr,
$keystep:expr,
$acl_categories:expr
$command_acl_categories:expr
]),* $(,)*
] $(,)*
$(event_handlers: [
Expand Down Expand Up @@ -270,18 +274,25 @@ macro_rules! redis_module {
}
)*

let mut module_acl_categories = CString::new("").unwrap();
$(
let category = CString::new($acl_category).unwrap();
module_acl_categories = CString::new($module_acl_categories).unwrap();
if let Some(RM_AddACLCategory) = raw::RedisModule_AddACLCategory {
if RM_AddACLCategory(ctx, category.as_ptr()) == raw::Status::Err as c_int {
raw::redis_log(ctx, &format!("Error: failed to add ACL category {}", $acl_category));
if RM_AddACLCategory(ctx, module_acl_categories.as_ptr()) == raw::Status::Err as c_int {
raw::redis_log(ctx, &format!("Error: failed to add ACL category {}", $module_acl_categories));
return raw::Status::Err as c_int;
}
}
)*
)?

let module_acl_categories = module_acl_categories.to_str().unwrap();
ephraimfeldblum marked this conversation as resolved.
Show resolved Hide resolved
$(
$crate::redis_command!(ctx, $name, $command, $flags, $firstkey, $lastkey, $keystep, $acl_categories);
let command_acl_categories = if module_acl_categories == "" {
$command_acl_categories.to_string()
} else {
format!("{} {}", module_acl_categories, $command_acl_categories)
};
$crate::redis_command!(ctx, $name, $command, $flags, $firstkey, $lastkey, $keystep, command_acl_categories.as_str());
)*

if $crate::commands::register_commands(&context) == raw::Status::Err {
Expand Down
Loading