From dffb2329e0aadc55bd7cfac62f3a402f5d56a140 Mon Sep 17 00:00:00 2001 From: Yash Budhia Date: Sun, 6 Oct 2024 18:58:22 +0530 Subject: [PATCH] bool-applied --- pkg/util/blacklist.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/util/blacklist.go b/pkg/util/blacklist.go index 7c7b19d..ad72a62 100644 --- a/pkg/util/blacklist.go +++ b/pkg/util/blacklist.go @@ -5,18 +5,17 @@ import ( "strings" ) -var blacklistedCommands = []string{ - "FLUSHALL", "FLUSHDB", "DUMP", "ABORT", "AUTH", "CONFIG", "SAVE", "BGSAVE", - "BGREWRITEAOF", "RESTORE", "MULTI", "EXEC", "DISCARD", "QWATCH", "QUNWATCH", - "LATENCY", "CLIENT", "SLEEP", "PERSIST", +var blocklistedCommands = map[string]bool{ + "FLUSHALL": true, "FLUSHDB": true, "DUMP": true, "ABORT": true, "AUTH": true, + "CONFIG": true, "SAVE": true, "BGSAVE": true, "BGREWRITEAOF": true, "RESTORE": true, + "MULTI": true, "EXEC": true, "DISCARD": true, "QWATCH": true, "QUNWATCH": true, + "LATENCY": true, "CLIENT": true, "SLEEP": true, "PERSIST": true, } // BlockListedCommand checks if a command is blocklisted func BlockListedCommand(cmd string) error { - for _, blacklistedCmd := range blacklistedCommands { - if strings.ToUpper(cmd) == blacklistedCmd { - return errors.New("command is blocklisted") - } + if blocklistedCommands[strings.ToUpper(cmd)] { + return errors.New("command is blocklisted") } return nil }