Skip to content

Commit 0b34b19

Browse files
authored
feat(command): add ACL commands, validate module categories exist (#3262)
* add ACL{SetUser,DelUser,List} commands * test presence of categories in acl cat * code cleanup * add basic acl tests * add acl modules tests * reset acl log before test * refactor acl tests * fix clientkillbyage test
1 parent 3d4310a commit 0b34b19

File tree

3 files changed

+505
-53
lines changed

3 files changed

+505
-53
lines changed

acl_commands.go

+54
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ import "context"
44

55
type ACLCmdable interface {
66
ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd
7+
78
ACLLog(ctx context.Context, count int64) *ACLLogCmd
89
ACLLogReset(ctx context.Context) *StatusCmd
10+
11+
ACLSetUser(ctx context.Context, username string, rules ...string) *StatusCmd
12+
ACLDelUser(ctx context.Context, username string) *IntCmd
13+
ACLList(ctx context.Context) *StringSliceCmd
14+
15+
ACLCat(ctx context.Context) *StringSliceCmd
16+
ACLCatArgs(ctx context.Context, options *ACLCatArgs) *StringSliceCmd
17+
}
18+
19+
type ACLCatArgs struct {
20+
Category string
921
}
1022

1123
func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd {
@@ -33,3 +45,45 @@ func (c cmdable) ACLLogReset(ctx context.Context) *StatusCmd {
3345
_ = c(ctx, cmd)
3446
return cmd
3547
}
48+
49+
func (c cmdable) ACLDelUser(ctx context.Context, username string) *IntCmd {
50+
cmd := NewIntCmd(ctx, "acl", "deluser", username)
51+
_ = c(ctx, cmd)
52+
return cmd
53+
}
54+
55+
func (c cmdable) ACLSetUser(ctx context.Context, username string, rules ...string) *StatusCmd {
56+
args := make([]interface{}, 3+len(rules))
57+
args[0] = "acl"
58+
args[1] = "setuser"
59+
args[2] = username
60+
for i, rule := range rules {
61+
args[i+3] = rule
62+
}
63+
cmd := NewStatusCmd(ctx, args...)
64+
_ = c(ctx, cmd)
65+
return cmd
66+
}
67+
68+
func (c cmdable) ACLList(ctx context.Context) *StringSliceCmd {
69+
cmd := NewStringSliceCmd(ctx, "acl", "list")
70+
_ = c(ctx, cmd)
71+
return cmd
72+
}
73+
74+
func (c cmdable) ACLCat(ctx context.Context) *StringSliceCmd {
75+
cmd := NewStringSliceCmd(ctx, "acl", "cat")
76+
_ = c(ctx, cmd)
77+
return cmd
78+
}
79+
80+
func (c cmdable) ACLCatArgs(ctx context.Context, options *ACLCatArgs) *StringSliceCmd {
81+
// if there is a category passed, build new cmd, if there isn't - use the ACLCat method
82+
if options != nil && options.Category != "" {
83+
cmd := NewStringSliceCmd(ctx, "acl", "cat", options.Category)
84+
_ = c(ctx, cmd)
85+
return cmd
86+
}
87+
88+
return c.ACLCat(ctx)
89+
}

0 commit comments

Comments
 (0)