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

feat(acl): add acl keys to acl setuser command #2258

Merged
merged 5 commits into from
Dec 8, 2023
Merged

feat(acl): add acl keys to acl setuser command #2258

merged 5 commits into from
Dec 8, 2023

Conversation

kostasrim
Copy link
Contributor

@kostasrim kostasrim commented Dec 5, 2023

PR2

  • add parsing of ACL keys
  • add ACL keys to acl setuser command

part of #2229

@kostasrim kostasrim self-assigned this Dec 5, 2023
@kostasrim kostasrim requested a review from dranikpg December 5, 2023 18:16
@kostasrim
Copy link
Contributor Author

@dranikpg I tested this well but I did after I implement acl get and acl list. All the tests will follow in the following PR's

@kostasrim kostasrim changed the base branch from main to aclkeys1 December 5, 2023 18:17
dranikpg
dranikpg previously approved these changes Dec 6, 2023
Comment on lines +209 to +214
size_t key_cap = std::accumulate(
msg->keys.key_globs.begin(), msg->keys.key_globs.end(), 0, [](auto acc, auto& str) {
return acc + (str.first.capacity() * sizeof(char)) + sizeof(str.second);
});
return sizeof(AclUpdateMessage) + msg->username.capacity() * sizeof(char) +
msg->commands.capacity() * sizeof(uint64_t) + key_cap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great you added it, but it doesn't make much of a difference, I skipped CheckpointMessage likewise because memory usage negligible. You can just avoid bothering with it next time you make a change 😄

Comment on lines 245 to +250
void Connection::DispatchOperations::operator()(const AclUpdateMessage& msg) {
if (self->cntx()) {
for (size_t id = 0; id < msg.username.size(); ++id) {
if (msg.username[id] == self->cntx()->authed_username) {
self->cntx()->acl_categories = msg.categories[id];
self->cntx()->acl_commands = msg.commands[id];
}
if (msg.username == self->cntx()->authed_username) {
self->cntx()->acl_categories = msg.categories;
self->cntx()->acl_commands = msg.commands;
self->cntx()->keys = msg.keys;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we can pass msg by value and move, can't we? It's owned by us after all (nit because the runtime cost is negligible again)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's either accept msg by value and move the msg.keys or accept my const ref and copy the msg.keys value (as is now). There is not really a difference so I chose the later because it's how the rest of overloads accept their parameters (and looks consistent)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or accept my const ref and copy

I just meant there is no reason to because it's gonna be dropped after this call either way

Comment on lines 93 to 110
if (absl::StartsWith(command, "%")) {
if (command.size() < 3) {
return {};
}

if (!(command.substr(1, 2) == "RW")) {
if (command[1] == 'R') {
op = KeyOp::READ;
} else if (command[1] == 'W') {
op = KeyOp::WRITE;
} else {
return {};
}
command = command.substr(2);
} else {
command = command.substr(3);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe checking 3 times startswith would even be easier 😅 , because I had to think at the if (! (substr == "RW")) part 🤣 (!=)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so much better now!

Comment on lines +48 to +53
struct ParseKeyResult {
std::string glob;
KeyOp op;
bool all_keys{false};
bool reset_keys{false};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have this type defined in the previous pr, you can just rebase on top of it

@@ -138,7 +138,7 @@ const AclKeys& User::Keys() const {
return keys_;
}

void User::SetKeyGlobs(std::vector<UpdateKey>&& keys) {
void User::SetKeyGlobs(std::vector<UpdateKey> keys) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it here cause I wanted to merge the previous PR :)

Base automatically changed from aclkeys1 to main December 7, 2023 17:34
@kostasrim kostasrim dismissed dranikpg’s stale review December 7, 2023 17:34

The base branch was changed.

dranikpg
dranikpg previously approved these changes Dec 7, 2023
@kostasrim kostasrim enabled auto-merge (squash) December 8, 2023 09:32
@kostasrim kostasrim merged commit b642fb6 into main Dec 8, 2023
10 checks passed
@kostasrim kostasrim deleted the aclkeys2 branch December 8, 2023 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants