-
Notifications
You must be signed in to change notification settings - Fork 65
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
Conversation
please elaborate what is this PR come to fix |
|
Please modify ACL test to verify the new functionality, and also add this option to the command proc macro (and verify it with test) |
$mandatory_acl_categories:expr | ||
$(, $optional_acl_categories:expr)? | ||
) => {{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the simplicity, I'd do two things:
- Add a separate enum:
CommandAclCategory
:
enum CommandAclCategory {
Write,
Read,
Fast,
Other(String),
}
impl std::fmt::Display for CommandAclCategory {
// ...
}
Where we would add all the already existing, commonly used acl categories which have already existed for a long time, and would always specifying a new one by having the Other
variant.
- If the mandatory ACL category is mandatory, why not simply omit it and add it automatically? We are not in C, so we can have two macros, with it and without. In the "without" macro branch, I'd invoke the "with" branch with the mandatory ACL category name as the module name (this is the case for all the modules we are currently adding the ACLs anyway).
- Rename the
acl_categories
arguments, as we specify them separately, not all within one argument:mandatory_acl_category
andoptional_acl_category
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- doable. will take under advisement.
- there is no one singular mandatory ACL category. the mandatory ACL categories are those that are mandatory for the module to work at all, and loading the module should fail if they are not added. optional ACL categories are those that we warn on failure to add, but do not fail.
- we do specify multiple categories within one argument. as a space delimited string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the response!
How we want to specify them for redis - this is the implementation detail. The interface here is in Rust, and we should allow the safest, most idiomatic way possible, which is an explicit set of type-safe values. Do you agree? For the user of this macro it shouldn't matter how exactly those end up being sent to the server, the user shouldn't care about this, nor should he know about this, if this is hidden behind the interface. This is not why this crate is simply forwarding the rust types to the C-api, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the user that decides which categories are mandatory and which are optional, not us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, okay, that I am not discussing anymore. I am talking now about the type safety and the explicit lists.
@@ -146,7 +181,8 @@ macro_rules! redis_module { | |||
$firstkey:expr, | |||
$lastkey:expr, | |||
$keystep:expr, | |||
$acl_categories:expr | |||
$mandatory_command_acl_categories:expr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this is plural but represents just one category; IIRC, there is just one mandatory category now, or am I wrong? Either way, I understand the precaution here of actually passing more than one as a string separated with spaces, but I'd really like to have it more verbose and explicit by having the enum and a [,]
expression instead then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there may be many mandatory categories. mandatory just means that if adding any of these categories fails, the module loading should fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, then I'd like to have those not as string literals but as a comma-separated values list, which implements From<T> for CommandAclCategory
enum either way, so either a string, or a CommandAclCategory
enum variant itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I don't strictly require any changes, just suggesting a few more things, but this is good to go.
impl From<&str> for AclCategory { | ||
fn from(value: &str) -> Self { | ||
match value { | ||
"" => AclCategory::None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should the result be in the case of read
or read
? Is it even possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error?
passing that to Redis will be rejected
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd personally add a method for this AclCategory::is_none()
and is_some()
. It may clash with the interface of Option
and confuse the reader, though, but there is no better alternative.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just $optional_acl_categories.to_string()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it needs to be a c_string
to pass to Redis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, I meant instead of using the format!
macro we could have simply used the to_string()
method of the fmt::Display
trait, no?
$acl_category
identically to its identifier.Reduces code duplication on the module side (egRedisJSON
), all commands from the module are given the ACL category of the module without having to be expressly listed per command.(This is not guaranteed to be correct behavior for all modules. removed).
redismodule-rs
side to ensure it works as expected.#393
#394