Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimfeldblum committed Nov 5, 2024
1 parent 670f9a4 commit 3f8ab1c
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,32 @@ macro_rules! redis_command {
return $crate::raw::Status::Err as c_int;
}

let mandatory_acl_categories = AclCategory::from($mandatory_acl_categories);
let mandatory = AclCategory::from($mandatory_acl_categories);
if let Some(RM_SetCommandACLCategories) = $crate::raw::RedisModule_SetCommandACLCategories {
let mut optional_failed = true;
let mut acl_categories = CString::default();
$(
let optional_acl_categories = AclCategory::from($optional_acl_categories);
if mandatory_acl_categories != AclCategory::None && optional_acl_categories != AclCategory::None {
acl_categories = CString::new(format!("{} {}", mandatory_acl_categories, optional_acl_categories)).unwrap();
} else if optional_acl_categories != AclCategory::None {
acl_categories = CString::new(format!("{}", $optional_acl_categories)).unwrap();
optional_failed = false;
let optional = AclCategory::from($optional_acl_categories);
if mandatory != AclCategory::None && optional != AclCategory::None {
acl_categories = CString::new(format!("{mandatory} {optional}")).unwrap();
} else if optional != AclCategory::None {
acl_categories = CString::new(format!("{optional}")).unwrap();
}
// Warn if optional ACL categories are not set, but don't fail.
if RM_SetCommandACLCategories(command, acl_categories.as_ptr()) == $crate::raw::Status::Err as c_int {
optional_failed = true;
$crate::raw::redis_log(
$ctx,
&format!(
"Warning: failed to set command `{}` ACL categories `{}`",
$command_name, acl_categories.to_str().unwrap()
),
);
} else
}
)?
if mandatory_acl_categories != AclCategory::None {
acl_categories = CString::new(format!("{}", mandatory_acl_categories)).unwrap();
if optional_failed && mandatory != AclCategory::None {
acl_categories = CString::new(format!("{}", mandatory)).unwrap();

// Fail if mandatory ACL categories are not set.
if RM_SetCommandACLCategories(command, acl_categories.as_ptr())
Expand All @@ -90,13 +93,13 @@ macro_rules! redis_command {
$ctx,
&format!(
"Error: failed to set command `{}` mandatory ACL categories `{}`",
$command_name, mandatory_acl_categories
$command_name, mandatory
),
);
return $crate::raw::Status::Err as c_int;
}
}
} else if mandatory_acl_categories != AclCategory::None {
} else if mandatory != AclCategory::None {
$crate::raw::redis_log(
$ctx,
"Error: Redis version does not support ACL categories",
Expand Down

0 comments on commit 3f8ab1c

Please sign in to comment.