From 3366245016edd86f0b8d64639321b0b7a20d55b9 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Tue, 4 Apr 2023 09:28:51 +0530 Subject: [PATCH 01/16] feat: Add ACL LOG --- command.go | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ commands.go | 26 +++++++++++++ commands_test.go | 49 +++++++++++++++++++++++- 3 files changed, 171 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index 21abe11c6..2a332356f 100644 --- a/command.go +++ b/command.go @@ -4710,3 +4710,100 @@ func (cmd *ClusterShardsCmd) readReply(rd *proto.Reader) error { return nil } + +// ------------------------------------------- + +type ACLLogEntry struct { + Count int64 + Reason string + Context string + Object string + Username string + AgeSeconds float64 + ClientInfo string + EntryID int64 + TimestampCreated int64 + TimestampLastUpdated int64 +} + +type ACLLogCmd struct { + baseCmd + + val []ACLLogEntry +} + +var _ Cmder = (*ACLLogCmd)(nil) + +func NewACLLogCmd(ctx context.Context, args ...interface{}) *ACLLogCmd { + return &ACLLogCmd{ + baseCmd: baseCmd{ + ctx: ctx, + args: args, + }, + } +} + +func (cmd *ACLLogCmd) SetVal(val []ACLLogEntry) { + cmd.val = val +} + +func (cmd *ACLLogCmd) Val() []ACLLogEntry { + return cmd.val +} + +func (cmd *ACLLogCmd) Result() ([]ACLLogEntry, error) { + return cmd.Val(), cmd.Err() +} + +func (cmd *ACLLogCmd) String() string { + return cmdString(cmd, cmd.val) +} + +func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { + n, err := rd.ReadArrayLen() + if err != nil { + return err + } + + cmd.val = make([]ACLLogEntry, n/2) + for i := 0; i < n/2; i++ { + entry := &cmd.val[i] + for j := 0; j < 10; j += 2 { + key, err := rd.ReadString() + if err != nil { + return err + } + + switch key { + case "count": + entry.Count, err = rd.ReadInt() + case "reason": + entry.Reason, err = rd.ReadString() + case "context": + entry.Context, err = rd.ReadString() + case "object": + entry.Object, err = rd.ReadString() + case "username": + entry.Username, err = rd.ReadString() + case "age-seconds": + entry.AgeSeconds, err = rd.ReadFloat() + case "client-info": + entry.ClientInfo, err = rd.ReadString() + case "entry-id": + entry.EntryID, err = rd.ReadInt() + case "timestamp-created": + entry.TimestampCreated, err = rd.ReadInt() + case "timestamp-last-updated": + entry.TimestampLastUpdated, err = rd.ReadInt() + default: + return fmt.Errorf("redis: unexpected key %q in ACL LOG reply", key) + } + + if err != nil { + return err + } + } + } + + return nil +} diff --git a/commands.go b/commands.go index 588b3a4f5..ef4f257a3 100644 --- a/commands.go +++ b/commands.go @@ -495,6 +495,8 @@ type Cmdable interface { GeoHash(ctx context.Context, key string, members ...string) *StringSliceCmd ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd + ACLLog(ctx context.Context, count ...int64) *ACLLogCmd + ACLLogReset(ctx context.Context) *StatusCmd } type StatefulCmdable interface { @@ -3873,3 +3875,27 @@ func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...inte _ = c(ctx, cmd) return cmd } + +func (c cmdable) ACLLog(ctx context.Context, count ...int64) *ACLLogCmd { + args := make([]interface{}, 0, 3) + args = append(args, "acl", "log") + + switch len(count) { + case 0: + break + case 1: + args = append(args, count[0]) + default: + panic("too many arguments") + } + + cmd := NewACLLogCmd(ctx, args) + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) ACLLogReset(ctx context.Context) *StatusCmd { + cmd := NewStatusCmd(ctx, "ACL", "LOG", "RESET") + _ = c(ctx, cmd) + return cmd +} diff --git a/commands_test.go b/commands_test.go index 72b2bb23d..53eb945bd 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1926,11 +1926,58 @@ var _ = Describe("Commands", func() { Expect(replace.Val()).To(Equal(int64(1))) }) - It("should acl dryryn", func() { + It("should acl dryrun", func() { dryRun := client.ACLDryRun(ctx, "default", "get", "randomKey") Expect(dryRun.Err()).NotTo(HaveOccurred()) Expect(dryRun.Val()).To(Equal("OK")) }) + + It("should ACL LOG", func() { + // Test without the count parameter + logs := client.ACLLog(ctx) + Expect(logs.Err()).NotTo(HaveOccurred()) + + logEntries := logs.Val() + Expect(logEntries).NotTo(BeNil()) + + for _, entry := range logEntries { + Expect(entry.Count).To(BeNumerically(">=", 0)) + Expect(entry.Reason).NotTo(BeEmpty()) + Expect(entry.Context).NotTo(BeEmpty()) + Expect(entry.Object).NotTo(BeEmpty()) + Expect(entry.Username).NotTo(BeEmpty()) + Expect(entry.AgeSeconds).To(BeNumerically(">=", 0)) + Expect(entry.ClientInfo).NotTo(BeEmpty()) + Expect(entry.EntryID).To(BeNumerically(">=", 0)) + Expect(entry.TimestampCreated).To(BeNumerically(">=", 0)) + Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0)) + } + + // Test with the count parameter + desiredCount := int64(5) + logs = client.ACLLog(ctx, desiredCount) + Expect(logs.Err()).NotTo(HaveOccurred()) + + logEntriesWithCount := logs.Val() + Expect(logEntriesWithCount).NotTo(BeNil()) + + // Verify the length of the returned entries + Expect(len(logEntriesWithCount)).To(BeNumerically("<=", desiredCount)) + + for _, entry := range logEntriesWithCount { + Expect(entry.Count).To(BeNumerically(">=", 0)) + Expect(entry.Reason).NotTo(BeEmpty()) + Expect(entry.Context).NotTo(BeEmpty()) + Expect(entry.Object).NotTo(BeEmpty()) + Expect(entry.Username).NotTo(BeEmpty()) + Expect(entry.AgeSeconds).To(BeNumerically(">=", 0)) + Expect(entry.ClientInfo).NotTo(BeEmpty()) + Expect(entry.EntryID).To(BeNumerically(">=", 0)) + Expect(entry.TimestampCreated).To(BeNumerically(">=", 0)) + Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0)) + } + }) + }) Describe("hashes", func() { From 11c363bd4a638008596aa73cbcb72f8b6a051b51 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Tue, 4 Apr 2023 09:56:02 +0530 Subject: [PATCH 02/16] feat: test for reset --- commands_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/commands_test.go b/commands_test.go index 53eb945bd..fc3e7282d 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1978,6 +1978,21 @@ var _ = Describe("Commands", func() { } }) + It("should ACL LOG RESET", func() { + // Call ACL LOG RESET + resetCmd := client.ACLLogReset(ctx) + Expect(resetCmd.Err()).NotTo(HaveOccurred()) + + // Check if it returns "OK" + Expect(resetCmd.Val()).To(Equal("OK")) + + // Verify that the log is empty after the reset + logCmd := client.ACLLog(ctx) + Expect(logCmd.Err()).NotTo(HaveOccurred()) + logEntries := logCmd.Val() + Expect(len(logEntries)).To(Equal(0)) + }) + }) Describe("hashes", func() { From 72976864d193ddb95cd01538c5e6a3b4b15edbdd Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:16:01 +0530 Subject: [PATCH 03/16] fix: attempt test --- commands.go | 14 ++++++-------- commands_test.go | 1 - 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/commands.go b/commands.go index ef4f257a3..fd66ae0c5 100644 --- a/commands.go +++ b/commands.go @@ -3877,16 +3877,14 @@ func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...inte } func (c cmdable) ACLLog(ctx context.Context, count ...int64) *ACLLogCmd { - args := make([]interface{}, 0, 3) + args := make([]interface{}, 0, 1) args = append(args, "acl", "log") - switch len(count) { - case 0: - break - case 1: + if len(count) > 0 { + if len(count) > 1 { + panic("too many arguments") + } args = append(args, count[0]) - default: - panic("too many arguments") } cmd := NewACLLogCmd(ctx, args) @@ -3895,7 +3893,7 @@ func (c cmdable) ACLLog(ctx context.Context, count ...int64) *ACLLogCmd { } func (c cmdable) ACLLogReset(ctx context.Context) *StatusCmd { - cmd := NewStatusCmd(ctx, "ACL", "LOG", "RESET") + cmd := NewStatusCmd(ctx, "acl", "log", "reset") _ = c(ctx, cmd) return cmd } diff --git a/commands_test.go b/commands_test.go index fc3e7282d..1b0b48754 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1983,7 +1983,6 @@ var _ = Describe("Commands", func() { resetCmd := client.ACLLogReset(ctx) Expect(resetCmd.Err()).NotTo(HaveOccurred()) - // Check if it returns "OK" Expect(resetCmd.Val()).To(Equal("OK")) // Verify that the log is empty after the reset From 0faf6223dae5eba785646c1fd8a18d7fc33ba332 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:29:06 +0530 Subject: [PATCH 04/16] fix: test fix --- command.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/command.go b/command.go index 2a332356f..0db05dc12 100644 --- a/command.go +++ b/command.go @@ -4765,10 +4765,10 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { return err } - cmd.val = make([]ACLLogEntry, n/2) - for i := 0; i < n/2; i++ { + cmd.val = make([]ACLLogEntry, n) + for i := 0; i < n; i++ { entry := &cmd.val[i] - for j := 0; j < 10; j += 2 { + for j := 0; j < 10; j++ { key, err := rd.ReadString() if err != nil { return err From eb0aecf5c2f2d97791d49637e0f82f66e88c18ec Mon Sep 17 00:00:00 2001 From: ktsivkov Date: Fri, 21 Apr 2023 10:27:44 +0200 Subject: [PATCH 05/16] Fixed acl command, arg spreading --- commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 1d2c9dc4f..8593ec018 100644 --- a/commands.go +++ b/commands.go @@ -3941,7 +3941,7 @@ func (c cmdable) ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *St } func (c cmdable) ACLLog(ctx context.Context, count ...int64) *ACLLogCmd { - args := make([]interface{}, 0, 1) + args := make([]interface{}, 0, 2+len(count)) args = append(args, "acl", "log") if len(count) > 0 { @@ -3951,7 +3951,7 @@ func (c cmdable) ACLLog(ctx context.Context, count ...int64) *ACLLogCmd { args = append(args, count[0]) } - cmd := NewACLLogCmd(ctx, args) + cmd := NewACLLogCmd(ctx, args...) _ = c(ctx, cmd) return cmd } From 3a22a12f98da402fa078b6809c3315b8c231508f Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Mon, 24 Apr 2023 20:13:34 +0530 Subject: [PATCH 06/16] feat: migrating to client info struct --- command.go | 12 ++++++++++-- commands_test.go | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/command.go b/command.go index a103abe0d..3f105d0cf 100644 --- a/command.go +++ b/command.go @@ -5067,7 +5067,7 @@ type ACLLogEntry struct { Object string Username string AgeSeconds float64 - ClientInfo string + ClientInfo ClientInfo EntryID int64 TimestampCreated int64 TimestampLastUpdated int64 @@ -5135,7 +5135,15 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { case "age-seconds": entry.AgeSeconds, err = rd.ReadFloat() case "client-info": - entry.ClientInfo, err = rd.ReadString() + txt, err := rd.ReadString() + if err != nil { + return err + } + clientInfoPtr, err := parseClientInfo(strings.TrimSpace(txt)) + if err != nil { + return err + } + entry.ClientInfo = *clientInfoPtr case "entry-id": entry.EntryID, err = rd.ReadInt() case "timestamp-created": diff --git a/commands_test.go b/commands_test.go index 272100ae5..a5dabf615 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2001,7 +2001,7 @@ var _ = Describe("Commands", func() { Expect(entry.Object).NotTo(BeEmpty()) Expect(entry.Username).NotTo(BeEmpty()) Expect(entry.AgeSeconds).To(BeNumerically(">=", 0)) - Expect(entry.ClientInfo).NotTo(BeEmpty()) + Expect(entry.ClientInfo).NotTo(BeNil()) Expect(entry.EntryID).To(BeNumerically(">=", 0)) Expect(entry.TimestampCreated).To(BeNumerically(">=", 0)) Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0)) @@ -2025,7 +2025,7 @@ var _ = Describe("Commands", func() { Expect(entry.Object).NotTo(BeEmpty()) Expect(entry.Username).NotTo(BeEmpty()) Expect(entry.AgeSeconds).To(BeNumerically(">=", 0)) - Expect(entry.ClientInfo).NotTo(BeEmpty()) + Expect(entry.ClientInfo).NotTo(BeNil()) Expect(entry.EntryID).To(BeNumerically(">=", 0)) Expect(entry.TimestampCreated).To(BeNumerically(">=", 0)) Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0)) From 7a709a9c83f0a3b209e5c5c11efce7de660f43d6 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Mon, 24 Apr 2023 20:57:50 +0530 Subject: [PATCH 07/16] fix: using ptr for ClientInfo --- command.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/command.go b/command.go index 3f105d0cf..d41e7a502 100644 --- a/command.go +++ b/command.go @@ -5067,7 +5067,7 @@ type ACLLogEntry struct { Object string Username string AgeSeconds float64 - ClientInfo ClientInfo + ClientInfo *ClientInfo EntryID int64 TimestampCreated int64 TimestampLastUpdated int64 @@ -5139,11 +5139,7 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { if err != nil { return err } - clientInfoPtr, err := parseClientInfo(strings.TrimSpace(txt)) - if err != nil { - return err - } - entry.ClientInfo = *clientInfoPtr + entry.ClientInfo, err = parseClientInfo(strings.TrimSpace(txt)) case "entry-id": entry.EntryID, err = rd.ReadInt() case "timestamp-created": From c7100b6a25cfbc9edb2baaa820c86dcdd00fa595 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Mon, 24 Apr 2023 22:54:35 +0530 Subject: [PATCH 08/16] fix: suppress lint check for the line --- command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command.go b/command.go index d41e7a502..a05eec89d 100644 --- a/command.go +++ b/command.go @@ -5139,7 +5139,7 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { if err != nil { return err } - entry.ClientInfo, err = parseClientInfo(strings.TrimSpace(txt)) + entry.ClientInfo, err = parseClientInfo(strings.TrimSpace(txt)) // nolint:ineffassign case "entry-id": entry.EntryID, err = rd.ReadInt() case "timestamp-created": From 93dcc3b80d5cd73244bb327216ce9444301d6846 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Mon, 24 Apr 2023 23:08:55 +0530 Subject: [PATCH 09/16] fix: suppress both linter warnings: --- command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command.go b/command.go index a05eec89d..26144696a 100644 --- a/command.go +++ b/command.go @@ -5139,7 +5139,7 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { if err != nil { return err } - entry.ClientInfo, err = parseClientInfo(strings.TrimSpace(txt)) // nolint:ineffassign + entry.ClientInfo, err = parseClientInfo(strings.TrimSpace(txt)) //nolint:ineffassign,staticcheck case "entry-id": entry.EntryID, err = rd.ReadInt() case "timestamp-created": From e668ea9bab76f22dc8ea9892837ff2d1bfc3bb71 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Mon, 24 Apr 2023 23:37:11 +0530 Subject: [PATCH 10/16] fix: re-running pipelines --- command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command.go b/command.go index 26144696a..17f0fb4a9 100644 --- a/command.go +++ b/command.go @@ -5139,7 +5139,7 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { if err != nil { return err } - entry.ClientInfo, err = parseClientInfo(strings.TrimSpace(txt)) //nolint:ineffassign,staticcheck + entry.ClientInfo, err = parseClientInfo(strings.TrimSpace(txt)) // nolint:ineffassign,staticcheck case "entry-id": entry.EntryID, err = rd.ReadInt() case "timestamp-created": From 3d4004dbdf8ec846fddfef95036d3ec58635a27c Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:59:13 +0530 Subject: [PATCH 11/16] fix: acc to comments --- command.go | 18 +++++++++++------- commands_test.go | 18 +++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/command.go b/command.go index 17f0fb4a9..37afe9114 100644 --- a/command.go +++ b/command.go @@ -5076,7 +5076,7 @@ type ACLLogEntry struct { type ACLLogCmd struct { baseCmd - val []ACLLogEntry + val []*ACLLogEntry } var _ Cmder = (*ACLLogCmd)(nil) @@ -5090,15 +5090,15 @@ func NewACLLogCmd(ctx context.Context, args ...interface{}) *ACLLogCmd { } } -func (cmd *ACLLogCmd) SetVal(val []ACLLogEntry) { +func (cmd *ACLLogCmd) SetVal(val []*ACLLogEntry) { cmd.val = val } -func (cmd *ACLLogCmd) Val() []ACLLogEntry { +func (cmd *ACLLogCmd) Val() []*ACLLogEntry { return cmd.val } -func (cmd *ACLLogCmd) Result() ([]ACLLogEntry, error) { +func (cmd *ACLLogCmd) Result() ([]*ACLLogEntry, error) { return cmd.Val(), cmd.Err() } @@ -5112,9 +5112,10 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { return err } - cmd.val = make([]ACLLogEntry, n) + cmd.val = make([]*ACLLogEntry, n) for i := 0; i < n; i++ { - entry := &cmd.val[i] + cmd.val[i] = &ACLLogEntry{} + entry := cmd.val[i] for j := 0; j < 10; j++ { key, err := rd.ReadString() if err != nil { @@ -5139,7 +5140,10 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { if err != nil { return err } - entry.ClientInfo, err = parseClientInfo(strings.TrimSpace(txt)) // nolint:ineffassign,staticcheck + entry.ClientInfo, err = parseClientInfo(strings.TrimSpace(txt)) + if err != nil { + return err + } case "entry-id": entry.EntryID, err = rd.ReadInt() case "timestamp-created": diff --git a/commands_test.go b/commands_test.go index a5dabf615..278af2353 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1988,10 +1988,8 @@ var _ = Describe("Commands", func() { It("should ACL LOG", func() { // Test without the count parameter - logs := client.ACLLog(ctx) - Expect(logs.Err()).NotTo(HaveOccurred()) - - logEntries := logs.Val() + logEntries, err := client.ACLLog(ctx).Result() + Expect(err).NotTo(HaveOccurred()) Expect(logEntries).NotTo(BeNil()) for _, entry := range logEntries { @@ -2009,10 +2007,8 @@ var _ = Describe("Commands", func() { // Test with the count parameter desiredCount := int64(5) - logs = client.ACLLog(ctx, desiredCount) - Expect(logs.Err()).NotTo(HaveOccurred()) - - logEntriesWithCount := logs.Val() + logEntriesWithCount, err := client.ACLLog(ctx, desiredCount).Result() + Expect(err).NotTo(HaveOccurred()) Expect(logEntriesWithCount).NotTo(BeNil()) // Verify the length of the returned entries @@ -2040,11 +2036,11 @@ var _ = Describe("Commands", func() { Expect(resetCmd.Val()).To(Equal("OK")) // Verify that the log is empty after the reset - logCmd := client.ACLLog(ctx) - Expect(logCmd.Err()).NotTo(HaveOccurred()) - logEntries := logCmd.Val() + logEntries, err := client.ACLLog(ctx).Result() + Expect(err).NotTo(HaveOccurred()) Expect(len(logEntries)).To(Equal(0)) }) + }) Describe("hashes", func() { From 64001d7f6bb133079e5f9c9c37ebb2089571eb42 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sat, 6 May 2023 20:30:13 +0530 Subject: [PATCH 12/16] fix: read resp response len --- command.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index 37afe9114..ee968db1c 100644 --- a/command.go +++ b/command.go @@ -5116,7 +5116,11 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { for i := 0; i < n; i++ { cmd.val[i] = &ACLLogEntry{} entry := cmd.val[i] - for j := 0; j < 10; j++ { + respLen, err := rd.ReadArrayLen() + if err != nil { + return err + } + for j := 0; j < respLen/2; j++ { key, err := rd.ReadString() if err != nil { return err From 7876ac540b96b71122733febc60cc081d1cc7270 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sat, 6 May 2023 21:06:25 +0530 Subject: [PATCH 13/16] fix: adding mandatory count --- commands.go | 13 ++++--------- commands_test.go | 28 +++------------------------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/commands.go b/commands.go index 8b83d889e..ad40e9a5c 100644 --- a/commands.go +++ b/commands.go @@ -500,7 +500,7 @@ type Cmdable interface { GeoHash(ctx context.Context, key string, members ...string) *StringSliceCmd ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd - ACLLog(ctx context.Context, count ...int64) *ACLLogCmd + ACLLog(ctx context.Context, count int64) *ACLLogCmd ACLLogReset(ctx context.Context) *StatusCmd ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *StringCmd @@ -3949,16 +3949,11 @@ func (c cmdable) ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *St return cmd } -func (c cmdable) ACLLog(ctx context.Context, count ...int64) *ACLLogCmd { - args := make([]interface{}, 0, 2+len(count)) +func (c cmdable) ACLLog(ctx context.Context, count int64) *ACLLogCmd { + args := make([]interface{}, 0, 3) args = append(args, "acl", "log") - if len(count) > 0 { - if len(count) > 1 { - panic("too many arguments") - } - args = append(args, count[0]) - } + args = append(args, count) cmd := NewACLLogCmd(ctx, args...) _ = c(ctx, cmd) diff --git a/commands_test.go b/commands_test.go index 278af2353..196a46d83 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1987,8 +1987,8 @@ var _ = Describe("Commands", func() { }) It("should ACL LOG", func() { - // Test without the count parameter - logEntries, err := client.ACLLog(ctx).Result() + + logEntries, err := client.ACLLog(ctx, 10).Result() Expect(err).NotTo(HaveOccurred()) Expect(logEntries).NotTo(BeNil()) @@ -2004,28 +2004,6 @@ var _ = Describe("Commands", func() { Expect(entry.TimestampCreated).To(BeNumerically(">=", 0)) Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0)) } - - // Test with the count parameter - desiredCount := int64(5) - logEntriesWithCount, err := client.ACLLog(ctx, desiredCount).Result() - Expect(err).NotTo(HaveOccurred()) - Expect(logEntriesWithCount).NotTo(BeNil()) - - // Verify the length of the returned entries - Expect(len(logEntriesWithCount)).To(BeNumerically("<=", desiredCount)) - - for _, entry := range logEntriesWithCount { - Expect(entry.Count).To(BeNumerically(">=", 0)) - Expect(entry.Reason).NotTo(BeEmpty()) - Expect(entry.Context).NotTo(BeEmpty()) - Expect(entry.Object).NotTo(BeEmpty()) - Expect(entry.Username).NotTo(BeEmpty()) - Expect(entry.AgeSeconds).To(BeNumerically(">=", 0)) - Expect(entry.ClientInfo).NotTo(BeNil()) - Expect(entry.EntryID).To(BeNumerically(">=", 0)) - Expect(entry.TimestampCreated).To(BeNumerically(">=", 0)) - Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0)) - } }) It("should ACL LOG RESET", func() { @@ -2036,7 +2014,7 @@ var _ = Describe("Commands", func() { Expect(resetCmd.Val()).To(Equal("OK")) // Verify that the log is empty after the reset - logEntries, err := client.ACLLog(ctx).Result() + logEntries, err := client.ACLLog(ctx, 10).Result() Expect(err).NotTo(HaveOccurred()) Expect(len(logEntries)).To(Equal(0)) }) From dba1eaf7d4b038c8f6a3720d5d05424ec367e9fd Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sat, 6 May 2023 21:08:12 +0530 Subject: [PATCH 14/16] fix: adding mandatory count --- commands.go | 5 +---- commands_test.go | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/commands.go b/commands.go index ad40e9a5c..34dcdc613 100644 --- a/commands.go +++ b/commands.go @@ -3951,10 +3951,7 @@ func (c cmdable) ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *St func (c cmdable) ACLLog(ctx context.Context, count int64) *ACLLogCmd { args := make([]interface{}, 0, 3) - args = append(args, "acl", "log") - - args = append(args, count) - + args = append(args, "acl", "log", count) cmd := NewACLLogCmd(ctx, args...) _ = c(ctx, cmd) return cmd diff --git a/commands_test.go b/commands_test.go index 196a46d83..3663adccc 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2010,7 +2010,6 @@ var _ = Describe("Commands", func() { // Call ACL LOG RESET resetCmd := client.ACLLogReset(ctx) Expect(resetCmd.Err()).NotTo(HaveOccurred()) - Expect(resetCmd.Val()).To(Equal("OK")) // Verify that the log is empty after the reset From b1be11bdbc63376bf3af7d1532d70cf5d65d34b9 Mon Sep 17 00:00:00 2001 From: Elena Kolevska Date: Sun, 7 May 2023 21:39:36 +0100 Subject: [PATCH 15/16] Expanding test and fixing reading of response for AclLog --- command.go | 4 ++-- commands_test.go | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/command.go b/command.go index ee968db1c..fd07d82a6 100644 --- a/command.go +++ b/command.go @@ -5116,11 +5116,11 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { for i := 0; i < n; i++ { cmd.val[i] = &ACLLogEntry{} entry := cmd.val[i] - respLen, err := rd.ReadArrayLen() + respLen, err := rd.ReadMapLen() if err != nil { return err } - for j := 0; j < respLen/2; j++ { + for j := 0; j < respLen; j++ { key, err := rd.ReadString() if err != nil { return err diff --git a/commands_test.go b/commands_test.go index 3663adccc..914a31494 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1988,22 +1988,38 @@ var _ = Describe("Commands", func() { It("should ACL LOG", func() { + err := client.Do(ctx, "acl", "setuser", "test", ">test", "on", "allkeys", "+get").Err() + Expect(err).NotTo(HaveOccurred()) + + clientAcl := redis.NewClient(redisOptions()) + clientAcl.Options().Username = "test" + clientAcl.Options().Password = "test" + clientAcl.Options().DB = 0 + _ = clientAcl.Set(ctx, "mystring", "foo", 0).Err() + _ = clientAcl.HSet(ctx, "myhash", "foo", "bar").Err() + _ = clientAcl.SAdd(ctx, "myset", "foo", "bar").Err() + logEntries, err := client.ACLLog(ctx, 10).Result() Expect(err).NotTo(HaveOccurred()) - Expect(logEntries).NotTo(BeNil()) + Expect(len(logEntries)).To(Equal(3)) for _, entry := range logEntries { - Expect(entry.Count).To(BeNumerically(">=", 0)) - Expect(entry.Reason).NotTo(BeEmpty()) - Expect(entry.Context).NotTo(BeEmpty()) + Expect(entry.Count).To(BeNumerically("==", 1)) + Expect(entry.Reason).To(Equal("command")) + Expect(entry.Context).To(Equal("toplevel")) Expect(entry.Object).NotTo(BeEmpty()) - Expect(entry.Username).NotTo(BeEmpty()) + Expect(entry.Username).To(Equal("test")) Expect(entry.AgeSeconds).To(BeNumerically(">=", 0)) Expect(entry.ClientInfo).NotTo(BeNil()) Expect(entry.EntryID).To(BeNumerically(">=", 0)) Expect(entry.TimestampCreated).To(BeNumerically(">=", 0)) Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0)) } + + limitedLogEntries, err := client.ACLLog(ctx, 2).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(len(limitedLogEntries)).To(Equal(2)) + }) It("should ACL LOG RESET", func() { From 0a0a1074f85b5cf94f75ed1bf42749db9b10eb28 Mon Sep 17 00:00:00 2001 From: monkey92t Date: Mon, 8 May 2023 21:27:18 +0800 Subject: [PATCH 16/16] correct acl-log count param Signed-off-by: monkey92t --- commands.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 34dcdc613..34f4d2c22 100644 --- a/commands.go +++ b/commands.go @@ -3951,7 +3951,10 @@ func (c cmdable) ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *St func (c cmdable) ACLLog(ctx context.Context, count int64) *ACLLogCmd { args := make([]interface{}, 0, 3) - args = append(args, "acl", "log", count) + args = append(args, "acl", "log") + if count > 0 { + args = append(args, count) + } cmd := NewACLLogCmd(ctx, args...) _ = c(ctx, cmd) return cmd