1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

feat(acl): add acl keys to acl save/load (#2273)

* add acl keys to acl savel/load
* add tests
This commit is contained in:
Kostas Kyrimis 2023-12-08 18:08:33 +02:00 committed by GitHub
parent 2703d4635d
commit 8323c82dc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 10 deletions

View file

@ -181,12 +181,14 @@ std::string AclFamily::RegistryToString() const {
pass == "nopass" ? "nopass " : absl::StrCat("#", PrettyPrintSha(pass, true), " ");
const std::string acl_cat = AclCatToString(user.AclCategory());
const std::string acl_commands = AclCommandToString(user.AclCommandsRef());
const std::string maybe_space = acl_commands.empty() ? "" : " ";
const std::string maybe_space_com = acl_commands.empty() ? "" : " ";
const std::string acl_keys = AclKeysToString(user.Keys());
const std::string maybe_space = acl_keys.empty() ? "" : " ";
using namespace std::string_view_literals;
absl::StrAppend(&result, command, username, " ", user.IsActive() ? "ON "sv : "OFF "sv, password,
acl_cat, maybe_space, acl_commands, "\n");
acl_cat, maybe_space_com, acl_commands, maybe_space, acl_keys, "\n");
}
if (!result.empty()) {

View file

@ -96,6 +96,7 @@ namespace dfly::acl {
}
}
}
return keys_allowed;
}

View file

@ -93,11 +93,11 @@ class CommandId : public facade::CommandId {
bool IsTransactional() const;
bool IsReadOnly() const {
return opt_mask_ & CO::CommandOpt::READONLY;
return opt_mask_ & CO::READONLY;
}
bool IsWriteOnly() const {
return opt_mask_ & CO::CommandOpt::WRITE;
return opt_mask_ & CO::WRITE;
}
static const char* OptName(CO::CommandOpt fl);

View file

@ -98,7 +98,7 @@ MultiCommandSquasher::SquashResult MultiCommandSquasher::TrySquash(StoredCmd* cm
auto& sinfo = PrepareShardInfo(last_sid);
sinfo.had_writes |= (cmd->Cid()->IsWriteOnly());
sinfo.had_writes |= cmd->Cid()->IsWriteOnly();
sinfo.cmds.push_back(cmd);
order_.push_back(last_sid);

View file

@ -1362,7 +1362,7 @@ void Transaction::LogAutoJournalOnShard(EngineShard* shard) {
return;
// Only write commands and/or no-key-transactional commands are logged
if ((cid_->IsWriteOnly()) == 0 && (cid_->opt_mask() & CO::NO_KEY_TRANSACTIONAL) == 0)
if (cid_->IsWriteOnly() == 0 && (cid_->opt_mask() & CO::NO_KEY_TRANSACTIONAL) == 0)
return;
// If autojournaling was disabled and not re-enabled, skip it

View file

@ -331,13 +331,13 @@ async def test_good_acl_file(df_local_factory, tmp_dir):
await client.execute_command("ACL SETUSER roy ON >mypass +@STRING +HSET")
await client.execute_command("ACL SETUSER shahar >mypass +@SET")
await client.execute_command("ACL SETUSER vlad +@STRING")
await client.execute_command("ACL SETUSER vlad +@STRING ~foo ~bar*")
result = await client.execute_command("ACL LIST")
assert 4 == len(result)
assert "user roy on ea71c25a7a60224 +@STRING +HSET" in result
assert "user shahar off ea71c25a7a60224 +@SET" in result
assert "user vlad off nopass +@STRING" in result
assert "user vlad off nopass +@STRING ~foo ~bar*" in result
assert "user default on nopass +@ALL +ALL ~*" in result
result = await client.execute_command("ACL DELUSER shahar")
@ -350,8 +350,8 @@ async def test_good_acl_file(df_local_factory, tmp_dir):
result = await client.execute_command("ACL LIST")
assert 3 == len(result)
assert "user roy on ea71c25a7a60224 +@STRING +HSET" in result
assert "user vlad off nopass +@STRING" in result
assert "user default on nopass +@ALL +ALL" in result
assert "user vlad off nopass +@STRING ~foo ~bar*" in result
assert "user default on nopass +@ALL +ALL ~*" in result
await client.close()